- /**
- * Attempts to locate a corner of the barcode by scanning up, down, left or right from a center
- * point which should be within the barcode.
- *
- * @param centerI center's i componennt (vertical)
- * @param di change in i per step. If scanning up this is negative; down, positive; left or right, 0
- * @param minI minimum value of i to search through (meaningless when di == 0)
- * @param maxI maximum value of i
- * @param centerJ center's j component (horizontal)
- * @param dj same as di but change in j per step instead
- * @param minJ see minI
- * @param maxJ see minJ
- * @param maxWhiteRun maximum run of white pixels that can still be considered to be within
- * the barcode
- * @return a {@link ResultPoint} encapsulating the corner that was found
- * @throws ReaderException if such a point cannot be found
- */
- private ResultPoint findCornerFromCenter(int centerI, int di, int minI, int maxI,
- int centerJ, int dj, int minJ, int maxJ,
- int maxWhiteRun) throws ReaderException {
- int[] lastRange = null;
- for (int i = centerI, j = centerJ;
- i < maxI && i >= minI && j < maxJ && j >= minJ;
- i += di, j += dj) {
- int[] range;
- if (dj == 0) {
- // horizontal slices, up and down
- range = blackWhiteRange(i, maxWhiteRun, minJ, maxJ, true);
- } else {
- // vertical slices, left and right
- range = blackWhiteRange(j, maxWhiteRun, minI, maxI, false);
- }
- if (range == null) {
- if (lastRange == null) {
- throw new ReaderException("Center of image not within barcode");
- }
- // lastRange was found
- if (dj == 0) {
- int lastI = i - di;
- if (lastRange[0] < centerJ) {
- if (lastRange[1] > centerJ) {
- // straddle, choose one or the other based on direction
- return new GenericResultPoint(di > 0 ? lastRange[0] : lastRange[1], lastI);
- }
- return new GenericResultPoint(lastRange[0], lastI);
- } else {
- return new GenericResultPoint(lastRange[1], lastI);
- }
- } else {
- int lastJ = j - dj;
- if (lastRange[0] < centerI) {
- if (lastRange[1] > centerI) {
- return new GenericResultPoint(lastJ, dj < 0 ? lastRange[0] : lastRange[1]);
- }
- return new GenericResultPoint(lastJ, lastRange[0]);
- } else {
- return new GenericResultPoint(lastJ, lastRange[1]);
- }
- }
- }
- lastRange = range;
- }
- throw new ReaderException("Couldn't find an end to barcode");
- }
-