Fixed handling of UPC/QR hints, improved error reporting

git-svn-id: https://zxing.googlecode.com/svn/trunk@121 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2007-12-18 16:43:38 +00:00
parent fd68032e1a
commit ac3e9d3335

View file

@ -26,8 +26,6 @@ import java.util.Hashtable;
* an image, and then decode what it finds. This implementation supports all
* barcode formats that this library supports.</p>
*
* <p>For now, only delegates to {@link QRCodeReader}.</p>
*
* @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
*/
public final class MultiFormatReader implements Reader {
@ -39,25 +37,29 @@ public final class MultiFormatReader implements Reader {
public Result decode(MonochromeBitmapSource image, Hashtable hints)
throws ReaderException {
Hashtable possibleFormats = hints == null ? null : (Hashtable) hints.get(DecodeHintType.POSSIBLE_FORMATS);
boolean tryUPC = false;
boolean tryQR = false;
boolean tryUPC;
boolean tryQR;
if (possibleFormats == null) {
tryUPC = true;
tryQR = true;
} else if (possibleFormats.contains(BarcodeFormat.UPC)) {
tryUPC = true;
} else if (possibleFormats.contains(BarcodeFormat.QR_CODE)) {
tryQR = true;
} else {
tryUPC = possibleFormats.contains(BarcodeFormat.UPC);
tryQR = possibleFormats.contains(BarcodeFormat.QR_CODE);
}
if (!(tryUPC || tryQR)) {
throw new ReaderException("POSSIBLE_FORMATS specifies no supported types");
}
// Save the last exception as what we'll report if nothing decodes
ReaderException savedRE = null;
// UPC is much faster to decode, so try it first.
if (tryUPC) {
try {
return new UPCReader().decode(image, hints);
} catch (ReaderException e) {
} catch (ReaderException re) {
savedRE = re;
}
}
@ -65,11 +67,12 @@ public final class MultiFormatReader implements Reader {
if (tryQR) {
try {
return new QRCodeReader().decode(image, hints);
} catch (ReaderException e) {
} catch (ReaderException re) {
savedRE = re;
}
}
throw new ReaderException("Could not locate and decode a barcode in the image");
throw savedRE;
}
}