Turned on ITF as a format you can request via hint. Also rejiggered the unit test...
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 22 Dec 2008 22:58:58 +0000 (22:58 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 22 Dec 2008 22:58:58 +0000 (22:58 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@803 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/oned/MultiFormatOneDReader.java
core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java
core/test/src/com/google/zxing/oned/ITFBlackBox1TestCase.java

index 84a1ba9..ef7d5fc 100644 (file)
@@ -49,16 +49,15 @@ public final class MultiFormatOneDReader extends AbstractOneDReader {
       if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
         readers.addElement(new Code128Reader());
       }
-      // TODO: Add ITFReader once it is validated as production ready. 
-      //if (possibleFormats.contains(BarcodeFormat.ITF)) {
-      //   readers.addElement(new ITFReader());
-      //}
+      if (possibleFormats.contains(BarcodeFormat.ITF)) {
+         readers.addElement(new ITFReader());
+      }
     }
     if (readers.isEmpty()) {
       readers.addElement(new MultiFormatUPCEANReader(hints));
       readers.addElement(new Code39Reader());
       readers.addElement(new Code128Reader());
-      // TODO: Add ITFReader once it is validated as production ready.
+      // TODO: Add ITFReader once it is validated as production ready, and tested for performance.
       //readers.addElement(new ITFReader());
     }
   }
index 9d4017e..9e3ccde 100644 (file)
@@ -115,6 +115,10 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
     return barcodeReader;
   }
 
+  protected Hashtable<DecodeHintType, Object> getHints() {
+    return null;
+  }
+
   public void testBlackBox() throws IOException {
     assertFalse(testResults.isEmpty());
 
@@ -172,7 +176,15 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
     String suffix = " (" + (tryHarder ? "try harder, " : "") + "rotation: " + rotation + ')';
 
     try {
-      result = barcodeReader.decode(source, tryHarder ? TRY_HARDER_HINT : null);
+      Hashtable<DecodeHintType, Object> hints = getHints();
+      if (tryHarder) {
+        if (hints == null) {
+          hints = TRY_HARDER_HINT;
+        } else {
+          hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
+        }
+      }
+      result = getReader().decode(source, hints);
     } catch (ReaderException re) {
       System.out.println(re + suffix);
       return false;
index 79e1c81..a1aa561 100644 (file)
 \r
 package com.google.zxing.oned;\r
 \r
-import com.google.zxing.MultiFormatReader;\r
 import com.google.zxing.BarcodeFormat;\r
+import com.google.zxing.DecodeHintType;\r
+import com.google.zxing.MultiFormatReader;\r
 import com.google.zxing.common.AbstractBlackBoxTestCase;\r
 \r
 import java.io.File;\r
+import java.util.Hashtable;\r
+import java.util.Vector;\r
 \r
 /**\r
  * @author kevin.osullivan@sita.aero\r
@@ -32,4 +35,25 @@ public final class ITFBlackBox1TestCase extends AbstractBlackBoxTestCase {
     addTest(9, 12, 0.0f);\r
   }\r
 \r
-}
\ No newline at end of file
+  // TODO(dswitkin): This is only used for the mean time because ITF is not turned on by default.\r
+  // The other formats are included here to make sure we don't recognize an ITF barcode as something\r
+  // else. Unfortunately this list is fragile. The right thing to do is profile ITF for performance,\r
+  // and if it doesn't impose significant overhead, turn it on by default. Then this method can be\r
+  // removed completely.\r
+  @Override\r
+  protected Hashtable<DecodeHintType, Object> getHints() {\r
+    Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(3);\r
+    Vector<BarcodeFormat> vector = new Vector<BarcodeFormat>();\r
+    vector.addElement(BarcodeFormat.UPC_A);\r
+    vector.addElement(BarcodeFormat.UPC_E);\r
+    vector.addElement(BarcodeFormat.EAN_13);\r
+    vector.addElement(BarcodeFormat.EAN_8);\r
+    vector.addElement(BarcodeFormat.CODE_39);\r
+    vector.addElement(BarcodeFormat.CODE_128);\r
+    vector.addElement(BarcodeFormat.ITF);\r
+    vector.addElement(BarcodeFormat.QR_CODE);\r
+    hints.put(DecodeHintType.POSSIBLE_FORMATS, vector);\r
+    return hints;\r
+  }\r
+\r
+}\r