Refactored the MonochromeBitmapSource class hierarchy into LuminanceSource, Binarizer...
[zxing.git] / core / src / com / google / zxing / qrcode / detector / FinderPatternFinder.java
index 1540402..70d9a39 100755 (executable)
@@ -16,8 +16,8 @@
 \r
 package com.google.zxing.qrcode.detector;\r
 \r
+import com.google.zxing.BinaryBitmap;\r
 import com.google.zxing.DecodeHintType;\r
-import com.google.zxing.MonochromeBitmapSource;\r
 import com.google.zxing.ReaderException;\r
 import com.google.zxing.ResultPoint;\r
 import com.google.zxing.common.BitArray;\r
@@ -42,7 +42,7 @@ public class FinderPatternFinder {
   protected static final int MAX_MODULES = 57; // support up to version 10 for mobile clients\r
   private static final int INTEGER_MATH_SHIFT = 8;\r
 \r
-  private final MonochromeBitmapSource image;\r
+  private final BinaryBitmap image;\r
   private final Vector possibleCenters;\r
   private boolean hasSkipped;\r
   private final int[] crossCheckStateCount;\r
@@ -52,13 +52,13 @@ public class FinderPatternFinder {
    *\r
    * @param image image to search\r
    */\r
-  public FinderPatternFinder(MonochromeBitmapSource image) {\r
+  public FinderPatternFinder(BinaryBitmap image) {\r
     this.image = image;\r
     this.possibleCenters = new Vector();\r
     this.crossCheckStateCount = new int[5];\r
   }\r
 \r
-  protected MonochromeBitmapSource getImage() {\r
+  protected BinaryBitmap getImage() {\r
     return image;\r
   }\r
 \r
@@ -230,8 +230,9 @@ public class FinderPatternFinder {
    * observed in any reading state, based on the results of the horizontal scan\r
    * @return vertical center of finder pattern, or {@link Float#NaN} if not found\r
    */\r
-  private float crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal) {\r
-    MonochromeBitmapSource image = this.image;\r
+  private float crossCheckVertical(int startI, int centerJ, int maxCount,\r
+      int originalStateCountTotal) throws ReaderException {\r
+    BinaryBitmap image = this.image;\r
 \r
     int maxI = image.getHeight();\r
     int[] stateCount = getCrossCheckStateCount();\r
@@ -287,7 +288,8 @@ public class FinderPatternFinder {
 \r
     // If we found a finder-pattern-like section, but its size is more than 20% different than\r
     // the original, assume it's a false positive\r
-    int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r
+    int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] +\r
+        stateCount[4];\r
     if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) {\r
       return Float.NaN;\r
     }\r
@@ -300,8 +302,9 @@ public class FinderPatternFinder {
    * except it reads horizontally instead of vertically. This is used to cross-cross\r
    * check a vertical cross check and locate the real center of the alignment pattern.</p>\r
    */\r
-  private float crossCheckHorizontal(int startJ, int centerI, int maxCount, int originalStateCountTotal) {\r
-    MonochromeBitmapSource image = this.image;\r
+  private float crossCheckHorizontal(int startJ, int centerI, int maxCount,\r
+      int originalStateCountTotal) throws ReaderException {\r
+    BinaryBitmap image = this.image;\r
 \r
     int maxJ = image.getWidth();\r
     int[] stateCount = getCrossCheckStateCount();\r
@@ -354,7 +357,8 @@ public class FinderPatternFinder {
 \r
     // If we found a finder-pattern-like section, but its size is significantly different than\r
     // the original, assume it's a false positive\r
-    int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r
+    int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] +\r
+        stateCount[4];\r
     if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) {\r
       return Float.NaN;\r
     }\r
@@ -378,10 +382,9 @@ public class FinderPatternFinder {
    * @param j end of possible finder pattern in row\r
    * @return true if a finder pattern candidate was found this time\r
    */\r
-  protected boolean handlePossibleCenter(int[] stateCount,\r
-                                       int i,\r
-                                       int j) {\r
-    int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];\r
+  protected boolean handlePossibleCenter(int[] stateCount, int i, int j) throws ReaderException {\r
+    int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] +\r
+        stateCount[4];\r
     float centerJ = centerFromEnd(stateCount, j);\r
     float centerI = crossCheckVertical(i, (int) centerJ, stateCount[2], stateCountTotal);\r
     if (!Float.isNaN(centerI)) {\r