private void setCounters(BitArray row) throws NotFoundException { this.counterLength = 0; int i = row.getNextUnset(0); int end = row.getSize(); if (i >= end) { throw NotFoundException.getNotFoundInstance(); } boolean isWhite = true; int count = 0; while (i < end) { if ((row.get(i) ^ isWhite) != 0) { count++; } else { counterAppend(count); count = 1; isWhite = !isWhite; } i++; } counterAppend(count); }
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix) throws NotFoundException { int[] numberOfCodewords = barcodeMatrix[0][1].getValue(); int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() * detectionResult.getBarcodeRowCount() - getNumberOfECCodeWords(detectionResult.getBarcodeECLevel()); if (numberOfCodewords.length == 0) { if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) { throw NotFoundException.getNotFoundInstance(); } barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords); } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) { // The calculated one is more reliable as it is derived from the row indicator columns barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords); } }
/** * Attempts to decode a single UPC/EAN-encoded digit. * * @param row row of black/white values to decode * @param counters the counts of runs of observed black/white/black/... values * @param rowOffset horizontal offset to start decoding from * @param patterns the set of patterns to use to decode -- sometimes different encodings * for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should * be used * @return horizontal offset of first pixel beyond the decoded digit * @throws NotFoundException if digit cannot be decoded */ static int decodeDigit(BitArray row, int[] counters, int rowOffset, int[][] patterns) throws NotFoundException { recordPattern(row, rowOffset, counters); float bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; int max = patterns.length; for (int i = 0; i < max; i++) { int[] pattern = patterns[i]; float variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); if (variance < bestVariance) { bestVariance = variance; bestMatch = i; } } if (bestMatch >= 0) { return bestMatch; } else { throw NotFoundException.getNotFoundInstance(); } }
private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) { try { int[] startEnd = findFinderPattern(row, 0, right); FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); if (resultPointCallback != null) { float center = (startEnd[0] + startEnd[1]) / 2.0f; if (right) { // row is actually reversed center = row.getSize() - 1 - center; } resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber)); } DataCharacter outside = decodeDataCharacter(row, pattern, true); DataCharacter inside = decodeDataCharacter(row, pattern, false); return new Pair(1597 * outside.getValue() + inside.getValue(), outside.getChecksumPortion() + 4 * inside.getChecksumPortion(), pattern); } catch (NotFoundException ignored) { return null; } }
private List<ExpandedPair> checkRows(boolean reverse) { if (this.rows.size() > 25) { this.rows.clear(); return null; } this.pairs.clear(); if (reverse) { Collections.reverse(this.rows); } List<ExpandedPair> ps = null; try { ps = checkRows(new ArrayList(), 0); } catch (NotFoundException e) { } if (!reverse) { return ps; } Collections.reverse(this.rows); return ps; }
private int findStartPattern() throws NotFoundException { for (int i = 1; i < counterLength; i += 2) { int charOffset = toNarrowWidePattern(i); if (charOffset != -1 && arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) { // Look for whitespace before start pattern, >= 50% of width of start pattern // We make an exception if the whitespace is the first element. int patternSize = 0; for (int j = i; j < i + 7; j++) { patternSize += counters[j]; } if (i == 1 || counters[i-1] >= patternSize / 2) { return i; } } } throw NotFoundException.getNotFoundInstance(); }
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException { StringBuilder result = decodeRowStringBuffer; result.setLength(0); int end = decodeMiddle(row, extensionStartRange, result); String resultString = result.toString(); Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString); Result extensionResult = new Result(resultString, null, new ResultPoint[] { new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber), new ResultPoint(end, rowNumber), }, BarcodeFormat.UPC_EAN_EXTENSION); if (extensionData != null) { extensionResult.putAllMetadata(extensionData); } return extensionResult; }
/** * Attempts to decode a sequence of ITF black/white lines into single * digit. * * @param counters the counts of runs of observed black/white/black/... values * @return The decoded digit * @throws NotFoundException if digit cannot be decoded */ private static int decodeDigit(int[] counters) throws NotFoundException { float bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; int max = PATTERNS.length; for (int i = 0; i < max; i++) { int[] pattern = PATTERNS[i]; float variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); if (variance < bestVariance) { bestVariance = variance; bestMatch = i; } } if (bestMatch >= 0) { return bestMatch; } else { throw NotFoundException.getNotFoundInstance(); } }
private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws NotFoundException { recordPattern(row, rowOffset, counters); float bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; for (int d = 0; d < CODE_PATTERNS.length; d++) { int[] pattern = CODE_PATTERNS[d]; float variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); if (variance < bestVariance) { bestVariance = variance; bestMatch = d; } } // TODO We're overlooking the fact that the STOP pattern has 7 values, not 6. if (bestMatch >= 0) { return bestMatch; } else { throw NotFoundException.getNotFoundInstance(); } }
protected static void recordPatternInReverse(BitArray row, int start, int[] counters) throws NotFoundException { // This could be more efficient I guess int numTransitionsLeft = counters.length; boolean last = row.get(start); while (start > 0 && numTransitionsLeft >= 0) { if (row.get(--start) != last) { numTransitionsLeft--; last = !last; } } if (numTransitionsLeft >= 0) { throw NotFoundException.getNotFoundInstance(); } recordPattern(row, start + 1, counters); }
private static float moduleSize(int[] leftTopBlack, BitMatrix image) throws NotFoundException { int height = image.getHeight(); int width = image.getWidth(); int x = leftTopBlack[0]; int y = leftTopBlack[1]; boolean inBlack = true; int transitions = 0; while (x < width && y < height) { if (inBlack != image.get(x, y)) { if (++transitions == 5) { break; } inBlack = !inBlack; } x++; y++; } if (x == width || y == height) { throw NotFoundException.getNotFoundInstance(); } return (x - leftTopBlack[0]) / 7.0f; }
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException { BitArray binary = BitArrayBuilder.buildBitArray(pairs); AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary); String resultingString = decoder.parseInformation(); ResultPoint[] firstPoints = pairs.get(0).getFinderPattern().getResultPoints(); ResultPoint[] lastPoints = pairs.get(pairs.size() - 1).getFinderPattern().getResultPoints(); return new Result( resultingString, null, new ResultPoint[]{firstPoints[0], firstPoints[1], lastPoints[0], lastPoints[1]}, BarcodeFormat.RSS_EXPANDED ); }
private static Result[] decode(BinaryBitmap image, Map<DecodeHintType, ?> hints, boolean multiple) throws NotFoundException, FormatException, ChecksumException { List<Result> results = new ArrayList(); PDF417DetectorResult detectorResult = Detector.detect(image, hints, multiple); for (ResultPoint[] points : detectorResult.getPoints()) { DecoderResult decoderResult = PDF417ScanningDecoder.decode(detectorResult.getBits(), points[4], points[5], points[6], points[7], getMinCodewordWidth(points), getMaxCodewordWidth(points)); Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.PDF_417); result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult .getECLevel()); PDF417ResultMetadata pdf417ResultMetadata = (PDF417ResultMetadata) decoderResult .getOther(); if (pdf417ResultMetadata != null) { result.putMetadata(ResultMetadataType.PDF417_EXTRA_METADATA, pdf417ResultMetadata); } results.add(result); } return (Result[]) results.toArray(new Result[results.size()]); }
public ResultPoint[] detect() throws NotFoundException { int height = this.image.getHeight(); int width = this.image.getWidth(); int halfHeight = height / 2; int halfWidth = width / 2; int deltaY = Math.max(1, height / 256); int deltaX = Math.max(1, width / 256); int bottom = height; int right = width; int top = ((int) findCornerFromCenter(halfWidth, 0, 0, right, halfHeight, -deltaY, 0, bottom, halfWidth / 2).getY()) - 1; int left = ((int) findCornerFromCenter(halfWidth, -deltaX, 0, right, halfHeight, 0, top, bottom, halfHeight / 2).getX()) - 1; right = ((int) findCornerFromCenter(halfWidth, deltaX, left, right, halfHeight, 0, top, bottom, halfHeight / 2).getX()) + 1; ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, deltaY, top, bottom, halfWidth / 2); ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, -deltaY, top, ((int) pointD.getY()) + 1, halfWidth / 4); return new ResultPoint[]{pointA, pointB, pointC, pointD}; }
static int[] findStartGuardPattern(BitArray row) throws NotFoundException { boolean foundStart = false; int[] startRange = null; int nextStart = 0; int[] counters = new int[START_END_PATTERN.length]; while (!foundStart) { Arrays.fill(counters, 0, START_END_PATTERN.length, 0); startRange = findGuardPattern(row, nextStart, false, START_END_PATTERN, counters); int start = startRange[0]; nextStart = startRange[1]; // Make sure there is a quiet zone at least as big as the start pattern before the barcode. // If this check would run off the left edge of the image, do not accept this barcode, // as it is very likely to be a false positive. int quietStart = start - (nextStart - start); if (quietStart >= 0) { foundStart = row.isRange(quietStart, start, false); } } return startRange; }
/** * Records the size of all runs of white and black pixels, starting with white. * This is just like recordPattern, except it records all the counters, and * uses our builtin "counters" member for storage. * @param row row to count from */ private void setCounters(BitArray row) throws NotFoundException { counterLength = 0; // Start from the first white bit. int i = row.getNextUnset(0); int end = row.getSize(); if (i >= end) { throw NotFoundException.getNotFoundInstance(); } boolean isWhite = true; int count = 0; while (i < end) { if (row.get(i) != isWhite) { count++; } else { counterAppend(count); count = 1; isWhite = !isWhite; } i++; } counterAppend(count); }
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix) throws NotFoundException { int[] numberOfCodewords = barcodeMatrix[0][1].getValue(); int calculatedNumberOfCodewords = (detectionResult.getBarcodeColumnCount() * detectionResult.getBarcodeRowCount()) - getNumberOfECCodeWords(detectionResult .getBarcodeECLevel()); if (numberOfCodewords.length == 0) { if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common .MAX_CODEWORDS_IN_BARCODE) { throw NotFoundException.getNotFoundInstance(); } barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords); } else if (numberOfCodewords[0] != calculatedNumberOfCodewords) { barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords); } }
private FinderPattern parseFoundFinderPattern(BitArray row, int rowNumber, boolean right, int[] startEnd) throws NotFoundException { // Actually we found elements 2-5 boolean firstIsBlack = row.get(startEnd[0]); int firstElementStart = startEnd[0] - 1; // Locate element 1 while (firstElementStart >= 0 && firstIsBlack != row.get(firstElementStart)) { firstElementStart--; } firstElementStart++; int firstCounter = startEnd[0] - firstElementStart; // Make 'counters' hold 1-4 int[] counters = getDecodeFinderCounters(); System.arraycopy(counters, 0, counters, 1, counters.length - 1); counters[0] = firstCounter; int value = parseFinderValue(counters, FINDER_PATTERNS); int start = firstElementStart; int end = startEnd[1]; if (right) { // row is actually reversed start = row.getSize() - 1 - start; end = row.getSize() - 1 - end; } return new FinderPattern(value, new int[] {firstElementStart, startEnd[1]}, start, end, rowNumber); }
private int findStartPattern() throws NotFoundException { for (int i = 1; i < counterLength; i += 2) { int charOffset = toNarrowWidePattern(i); if (charOffset != -1 && arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) { // Look for whitespace before start pattern, >= 50% of width of start pattern // We make an exception if the whitespace is the first element. int patternSize = 0; for (int j = i; j < i + 7; j++) { patternSize += counters[j]; } if (i == 1 || counters[i - 1] >= patternSize / 2) { return i; } } } throw NotFoundException.getNotFoundInstance(); }
private static int decodeCode(BitArray row, int[] counters, int rowOffset) throws NotFoundException { OneDReader.recordPattern(row, rowOffset, counters); float bestVariance = 0.25f; int bestMatch = -1; for (int d = 0; d < CODE_PATTERNS.length; d++) { float variance = OneDReader.patternMatchVariance(counters, CODE_PATTERNS[d], MAX_INDIVIDUAL_VARIANCE); if (variance < bestVariance) { bestVariance = variance; bestMatch = d; } } if (bestMatch >= 0) { return bestMatch; } throw NotFoundException.getNotFoundInstance(); }
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { Pair leftPair = decodePair(row, false, rowNumber, hints); addOrTally(possibleLeftPairs, leftPair); row.reverse(); Pair rightPair = decodePair(row, true, rowNumber, hints); addOrTally(possibleRightPairs, rightPair); row.reverse(); for (Pair left : possibleLeftPairs) { if (left.getCount() > 1) { for (Pair right : possibleRightPairs) { if (right.getCount() > 1 && checkChecksum(left, right)) { return constructResult(left, right); } } } } throw NotFoundException.getNotFoundInstance(); }
private int findStartPattern() throws NotFoundException { int i = 1; while (i < this.counterLength) { int charOffset = toNarrowWidePattern(i); if (charOffset != -1 && arrayContains(STARTEND_ENCODING, ALPHABET[charOffset])) { int patternSize = 0; for (int j = i; j < i + 7; j++) { patternSize += this.counters[j]; } if (i == 1 || this.counters[i - 1] >= patternSize / 2) { return i; } } i += 2; } throw NotFoundException.getNotFoundInstance(); }
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws NotFoundException, ChecksumException, FormatException { DecoderResult decoderResult; ResultPoint[] points; if (hints == null || !hints.containsKey(DecodeHintType.PURE_BARCODE)) { DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(); decoderResult = this.decoder.decode(detectorResult.getBits()); points = detectorResult.getPoints(); } else { decoderResult = this.decoder.decode(extractPureBits(image.getBlackMatrix())); points = NO_POINTS; } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.DATA_MATRIX); List<byte[]> byteSegments = decoderResult.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String ecLevel = decoderResult.getECLevel(); if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } return result; }
/** * Creates a BitMatrix by sampling the provided image. * topLeft, topRight, bottomRight, and bottomLeft are the centers of the squares on the * diagonal just outside the bull's eye. */ private BitMatrix sampleGrid(BitMatrix image, ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomRight, ResultPoint bottomLeft) throws NotFoundException { GridSampler sampler = GridSampler.getInstance(); int dimension = getDimension(); float low = dimension / 2.0f - nbCenterLayers; float high = dimension / 2.0f + nbCenterLayers; return sampler.sampleGrid(image, dimension, dimension, low, low, // topleft high, low, // topright high, high, // bottomright low, high, // bottomleft topLeft.getX(), topLeft.getY(), topRight.getX(), topRight.getY(), bottomRight.getX(), bottomRight.getY(), bottomLeft.getX(), bottomLeft.getY()); }
private int[] findAsteriskPattern(BitArray row) throws NotFoundException { int width = row.getSize(); int rowOffset = row.getNextSet(0); Arrays.fill(counters, 0); int[] theCounters = counters; int patternStart = rowOffset; boolean isWhite = false; int patternLength = theCounters.length; int counterPosition = 0; for (int i = rowOffset; i < width; i++) { if (row.get(i) ^ isWhite) { theCounters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { if (toPattern(theCounters) == ASTERISK_ENCODING) { return new int[]{patternStart, i}; } patternStart += theCounters[0] + theCounters[1]; System.arraycopy(theCounters, 2, theCounters, 0, patternLength - 2); theCounters[patternLength - 2] = 0; theCounters[patternLength - 1] = 0; counterPosition--; } else { counterPosition++; } theCounters[counterPosition] = 1; isWhite = !isWhite; } } throw NotFoundException.getNotFoundInstance(); }
static Result constructResult(List<ExpandedPair> pairs) throws NotFoundException, FormatException { String resultingString = AbstractExpandedDecoder.createDecoder(BitArrayBuilder .buildBitArray(pairs)).parseInformation(); ResultPoint[] firstPoints = ((ExpandedPair) pairs.get(0)).getFinderPattern() .getResultPoints(); ResultPoint[] lastPoints = ((ExpandedPair) pairs.get(pairs.size() - 1)).getFinderPattern ().getResultPoints(); return new Result(resultingString, null, new ResultPoint[]{firstPoints[0], firstPoints[1], lastPoints[0], lastPoints[1]}, BarcodeFormat.RSS_EXPANDED); }
private static BitMatrix sampleGrid(BitMatrix image, ResultPoint topLeft, ResultPoint bottomLeft, ResultPoint bottomRight, ResultPoint topRight, int dimensionX, int dimensionY) throws NotFoundException { return GridSampler.getInstance().sampleGrid(image, dimensionX, dimensionY, 0.5f, 0.5f, ( (float) dimensionX) - 0.5f, 0.5f, ((float) dimensionX) - 0.5f, ((float) dimensionY) - 0.5f, 0.5f, ((float) dimensionY) - 0.5f, topLeft.getX(), topLeft .getY(), topRight.getX(), topRight.getY(), bottomRight.getX(), bottomRight.getY() , bottomLeft.getX(), bottomLeft.getY()); }
private static DetectionResult merge(DetectionResultRowIndicatorColumn leftRowIndicatorColumn, DetectionResultRowIndicatorColumn rightRowIndicatorColumn) throws NotFoundException, FormatException { if (leftRowIndicatorColumn == null && rightRowIndicatorColumn == null) { return null; } BarcodeMetadata barcodeMetadata = getBarcodeMetadata(leftRowIndicatorColumn, rightRowIndicatorColumn); if (barcodeMetadata == null) { return null; } BoundingBox boundingBox = BoundingBox.merge(adjustBoundingBox(leftRowIndicatorColumn), adjustBoundingBox(rightRowIndicatorColumn)); return new DetectionResult(barcodeMetadata, boundingBox); }
private static BoundingBox adjustBoundingBox(DetectionResultRowIndicatorColumn rowIndicatorColumn) throws NotFoundException, FormatException { if (rowIndicatorColumn == null) { return null; } int[] rowHeights = rowIndicatorColumn.getRowHeights(); if (rowHeights == null) { return null; } int maxRowHeight = getMax(rowHeights); int missingStartRows = 0; for (int rowHeight : rowHeights) { missingStartRows += maxRowHeight - rowHeight; if (rowHeight > 0) { break; } } Codeword[] codewords = rowIndicatorColumn.getCodewords(); for (int row = 0; missingStartRows > 0 && codewords[row] == null; row++) { missingStartRows--; } int missingEndRows = 0; for (int row = rowHeights.length - 1; row >= 0; row--) { missingEndRows += maxRowHeight - rowHeights[row]; if (rowHeights[row] > 0) { break; } } for (int row = codewords.length - 1; missingEndRows > 0 && codewords[row] == null; row--) { missingEndRows--; } return rowIndicatorColumn.getBoundingBox().addMissingRows(missingStartRows, missingEndRows, rowIndicatorColumn.isLeft()); }
static BoundingBox merge(BoundingBox leftBox, BoundingBox rightBox) throws NotFoundException { if (leftBox == null) { return rightBox; } if (rightBox == null) { return leftBox; } return new BoundingBox(leftBox.image, leftBox.topLeft, leftBox.bottomLeft, rightBox.topRight, rightBox.bottomRight); }
private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension) throws NotFoundException { GridSampler sampler = GridSampler.getInstance(); return sampler.sampleGrid(image, dimension, dimension, transform); }
/** * <p>Attempts to locate an alignment pattern in a limited region of the image, which is * guessed to contain it. This method uses {@link AlignmentPattern}.</p> * * @param overallEstModuleSize estimated module size so far * @param estAlignmentX x coordinate of center of area probably containing alignment pattern * @param estAlignmentY y coordinate of above * @param allowanceFactor number of pixels in all directions to search from the center * @return {@link AlignmentPattern} if found, or null otherwise * @throws NotFoundException if an unexpected error occurs during detection */ protected final AlignmentPattern findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY, float allowanceFactor) throws NotFoundException { // Look for an alignment pattern (3 modules in size) around where it // should be int allowance = (int) (allowanceFactor * overallEstModuleSize); int alignmentAreaLeftX = Math.max(0, estAlignmentX - allowance); int alignmentAreaRightX = Math.min(image.getWidth() - 1, estAlignmentX + allowance); if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) { throw NotFoundException.getNotFoundInstance(); } int alignmentAreaTopY = Math.max(0, estAlignmentY - allowance); int alignmentAreaBottomY = Math.min(image.getHeight() - 1, estAlignmentY + allowance); if (alignmentAreaBottomY - alignmentAreaTopY < overallEstModuleSize * 3) { throw NotFoundException.getNotFoundInstance(); } AlignmentPatternFinder alignmentFinder = new AlignmentPatternFinder( image, alignmentAreaLeftX, alignmentAreaTopY, alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaBottomY - alignmentAreaTopY, overallEstModuleSize, resultPointCallback); return alignmentFinder.find(); }
/** * Identify where the start of the middle / payload section starts. * * @param row row of black/white values to search * @return Array, containing index of start of 'start block' and end of * 'start block' */ private int[] decodeStart(BitArray row) throws NotFoundException { int endStart = skipWhiteSpace(row); int[] startPattern = findGuardPattern(row, endStart, START_PATTERN); // Determine the width of a narrow line in pixels. We can do this by // getting the width of the start pattern and dividing by 4 because its // made up of 4 narrow lines. this.narrowLineWidth = (startPattern[1] - startPattern[0]) / 4; validateQuietZone(row, startPattern[0]); return startPattern; }
@Override protected int decodeMiddle(BitArray row, int[] startRange, StringBuilder result) throws NotFoundException { int[] counters = decodeMiddleCounters; counters[0] = 0; counters[1] = 0; counters[2] = 0; counters[3] = 0; int end = row.getSize(); int rowOffset = startRange[1]; int lgPatternFound = 0; for (int x = 0; x < 6 && rowOffset < end; x++) { int bestMatch = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS); result.append((char) ('0' + bestMatch % 10)); for (int counter : counters) { rowOffset += counter; } if (bestMatch >= 10) { lgPatternFound |= 1 << (5 - x); } } determineNumSysAndCheckDigit(result, lgPatternFound); return rowOffset; }
public AztecDetectorResult detect(boolean isMirror) throws NotFoundException { ResultPoint[] bullsEyeCorners = getBullsEyeCorners(getMatrixCenter()); if (isMirror) { ResultPoint temp = bullsEyeCorners[0]; bullsEyeCorners[0] = bullsEyeCorners[2]; bullsEyeCorners[2] = temp; } extractParameters(bullsEyeCorners); return new AztecDetectorResult(sampleGrid(this.image, bullsEyeCorners[this.shift % 4], bullsEyeCorners[(this.shift + 1) % 4], bullsEyeCorners[(this.shift + 2) % 4], bullsEyeCorners[(this.shift + 3) % 4]), getMatrixCornerPoints(bullsEyeCorners), this.compact, this.nbDataBlocks, this.nbLayers); }
private static void determineNumSysAndCheckDigit(StringBuilder resultString, int lgPatternFound) throws NotFoundException { for (int numSys = 0; numSys <= 1; numSys++) { for (int d = 0; d < 10; d++) { if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) { resultString.insert(0, (char) ('0' + numSys)); resultString.append((char) ('0' + d)); return; } } } throw NotFoundException.getNotFoundInstance(); }
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { for (OneDReader reader : readers) { try { return reader.decodeRow(rowNumber, row, hints); } catch (ReaderException re) { // continue } } throw NotFoundException.getNotFoundInstance(); }
private void extractParameters(ResultPoint[] bullsEyeCorners) throws NotFoundException { if (isValid(bullsEyeCorners[0]) && isValid(bullsEyeCorners[1]) && isValid (bullsEyeCorners[2]) && isValid(bullsEyeCorners[3])) { int[] sides = new int[]{sampleLine(bullsEyeCorners[0], bullsEyeCorners[1], length), sampleLine(bullsEyeCorners[1], bullsEyeCorners[2], length), sampleLine (bullsEyeCorners[2], bullsEyeCorners[3], length), sampleLine (bullsEyeCorners[3], bullsEyeCorners[0], this.nbCenterLayers * 2)}; this.shift = getRotation(sides, this.nbCenterLayers * 2); long parameterData = 0; for (int i = 0; i < 4; i++) { int side = sides[(this.shift + i) % 4]; if (this.compact) { parameterData = (parameterData << 7) + ((long) ((side >> 1) & 127)); } else { parameterData = (parameterData << 10) + ((long) (((side >> 2) & 992) + ((side >> 1) & 31))); } } int correctedData = getCorrectedParameterData(parameterData, this.compact); if (this.compact) { this.nbLayers = (correctedData >> 6) + 1; this.nbDataBlocks = (correctedData & 63) + 1; return; } this.nbLayers = (correctedData >> 11) + 1; this.nbDataBlocks = (correctedData & 2047) + 1; return; } throw NotFoundException.getNotFoundInstance(); }