/**
* <p>Decodes Code 128 barcodes.</p>
*
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
*/
public final class Code128Reader extends AbstractOneDReader {
}
}
if (bestMatch >= 0) {
- return new int[]{patternStart, i, bestMatch};
+ // Look for whitespace before start pattern, >= 50% of width of start pattern
+ if (row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
+ return new int[]{patternStart, i, bestMatch};
+ }
}
patternStart += counters[0] + counters[1];
for (int y = 2; y < patternLength; y++) {
isWhite = !isWhite;
}
}
- throw new ReaderException("Can't find pattern");
+ throw ReaderException.getInstance();
}
private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws ReaderException {
if (bestMatch >= 0) {
return bestMatch;
} else {
- throw new ReaderException("Could not match any code pattern");
+ throw ReaderException.getInstance();
}
}
codeSet = CODE_CODE_C;
break;
default:
- throw new ReaderException("Illegal start code");
+ throw ReaderException.getInstance();
}
boolean done = false;
case CODE_START_A:
case CODE_START_B:
case CODE_START_C:
- throw new ReaderException("Unexpected start code");
+ throw ReaderException.getInstance();
}
switch (codeSet) {
}
+ // Check for ample whitespice following pattern, but, to do this we first need to remember that we
+ // fudged decoding CODE_STOP since it actually has 7 bars, not 6. There is a black bar left to read off.
+ // Would be slightly better to properly read. Here we just skip it:
+ while (row.get(nextStart)) {
+ nextStart++;
+ }
+ if (!row.isRange(nextStart, Math.min(row.getSize(), nextStart + (nextStart - lastStart) / 2), false)) {
+ throw ReaderException.getInstance();
+ }
+
// Pull out from sum the value of the penultimate check code
checksumTotal -= multiplier * lastCode;
// lastCode is the checksum then:
if (checksumTotal % 103 != lastCode) {
- throw new ReaderException("Checksum failed");
+ throw ReaderException.getInstance();
}
// Need to pull out the check digits from string
if (resultString.length() == 0) {
// Almost surely a false positive
- throw new ReaderException("Empty barcode found; assuming a false positive");
+ throw ReaderException.getInstance();
}
float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;