At last, removing SKIP_N_BARCODES and separating this logic out in a way that individual projects can implement it on their own. It's a bit too onerous and project-specific to live on in the main code.

git-svn-id: https://zxing.googlecode.com/svn/trunk@340 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-04-03 16:39:44 +00:00
parent 28ea8e02f0
commit d1d7e96238
2 changed files with 5 additions and 61 deletions

View file

@ -52,13 +52,6 @@ public final class DecodeHintType {
*/
public static final DecodeHintType TRY_HARDER = new DecodeHintType();
/**
* Skip the first n barcodes found. Currently applies only to 1D formats. This
* enables a caller to repeatedly decode and find multiple barcodes. Maps
* to an {@link Integer}.
*/
public static final DecodeHintType SKIP_N_BARCODES = new DecodeHintType();
private DecodeHintType() {
}

View file

@ -79,23 +79,12 @@ public abstract class AbstractOneDReader implements OneDReader {
int middle = height >> 1;
int rowStep = Math.max(1, height >> (tryHarder ? 7 : 4));
int maxLines;
//if (tryHarder || barcodesToSkip > 0) {
if (tryHarder) {
maxLines = height; // Look at the whole image; looking for more than one barcode
} else {
maxLines = 7;
}
// Remember last barcode to avoid thinking we've found a new barcode when
// we just rescanned the last one. Actually remember two, the last one
// found above and below.
String lastResultAboveText = null;
String lastResultBelowText = null;
boolean skippingSomeBarcodes =
hints != null &&
hints.containsKey(DecodeHintType.SKIP_N_BARCODES) &&
((Integer) hints.get(DecodeHintType.SKIP_N_BARCODES)).intValue() > 0;
for (int x = 0; x < maxLines; x++) {
// Scanning from the middle out. Determine which row we're looking at next:
@ -117,7 +106,6 @@ public abstract class AbstractOneDReader implements OneDReader {
// We may try twice for each row, if "trying harder":
for (int attempt = 0; attempt < 2; attempt++) {
if (attempt == 1) { // trying again?
if (tryHarder) { // only if "trying harder"
row.reverse(); // reverse the row and continue
@ -125,58 +113,21 @@ public abstract class AbstractOneDReader implements OneDReader {
break;
}
}
try {
// Look for a barcode
Result result = decodeRow(rowNumber, row, hints);
String resultText = result.getText();
// make sure we terminate inner loop after this because we found something
attempt = 1;
// See if we should skip and keep looking
if (( isAbove && resultText.equals(lastResultAboveText)) ||
(!isAbove && resultText.equals(lastResultBelowText))) {
// Just saw the last barcode again, proceed
continue;
}
if (skippingSomeBarcodes) {
int oldValue = ((Integer) hints.get(DecodeHintType.SKIP_N_BARCODES)).intValue();
if (oldValue > 1) {
hints.put(DecodeHintType.SKIP_N_BARCODES, new Integer(oldValue - 1));
} else {
hints.remove(DecodeHintType.SKIP_N_BARCODES);
skippingSomeBarcodes = false;
}
if (isAbove) {
lastResultAboveText = resultText;
} else {
lastResultBelowText = resultText;
}
} else {
// We found our barcode
if (attempt == 1) {
// But it was upside down, so note that
result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
}
return result;
}
} catch (ReaderException re) {
// continue -- just couldn't decode this row
if (skippingSomeBarcodes) {
if (isAbove) {
lastResultAboveText = null;
} else {
lastResultBelowText = null;
}
}
}
}
}
throw new ReaderException("No barcode found");
}