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: https://zxing.googlecode.com/svn/trunk@803 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
dswitkin 2008-12-22 22:58:58 +00:00
parent 0a3ddd33dc
commit 96b80c3550
3 changed files with 43 additions and 8 deletions

View file

@ -49,16 +49,15 @@ public final class MultiFormatOneDReader extends AbstractOneDReader {
if (possibleFormats.contains(BarcodeFormat.CODE_128)) { if (possibleFormats.contains(BarcodeFormat.CODE_128)) {
readers.addElement(new Code128Reader()); readers.addElement(new Code128Reader());
} }
// TODO: Add ITFReader once it is validated as production ready. if (possibleFormats.contains(BarcodeFormat.ITF)) {
//if (possibleFormats.contains(BarcodeFormat.ITF)) { readers.addElement(new ITFReader());
// readers.addElement(new ITFReader()); }
//}
} }
if (readers.isEmpty()) { if (readers.isEmpty()) {
readers.addElement(new MultiFormatUPCEANReader(hints)); readers.addElement(new MultiFormatUPCEANReader(hints));
readers.addElement(new Code39Reader()); readers.addElement(new Code39Reader());
readers.addElement(new Code128Reader()); 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()); //readers.addElement(new ITFReader());
} }
} }

View file

@ -115,6 +115,10 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
return barcodeReader; return barcodeReader;
} }
protected Hashtable<DecodeHintType, Object> getHints() {
return null;
}
public void testBlackBox() throws IOException { public void testBlackBox() throws IOException {
assertFalse(testResults.isEmpty()); assertFalse(testResults.isEmpty());
@ -172,7 +176,15 @@ public abstract class AbstractBlackBoxTestCase extends TestCase {
String suffix = " (" + (tryHarder ? "try harder, " : "") + "rotation: " + rotation + ')'; String suffix = " (" + (tryHarder ? "try harder, " : "") + "rotation: " + rotation + ')';
try { 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) { } catch (ReaderException re) {
System.out.println(re + suffix); System.out.println(re + suffix);
return false; return false;

View file

@ -16,11 +16,14 @@
package com.google.zxing.oned; package com.google.zxing.oned;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase; import com.google.zxing.common.AbstractBlackBoxTestCase;
import java.io.File; import java.io.File;
import java.util.Hashtable;
import java.util.Vector;
/** /**
* @author kevin.osullivan@sita.aero * @author kevin.osullivan@sita.aero
@ -32,4 +35,25 @@ public final class ITFBlackBox1TestCase extends AbstractBlackBoxTestCase {
addTest(9, 12, 0.0f); addTest(9, 12, 0.0f);
} }
} // 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<DecodeHintType, Object> getHints() {
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(3);
Vector<BarcodeFormat> vector = new Vector<BarcodeFormat>();
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;
}
}