Added some comments and fixed up lines over 100 columns.
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 3 Dec 2009 20:35:10 +0000 (20:35 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 3 Dec 2009 20:35:10 +0000 (20:35 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1134 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/oned/AbstractOneDReader.java
core/src/com/google/zxing/oned/AbstractUPCEANReader.java
core/src/com/google/zxing/oned/EAN13Reader.java
core/src/com/google/zxing/oned/MultiFormatOneDReader.java
core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java
core/src/com/google/zxing/oned/UPCEReader.java

index 93e3661..bab29e3 100644 (file)
@@ -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;
   }
index f25cdf4..ee39d08 100644 (file)
@@ -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();
index f805e6c..d8f8775 100644 (file)
@@ -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));
index c22437b..14ddb2e 100644 (file)
@@ -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) ||
index 295df32..502b086 100644 (file)
@@ -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;
     }
index f8b885a..1ba1fce 100644 (file)
@@ -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;
   }
 
   /**