diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index 6821dfcd7..ae7d9f551 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -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); + 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 - } + // 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 + } /** *

This method traces a line from a point in the image, in the direction towards another point. diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java index 608058558..2901ac1eb 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox3TestCase.java @@ -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); } }