mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
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:
parent
fd68032e1a
commit
ac3e9d3335
|
@ -26,8 +26,6 @@ import java.util.Hashtable;
|
||||||
* an image, and then decode what it finds. This implementation supports all
|
* an image, and then decode what it finds. This implementation supports all
|
||||||
* barcode formats that this library supports.</p>
|
* 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)
|
* @author srowen@google.com (Sean Owen), dswitkin@google.com (Daniel Switkin)
|
||||||
*/
|
*/
|
||||||
public final class MultiFormatReader implements Reader {
|
public final class MultiFormatReader implements Reader {
|
||||||
|
@ -39,25 +37,29 @@ public final class MultiFormatReader implements Reader {
|
||||||
public Result decode(MonochromeBitmapSource image, Hashtable hints)
|
public Result decode(MonochromeBitmapSource image, Hashtable hints)
|
||||||
throws ReaderException {
|
throws ReaderException {
|
||||||
Hashtable possibleFormats = hints == null ? null : (Hashtable) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
Hashtable possibleFormats = hints == null ? null : (Hashtable) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
||||||
boolean tryUPC = false;
|
|
||||||
boolean tryQR = false;
|
|
||||||
|
|
||||||
|
boolean tryUPC;
|
||||||
|
boolean tryQR;
|
||||||
if (possibleFormats == null) {
|
if (possibleFormats == null) {
|
||||||
tryUPC = true;
|
tryUPC = true;
|
||||||
tryQR = true;
|
tryQR = true;
|
||||||
} else if (possibleFormats.contains(BarcodeFormat.UPC)) {
|
|
||||||
tryUPC = true;
|
|
||||||
} else if (possibleFormats.contains(BarcodeFormat.QR_CODE)) {
|
|
||||||
tryQR = true;
|
|
||||||
} else {
|
} else {
|
||||||
|
tryUPC = possibleFormats.contains(BarcodeFormat.UPC);
|
||||||
|
tryQR = possibleFormats.contains(BarcodeFormat.QR_CODE);
|
||||||
|
}
|
||||||
|
if (!(tryUPC || tryQR)) {
|
||||||
throw new ReaderException("POSSIBLE_FORMATS specifies no supported types");
|
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.
|
// UPC is much faster to decode, so try it first.
|
||||||
if (tryUPC) {
|
if (tryUPC) {
|
||||||
try {
|
try {
|
||||||
return new UPCReader().decode(image, hints);
|
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) {
|
if (tryQR) {
|
||||||
try {
|
try {
|
||||||
return new QRCodeReader().decode(image, hints);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue