/** * 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 centerX center's x component (horizontal) * @param deltaX same as deltaY but change in x per step instead * @param left minimum value of x * @param right maximum value of x * @param centerY center's y component (vertical) * @param deltaY change in y per step. If scanning up this is negative; down, positive; left or * right, 0 * @param top minimum value of y to search through (meaningless when di == 0) * @param bottom maximum value of y * @param maxWhiteRun maximum run of white pixels that can still be considered to be within the * barcode * @return a {@link com.managed.zxing.ResultPoint} encapsulating the corner that was found * @throws NotFoundException if such a point cannot be found */ private ResultPoint findCornerFromCenter( int centerX, int deltaX, int left, int right, int centerY, int deltaY, int top, int bottom, int maxWhiteRun) throws NotFoundException { int[] lastRange = null; for (int y = centerY, x = centerX; y < bottom && y >= top && x < right && x >= left; y += deltaY, x += deltaX) { int[] range; if (deltaX == 0) { // horizontal slices, up and down range = blackWhiteRange(y, maxWhiteRun, left, right, true); } else { // vertical slices, left and right range = blackWhiteRange(x, maxWhiteRun, top, bottom, false); } if (range == null) { if (lastRange == null) { throw NotFoundException.getNotFoundInstance(); } // lastRange was found if (deltaX == 0) { int lastY = y - deltaY; if (lastRange[0] < centerX) { if (lastRange[1] > centerX) { // straddle, choose one or the other based on direction return new ResultPoint(deltaY > 0 ? lastRange[0] : lastRange[1], lastY); } return new ResultPoint(lastRange[0], lastY); } else { return new ResultPoint(lastRange[1], lastY); } } else { int lastX = x - deltaX; if (lastRange[0] < centerY) { if (lastRange[1] > centerY) { return new ResultPoint(lastX, deltaX < 0 ? lastRange[0] : lastRange[1]); } return new ResultPoint(lastX, lastRange[0]); } else { return new ResultPoint(lastX, lastRange[1]); } } } lastRange = range; } throw NotFoundException.getNotFoundInstance(); }
public String parseInformation() throws NotFoundException { if (this.information.size != headerSize + gtinSize + weightSize + dateSize) { throw NotFoundException.getNotFoundInstance(); } StringBuffer buf = new StringBuffer(); encodeCompressedGtin(buf, headerSize); encodeCompressedWeight(buf, headerSize + gtinSize, weightSize); encodeCompressedDate(buf, headerSize + gtinSize + weightSize); return buf.toString(); }