Issue 158: Correct some off-by-one problems in Data Matrix detector and a few more improvements, ignore unsupported DM symbols

git-svn-id: https://zxing.googlecode.com/svn/trunk@895 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2009-04-06 21:22:07 +00:00
parent 0210ec9fe9
commit d4e82758eb
4 changed files with 19 additions and 24 deletions

View file

@ -159,7 +159,7 @@ public final class MonochromeRectangleDetector {
*/ */
private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, boolean horizontal) { 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()) BitArray rowOrColumn = horizontal ? image.getBlackRow(fixedDimension, null, 0, image.getWidth())
: image.getBlackColumn(fixedDimension, null, 0, image.getHeight()); : image.getBlackColumn(fixedDimension, null, 0, image.getHeight());
@ -176,7 +176,7 @@ public final class MonochromeRectangleDetector {
} while (start >= minDim && !rowOrColumn.get(start)); } while (start >= minDim && !rowOrColumn.get(start));
int whiteRunSize = whiteRunStart - start; int whiteRunSize = whiteRunStart - start;
if (start < minDim || whiteRunSize > maxWhiteRun) { if (start < minDim || whiteRunSize > maxWhiteRun) {
start = whiteRunStart + 1; // back up start = whiteRunStart;
break; break;
} }
} }
@ -195,18 +195,14 @@ public final class MonochromeRectangleDetector {
} while (end < maxDim && !rowOrColumn.get(end)); } while (end < maxDim && !rowOrColumn.get(end));
int whiteRunSize = end - whiteRunStart; int whiteRunSize = end - whiteRunStart;
if (end >= maxDim || whiteRunSize > maxWhiteRun) { if (end >= maxDim || whiteRunSize > maxWhiteRun) {
end = whiteRunStart - 1; end = whiteRunStart;
break; break;
} }
} }
} }
end--; end--;
if (end > start) { return end > start ? new int[]{start, end} : null;
return new int[] { start, end };
} else {
return null;
}
} }
} }

View file

@ -141,11 +141,14 @@ final class DecodedBitStreamParser {
} else if (oneByte == 231) { // Latch to Base 256 encodation } else if (oneByte == 231) { // Latch to Base 256 encodation
return BASE256_ENCODE; return BASE256_ENCODE;
} else if (oneByte == 232) { // FNC1 } else if (oneByte == 232) { // FNC1
throw ReaderException.getInstance(); //throw ReaderException.getInstance();
// Ignore this symbol for now
} else if (oneByte == 233) { // Structured Append } else if (oneByte == 233) { // Structured Append
throw ReaderException.getInstance(); //throw ReaderException.getInstance();
// Ignore this symbol for now
} else if (oneByte == 234) { // Reader Programming } 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) } else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII)
upperShift = true; upperShift = true;
} else if (oneByte == 236) { // 05 Macro } else if (oneByte == 236) { // 05 Macro
@ -162,7 +165,8 @@ final class DecodedBitStreamParser {
return EDIFACT_ENCODE; return EDIFACT_ENCODE;
} else if (oneByte == 241) { // ECI Character } else if (oneByte == 241) { // ECI Character
// TODO(bbrown): I think we need to support ECI // 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 } else if (oneByte >= 242) { // Not to be used in ASCII encodation
throw ReaderException.getInstance(); throw ReaderException.getInstance();
} }

View file

@ -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 // 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 // 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 // or bottom right should work here. The number of transitions could be higher than it should be
// up or across, rather than at a slight angle. We use dot products to figure out which is // due to noise. So we try both and take the min.
// better to use:
int dimension; int dimension = Math.min(transitionsBetween(topLeft, topRight).getTransitions(),
if (GenericResultPoint.crossProductZ(bottomLeft, bottomRight, topRight) < transitionsBetween(bottomRight, topRight).getTransitions());
GenericResultPoint.crossProductZ(topRight, topLeft, bottomLeft)) {
dimension = transitionsBetween(topLeft, topRight).getTransitions();
} else {
dimension = transitionsBetween(bottomRight, topRight).getTransitions();
}
dimension += 2; dimension += 2;
BitMatrix bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, dimension); BitMatrix bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, dimension);

View file

@ -29,8 +29,8 @@ public final class DataMatrixBlackBox2TestCase extends AbstractBlackBoxTestCase
super("test/data/blackbox/datamatrix-2", new DataMatrixReader(), BarcodeFormat.DATAMATRIX); super("test/data/blackbox/datamatrix-2", new DataMatrixReader(), BarcodeFormat.DATAMATRIX);
addTest(3, 3, 0.0f); addTest(3, 3, 0.0f);
addTest(1, 1, 90.0f); addTest(1, 1, 90.0f);
addTest(3, 3, 180.0f); addTest(4, 4, 180.0f);
addTest(4, 4, 270.0f); addTest(3, 3, 270.0f);
} }
} }