Avoid RSS-14 false positive issue, which temporarily hurts its scanning a lot, but...
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 25 Mar 2010 11:42:08 +0000 (11:42 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 25 Mar 2010 11:42:08 +0000 (11:42 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1251 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/oned/rss/Pair.java
core/src/com/google/zxing/oned/rss/RSS14Reader.java
core/test/src/com/google/zxing/negative/FalsePositivesBlackBoxTestCase.java
core/test/src/com/google/zxing/negative/PartialBlackBoxTestCase.java
core/test/src/com/google/zxing/negative/UnsupportedBlackBoxTestCase.java
core/test/src/com/google/zxing/oned/Code128BlackBox2TestCase.java
core/test/src/com/google/zxing/oned/EAN13BlackBox1TestCase.java
core/test/src/com/google/zxing/oned/EAN13BlackBox2TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox1TestCase.java
core/test/src/com/google/zxing/oned/UPCABlackBox4TestCase.java
core/test/src/com/google/zxing/oned/rss/RSS14BlackBox2TestCase.java

index 4518ba3..e2371d2 100644 (file)
@@ -19,6 +19,7 @@ package com.google.zxing.oned.rss;
 final class Pair extends DataCharacter {
 
   private final FinderPattern finderPattern;
+  private int count;
 
   Pair(int value, int checksumPortion, FinderPattern finderPattern) {
     super(value, checksumPortion);
@@ -29,4 +30,12 @@ final class Pair extends DataCharacter {
     return finderPattern;
   }
 
+  int getCount() {
+    return count;
+  }
+
+  void incrementCount() {
+    count++;
+  }
+
 }
\ No newline at end of file
index c9f84c3..941107a 100644 (file)
@@ -25,6 +25,7 @@ import com.google.zxing.ResultPointCallback;
 import com.google.zxing.common.BitArray;
 import com.google.zxing.oned.OneDReader;
 
+import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Vector;
 
@@ -80,29 +81,48 @@ public final class RSS14Reader extends OneDReader {
 
   public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException {
     Pair leftPair = decodePair(row, false, rowNumber, hints);
-    if (leftPair != null) {
-      possibleLeftPairs.addElement(leftPair);
-    }
+    addOrTally(possibleLeftPairs, leftPair);
     row.reverse();
     Pair rightPair = decodePair(row, true, rowNumber, hints);
-    if (rightPair != null) {
-      possibleRightPairs.addElement(rightPair);
-    }
+    addOrTally(possibleRightPairs, rightPair);
     row.reverse();
     int numLeftPairs = possibleLeftPairs.size();
     int numRightPairs = possibleRightPairs.size();
     for (int l = 0; l < numLeftPairs; l++) {
       Pair left = (Pair) possibleLeftPairs.elementAt(l);
-      for (int r = 0; r < numRightPairs; r++) {
-        Pair right = (Pair) possibleRightPairs.elementAt(r);
-        if (checkChecksum(left, right)) {
-          return constructResult(left, right);
+      if (left.getCount() > 1) {
+        for (int r = 0; r < numRightPairs; r++) {
+          Pair right = (Pair) possibleRightPairs.elementAt(r);
+          if (right.getCount() > 1) {
+            if (checkChecksum(left, right)) {
+              return constructResult(left, right);
+            }
+          }
         }
       }
     }
     throw NotFoundException.getNotFoundInstance();
   }
 
+  private static void addOrTally(Vector possiblePairs, Pair pair) {
+    if (pair == null) {
+      return;
+    }
+    Enumeration e = possiblePairs.elements();
+    boolean found = false;
+    while (e.hasMoreElements()) {
+      Pair other = (Pair) e.nextElement();
+      if (other.getValue() == pair.getValue()) {
+        other.incrementCount();
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      possiblePairs.addElement(pair);
+    }
+  }
+
   public void reset() {
     possibleLeftPairs.setSize(0);
     possibleRightPairs.setSize(0);
index e204108..2d8c0b2 100644 (file)
@@ -29,8 +29,8 @@ public final class FalsePositivesBlackBoxTestCase extends AbstractNegativeBlackB
     super("test/data/blackbox/falsepositives");
     addTest(2, 0.0f);
     addTest(0, 90.0f);
-    addTest(0, 180.0f);
-    addTest(0, 270.0f);
+    addTest(1, 180.0f);
+    addTest(1, 270.0f);
   }
 
 }
index 016aac7..6a63da8 100644 (file)
@@ -27,7 +27,7 @@ public final class PartialBlackBoxTestCase extends AbstractNegativeBlackBoxTestC
 
   public PartialBlackBoxTestCase() {
     super("test/data/blackbox/partial");
-    addTest(0, 0.0f);
+    addTest(1, 0.0f);
     addTest(1, 90.0f);
     addTest(1, 180.0f);
     addTest(0, 270.0f);
index a3d9fdb..969a042 100644 (file)
@@ -27,7 +27,7 @@ public final class UnsupportedBlackBoxTestCase extends AbstractNegativeBlackBoxT
 
   public UnsupportedBlackBoxTestCase() {
     super("test/data/blackbox/unsupported");
-    addTest(0, 0.0f);
+    addTest(1, 0.0f);
     addTest(0, 90.0f);
     addTest(1, 180.0f);
     addTest(0, 270.0f);
index 4f206fc..b2fb164 100644 (file)
@@ -28,7 +28,7 @@ public final class Code128BlackBox2TestCase extends AbstractBlackBoxTestCase {
   public Code128BlackBox2TestCase() {
     super("test/data/blackbox/code128-2", new MultiFormatReader(), BarcodeFormat.CODE_128);
     addTest(33, 39, 0.0f);
-    addTest(34, 37, 180.0f);
+    addTest(34, 39, 180.0f);
   }
 
 }
\ No newline at end of file
index d3f9e6f..07ee093 100644 (file)
@@ -27,8 +27,8 @@ public final class EAN13BlackBox1TestCase extends AbstractBlackBoxTestCase {
 
   public EAN13BlackBox1TestCase() {
     super("test/data/blackbox/ean13-1", new MultiFormatReader(), BarcodeFormat.EAN_13);
-    addTest(28, 30, 0.0f);
-    addTest(26, 30, 180.0f);
+    addTest(28, 31, 0.0f);
+    addTest(26, 31, 180.0f);
   }
 
 }
\ No newline at end of file
index f79a97b..6f7a98d 100644 (file)
@@ -29,7 +29,7 @@ public final class EAN13BlackBox2TestCase extends AbstractBlackBoxTestCase {
 
   public EAN13BlackBox2TestCase() {
     super("test/data/blackbox/ean13-2", new MultiFormatReader(), BarcodeFormat.EAN_13);
-    addTest(10, 14, 0.0f);
+    addTest(10, 16, 0.0f);
     addTest(10, 16, 180.0f);
   }
 
index 285aa22..84784c7 100644 (file)
@@ -27,8 +27,8 @@ public final class UPCABlackBox1TestCase extends AbstractBlackBoxTestCase {
 
   public UPCABlackBox1TestCase() {
     super("test/data/blackbox/upca-1", new MultiFormatReader(), BarcodeFormat.UPC_A);
-    addTest(15, 16, 0.0f);
-    addTest(15, 19, 180.0f);
+    addTest(15, 18, 0.0f);
+    addTest(15, 18, 180.0f);
   }
 
 }
\ No newline at end of file
index d18eab6..7c20af6 100644 (file)
@@ -27,8 +27,8 @@ public final class UPCABlackBox4TestCase extends AbstractBlackBoxTestCase {
 
   public UPCABlackBox4TestCase() {
     super("test/data/blackbox/upca-4", new MultiFormatReader(), BarcodeFormat.UPC_A);
-    addTest(8, 13, 0.0f);
-    addTest(8, 12, 180.0f);
+    addTest(7, 11, 0.0f);
+    addTest(8, 11, 180.0f);
   }
 
 }
index 203e5f1..208da20 100644 (file)
@@ -27,8 +27,8 @@ public final class RSS14BlackBox2TestCase extends AbstractBlackBoxTestCase {
 
   public RSS14BlackBox2TestCase() {
     super("test/data/blackbox/rss14-2", new MultiFormatReader(), BarcodeFormat.RSS14);
-    addTest(7, 9, 0.0f);
-    addTest(6, 9, 180.0f);
+    addTest(0, 8, 0.0f);
+    addTest(0, 8, 180.0f);
   }
 
 }
\ No newline at end of file