From: srowen Date: Thu, 13 Mar 2008 19:32:08 +0000 (+0000) Subject: Trying out a new user-requested decode hint, allowing a caller to skip the first... X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=925ce2e80f7be57748ce4f414bda5296e717bf0d;p=zxing.git Trying out a new user-requested decode hint, allowing a caller to skip the first n barcodes found. git-svn-id: http://zxing.googlecode.com/svn/trunk@276 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/DecodeHintType.java b/core/src/com/google/zxing/DecodeHintType.java index a8e1c839..20c30c09 100644 --- a/core/src/com/google/zxing/DecodeHintType.java +++ b/core/src/com/google/zxing/DecodeHintType.java @@ -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() { } diff --git a/core/src/com/google/zxing/oned/AbstractOneDReader.java b/core/src/com/google/zxing/oned/AbstractOneDReader.java index b30f5f34..415bd7b7 100644 --- a/core/src/com/google/zxing/oned/AbstractOneDReader.java +++ b/core/src/com/google/zxing/oned/AbstractOneDReader.java @@ -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 }