From 93054c2213b1736f60e5ddbcd8012f8bc5d444e5 Mon Sep 17 00:00:00 2001 From: srowen Date: Thu, 20 Mar 2008 17:01:19 +0000 Subject: [PATCH] Restored SKIP_N_BARCODES functionality and corrected a logic error git-svn-id: https://zxing.googlecode.com/svn/trunk@304 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- core/src/com/google/zxing/DecodeHintType.java | 1 - .../google/zxing/oned/AbstractOneDReader.java | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/core/src/com/google/zxing/DecodeHintType.java b/core/src/com/google/zxing/DecodeHintType.java index 4d48a4a22..20c30c09d 100644 --- a/core/src/com/google/zxing/DecodeHintType.java +++ b/core/src/com/google/zxing/DecodeHintType.java @@ -56,7 +56,6 @@ public final class 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}. - * @deprecated */ public static final DecodeHintType SKIP_N_BARCODES = new DecodeHintType(); diff --git a/core/src/com/google/zxing/oned/AbstractOneDReader.java b/core/src/com/google/zxing/oned/AbstractOneDReader.java index 66eee2b03..5df8478d4 100644 --- a/core/src/com/google/zxing/oned/AbstractOneDReader.java +++ b/core/src/com/google/zxing/oned/AbstractOneDReader.java @@ -69,13 +69,13 @@ 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(); - // } - //} + 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 @@ -94,7 +94,7 @@ public abstract class AbstractOneDReader implements OneDReader { maxLines = 7; } - //Result lastResult = null; + Hashtable lastResults = null; for (int x = 0; x < maxLines; x++) { @@ -131,22 +131,25 @@ public abstract class AbstractOneDReader implements OneDReader { // Look for a barcode Result result = decodeRow(rowNumber, row, hints); - //if (lastResult != null && lastResult.getText().equals(result.getText())) { + if (lastResults != null && lastResults.containsKey(result.getText())) { // Just saw the last barcode again, proceed - //continue; - //} + continue; + } - //if (barcodesToSkip > 0) { // See if we should skip and keep looking - // barcodesToSkip--; - // lastResult = result; // Remember what we just saw - //} else { + if (barcodesToSkip > 0) { // See if we should skip and keep looking + barcodesToSkip--; + if (lastResults == null) { + lastResults = new Hashtable(3); + } + lastResults.put(result.getText(), Boolean.TRUE); // Remember what we just saw + } else { // We found our barcode if (attempt == 1) { // But it was upside down, so note that result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180)); } return result; - //} + } } catch (ReaderException re) { // continue -- just couldn't decode this row