From 24690a49a625e42b81d386688f698cebf372d543 Mon Sep 17 00:00:00 2001 From: srowen Date: Fri, 21 Dec 2007 18:32:49 +0000 Subject: [PATCH] Be more forgiving about endpoints that transform to be just off the image git-svn-id: http://zxing.googlecode.com/svn/trunk@128 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/qrcode/detector/GridSampler.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/core/src/com/google/zxing/qrcode/detector/GridSampler.java b/core/src/com/google/zxing/qrcode/detector/GridSampler.java index 36f99311..533e9184 100644 --- a/core/src/com/google/zxing/qrcode/detector/GridSampler.java +++ b/core/src/com/google/zxing/qrcode/detector/GridSampler.java @@ -107,20 +107,36 @@ public abstract class GridSampler { * This method actually only checks the endpoints since the points are assumed to lie * on a line.

* + *

This method will actually "nudge" the endpoints back onto the image if they are found to be barely + * (less than 1 pixel) off the image. This accounts for imperfect detection of finder patterns in an image + * where the QR Code runs all the way to the image border.

+ * * @param image image into which the points should map * @param points actual points in x1,y1,...,xn,yn form * @throws ReaderException if an endpoint is lies outside the image boundaries */ protected static void checkEndpoint(MonochromeBitmapSource image, float[] points) throws ReaderException { - int x = (int) points[0]; - int y = (int) points[1]; - if (x < 0 || x >= image.getWidth() || y < 0 || y >= image.getHeight()) { + int width = image.getWidth(); + int height = image.getHeight(); + checkOneEndpoint(points, (int) points[0], (int) points[1], width, height); + checkOneEndpoint(points, (int) points[points.length - 2], (int) points[points.length - 1], width, height); + } + + private static void checkOneEndpoint(float[] points, int x, int y, int width, int height) throws ReaderException { + if (x < -1 || x > width || y < -1 || y > height) { throw new ReaderException("Transformed point out of bounds at " + x + ',' + y); } - x = (int) points[points.length - 2]; - y = (int) points[points.length - 1]; - if (x < 0 || x >= image.getWidth() || y < 0 || y >= image.getHeight()) { - throw new ReaderException("Transformed point out of bounds at " + x + ',' + y); + if (x == -1) { + points[0] = 0.0f; + } + if (y == -1) { + points[1] = 0.0f; + } + if (x == width) { + points[0] = width - 1; + } + if (y == height) { + points[1] = height - 1; } } -- 2.20.1