Pre-RSS-14 changes. Necessary code changes, but not the decoder. Committing this since it does no harm and clears out my client so I can modify these files for other purposes.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1193 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-02-01 19:41:17 +00:00
parent 7cd9541e90
commit 87f2fada9a
11 changed files with 88 additions and 7 deletions

View file

@ -42,6 +42,7 @@ import java.util.Vector;
* @author dswitkin@google.com (Daniel Switkin) * @author dswitkin@google.com (Daniel Switkin)
*/ */
final class DecodeThread extends Thread { final class DecodeThread extends Thread {
public static final String BARCODE_BITMAP = "barcode_bitmap"; public static final String BARCODE_BITMAP = "barcode_bitmap";
private static final String TAG = "DecodeThread"; private static final String TAG = "DecodeThread";
@ -107,7 +108,8 @@ final class DecodeThread extends Thread {
doSetDecodeMode(BarcodeFormat.UPC_A, doSetDecodeMode(BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E, BarcodeFormat.UPC_E,
BarcodeFormat.EAN_13, BarcodeFormat.EAN_13,
BarcodeFormat.EAN_8); BarcodeFormat.EAN_8,
BarcodeFormat.RSS14);
} }
/** /**
@ -120,7 +122,8 @@ final class DecodeThread extends Thread {
BarcodeFormat.EAN_8, BarcodeFormat.EAN_8,
BarcodeFormat.CODE_39, BarcodeFormat.CODE_39,
BarcodeFormat.CODE_128, BarcodeFormat.CODE_128,
BarcodeFormat.ITF); BarcodeFormat.ITF,
BarcodeFormat.RSS14);
} }
private void setDecodeQRMode() { private void setDecodeQRMode() {
@ -139,6 +142,7 @@ final class DecodeThread extends Thread {
BarcodeFormat.CODE_39, BarcodeFormat.CODE_39,
BarcodeFormat.CODE_128, BarcodeFormat.CODE_128,
BarcodeFormat.ITF, BarcodeFormat.ITF,
BarcodeFormat.RSS14,
BarcodeFormat.QR_CODE); BarcodeFormat.QR_CODE);
} }
@ -170,6 +174,8 @@ final class DecodeThread extends Thread {
rawResult = multiFormatReader.decodeWithState(bitmap); rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) { } catch (ReaderException re) {
// continue // continue
} finally {
multiFormatReader.reset();
} }
if (rawResult != null) { if (rawResult != null) {

View file

@ -56,6 +56,9 @@ public final class BarcodeFormat {
/** ITF (Interleaved Two of Five) 1D format. */ /** ITF (Interleaved Two of Five) 1D format. */
public static final BarcodeFormat ITF = new BarcodeFormat("ITF"); public static final BarcodeFormat ITF = new BarcodeFormat("ITF");
/** RSS 14 */
public static final BarcodeFormat RSS14 = new BarcodeFormat("RSS14");
/** PDF417 format. */ /** PDF417 format. */
public static final BarcodeFormat PDF417 = new BarcodeFormat("PDF417"); public static final BarcodeFormat PDF417 = new BarcodeFormat("PDF417");

View file

@ -101,7 +101,8 @@ public final class MultiFormatReader implements Reader {
formats.contains(BarcodeFormat.EAN_8) || formats.contains(BarcodeFormat.EAN_8) ||
formats.contains(BarcodeFormat.CODE_39) || formats.contains(BarcodeFormat.CODE_39) ||
formats.contains(BarcodeFormat.CODE_128) || formats.contains(BarcodeFormat.CODE_128) ||
formats.contains(BarcodeFormat.ITF); formats.contains(BarcodeFormat.ITF) ||
formats.contains(BarcodeFormat.RSS14);
// Put 1D readers upfront in "normal" mode // Put 1D readers upfront in "normal" mode
if (addOneDReader && !tryHarder) { if (addOneDReader && !tryHarder) {
readers.addElement(new MultiFormatOneDReader(hints)); readers.addElement(new MultiFormatOneDReader(hints));
@ -138,6 +139,14 @@ public final class MultiFormatReader implements Reader {
} }
} }
public void reset() {
int size = readers.size();
for (int i = 0; i < size; i++) {
Reader reader = (Reader) readers.elementAt(i);
reader.reset();
}
}
private Result decodeInternal(BinaryBitmap image) throws ReaderException { private Result decodeInternal(BinaryBitmap image) throws ReaderException {
int size = readers.size(); int size = readers.size();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {

View file

@ -55,4 +55,10 @@ public interface Reader {
*/ */
Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException; Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException;
/**
* Resets any internal state the implementation has after a decode, to prepare it
* for reuse.
*/
void reset();
} }

View file

@ -76,6 +76,10 @@ public final class DataMatrixReader implements Reader {
return result; return result;
} }
public void reset() {
// do nothing
}
/** /**
* This method detects a Data Matrix code in a "pure" image -- that is, pure monochrome image * This method detects a Data Matrix code in a "pure" image -- that is, pure monochrome image
* which contains only an unrotated, unskewed, image of a Data Matrix code, with some white border * which contains only an unrotated, unskewed, image of a Data Matrix code, with some white border

View file

@ -85,4 +85,8 @@ public final class ByQuadrantReader implements Reader {
return delegate.decode(center, hints); return delegate.decode(center, hints);
} }
public void reset() {
delegate.reset();
}
} }

View file

@ -18,9 +18,11 @@ package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType; import com.google.zxing.DecodeHintType;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
import com.google.zxing.Result; import com.google.zxing.Result;
import com.google.zxing.common.BitArray; import com.google.zxing.common.BitArray;
import com.google.zxing.oned.rss.RSS14Reader;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
@ -55,12 +57,16 @@ public final class MultiFormatOneDReader extends OneDReader {
if (possibleFormats.contains(BarcodeFormat.ITF)) { if (possibleFormats.contains(BarcodeFormat.ITF)) {
readers.addElement(new ITFReader()); readers.addElement(new ITFReader());
} }
if (possibleFormats.contains(BarcodeFormat.RSS14)) {
// TODO enable later readers.addElement(new RSS14Reader());
}
} }
if (readers.isEmpty()) { if (readers.isEmpty()) {
readers.addElement(new MultiFormatUPCEANReader(hints)); readers.addElement(new MultiFormatUPCEANReader(hints));
readers.addElement(new Code39Reader()); readers.addElement(new Code39Reader());
readers.addElement(new Code128Reader()); readers.addElement(new Code128Reader());
readers.addElement(new ITFReader()); readers.addElement(new ITFReader());
// TODO enable later readers.addElement(new RSS14Reader());
} }
} }
@ -78,4 +84,12 @@ public final class MultiFormatOneDReader extends OneDReader {
throw ReaderException.getInstance(); throw ReaderException.getInstance();
} }
public void reset() {
int size = readers.size();
for (int i = 0; i < size; i++) {
Reader reader = (Reader) readers.elementAt(i);
reader.reset();
}
}
} }

View file

@ -18,6 +18,7 @@ package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType; import com.google.zxing.DecodeHintType;
import com.google.zxing.Reader;
import com.google.zxing.ReaderException; import com.google.zxing.ReaderException;
import com.google.zxing.Result; import com.google.zxing.Result;
import com.google.zxing.common.BitArray; import com.google.zxing.common.BitArray;
@ -94,4 +95,12 @@ public final class MultiFormatUPCEANReader extends OneDReader {
throw ReaderException.getInstance(); throw ReaderException.getInstance();
} }
public void reset() {
int size = readers.size();
for (int i = 0; i < size; i++) {
Reader reader = (Reader) readers.elementAt(i);
reader.reset();
}
}
} }

View file

@ -38,7 +38,7 @@ import java.util.Hashtable;
public abstract class OneDReader implements Reader { public abstract class OneDReader implements Reader {
private static final int INTEGER_MATH_SHIFT = 8; private static final int INTEGER_MATH_SHIFT = 8;
static final int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT; protected static final int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT;
public Result decode(BinaryBitmap image) throws ReaderException { public Result decode(BinaryBitmap image) throws ReaderException {
return decode(image, null); return decode(image, null);
@ -75,6 +75,10 @@ public abstract class OneDReader implements Reader {
} }
} }
public void reset() {
// do nothing
}
/** /**
* We're going to examine rows from the middle outward, searching alternately above and below the * We're going to examine rows from the middle outward, searching alternately above and below the
* middle, and farther out each time. rowStep is the number of rows between each successive * middle, and farther out each time. rowStep is the number of rows between each successive
@ -178,7 +182,7 @@ public abstract class OneDReader implements Reader {
* @throws ReaderException if counters cannot be filled entirely from row before running out * @throws ReaderException if counters cannot be filled entirely from row before running out
* of pixels * of pixels
*/ */
static void recordPattern(BitArray row, int start, int[] counters) throws ReaderException { protected static void recordPattern(BitArray row, int start, int[] counters) throws ReaderException {
int numCounters = counters.length; int numCounters = counters.length;
for (int i = 0; i < numCounters; i++) { for (int i = 0; i < numCounters; i++) {
counters[i] = 0; counters[i] = 0;
@ -200,7 +204,7 @@ public abstract class OneDReader implements Reader {
break; break;
} else { } else {
counters[counterPosition] = 1; counters[counterPosition] = 1;
isWhite ^= true; // isWhite = !isWhite; isWhite = !isWhite;
} }
} }
i++; i++;
@ -212,6 +216,23 @@ public abstract class OneDReader implements Reader {
} }
} }
protected static void recordPatternInReverse(BitArray row, int start, int[] counters)
throws ReaderException {
// This could be more efficient I guess
int numTransitionsLeft = counters.length;
boolean last = row.get(start);
while (start > 0 && numTransitionsLeft >= 0) {
if (row.get(--start) != last) {
numTransitionsLeft--;
last = !last;
}
}
if (numTransitionsLeft >= 0) {
throw ReaderException.getInstance();
}
recordPattern(row, start + 1, counters);
}
/** /**
* Determines how closely a set of observed counts of runs of black/white values matches a given * Determines how closely a set of observed counts of runs of black/white values matches a given
* target pattern. This is reported as the ratio of the total variance from the expected pattern * target pattern. This is reported as the ratio of the total variance from the expected pattern
@ -225,7 +246,7 @@ public abstract class OneDReader implements Reader {
* the total variance between counters and patterns equals the pattern length, higher values mean * the total variance between counters and patterns equals the pattern length, higher values mean
* even more variance * even more variance
*/ */
static int patternMatchVariance(int[] counters, int[] pattern, int maxIndividualVariance) { protected static int patternMatchVariance(int[] counters, int[] pattern, int maxIndividualVariance) {
int numCounters = counters.length; int numCounters = counters.length;
int total = 0; int total = 0;
int patternLength = 0; int patternLength = 0;

View file

@ -69,6 +69,10 @@ public final class PDF417Reader implements Reader {
BarcodeFormat.PDF417); BarcodeFormat.PDF417);
} }
public void reset() {
// do nothing
}
/** /**
* This method detects a barcode in a "pure" image -- that is, pure monochrome image * This method detects a barcode in a "pure" image -- that is, pure monochrome image
* which contains only an unrotated, unskewed, image of a barcode, with some white border * which contains only an unrotated, unskewed, image of a barcode, with some white border

View file

@ -102,6 +102,7 @@ public final class DecodeServlet extends HttpServlet {
possibleFormats.add(BarcodeFormat.CODE_39); possibleFormats.add(BarcodeFormat.CODE_39);
possibleFormats.add(BarcodeFormat.CODE_128); possibleFormats.add(BarcodeFormat.CODE_128);
possibleFormats.add(BarcodeFormat.ITF); possibleFormats.add(BarcodeFormat.ITF);
possibleFormats.add(BarcodeFormat.RSS14);
possibleFormats.add(BarcodeFormat.QR_CODE); possibleFormats.add(BarcodeFormat.QR_CODE);
possibleFormats.add(BarcodeFormat.DATAMATRIX); possibleFormats.add(BarcodeFormat.DATAMATRIX);
possibleFormats.add(BarcodeFormat.PDF417); possibleFormats.add(BarcodeFormat.PDF417);