Better, still some bugs
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 9 Nov 2007 19:13:28 +0000 (19:13 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 9 Nov 2007 19:13:28 +0000 (19:13 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@22 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/qrcode/detector/DefaultGridSampler.java
core/src/com/google/zxing/qrcode/detector/PerspectiveTransform.java

index 4f6bbed..4b71ece 100644 (file)
@@ -74,9 +74,8 @@ public final class DefaultGridSampler extends GridSampler {
       // Quick check to see if points transformed to something inside the image;
       // sufficent to check the endpoints
       checkEndpoint(image, points);
-      for (int j = 0; j < dimension; j++) {
-        int offset = j << 1;
-        if (image.isBlack((int) points[offset], (int) points[offset + 1])) {
+      for (int j = 0; j < max; j += 2) {
+        if (image.isBlack((int) points[j], (int) points[j + 1])) {
           // Black(-ish) pixel
           bits.set(i, j);
         }
index c9e9820..f07f097 100644 (file)
@@ -27,9 +27,9 @@ final class PerspectiveTransform {
 \r
   private final float a11, a12, a13, a21, a22, a23, a31, a32, a33;\r
 \r
-  private PerspectiveTransform(float a11, float a12, float a13,\r
-                               float a21, float a22, float a23,\r
-                               float a31, float a32, float a33) {\r
+  private PerspectiveTransform(float a11, float a21, float a31,\r
+                               float a12, float a22, float a32,\r
+                               float a13, float a23, float a33) {\r
     this.a11 = a11;\r
     this.a12 = a12;\r
     this.a13 = a13;\r
@@ -49,16 +49,28 @@ final class PerspectiveTransform {
                                                            float x1p, float y1p,\r
                                                            float x2p, float y2p,\r
                                                            float x3p, float y3p) {\r
-    return quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3).times(\r
+    return\r
+        quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3).times(\r
         squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p));\r
   }\r
 \r
   void transformPoints(float[] points) {\r
-    for (int i = 0; i < points.length; i += 2) {\r
+    int max = points.length;\r
+    float a11 = this.a11;\r
+    float a12 = this.a12;\r
+    float a13 = this.a13;\r
+    float a21 = this.a21;\r
+    float a22 = this.a22;\r
+    float a23 = this.a23;\r
+         float a31 = this.a31;\r
+         float a32 = this.a32;\r
+         float a33 = this.a33;\r
+    for (int i = 0; i < max; i += 2) {\r
       float x = points[i];\r
       float y = points[i+1];\r
-      points[i] = a11*x + a12*y + a13;\r
-      points[i+1] = a21*x + a22*y + a23;\r
+           float denominator = a13*x + a23*y + a33;\r
+      points[i] = (a11*x + a21*y + a31) / denominator;\r
+      points[i+1] = (a12*x + a22*y + a32) / denominator;\r
     }\r
   }\r
 \r
@@ -76,15 +88,15 @@ final class PerspectiveTransform {
     float a13 = (dx3*dy2 - dx2*dy3) / denominator;\r
     float a23 = (dx1*dy3 - dx3*dy1) / denominator;\r
 \r
-    return new PerspectiveTransform(x1 - x0 + a13*x1,\r
-                                    y1 - y0 + a13*y1,\r
-                                    a13,\r
-                                    x3 - x0 + a23*x3,\r
-                                    y3 - y0 + a23*y3,\r
-                                    a23,\r
-                                    x0,\r
-                                    y0,\r
-                                    1.0f);\r
+       return new PerspectiveTransform(x1 - x0 + a13*x1,\r
+                                  x3 - x0 + a23*x3,\r
+                                  x0,\r
+                                  y1 - y0 + a13*y1,\r
+                                  y3 - y0 + a23*y3,\r
+                                  y0,\r
+                                  a13,\r
+                                  a23,\r
+                                  1.0f);\r
   }\r
 \r
   private static PerspectiveTransform quadrilateralToSquare(float x0, float y0,\r
@@ -97,19 +109,19 @@ final class PerspectiveTransform {
 \r
   private PerspectiveTransform buildAdjoint() {\r
     // Adjoint is the transpose of the cofactor matrix:\r
-    return new PerspectiveTransform(a22*a33 - a23*a32,\r
-                                    a12*a33 - a13*a32,\r
-                                    a12*a23 - a13*a22,\r
-                                    a21*a33 - a23*a31,\r
-                                    a11*a33 - a13*a31,\r
-                                    a11*a23 - a13*a21,\r
-                                    a21*a32 - a22*a31,\r
-                                    a11*a32 - a12*a31,\r
-                                    a11*a22 - a12*a21);\r
+       return new PerspectiveTransform(a22*a33 - a23*a32,\r
+                                  a23*a31 - a21*a33,\r
+                                  a21*a32 - a22*a31,\r
+                                  a13*a32 - a12*a33,\r
+                                  a11*a33 - a13*a31,\r
+                                  a12*a31 - a11*a32,\r
+                                  a12*a23 - a13*a22,\r
+                                  a13*a21 - a11*a23,\r
+                                  a11*a22 - a12*a21);\r
   }\r
 \r
   private PerspectiveTransform times(PerspectiveTransform other) {\r
-    return new PerspectiveTransform(a11*other.a11 + a12*other.a21 + a13*other.a31,\r
+    return new PerspectiveTransform(a11*other.a11 + a21*other.a12 + a31*other.a13,\r
                                     a11*other.a12 + a12*other.a22 + a13*other.a32,\r
                                     a11*other.a13 + a12*other.a23 + a13*other.a33,\r
                                     a21*other.a11 + a22*other.a21 + a23*other.a31,\r