Fixed an old misspelling and a few tiny tweaks
[zxing.git] / core / src / com / google / zxing / qrcode / detector / FinderPatternFinder.java
index c8370d5..e0b0dc9 100755 (executable)
@@ -19,10 +19,10 @@ package com.google.zxing.qrcode.detector;
 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
 import com.google.zxing.common.Collections;\r
 import com.google.zxing.common.Comparator;\r
-import com.google.zxing.common.GenericResultPoint;\r
 \r
 import java.util.Hashtable;\r
 import java.util.Vector;\r
@@ -35,11 +35,11 @@ import java.util.Vector;
  *\r
  * @author Sean Owen\r
  */\r
-final class FinderPatternFinder {\r
+public class FinderPatternFinder {\r
 \r
   private static final int CENTER_QUORUM = 2;\r
-  private static final int MIN_SKIP = 3; // 1 pixel/module times 3 modules/center\r
-  private static final int MAX_MODULES = 57; // support up to version 10 for mobile clients\r
+  protected static final int MIN_SKIP = 3; // 1 pixel/module times 3 modules/center\r
+  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
@@ -52,12 +52,20 @@ final class FinderPatternFinder {
    *\r
    * @param image image to search\r
    */\r
-  FinderPatternFinder(MonochromeBitmapSource image) {\r
+  public FinderPatternFinder(MonochromeBitmapSource image) {\r
     this.image = image;\r
     this.possibleCenters = new Vector();\r
     this.crossCheckStateCount = new int[5];\r
   }\r
 \r
+  protected MonochromeBitmapSource getImage() {\r
+    return image;\r
+  }\r
+\r
+  protected Vector getPossibleCenters() {\r
+    return possibleCenters;\r
+  }\r
+\r
   FinderPatternInfo find(Hashtable hints) throws ReaderException {\r
     boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);\r
     int maxI = image.getHeight();\r
@@ -69,7 +77,7 @@ final class FinderPatternFinder {
     // image, and then account for the center being 3 modules in size. This gives the smallest\r
     // number of pixels the center could be, so skip this often. When trying harder, look for all\r
     // QR versions regardless of how dense they are.\r
-    int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3);\r
+    int iSkip = (3 * maxI) / (4 * MAX_MODULES);\r
     if (iSkip < MIN_SKIP || tryHarder) {\r
       iSkip = MIN_SKIP;\r
     }\r
@@ -103,7 +111,7 @@ final class FinderPatternFinder {
                   // expensive and didn't improve performance.\r
                   iSkip = 2;\r
                   if (hasSkipped) {\r
-                    done = haveMulitplyConfirmedCenters();\r
+                    done = haveMultiplyConfirmedCenters();\r
                   } else {\r
                     int rowSkip = findRowSkip();\r
                     if (rowSkip > stateCount[2]) {\r
@@ -155,14 +163,14 @@ final class FinderPatternFinder {
           iSkip = stateCount[0];\r
           if (hasSkipped) {\r
             // Found a third one\r
-            done = haveMulitplyConfirmedCenters();\r
+            done = haveMultiplyConfirmedCenters();\r
           }\r
         }\r
       }\r
     }\r
 \r
     FinderPattern[] patternInfo = selectBestPatterns();\r
-    GenericResultPoint.orderBestPatterns(patternInfo);\r
+    ResultPoint.orderBestPatterns(patternInfo);\r
 \r
     return new FinderPatternInfo(patternInfo);\r
   }\r
@@ -180,7 +188,7 @@ final class FinderPatternFinder {
    * @return true iff the proportions of the counts is close enough to the 1/1/3/1/1 ratios\r
    *         used by finder patterns to be considered a match\r
    */\r
-  private static boolean foundPatternCross(int[] stateCount) {\r
+  protected static boolean foundPatternCross(int[] stateCount) {\r
     int totalModuleSize = 0;\r
     for (int i = 0; i < 5; i++) {\r
       int count = stateCount[i];\r
@@ -370,7 +378,7 @@ final 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
-  private boolean handlePossibleCenter(int[] stateCount,\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
@@ -438,7 +446,7 @@ final class FinderPatternFinder {
    *         at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the\r
    *         candidates is "pretty similar"\r
    */\r
-  private boolean haveMulitplyConfirmedCenters() {\r
+  private boolean haveMultiplyConfirmedCenters() {\r
     int confirmedCount = 0;\r
     float totalModuleSize = 0.0f;\r
     int max = possibleCenters.size();\r
@@ -456,13 +464,13 @@ final class FinderPatternFinder {
     // and that we need to keep looking. We detect this by asking if the estimated module sizes\r
     // vary too much. We arbitrarily say that when the total deviation from average exceeds\r
     // 15% of the total module size estimates, it's too much.\r
-    float average = totalModuleSize / max;\r
+    float average = totalModuleSize / (float) max;\r
     float totalDeviation = 0.0f;\r
     for (int i = 0; i < max; i++) {\r
       FinderPattern pattern = (FinderPattern) possibleCenters.elementAt(i);\r
       totalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average);\r
     }\r
-    return totalDeviation <= 0.15f * totalModuleSize;\r
+    return totalDeviation <= 0.05f * totalModuleSize;\r
   }\r
 \r
   /**\r