Refactored the MonochromeBitmapSource class hierarchy into LuminanceSource, Binarizer...
[zxing.git] / core / src / com / google / zxing / qrcode / detector / Detector.java
index 0f28ec9..9a2c64f 100644 (file)
 
 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 {
    * <p>Computes an average estimated module size based on estimated derived from the positions
    * of the three finder patterns.</p>
    */
-  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.</p>
    */
-  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.</p>
    */
-  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 {
    * <p>This is used when figuring out how wide a finder pattern is, when the finder pattern
    * may be skewed or rotated.</p>
    */
-  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);