*/
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());
} while (start >= minDim && !rowOrColumn.get(start));
int whiteRunSize = whiteRunStart - start;
if (start < minDim || whiteRunSize > maxWhiteRun) {
- start = whiteRunStart + 1; // back up
+ start = whiteRunStart;
break;
}
}
} 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
} 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
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();
}
// 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);
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);
}
}