mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
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:
parent
28ea8e02f0
commit
d1d7e96238
|
@ -52,13 +52,6 @@ public final class DecodeHintType {
|
||||||
*/
|
*/
|
||||||
public static final DecodeHintType TRY_HARDER = new 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() {
|
private DecodeHintType() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,23 +79,12 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
int middle = height >> 1;
|
int middle = height >> 1;
|
||||||
int rowStep = Math.max(1, height >> (tryHarder ? 7 : 4));
|
int rowStep = Math.max(1, height >> (tryHarder ? 7 : 4));
|
||||||
int maxLines;
|
int maxLines;
|
||||||
//if (tryHarder || barcodesToSkip > 0) {
|
|
||||||
if (tryHarder) {
|
if (tryHarder) {
|
||||||
maxLines = height; // Look at the whole image; looking for more than one barcode
|
maxLines = height; // Look at the whole image; looking for more than one barcode
|
||||||
} else {
|
} else {
|
||||||
maxLines = 7;
|
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++) {
|
for (int x = 0; x < maxLines; x++) {
|
||||||
|
|
||||||
// Scanning from the middle out. Determine which row we're looking at next:
|
// 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":
|
// We may try twice for each row, if "trying harder":
|
||||||
for (int attempt = 0; attempt < 2; attempt++) {
|
for (int attempt = 0; attempt < 2; attempt++) {
|
||||||
|
|
||||||
if (attempt == 1) { // trying again?
|
if (attempt == 1) { // trying again?
|
||||||
if (tryHarder) { // only if "trying harder"
|
if (tryHarder) { // only if "trying harder"
|
||||||
row.reverse(); // reverse the row and continue
|
row.reverse(); // reverse the row and continue
|
||||||
|
@ -125,58 +113,21 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Look for a barcode
|
// Look for a barcode
|
||||||
Result result = decodeRow(rowNumber, row, hints);
|
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
|
// We found our barcode
|
||||||
if (attempt == 1) {
|
if (attempt == 1) {
|
||||||
// But it was upside down, so note that
|
// But it was upside down, so note that
|
||||||
result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
|
result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
} catch (ReaderException re) {
|
} catch (ReaderException re) {
|
||||||
// continue -- just couldn't decode this row
|
// continue -- just couldn't decode this row
|
||||||
if (skippingSomeBarcodes) {
|
|
||||||
if (isAbove) {
|
|
||||||
lastResultAboveText = null;
|
|
||||||
} else {
|
|
||||||
lastResultBelowText = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new ReaderException("No barcode found");
|
throw new ReaderException("No barcode found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue