Fix/improvement from Jiayong
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 11 Jan 2010 06:08:20 +0000 (06:08 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Mon, 11 Jan 2010 06:08:20 +0000 (06:08 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1184 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/qrcode/detector/Detector.java
core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java

index 6821dfc..ae7d9f5 100644 (file)
@@ -255,24 +255,33 @@ public class Detector {
    */
   private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) {
 
-    float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
-
-    // Now count other way -- don't run off image though of course
-    int otherToX = fromX - (toX - fromX);
-    if (otherToX < 0) {
-      otherToX = 0;
-    } else if (otherToX >= image.getWidth()) {
-      otherToX = image.getWidth() - 1;
-    }
-    int otherToY = fromY - (toY - fromY);
-    if (otherToY < 0) {
-      otherToY = 0;
-    } else if (otherToY >= image.getHeight()) {
-      otherToY = image.getHeight() - 1;
-    }
-    result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
-    return result - 1.0f; // -1 because we counted the middle pixel twice
-  }
+   float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
+
+   // Now count other way -- don't run off image though of course
+   float scale = 1.0f;
+   int otherToX = fromX - (toX - fromX);
+   if (otherToX < 0) {
+     scale = (float) fromX / (float) (fromX - otherToX);
+     otherToX = 0;
+   } else if (otherToX >= image.getWidth()) {
+     scale = (float) (image.getWidth() - 1 - fromX) / (float) (otherToX - fromX);
+     otherToX = image.getWidth() - 1;
+   }
+   int otherToY = (int) (fromY - (toY - fromY) * scale);
+
+   scale = 1.0f;
+   if (otherToY < 0) {
+     scale = (float) fromY / (float) (fromY - otherToY);
+     otherToY = 0;
+   } else if (otherToY >= image.getHeight()) {
+     scale = (float) (image.getHeight() - 1 - fromY) / (float) (otherToY - fromY);
+     otherToY = image.getHeight() - 1;
+   }
+   otherToX = (int) (fromX + (otherToX - fromX) * scale);
+
+   result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
+   return result - 1.0f; // -1 because we counted the middle pixel twice
+ }
 
   /**
    * <p>This method traces a line from a point in the image, in the direction towards another point.
index 6080585..2901ac1 100644 (file)
@@ -28,9 +28,9 @@ public final class QRCodeBlackBox3TestCase extends AbstractBlackBoxTestCase {
   public QRCodeBlackBox3TestCase() {
     super("test/data/blackbox/qrcode-3", new MultiFormatReader(), BarcodeFormat.QR_CODE);
     addTest(36, 36, 0.0f);
-    addTest(37, 37, 90.0f);
-    addTest(35, 35, 180.0f);
-    addTest(36, 36, 270.0f);
+    addTest(38, 38, 90.0f);
+    addTest(36, 36, 180.0f);
+    addTest(37, 37, 270.0f);
   }
 
 }