Trying out a new user-requested decode hint, allowing a caller to skip the first...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 13 Mar 2008 19:32:08 +0000 (19:32 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 13 Mar 2008 19:32:08 +0000 (19:32 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@276 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/DecodeHintType.java
core/src/com/google/zxing/oned/AbstractOneDReader.java

index a8e1c83..20c30c0 100644 (file)
@@ -52,6 +52,13 @@ public final class DecodeHintType {
    */
   public static final DecodeHintType TRY_HARDER = new DecodeHintType();
 
+  /**
+   * Skip the first n barcodes found. Currently applies only to 1D formats. This
+   * enables a caller to repeatedly decode and find multiple barcodes. Maps
+   * to an {@link Integer}.
+   */
+  public static final DecodeHintType SKIP_N_BARCODES = new DecodeHintType();
+
   private DecodeHintType() {
   }
 
index b30f5f3..415bd7b 100644 (file)
@@ -59,6 +59,14 @@ 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();
+      }
+    }
+
     // 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
     // the middle. So we'd scan row middle, then middle - rowStep, then middle + rowStep,
@@ -67,7 +75,12 @@ public abstract class AbstractOneDReader implements OneDReader {
     // that moving up and down by about 1/16 of the image is pretty good.
     int middle = height >> 1;
     int rowStep = Math.max(1, height >> 4);
-    int maxLines = tryHarder ? 15 : 7;
+    int maxLines;
+    if (barcodesToSkip > 0) {
+      maxLines = height; // Look at the whole image; looking for more than one barcode
+    } else {
+      maxLines = tryHarder ? 15 : 7; // If "trying harder", examine more lines
+    }
     for (int x = 0; x < maxLines; x++) {
 
       int rowStepsAboveOrBelow = (x + 1) >> 1;
@@ -81,12 +94,22 @@ public abstract class AbstractOneDReader implements OneDReader {
       image.getBlackRow(rowNumber, row, 0, width);
 
       try {
-        return decodeRow(rowNumber, row, hints);
+        Result result = decodeRow(rowNumber, row, hints);
+        if (barcodesToSkip > 0) { // See if we should skip and keep looking
+          barcodesToSkip--;
+        } else {
+          return result;
+        }
       } catch (ReaderException re) {
         if (tryHarder) {
           row.reverse(); // try scanning the row backwards
           try {
-            return decodeRow(rowNumber, row, hints);
+            Result result = decodeRow(rowNumber, row, hints);
+            if (barcodesToSkip > 0) { // See if we should skip and keep looking
+              barcodesToSkip--;
+            } else {
+              return result;
+            }
           } catch (ReaderException re2) {
             // continue
           }