Fix/improvement from Jiayong

git-svn-id: https://zxing.googlecode.com/svn/trunk@1184 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-01-11 06:08:20 +00:00
parent 30c41e5182
commit c2a6255e19
2 changed files with 29 additions and 20 deletions

View file

@ -258,18 +258,27 @@ public class Detector {
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 // Now count other way -- don't run off image though of course
float scale = 1.0f;
int otherToX = fromX - (toX - fromX); int otherToX = fromX - (toX - fromX);
if (otherToX < 0) { if (otherToX < 0) {
scale = (float) fromX / (float) (fromX - otherToX);
otherToX = 0; otherToX = 0;
} else if (otherToX >= image.getWidth()) { } else if (otherToX >= image.getWidth()) {
scale = (float) (image.getWidth() - 1 - fromX) / (float) (otherToX - fromX);
otherToX = image.getWidth() - 1; otherToX = image.getWidth() - 1;
} }
int otherToY = fromY - (toY - fromY); int otherToY = (int) (fromY - (toY - fromY) * scale);
scale = 1.0f;
if (otherToY < 0) { if (otherToY < 0) {
scale = (float) fromY / (float) (fromY - otherToY);
otherToY = 0; otherToY = 0;
} else if (otherToY >= image.getHeight()) { } else if (otherToY >= image.getHeight()) {
scale = (float) (image.getHeight() - 1 - fromY) / (float) (otherToY - fromY);
otherToY = image.getHeight() - 1; otherToY = image.getHeight() - 1;
} }
otherToX = (int) (fromX + (otherToX - fromX) * scale);
result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);
return result - 1.0f; // -1 because we counted the middle pixel twice return result - 1.0f; // -1 because we counted the middle pixel twice
} }

View file

@ -28,9 +28,9 @@ public final class QRCodeBlackBox3TestCase extends AbstractBlackBoxTestCase {
public QRCodeBlackBox3TestCase() { public QRCodeBlackBox3TestCase() {
super("test/data/blackbox/qrcode-3", new MultiFormatReader(), BarcodeFormat.QR_CODE); super("test/data/blackbox/qrcode-3", new MultiFormatReader(), BarcodeFormat.QR_CODE);
addTest(36, 36, 0.0f); addTest(36, 36, 0.0f);
addTest(37, 37, 90.0f); addTest(38, 38, 90.0f);
addTest(35, 35, 180.0f); addTest(36, 36, 180.0f);
addTest(36, 36, 270.0f); addTest(37, 37, 270.0f);
} }
} }