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) {
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;
}
}

View file

@ -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();
}

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
// 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);

View file

@ -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);
}
}