From 82097a85f2f22a26231ba6a7e8825955761ccb4d Mon Sep 17 00:00:00 2001 From: srowen Date: Thu, 12 Aug 2010 20:18:08 +0000 Subject: [PATCH] Issue 511 git-svn-id: http://zxing.googlecode.com/svn/trunk@1522 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../google/zxing/qrcode/detector/Detector.java | 17 ++++++++++------- core/test/data/blackbox/qrcode-2/32.gif | Bin 0 -> 708 bytes core/test/data/blackbox/qrcode-2/32.txt | 12 ++++++++++++ .../zxing/qrcode/QRCodeBlackBox2TestCase.java | 8 ++++---- .../src/zxing/qrcode/detector/Detector.cpp | 17 ++++++++++------- 5 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 core/test/data/blackbox/qrcode-2/32.gif create mode 100644 core/test/data/blackbox/qrcode-2/32.txt diff --git a/core/src/com/google/zxing/qrcode/detector/Detector.java b/core/src/com/google/zxing/qrcode/detector/Detector.java index 82d50a63..b9d7f2c5 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 0000000000000000000000000000000000000000..7bdbc7618e27b9845adbf87396fa3c3992715d4b GIT binary patch literal 708 zcmV;#0z3UjNk%v~VL<>v0DuAj0002~{{Acg0000%06_o%0{(;#5x2V8oKX{26m6x5 zxhPRj0zDEleJPoSB{w$Y7oH}a%{4r;Z2U8ohNz&2hS6AnJ{eKh6OAxVozulcPG8y8 zvn3qfK%7qWEK8%;>b99{i;1Xn>~UGPYCBRRJp85-*W=T|2UWubmP2$S_6JlJR_CDs zh;&hzCa1JxSky0(x#!^1nZy3XTCeu6EQ{e9in6iOeN-9365 zXZMLy6EHz`$ zOmP@B0!mPJbRk(rG@0hjYu>b`m~2>ihm#}UB{q^wFI__5W84un-$e@nZFZYIJ^sj_Neaf8$zahOlpP{O!W9^ACdDKULvP*3UOy4u qL)|Pk{uO49H3s+}i%FqpPnV1lMbUqBS!UOI&^7d8J0*Hh002829!6sT literal 0 HcmV?d00001 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 00000000..2b574b76 --- /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 80bac2f7..8bee5cdf 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 6c325586..eef30954 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; -- 2.20.1