return decode(image, null);
}
+ // Note that we don't try rotation without the try harder flag, even if rotation was supported.
public final Result decode(BinaryBitmap image, Hashtable hints) throws ReaderException {
try {
return doDecode(image, hints);
row = image.getBlackRow(rowNumber, row);
} catch (ReaderException re) {
continue;
- }
+ }
// While we have the image data in a BitArray, it's fairly cheap to reverse it in place to
// handle decoding upside down barcodes.
break;
} else {
counters[counterPosition] = 1;
- isWhite ^= true; // isWhite = !isWhite; Is this too clever? shorter byte code, no conditional
+ isWhite = !isWhite;
}
}
i++;
if (variance > maxIndividualVariance) {
return Integer.MAX_VALUE;
}
- totalVariance += variance;
+ totalVariance += variance;
}
return totalVariance / total;
}
*/
public abstract class AbstractUPCEANReader extends AbstractOneDReader implements UPCEANReader {
+ // These two values are critical for determining how permissive the decoding will be.
+ // We've arrived at these values through a lot of trial and error. Setting them any higher
+ // lets false positives creep in quickly.
private static final int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
private static final int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f);
abstract BarcodeFormat getBarcodeFormat();
/**
- * @return {@link #checkStandardUPCEANChecksum(String)}
+ * @return {@link #checkStandardUPCEANChecksum(String)}
*/
boolean checkChecksum(String s) throws ReaderException {
return checkStandardUPCEANChecksum(s);
counterPosition++;
}
counters[counterPosition] = 1;
- isWhite ^= true; // isWhite = !isWhite;
+ isWhite = !isWhite;
}
}
throw ReaderException.getInstance();
decodeMiddleCounters = new int[4];
}
- protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString) throws ReaderException {
+ protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer resultString)
+ throws ReaderException {
int[] counters = decodeMiddleCounters;
counters[0] = 0;
counters[1] = 0;
}
/**
- * Based on pattern of odd-even ('L' and 'G') patterns used to encoded the explicitly-encoded digits
- * in a barcode, determines the implicitly encoded first digit and adds it to the result string.
+ * Based on pattern of odd-even ('L' and 'G') patterns used to encoded the explicitly-encoded
+ * digits in a barcode, determines the implicitly encoded first digit and adds it to the
+ * result string.
*
* @param resultString string to insert decoded first digit into
* @param lgPatternFound int whose bits indicates the pattern of odd/even L/G patterns used to
- * encode digits
+ * encode digits
* @throws ReaderException if first digit cannot be determined
*/
- private static void determineFirstDigit(StringBuffer resultString, int lgPatternFound) throws ReaderException {
+ private static void determineFirstDigit(StringBuffer resultString, int lgPatternFound)
+ throws ReaderException {
for (int d = 0; d < 10; d++) {
if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
resultString.insert(0, (char) ('0' + d));
private final Vector readers;
public MultiFormatOneDReader(Hashtable hints) {
- Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
- boolean useCode39CheckDigit = hints != null && hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
+ Vector possibleFormats = hints == null ? null :
+ (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
+ boolean useCode39CheckDigit = hints != null &&
+ hints.get(DecodeHintType.ASSUME_CODE_39_CHECK_DIGIT) != null;
readers = new Vector();
if (possibleFormats != null) {
if (possibleFormats.contains(BarcodeFormat.EAN_13) ||
private final Vector readers;
public MultiFormatUPCEANReader(Hashtable hints) {
- Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
+ Vector possibleFormats = hints == null ? null :
+ (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS);
readers = new Vector();
if (possibleFormats != null) {
if (possibleFormats.contains(BarcodeFormat.EAN_13)) {
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
// result if appropriate.
- if (result.getBarcodeFormat().equals(BarcodeFormat.EAN_13) && result.getText().charAt(0) == '0') {
- return new Result(result.getText().substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
+ if (result.getBarcodeFormat().equals(BarcodeFormat.EAN_13) &&
+ result.getText().charAt(0) == '0') {
+ return new Result(result.getText().substring(1), null, result.getResultPoints(),
+ BarcodeFormat.UPC_A);
}
return result;
}
decodeMiddleCounters = new int[4];
}
- protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result) throws ReaderException {
+ protected int decodeMiddle(BitArray row, int[] startRange, StringBuffer result)
+ throws ReaderException {
int[] counters = decodeMiddleCounters;
counters[0] = 0;
counters[1] = 0;
}
BarcodeFormat getBarcodeFormat() {
- return BarcodeFormat.UPC_E;
+ return BarcodeFormat.UPC_E;
}
/**