X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2FMultiFormatReader.java;h=0409436ada9ed6b39318825b92f3b1910ed066ec;hb=0ee5f7050379e4edac731b8bc15ff68b6e03949c;hp=09c66fa15e7d115cdb160fa8c9268ba1275b3811;hpb=4b7e347031d7d2053257c15ce5a9b301de777824;p=zxing.git diff --git a/core/src/com/google/zxing/MultiFormatReader.java b/core/src/com/google/zxing/MultiFormatReader.java index 09c66fa1..0409436a 100644 --- a/core/src/com/google/zxing/MultiFormatReader.java +++ b/core/src/com/google/zxing/MultiFormatReader.java @@ -18,8 +18,10 @@ package com.google.zxing; import com.google.zxing.oned.MultiFormatOneDReader; import com.google.zxing.qrcode.QRCodeReader; +import com.google.zxing.datamatrix.DataMatrixReader; import java.util.Hashtable; +import java.util.Vector; /** *

This implementation can detect barcodes in one of several formats within @@ -34,39 +36,41 @@ public final class MultiFormatReader implements Reader { return decode(image, null); } - public Result decode(MonochromeBitmapSource image, Hashtable hints) - throws ReaderException { - Hashtable possibleFormats = hints == null ? null : (Hashtable) hints.get(DecodeHintType.POSSIBLE_FORMATS); + public Result decode(MonochromeBitmapSource image, Hashtable hints) throws ReaderException { - boolean tryOneD; - boolean tryQR; - if (possibleFormats == null) { - tryOneD = true; - tryQR = true; - } else { - tryOneD = possibleFormats.contains(BarcodeFormat.ONED); - tryQR = possibleFormats.contains(BarcodeFormat.QR_CODE); + Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS); + Vector readers = new Vector(); + if (possibleFormats != null) { + if (possibleFormats.contains(BarcodeFormat.UPC_A) || + possibleFormats.contains(BarcodeFormat.UPC_E) || + possibleFormats.contains(BarcodeFormat.EAN_13) || + possibleFormats.contains(BarcodeFormat.EAN_8) || + possibleFormats.contains(BarcodeFormat.CODE_39) || + possibleFormats.contains(BarcodeFormat.CODE_128)) { + readers.addElement(new MultiFormatOneDReader()); + } + if (possibleFormats.contains(BarcodeFormat.QR_CODE)) { + readers.addElement(new QRCodeReader()); + } + if (possibleFormats.contains(BarcodeFormat.DATAMATRIX)) { + readers.addElement(new DataMatrixReader()); + } } - if (!(tryOneD || tryQR)) { - throw new ReaderException("POSSIBLE_FORMATS specifies no supported types"); + if (readers.isEmpty()) { + readers.addElement(new MultiFormatOneDReader()); + readers.addElement(new QRCodeReader()); + readers.addElement(new DataMatrixReader()); } - // UPC is much faster to decode, so try it first. - if (tryOneD) { - try { - return new MultiFormatOneDReader().decode(image, hints); - } catch (ReaderException re) { - } - } - - // Then fall through to QR codes. - if (tryQR) { + for (int i = 0; i < readers.size(); i++) { + Reader reader = (Reader) readers.elementAt(i); try { - return new QRCodeReader().decode(image, hints); + return reader.decode(image, hints); } catch (ReaderException re) { + // continue } } - + throw new ReaderException("No barcode was detected in this image."); }