Trying out a new user-requested decode hint, allowing a caller to skip the first n barcodes found.

git-svn-id: https://zxing.googlecode.com/svn/trunk@276 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2008-03-13 19:32:08 +00:00
parent 5989e8209b
commit 3219223f9d
2 changed files with 33 additions and 3 deletions

View file

@ -52,6 +52,13 @@ 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

@ -59,6 +59,14 @@ public abstract class AbstractOneDReader implements OneDReader {
BitArray row = new BitArray(width);
int barcodesToSkip = 0;
if (hints != null) {
Integer number = (Integer) hints.get(DecodeHintType.SKIP_N_BARCODES);
if (number != null) {
barcodesToSkip = number.intValue();
}
}
// We're going to examine rows from the middle outward, searching alternately above and below the middle,
// and farther out each time. rowStep is the number of rows between each successive attempt above and below
// the middle. So we'd scan row middle, then middle - rowStep, then middle + rowStep,
@ -67,7 +75,12 @@ public abstract class AbstractOneDReader implements OneDReader {
// that moving up and down by about 1/16 of the image is pretty good.
int middle = height >> 1;
int rowStep = Math.max(1, height >> 4);
int maxLines = tryHarder ? 15 : 7;
int maxLines;
if (barcodesToSkip > 0) {
maxLines = height; // Look at the whole image; looking for more than one barcode
} else {
maxLines = tryHarder ? 15 : 7; // If "trying harder", examine more lines
}
for (int x = 0; x < maxLines; x++) {
int rowStepsAboveOrBelow = (x + 1) >> 1;
@ -81,12 +94,22 @@ public abstract class AbstractOneDReader implements OneDReader {
image.getBlackRow(rowNumber, row, 0, width);
try {
return decodeRow(rowNumber, row, hints);
Result result = decodeRow(rowNumber, row, hints);
if (barcodesToSkip > 0) { // See if we should skip and keep looking
barcodesToSkip--;
} else {
return result;
}
} catch (ReaderException re) {
if (tryHarder) {
row.reverse(); // try scanning the row backwards
try {
return decodeRow(rowNumber, row, hints);
Result result = decodeRow(rowNumber, row, hints);
if (barcodesToSkip > 0) { // See if we should skip and keep looking
barcodesToSkip--;
} else {
return result;
}
} catch (ReaderException re2) {
// continue
}