"Try harder" mode now tries 2D formats first. BlackPointEstimator more conservative...
[zxing.git] / core / src / com / google / zxing / oned / AbstractOneDReader.java
index 53a04a3..66eee2b 100644 (file)
@@ -69,13 +69,13 @@ public abstract class AbstractOneDReader implements OneDReader {
 
     BitArray row = new BitArray(width);
 
-    int barcodesToSkip = 0;
-    if (hints != null) {
-      Integer number = (Integer) hints.get(DecodeHintType.SKIP_N_BARCODES);
-      if (number != null) {
-        barcodesToSkip = number.intValue();
-      }
-    }
+    //int barcodesToSkip = 0;
+    //if (hints != null) {
+    //  Integer number = (Integer) hints.get(DecodeHintType.SKIP_N_BARCODES);
+    //  if (number != null) {
+    //    barcodesToSkip = number.intValue();
+    //  }
+    //}
 
     // 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 attempt above and below
@@ -87,23 +87,27 @@ public abstract class AbstractOneDReader implements OneDReader {
     int middle = height >> 1;
     int rowStep = Math.max(1, height >> (tryHarder ? 7 : 4));
     int maxLines;
-    if (tryHarder || barcodesToSkip > 0) {
+    //if (tryHarder || barcodesToSkip > 0) {
+    if (tryHarder) {
       maxLines = height; // Look at the whole image; looking for more than one barcode
     } else {
       maxLines = 7;
     }
 
-    Result lastResult = null;
+    //Result lastResult = null;
 
     for (int x = 0; x < maxLines; x++) {
 
+      // Scanning from the middle out. Determine which row we're looking at next:
       int rowStepsAboveOrBelow = (x + 1) >> 1;
       boolean isAbove = (x & 0x01) == 0; // i.e. is x even?
       int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow);
       if (rowNumber < 0 || rowNumber >= height) {
+        // Oops, if we run off the top or bottom, stop
         break;
       }
 
+      // Estimate black point for this row and load it:
       try {
         image.estimateBlackPoint(BlackPointEstimationMethod.ROW_SAMPLING, rowNumber);
       } catch (ReaderException re) {
@@ -111,7 +115,9 @@ public abstract class AbstractOneDReader implements OneDReader {
       }
       image.getBlackRow(rowNumber, row, 0, width);
 
+      // We may try twice for each row, if "trying harder":
       for (int attempt = 0; attempt < 2; attempt++) {
+
         if (attempt == 1) { // trying again?
           if (tryHarder) { // only if "trying harder"
             row.reverse(); // reverse the row and continue
@@ -119,24 +125,33 @@ public abstract class AbstractOneDReader implements OneDReader {
             break;
           }
         }
+
         try {
+
+          // Look for a barcode
           Result result = decodeRow(rowNumber, row, hints);
-          if (lastResult == null || !lastResult.getText().equals(result.getText())) {
-            // Found new barcode, not just the last one again
-            if (barcodesToSkip > 0) { // See if we should skip and keep looking
-              barcodesToSkip--;
-              lastResult = result; // Remember what we just saw
-            } else {
-              if (attempt == 1) {
-                // Found it, but upside-down:
-                result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
-              }
-              return result;
+
+          //if (lastResult != null && lastResult.getText().equals(result.getText())) {
+            // Just saw the last barcode again, proceed
+            //continue;
+          //}
+
+          //if (barcodesToSkip > 0) { // See if we should skip and keep looking
+          //  barcodesToSkip--;
+          //  lastResult = result; // Remember what we just saw
+          //} else {
+            // We found our barcode
+            if (attempt == 1) {
+              // But it was upside down, so note that
+              result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
             }
-          }
+            return result;
+          //}
+
         } catch (ReaderException re) {
-          // continue
+          // continue -- just couldn't decode this row
         }
+
       }
     }