mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 11:47:26 -08:00
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:
parent
5989e8209b
commit
3219223f9d
|
@ -52,6 +52,13 @@ 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() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,14 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
|
|
||||||
BitArray row = new BitArray(width);
|
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,
|
// 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
|
// 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,
|
// 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.
|
// that moving up and down by about 1/16 of the image is pretty good.
|
||||||
int middle = height >> 1;
|
int middle = height >> 1;
|
||||||
int rowStep = Math.max(1, height >> 4);
|
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++) {
|
for (int x = 0; x < maxLines; x++) {
|
||||||
|
|
||||||
int rowStepsAboveOrBelow = (x + 1) >> 1;
|
int rowStepsAboveOrBelow = (x + 1) >> 1;
|
||||||
|
@ -81,12 +94,22 @@ public abstract class AbstractOneDReader implements OneDReader {
|
||||||
image.getBlackRow(rowNumber, row, 0, width);
|
image.getBlackRow(rowNumber, row, 0, width);
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (ReaderException re) {
|
||||||
if (tryHarder) {
|
if (tryHarder) {
|
||||||
row.reverse(); // try scanning the row backwards
|
row.reverse(); // try scanning the row backwards
|
||||||
try {
|
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) {
|
} catch (ReaderException re2) {
|
||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue