From 904a491ebf20b4d7aed7de0958549110c547ce51 Mon Sep 17 00:00:00 2001 From: srowen Date: Sun, 10 Oct 2010 21:26:44 +0000 Subject: [PATCH] Guard against exception case discovered in new DM code, clean up its formatting a bit git-svn-id: http://zxing.googlecode.com/svn/trunk@1620 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../zxing/common/DefaultGridSampler.java | 3 ++ .../zxing/datamatrix/detector/Detector.java | 35 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/src/com/google/zxing/common/DefaultGridSampler.java b/core/src/com/google/zxing/common/DefaultGridSampler.java index 9233ef8e..74c9e7c6 100644 --- a/core/src/com/google/zxing/common/DefaultGridSampler.java +++ b/core/src/com/google/zxing/common/DefaultGridSampler.java @@ -46,6 +46,9 @@ public final class DefaultGridSampler extends GridSampler { int dimensionX, int dimensionY, PerspectiveTransform transform) throws NotFoundException { + if (dimensionX <= 0 || dimensionY <= 0) { + throw NotFoundException.getNotFoundInstance(); + } BitMatrix bits = new BitMatrix(dimensionX, dimensionY); float[] points = new float[dimensionX << 1]; for (int y = 0; y < dimensionY; y++) { diff --git a/core/src/com/google/zxing/datamatrix/detector/Detector.java b/core/src/com/google/zxing/datamatrix/detector/Detector.java index 49c54249..08c93198 100644 --- a/core/src/com/google/zxing/datamatrix/detector/Detector.java +++ b/core/src/com/google/zxing/datamatrix/detector/Detector.java @@ -158,13 +158,14 @@ public final class Detector { } dimensionRight += 2; - BitMatrix bits = null; - ResultPoint correctedTopRight = null; + BitMatrix bits; + ResultPoint correctedTopRight; if (dimensionTop >= dimensionRight * 2 || dimensionRight >= dimensionTop * 2){ //The matrix is rectangular - correctedTopRight = correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, dimensionTop, dimensionRight); + correctedTopRight = + correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, dimensionTop, dimensionRight); if (correctedTopRight == null){ correctedTopRight = topRight; } @@ -178,11 +179,11 @@ public final class Detector { } if ((dimensionRight & 0x01) == 1) { - // it can't be odd, so, round... up? - dimensionRight++; - } - - bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, correctedTopRight, dimensionTop, dimensionRight); + // it can't be odd, so, round... up? + dimensionRight++; + } + + bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, correctedTopRight, dimensionTop, dimensionRight); } else { //The matrix is square @@ -202,7 +203,13 @@ public final class Detector { dimensionCorrected++; } - bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, correctedTopRight, dimensionCorrected, dimensionCorrected); + bits = sampleGrid(image, + topLeft, + bottomLeft, + bottomRight, + correctedTopRight, + dimensionCorrected, + dimensionCorrected); } @@ -210,7 +217,8 @@ public final class Detector { } /** - * Calculates the position of the white top right module using the output of the rectangle detector for a rectangular matrix + * Calculates the position of the white top right module using the output of the rectangle detector + * for a rectangular matrix */ private ResultPoint correctTopRightRectangular(ResultPoint bottomLeft, ResultPoint bottomRight, ResultPoint topLeft, ResultPoint topRight, @@ -249,10 +257,11 @@ public final class Detector { } return c2; -} + } -/** - * Calculates the position of the white top right module using the output of the rectangle detector for a square matrix + /** + * Calculates the position of the white top right module using the output of the rectangle detector + * for a square matrix */ private ResultPoint correctTopRight(ResultPoint bottomLeft, ResultPoint bottomRight, -- 2.20.1