From 7e271e44cbc65241a9dc73e47d6acf6f7e5ef150 Mon Sep 17 00:00:00 2001 From: dswitkin Date: Mon, 22 Dec 2008 22:58:58 +0000 Subject: [PATCH] Turned on ITF as a format you can request via hint. Also rejiggered the unit test framework to accept an optional hint so that the ITF unit test runs (and passes) without modifying the source. git-svn-id: http://zxing.googlecode.com/svn/trunk@803 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/oned/MultiFormatOneDReader.java | 9 +++--- .../common/AbstractBlackBoxTestCase.java | 14 +++++++++- .../zxing/oned/ITFBlackBox1TestCase.java | 28 +++++++++++++++++-- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/core/src/com/google/zxing/oned/MultiFormatOneDReader.java b/core/src/com/google/zxing/oned/MultiFormatOneDReader.java index 84a1ba9c..ef7d5fcb 100644 --- a/core/src/com/google/zxing/oned/MultiFormatOneDReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatOneDReader.java @@ -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()); } } diff --git a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java index 9d4017ea..9e3ccde9 100644 --- a/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/test/src/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -115,6 +115,10 @@ public abstract class AbstractBlackBoxTestCase extends TestCase { return barcodeReader; } + protected Hashtable 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 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; diff --git a/core/test/src/com/google/zxing/oned/ITFBlackBox1TestCase.java b/core/test/src/com/google/zxing/oned/ITFBlackBox1TestCase.java index 79e1c81b..a1aa5619 100644 --- a/core/test/src/com/google/zxing/oned/ITFBlackBox1TestCase.java +++ b/core/test/src/com/google/zxing/oned/ITFBlackBox1TestCase.java @@ -16,11 +16,14 @@ package com.google.zxing.oned; -import com.google.zxing.MultiFormatReader; import com.google.zxing.BarcodeFormat; +import com.google.zxing.DecodeHintType; +import com.google.zxing.MultiFormatReader; import com.google.zxing.common.AbstractBlackBoxTestCase; import java.io.File; +import java.util.Hashtable; +import java.util.Vector; /** * @author kevin.osullivan@sita.aero @@ -32,4 +35,25 @@ public final class ITFBlackBox1TestCase extends AbstractBlackBoxTestCase { addTest(9, 12, 0.0f); } -} \ No newline at end of file + // TODO(dswitkin): This is only used for the mean time because ITF is not turned on by default. + // The other formats are included here to make sure we don't recognize an ITF barcode as something + // else. Unfortunately this list is fragile. The right thing to do is profile ITF for performance, + // and if it doesn't impose significant overhead, turn it on by default. Then this method can be + // removed completely. + @Override + protected Hashtable getHints() { + Hashtable hints = new Hashtable(3); + Vector vector = new Vector(); + vector.addElement(BarcodeFormat.UPC_A); + vector.addElement(BarcodeFormat.UPC_E); + vector.addElement(BarcodeFormat.EAN_13); + vector.addElement(BarcodeFormat.EAN_8); + vector.addElement(BarcodeFormat.CODE_39); + vector.addElement(BarcodeFormat.CODE_128); + vector.addElement(BarcodeFormat.ITF); + vector.addElement(BarcodeFormat.QR_CODE); + hints.put(DecodeHintType.POSSIBLE_FORMATS, vector); + return hints; + } + +} -- 2.20.1