From 5c627db2890deb9611a999e2caaa122737ca737c Mon Sep 17 00:00:00 2001 From: dswitkin Date: Thu, 3 Dec 2009 20:35:10 +0000 Subject: [PATCH] Added some comments and fixed up lines over 100 columns. git-svn-id: https://zxing.googlecode.com/svn/trunk@1134 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../com/google/zxing/oned/AbstractOneDReader.java | 7 ++++--- .../com/google/zxing/oned/AbstractUPCEANReader.java | 7 +++++-- core/src/com/google/zxing/oned/EAN13Reader.java | 13 ++++++++----- .../google/zxing/oned/MultiFormatOneDReader.java | 6 ++++-- .../google/zxing/oned/MultiFormatUPCEANReader.java | 9 ++++++--- core/src/com/google/zxing/oned/UPCEReader.java | 5 +++-- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/core/src/com/google/zxing/oned/AbstractOneDReader.java b/core/src/com/google/zxing/oned/AbstractOneDReader.java index 93e3661eb..bab29e344 100644 --- a/core/src/com/google/zxing/oned/AbstractOneDReader.java +++ b/core/src/com/google/zxing/oned/AbstractOneDReader.java @@ -42,6 +42,7 @@ public abstract class AbstractOneDReader implements OneDReader { 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); @@ -111,7 +112,7 @@ public abstract class AbstractOneDReader implements OneDReader { 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. @@ -184,7 +185,7 @@ public abstract class AbstractOneDReader implements OneDReader { break; } else { counters[counterPosition] = 1; - isWhite ^= true; // isWhite = !isWhite; Is this too clever? shorter byte code, no conditional + isWhite = !isWhite; } } i++; @@ -236,7 +237,7 @@ public abstract class AbstractOneDReader implements OneDReader { if (variance > maxIndividualVariance) { return Integer.MAX_VALUE; } - totalVariance += variance; + totalVariance += variance; } return totalVariance / total; } diff --git a/core/src/com/google/zxing/oned/AbstractUPCEANReader.java b/core/src/com/google/zxing/oned/AbstractUPCEANReader.java index f25cdf439..ee39d08a1 100644 --- a/core/src/com/google/zxing/oned/AbstractUPCEANReader.java +++ b/core/src/com/google/zxing/oned/AbstractUPCEANReader.java @@ -36,6 +36,9 @@ import java.util.Hashtable; */ 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); @@ -172,7 +175,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements abstract BarcodeFormat getBarcodeFormat(); /** - * @return {@link #checkStandardUPCEANChecksum(String)} + * @return {@link #checkStandardUPCEANChecksum(String)} */ boolean checkChecksum(String s) throws ReaderException { return checkStandardUPCEANChecksum(s); @@ -274,7 +277,7 @@ public abstract class AbstractUPCEANReader extends AbstractOneDReader implements counterPosition++; } counters[counterPosition] = 1; - isWhite ^= true; // isWhite = !isWhite; + isWhite = !isWhite; } } throw ReaderException.getInstance(); diff --git a/core/src/com/google/zxing/oned/EAN13Reader.java b/core/src/com/google/zxing/oned/EAN13Reader.java index f805e6cdc..d8f8775b7 100644 --- a/core/src/com/google/zxing/oned/EAN13Reader.java +++ b/core/src/com/google/zxing/oned/EAN13Reader.java @@ -68,7 +68,8 @@ public final class EAN13Reader extends AbstractUPCEANReader { 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; @@ -111,15 +112,17 @@ public final class EAN13Reader extends AbstractUPCEANReader { } /** - * 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)); diff --git a/core/src/com/google/zxing/oned/MultiFormatOneDReader.java b/core/src/com/google/zxing/oned/MultiFormatOneDReader.java index c22437b9e..14ddb2e7d 100644 --- a/core/src/com/google/zxing/oned/MultiFormatOneDReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatOneDReader.java @@ -34,8 +34,10 @@ public final class MultiFormatOneDReader extends AbstractOneDReader { 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) || diff --git a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java index 295df32ff..502b086f1 100644 --- a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java @@ -37,7 +37,8 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader { 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)) { @@ -82,8 +83,10 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader { // 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; } diff --git a/core/src/com/google/zxing/oned/UPCEReader.java b/core/src/com/google/zxing/oned/UPCEReader.java index f8b885aa6..1ba1fce25 100644 --- a/core/src/com/google/zxing/oned/UPCEReader.java +++ b/core/src/com/google/zxing/oned/UPCEReader.java @@ -52,7 +52,8 @@ public final class UPCEReader extends AbstractUPCEANReader { 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; @@ -103,7 +104,7 @@ public final class UPCEReader extends AbstractUPCEANReader { } BarcodeFormat getBarcodeFormat() { - return BarcodeFormat.UPC_E; + return BarcodeFormat.UPC_E; } /**