diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index 82d50a63c..b9d7f2c56 100644 --- a/core/src/com/google/zxing/qrcode/detector/Detector.java +++ b/core/src/com/google/zxing/qrcode/detector/Detector.java @@ -266,9 +266,9 @@ public class Detector { 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; + } else if (otherToX > image.getWidth()) { + scale = (float) (image.getWidth() - fromX) / (float) (otherToX - fromX); + otherToX = image.getWidth(); } int otherToY = (int) (fromY - (toY - fromY) * scale); @@ -276,14 +276,14 @@ public class Detector { 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; + } else if (otherToY > image.getHeight()) { + scale = (float) (image.getHeight() - fromY) / (float) (otherToY - fromY); + otherToY = image.getHeight(); } otherToX = (int) (fromX + (otherToX - fromX) * scale); result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); - return result - 1.0f; // -1 because we counted the middle pixel twice + return result; } /** @@ -330,6 +330,9 @@ public class Detector { if (state == 3) { // Found black, white, black, and stumbled back onto white; done int diffX = x - fromX; int diffY = y - fromY; + if (xstep < 0) { + diffX++; + } return (float) Math.sqrt((double) (diffX * diffX + diffY * diffY)); } error += dy; diff --git a/core/test/data/blackbox/qrcode-2/32.gif b/core/test/data/blackbox/qrcode-2/32.gif new file mode 100644 index 000000000..7bdbc7618 Binary files /dev/null and b/core/test/data/blackbox/qrcode-2/32.gif differ diff --git a/core/test/data/blackbox/qrcode-2/32.txt b/core/test/data/blackbox/qrcode-2/32.txt new file mode 100644 index 000000000..2b574b768 --- /dev/null +++ b/core/test/data/blackbox/qrcode-2/32.txt @@ -0,0 +1,12 @@ +BEGIN:VCARD +N:Kennedy;Steve +TEL:+44 (0)7775 755503 +ADR;HOME:;;Flat 2, 43 Howitt Road, Belsize Park;London;;NW34LU;UK +ORG:NetTek Ltd; +TITLE:Consultant +EMAIL:steve@nettek.co.uk +URL:www.nettek.co.uk +EMAIL;IM:MSN:steve@gbnet.net +NOTE:Testing 1 2 3 +BDAY:19611105 +END:VCARD \ No newline at end of file diff --git a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java index 80bac2f75..8bee5cdfe 100644 --- a/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/qrcode/QRCodeBlackBox2TestCase.java @@ -27,10 +27,10 @@ public final class QRCodeBlackBox2TestCase extends AbstractBlackBoxTestCase { public QRCodeBlackBox2TestCase() { super("test/data/blackbox/qrcode-2", new MultiFormatReader(), BarcodeFormat.QR_CODE); - addTest(23, 23, 0.0f); - addTest(21, 21, 90.0f); - addTest(23, 23, 180.0f); - addTest(20, 21, 270.0f); + addTest(26, 26, 0.0f); + addTest(24, 24, 90.0f); + addTest(24, 24, 180.0f); + addTest(22, 23, 270.0f); } } diff --git a/cpp/core/src/zxing/qrcode/detector/Detector.cpp b/cpp/core/src/zxing/qrcode/detector/Detector.cpp index 6c325586e..eef309542 100644 --- a/cpp/core/src/zxing/qrcode/detector/Detector.cpp +++ b/cpp/core/src/zxing/qrcode/detector/Detector.cpp @@ -185,9 +185,9 @@ float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, if (otherToX < 0) { scale = (float) fromX / (float) (fromX - otherToX); otherToX = 0; - } else if (otherToX >= (int)image_->getWidth()) { - scale = (float) (image_->getWidth() - 1 - fromX) / (float) (otherToX - fromX); - otherToX = image_->getWidth() - 1; + } else if (otherToX > (int)image_->getWidth()) { + scale = (float) (image_->getWidth() - fromX) / (float) (otherToX - fromX); + otherToX = image_->getWidth(); } int otherToY = (int) (fromY - (toY - fromY) * scale); @@ -195,14 +195,14 @@ float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, if (otherToY < 0) { scale = (float) fromY / (float) (fromY - otherToY); otherToY = 0; - } else if (otherToY >= (int)image_->getHeight()) { - scale = (float) (image_->getHeight() - 1 - fromY) / (float) (otherToY - fromY); - otherToY = image_->getHeight() - 1; + } else if (otherToY > (int)image_->getHeight()) { + scale = (float) (image_->getHeight() - fromY) / (float) (otherToY - fromY); + otherToY = image_->getHeight(); } otherToX = (int) (fromX + (otherToX - fromX) * scale); result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); - return result - 1.0f; // -1 because we counted the middle pixel twice + return result; } float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) { @@ -241,6 +241,9 @@ float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) if (state == 3) { // Found black, white, black, and stumbled back onto white; done int diffX = x - fromX; int diffY = y - fromY; + if (xstep < 0) { + diffX++; + } return (float)sqrt((double)(diffX * diffX + diffY * diffY)); } error += dy;