- /**
- * Computes the start and end of a region of pixels, either horizontally or vertically, that could be
- * part of a Data Matrix barcode.
- *
- * @param fixedDimension if scanning horizontally, this is the row (the fixed vertical location) where
- * we are scanning. If scanning vertically it's the colummn, the fixed horizontal location
- * @param maxWhiteRun largest run of white pixels that can still be considered part of the barcode region
- * @param minDim minimum pixel location, horizontally or vertically, to consider
- * @param maxDim maximum pixel location, horizontally or vertically, to consider
- * @param horizontal if true, we're scanning left-right, instead of up-down
- * @return int[] with start and end of found range, or null if no such range is found (e.g. only white was found)
- */
- private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, boolean horizontal) {
-
- int center = (minDim + maxDim) / 2;
-
- BitArray rowOrColumn = horizontal ? image.getBlackRow(fixedDimension, null, 0, image.getWidth())
- : image.getBlackColumn(fixedDimension, null, 0, image.getHeight());
-
- // Scan left/up first
- int start = center;
- while (start >= minDim) {
- if (rowOrColumn.get(start)) {
- start--;
- } else {
- int whiteRunStart = start;
- do {
- start--;
- } while (start >= minDim && !rowOrColumn.get(start));
- int whiteRunSize = whiteRunStart - start;
- if (start < minDim || whiteRunSize > maxWhiteRun) {
- start = whiteRunStart + 1; // back up
- break;
- }
- }
- }
- start++;
-
- // Then try right/down
- int end = center;
- while (end < maxDim) {
- if (rowOrColumn.get(end)) {
- end++;
- } else {
- int whiteRunStart = end;
- do {
- end++;
- } while (end < maxDim && !rowOrColumn.get(end));
- int whiteRunSize = end - whiteRunStart;
- if (end >= maxDim || whiteRunSize > maxWhiteRun) {
- end = whiteRunStart - 1;
- break;
- }
- }
- }
- end--;
-
- if (end > start) {
- return new int[] { start, end };
- } else {
- return null;
- }
- }
-
- private static BitMatrix sampleGrid(MonochromeBitmapSource image,