X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Foned%2FMultiFormatUPCEANReader.java;h=e561f59806e8f0578efe6b545ed1a2ba9d3fd41c;hb=15c31851811509205c843513211574f3b80db110;hp=03b0537936d35275aba9ac15d4178297187e4a19;hpb=1170ad08b19f495ae38daf72a816ac60e5606aae;p=zxing.git diff --git a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java index 03b05379..e561f598 100644 --- a/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java +++ b/core/src/com/google/zxing/oned/MultiFormatUPCEANReader.java @@ -18,6 +18,8 @@ package com.google.zxing.oned; import com.google.zxing.BarcodeFormat; import com.google.zxing.DecodeHintType; +import com.google.zxing.NotFoundException; +import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.common.BitArray; @@ -27,17 +29,18 @@ import java.util.Vector; /** *

A reader that can read all available UPC/EAN formats. If a caller wants to try to - * read all such formats, it is most efficent to use this implementation rather than invoke + * read all such formats, it is most efficient to use this implementation rather than invoke * individual readers.

* * @author Sean Owen */ -public final class MultiFormatUPCEANReader extends AbstractOneDReader { +public final class MultiFormatUPCEANReader extends OneDReader { private final Vector readers; public MultiFormatUPCEANReader(Hashtable hints) { - Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS); + Vector possibleFormats = hints == null ? null : + (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS); readers = new Vector(); if (possibleFormats != null) { if (possibleFormats.contains(BarcodeFormat.EAN_13)) { @@ -60,15 +63,15 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader { } } - public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws ReaderException { + public Result decodeRow(int rowNumber, BitArray row, Hashtable hints) throws NotFoundException { // Compute this location once and reuse it on multiple implementations - int[] startGuardPattern = AbstractUPCEANReader.findStartGuardPattern(row); + int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row); int size = readers.size(); for (int i = 0; i < size; i++) { UPCEANReader reader = (UPCEANReader) readers.elementAt(i); Result result; try { - result = reader.decodeRow(rowNumber, row, startGuardPattern); + result = reader.decodeRow(rowNumber, row, startGuardPattern, hints); } catch (ReaderException re) { continue; } @@ -82,13 +85,29 @@ public final class MultiFormatUPCEANReader extends AbstractOneDReader { // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A // result if appropriate. - if (result.getBarcodeFormat().equals(BarcodeFormat.EAN_13) && result.getText().charAt(0) == '0') { + // + // But, don't return UPC-A if UPC-A was not a requested format! + boolean ean13MayBeUPCA = + BarcodeFormat.EAN_13.equals(result.getBarcodeFormat()) && + result.getText().charAt(0) == '0'; + Vector possibleFormats = hints == null ? null : (Vector) hints.get(DecodeHintType.POSSIBLE_FORMATS); + boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A); + + if (ean13MayBeUPCA && canReturnUPCA) { return new Result(result.getText().substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A); } return result; } - throw ReaderException.getInstance(); + throw NotFoundException.getNotFoundInstance(); + } + + public void reset() { + int size = readers.size(); + for (int i = 0; i < size; i++) { + Reader reader = (Reader) readers.elementAt(i); + reader.reset(); + } } }