X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fqrcode%2Fdetector%2FDetector.java;fp=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fqrcode%2Fdetector%2FDetector.java;h=9a2c64f4b8c2b9328a5a23a4c63ae9a31ead1b4e;hb=afc10a58143505842f5a3433ba5675d45346f0be;hp=0f28ec9bcd54af0a9f3aac81fbfbed243865d236;hpb=c12299981507dba0a690febd9a06c528f59f8b1b;p=zxing.git diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index 0f28ec9b..9a2c64f4 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -16,10 +16,9 @@ package com.google.zxing.qrcode.detector; -import com.google.zxing.BlackPointEstimationMethod; -import com.google.zxing.MonochromeBitmapSource; import com.google.zxing.ReaderException; import com.google.zxing.ResultPoint; +import com.google.zxing.BinaryBitmap; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DetectorResult; import com.google.zxing.common.GridSampler; @@ -35,13 +34,13 @@ import java.util.Hashtable; */ public class Detector { - private final MonochromeBitmapSource image; + private final BinaryBitmap image; - public Detector(MonochromeBitmapSource image) { + public Detector(BinaryBitmap image) { this.image = image; } - protected MonochromeBitmapSource getImage() { + protected BinaryBitmap getImage() { return image; } @@ -64,11 +63,7 @@ public class Detector { */ public DetectorResult detect(Hashtable hints) throws ReaderException { - MonochromeBitmapSource image = this.image; - if (!BlackPointEstimationMethod.TWO_D_SAMPLING.equals(image.getLastEstimationMethod())) { - image.estimateBlackPoint(BlackPointEstimationMethod.TWO_D_SAMPLING, 0); - } - + BinaryBitmap image = this.image; FinderPatternFinder finder = new FinderPatternFinder(image); FinderPatternInfo info = finder.find(hints); @@ -129,7 +124,7 @@ public class Detector { return new DetectorResult(bits, points); } - private static BitMatrix sampleGrid(MonochromeBitmapSource image, + private static BitMatrix sampleGrid(BinaryBitmap image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, @@ -202,7 +197,8 @@ public class Detector { *

Computes an average estimated module size based on estimated derived from the positions * of the three finder patterns.

*/ - private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) { + private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, + ResultPoint bottomLeft) throws ReaderException { // Take the average return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f; @@ -213,7 +209,8 @@ public class Detector { * {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the * width of each, measuring along the axis between their centers.

*/ - private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) { + private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) + throws ReaderException { float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(), (int) pattern.getY(), (int) otherPattern.getX(), @@ -238,7 +235,8 @@ public class Detector { * a finder pattern by looking for a black-white-black run from the center in the direction * of another point (another finder pattern center), and in the opposite direction too.

*/ - private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) { + private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) + throws ReaderException { float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); @@ -269,7 +267,8 @@ public class Detector { *

This is used when figuring out how wide a finder pattern is, when the finder pattern * may be skewed or rotated.

*/ - private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) { + private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) + throws ReaderException { // Mild variant of Bresenham's algorithm; // see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);