From: srowen Date: Mon, 6 Apr 2009 21:22:07 +0000 (+0000) Subject: Issue 158: Correct some off-by-one problems in Data Matrix detector and a few more... X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=a6f2683ccc234dd3a70b2758f31e86d3fa810279;hp=f5f458fc312e35c7e18280fd06d0b7e809749908;p=zxing.git Issue 158: Correct some off-by-one problems in Data Matrix detector and a few more improvements, ignore unsupported DM symbols git-svn-id: http://zxing.googlecode.com/svn/trunk@895 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java b/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java index 3b3ced1a..63240d0a 100644 --- a/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java +++ b/core/src/com/google/zxing/common/detector/MonochromeRectangleDetector.java @@ -159,7 +159,7 @@ public final class MonochromeRectangleDetector { */ private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, boolean horizontal) { - int center = (minDim + maxDim) / 2; + int center = (minDim + maxDim) >> 1; BitArray rowOrColumn = horizontal ? image.getBlackRow(fixedDimension, null, 0, image.getWidth()) : image.getBlackColumn(fixedDimension, null, 0, image.getHeight()); @@ -176,7 +176,7 @@ public final class MonochromeRectangleDetector { } while (start >= minDim && !rowOrColumn.get(start)); int whiteRunSize = whiteRunStart - start; if (start < minDim || whiteRunSize > maxWhiteRun) { - start = whiteRunStart + 1; // back up + start = whiteRunStart; break; } } @@ -195,18 +195,14 @@ public final class MonochromeRectangleDetector { } while (end < maxDim && !rowOrColumn.get(end)); int whiteRunSize = end - whiteRunStart; if (end >= maxDim || whiteRunSize > maxWhiteRun) { - end = whiteRunStart - 1; + end = whiteRunStart; break; } } } end--; - if (end > start) { - return new int[] { start, end }; - } else { - return null; - } + return end > start ? new int[]{start, end} : null; } } \ No newline at end of file diff --git a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java index 2f7c1f41..b5996cce 100644 --- a/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java +++ b/core/src/com/google/zxing/datamatrix/decoder/DecodedBitStreamParser.java @@ -141,11 +141,14 @@ final class DecodedBitStreamParser { } else if (oneByte == 231) { // Latch to Base 256 encodation return BASE256_ENCODE; } else if (oneByte == 232) { // FNC1 - throw ReaderException.getInstance(); + //throw ReaderException.getInstance(); + // Ignore this symbol for now } else if (oneByte == 233) { // Structured Append - throw ReaderException.getInstance(); + //throw ReaderException.getInstance(); + // Ignore this symbol for now } else if (oneByte == 234) { // Reader Programming - throw ReaderException.getInstance(); + //throw ReaderException.getInstance(); + // Ignore this symbol for now } else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII) upperShift = true; } else if (oneByte == 236) { // 05 Macro @@ -162,7 +165,8 @@ final class DecodedBitStreamParser { return EDIFACT_ENCODE; } else if (oneByte == 241) { // ECI Character // TODO(bbrown): I think we need to support ECI - throw ReaderException.getInstance(); + //throw ReaderException.getInstance(); + // Ignore this symbol for now } else if (oneByte >= 242) { // Not to be used in ASCII encodation throw ReaderException.getInstance(); } diff --git a/core/src/com/google/zxing/datamatrix/detector/Detector.java b/core/src/com/google/zxing/datamatrix/detector/Detector.java index 3cd2c1da..30fb437f 100644 --- a/core/src/com/google/zxing/datamatrix/detector/Detector.java +++ b/core/src/com/google/zxing/datamatrix/detector/Detector.java @@ -143,16 +143,11 @@ public final class Detector { // The top right point is actually the corner of a module, which is one of the two black modules // adjacent to the white module at the top right. Tracing to that corner from either the top left - // or bottom right should work here, but, one will be more reliable since it's traced straight - // up or across, rather than at a slight angle. We use dot products to figure out which is - // better to use: - int dimension; - if (GenericResultPoint.crossProductZ(bottomLeft, bottomRight, topRight) < - GenericResultPoint.crossProductZ(topRight, topLeft, bottomLeft)) { - dimension = transitionsBetween(topLeft, topRight).getTransitions(); - } else { - dimension = transitionsBetween(bottomRight, topRight).getTransitions(); - } + // or bottom right should work here. The number of transitions could be higher than it should be + // due to noise. So we try both and take the min. + + int dimension = Math.min(transitionsBetween(topLeft, topRight).getTransitions(), + transitionsBetween(bottomRight, topRight).getTransitions()); dimension += 2; BitMatrix bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, dimension); diff --git a/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox2TestCase.java b/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox2TestCase.java index 9d84be7e..bb13f1ca 100644 --- a/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox2TestCase.java +++ b/core/test/src/com/google/zxing/datamatrix/DataMatrixBlackBox2TestCase.java @@ -29,8 +29,8 @@ public final class DataMatrixBlackBox2TestCase extends AbstractBlackBoxTestCase super("test/data/blackbox/datamatrix-2", new DataMatrixReader(), BarcodeFormat.DATAMATRIX); addTest(3, 3, 0.0f); addTest(1, 1, 90.0f); - addTest(3, 3, 180.0f); - addTest(4, 4, 270.0f); + addTest(4, 4, 180.0f); + addTest(3, 3, 270.0f); } }