From fc2f28080d72f155aa013704b597d63cc1ff2182 Mon Sep 17 00:00:00 2001 From: srowen Date: Wed, 19 Mar 2008 17:10:58 +0000 Subject: [PATCH] Take small advantage of "TRY_HARDER" in QR code decoder git-svn-id: https://zxing.googlecode.com/svn/trunk@299 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../src/com/google/zxing/qrcode/QRCodeReader.java | 2 +- .../google/zxing/qrcode/detector/Detector.java | 15 ++++++++++++++- .../qrcode/detector/FinderPatternFinder.java | 7 +++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/src/com/google/zxing/qrcode/QRCodeReader.java b/core/src/com/google/zxing/qrcode/QRCodeReader.java index 34fe999bf..c36fe877d 100644 --- a/core/src/com/google/zxing/qrcode/QRCodeReader.java +++ b/core/src/com/google/zxing/qrcode/QRCodeReader.java @@ -61,7 +61,7 @@ public final class QRCodeReader implements Reader { decoderResult = decoder.decode(bits); points = NO_POINTS; } else { - DetectorResult result = new Detector(image).detect(); + DetectorResult result = new Detector(image).detect(hints); decoderResult = decoder.decode(result.getBits()); points = result.getPoints(); } diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index fad8b061b..37d3bd342 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -25,6 +25,8 @@ import com.google.zxing.common.DetectorResult; import com.google.zxing.common.GridSampler; import com.google.zxing.qrcode.decoder.Version; +import java.util.Hashtable; + /** *

Encapsulates logic that can detect a QR Code in an image, even if the QR Code * is rotated or skewed, or partially obscured.

@@ -46,6 +48,17 @@ public final class Detector { * @throws ReaderException if no QR Code can be found */ public DetectorResult detect() throws ReaderException { + return detect(null); + } + + /** + *

Detects a QR Code in an image, simply.

+ * + * @param hints optional hints to detector + * @return {@link DetectorResult} encapsulating results of detecting a QR Code + * @throws ReaderException if no QR Code can be found + */ + public DetectorResult detect(Hashtable hints) throws ReaderException { MonochromeBitmapSource image = this.image; if (!BlackPointEstimationMethod.TWO_D_SAMPLING.equals(image.getLastEstimationMethod())) { @@ -53,7 +66,7 @@ public final class Detector { } FinderPatternFinder finder = new FinderPatternFinder(image); - FinderPatternInfo info = finder.find(); + FinderPatternInfo info = finder.find(hints); FinderPattern topLeft = info.getTopLeft(); FinderPattern topRight = info.getTopRight(); diff --git a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java index 91f847382..4bc33d443 100755 --- a/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/FinderPatternFinder.java @@ -16,6 +16,7 @@ package com.google.zxing.qrcode.detector; +import com.google.zxing.DecodeHintType; import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.ReaderException; import com.google.zxing.ResultPoint; @@ -23,6 +24,7 @@ import com.google.zxing.common.BitArray; import com.google.zxing.common.Collections; import com.google.zxing.common.Comparator; +import java.util.Hashtable; import java.util.Vector; /** @@ -52,7 +54,8 @@ final class FinderPatternFinder { this.possibleCenters = new Vector(); } - FinderPatternInfo find() throws ReaderException { + FinderPatternInfo find(Hashtable hints) throws ReaderException { + boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); int maxI = image.getHeight(); int maxJ = image.getWidth(); // We are looking for black/white/black/white/black modules in @@ -61,7 +64,7 @@ final class FinderPatternFinder { boolean done = false; // We can afford to examine every few lines until we've started finding // the patterns - int iSkip = BIG_SKIP; + int iSkip = tryHarder ? 1 : BIG_SKIP; for (int i = iSkip - 1; i < maxI && !done; i += iSkip) { // Get a row of black/white values BitArray blackRow = image.getBlackRow(i, null, 0, maxJ);