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,
// 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;
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
}