@Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(CANCELAR)) { PPal.get().seleccionarPrimerFactura(); } else if (e.getActionCommand().equals(CONFIRMAR)) { PPal.get().agregarFactura(getNewFactura()); } else if (e.getActionCommand().equals(CARGAR)) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { txtBono.setText(ManagerQR.readQRCode(chooser.getSelectedFile())); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (NotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }
private static BitMatrix extractPureBits(BitMatrix bitmatrix) throws NotFoundException { int ai[] = bitmatrix.getTopLeftOnBit(); int ai1[] = bitmatrix.getBottomRightOnBit(); if (ai == null || ai1 == null) { throw NotFoundException.getNotFoundInstance(); } int l = moduleSize(ai, bitmatrix); int i1 = ai[1]; int i = ai1[1]; int j1 = ai[0]; int k1 = ((ai1[0] - j1) + 1) / l; int l1 = ((i - i1) + 1) / l; if (k1 <= 0 || l1 <= 0) { throw NotFoundException.getNotFoundInstance(); } int i2 = l >> 1; BitMatrix bitmatrix1 = new BitMatrix(k1, l1); for (int j = 0; j < l1; j++) { for (int k = 0; k < k1; k++) { if (bitmatrix.get(k * l + (j1 + i2), i1 + i2 + j * l)) { bitmatrix1.set(k, j); } } } return bitmatrix1; }
// YUVオブジェクトのバイナリデータを読み込み、マーカーを検知 public void readYUV( final byte[] data, int dataWidth, int dataHeight, int left, int top, int width, int height, boolean reserversion) { final LuminanceSource source = new PlanarYUVLuminanceSource( data, dataWidth, dataHeight, left, top, width, height, reserversion); final BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); // final Reader reader = new MultiFormatReader(); final Reader reader = new QRCodeReader(); try { // 結果をゲット mQRResult.setResultData(reader.decode(binaryBitmap)); mFoundFlag = true; } // 見つからなかった! catch (NotFoundException ex) { ex.printStackTrace(); mFoundFlag = false; } catch (ChecksumException ex) { ex.printStackTrace(); mFoundFlag = false; } catch (FormatException ex) { ex.printStackTrace(); mFoundFlag = false; } }
public final BitMatrix sampleGrid( BitMatrix bitmatrix, int i, int j, PerspectiveTransform perspectivetransform) throws NotFoundException { if (i <= 0 || j <= 0) { throw NotFoundException.getNotFoundInstance(); } BitMatrix bitmatrix1 = new BitMatrix(i, j); float af[] = new float[i << 1]; for (i = 0; i < j; i++) { int i1 = af.length; float f = i; for (int k = 0; k < i1; k += 2) { af[k] = (float) (k >> 1) + 0.5F; af[k + 1] = f + 0.5F; } perspectivetransform.transformPoints(af); checkAndNudgePoints(bitmatrix, af); int l = 0; while (l < i1) { try { if (bitmatrix.get((int) af[l], (int) af[l + 1])) { bitmatrix1.set(l >> 1, i); } } // Misplaced declaration of an exception variable catch (BitMatrix bitmatrix) { throw NotFoundException.getNotFoundInstance(); } l += 2; } } return bitmatrix1; }
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType, ?> hints) throws NotFoundException, ChecksumException, FormatException { int[] start = findAsteriskPattern(row); // Read off white space int nextStart = row.getNextSet(start[1]); int end = row.getSize(); StringBuilder result = new StringBuilder(20); int[] counters = new int[6]; char decodedChar; int lastStart; do { recordPattern(row, nextStart, counters); int pattern = toPattern(counters); if (pattern < 0) { throw NotFoundException.getNotFoundInstance(); } decodedChar = patternToChar(pattern); result.append(decodedChar); lastStart = nextStart; for (int counter : counters) { nextStart += counter; } // Read off white space nextStart = row.getNextSet(nextStart); } while (decodedChar != '*'); result.deleteCharAt(result.length() - 1); // remove asterisk // Should be at least one more black module if (nextStart == end || !row.get(nextStart)) { throw NotFoundException.getNotFoundInstance(); } if (result.length() < 2) { // false positive -- need at least 2 checksum digits throw NotFoundException.getNotFoundInstance(); } checkChecksums(result); // Remove checksum digits result.setLength(result.length() - 2); String resultString = decodeExtended(result); float left = (float) (start[1] + start[0]) / 2.0f; float right = (float) (nextStart + lastStart) / 2.0f; return new Result( resultString, null, new ResultPoint[] { new ResultPoint(left, (float) rowNumber), new ResultPoint(right, (float) rowNumber) }, BarcodeFormat.CODE_93); }
public Result getRawResult(Bitmap bitmap) { if (bitmap == null) { return null; } try { return multiFormatReader.decodeWithState( new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(bitmap)))); } catch (NotFoundException e) { e.printStackTrace(); } return null; }
/** * This method detects a code in a "pure" image -- that is, pure monochrome image which contains * only an unrotated, unskewed, image of a code, with some white border around it. This is a * specialized method that works exceptionally fast in this special case. * * @see com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix) * @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix) */ private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException { int[] leftTopBlack = image.getTopLeftOnBit(); int[] rightBottomBlack = image.getBottomRightOnBit(); if (leftTopBlack == null || rightBottomBlack == null) { throw NotFoundException.getNotFoundInstance(); } int moduleSize = moduleSize(leftTopBlack, image); int top = leftTopBlack[1]; int bottom = rightBottomBlack[1]; int left = leftTopBlack[0]; int right = rightBottomBlack[0]; if (bottom - top != right - left) { // Special case, where bottom-right module wasn't black so we found // something else in // the last row // Assume it's a square, so use height as the width right = left + (bottom - top); } int matrixWidth = (right - left + 1) / moduleSize; int matrixHeight = (bottom - top + 1) / moduleSize; if (matrixWidth <= 0 || matrixHeight <= 0) { throw NotFoundException.getNotFoundInstance(); } if (matrixHeight != matrixWidth) { // Only possibly decode square regions throw NotFoundException.getNotFoundInstance(); } // Push in the "border" by half the module width so that we start // sampling in the middle of the module. Just in case the image is a // little off, this will help recover. int nudge = moduleSize >> 1; top += nudge; left += nudge; // Now just read off the bits BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight); for (int y = 0; y < matrixHeight; y++) { int iOffset = top + y * moduleSize; for (int x = 0; x < matrixWidth; x++) { if (image.get(left + x * moduleSize, iOffset)) { bits.set(x, y); } } } return bits; }
protected final AlignmentPattern a(float paramFloat1, int paramInt1, int paramInt2, float paramFloat2) { int i = (int)(paramFloat2 * paramFloat1); int j = Math.max(0, paramInt1 - i); int k = Math.min(-1 + this.a.c(), paramInt1 + i); if (k - j < paramFloat1 * 3.0F) throw NotFoundException.a(); int m = Math.max(0, paramInt2 - i); int n = Math.min(-1 + this.a.d(), i + paramInt2); if (n - m < paramFloat1 * 3.0F) throw NotFoundException.a(); return new AlignmentPatternFinder(this.a, j, m, k - j, n - m, paramFloat1, this.b).a(); }
private static int moduleSize(int ai[], BitMatrix bitmatrix) throws NotFoundException { int j = bitmatrix.getWidth(); int i = ai[0]; for (int k = ai[1]; i < j && bitmatrix.get(i, k); i++) {} if (i == j) { throw NotFoundException.getNotFoundInstance(); } i -= ai[0]; if (i == 0) { throw NotFoundException.getNotFoundInstance(); } else { return i; } }
private static int[] findAsteriskPattern(BitArray row) throws NotFoundException { int width = row.getSize(); int rowOffset = row.getNextSet(0); int counterPosition = 0; int[] counters = new int[6]; int patternStart = rowOffset; boolean isWhite = false; int patternLength = counters.length; for (int i = rowOffset; i < width; i++) { if (row.get(i) ^ isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { if (toPattern(counters) == ASTERISK_ENCODING) { return new int[] {patternStart, i}; } patternStart += counters[0] + counters[1]; System.arraycopy(counters, 2, counters, 0, patternLength - 2); counters[patternLength - 2] = 0; counters[patternLength - 1] = 0; counterPosition--; } else { counterPosition++; } counters[counterPosition] = 1; isWhite = !isWhite; } } throw NotFoundException.getNotFoundInstance(); }
/** * @param row row of black/white values to search * @param rowOffset position to start search * @param pattern pattern of counts of number of black and white pixels that are being searched * for as a pattern * @return start/end horizontal offset of guard pattern, as an array of two ints * @throws NotFoundException if pattern is not found */ private static int[] findGuardPattern(BitArray row, int rowOffset, int[] pattern) throws NotFoundException { // TODO: This is very similar to implementation in UPCEANReader. // Consider if they can be // merged to a single method. int patternLength = pattern.length; int[] counters = new int[patternLength]; int width = row.getSize(); boolean isWhite = false; int counterPosition = 0; int patternStart = rowOffset; for (int x = rowOffset; x < width; x++) { if (row.get(x) ^ isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { return new int[] {patternStart, x}; } patternStart += counters[0] + counters[1]; System.arraycopy(counters, 2, counters, 0, patternLength - 2); counters[patternLength - 2] = 0; counters[patternLength - 1] = 0; counterPosition--; } else { counterPosition++; } counters[counterPosition] = 1; isWhite = !isWhite; } } throw NotFoundException.getNotFoundInstance(); }
private static int moduleSize(int[] leftTopBlack, BitMatrix image) throws NotFoundException { int width = image.getWidth(); int x = leftTopBlack[0]; int y = leftTopBlack[1]; while (x < width && image.get(x, y)) { x++; } if (x == width) { throw NotFoundException.getNotFoundInstance(); } int moduleSize = x - leftTopBlack[0]; if (moduleSize == 0) { throw NotFoundException.getNotFoundInstance(); } return moduleSize; }
private static char patternToChar(int pattern) throws NotFoundException { for (int i = 0; i < CHARACTER_ENCODINGS.length; i++) { if (CHARACTER_ENCODINGS[i] == pattern) { return ALPHABET[i]; } } throw NotFoundException.getNotFoundInstance(); }
private static int determineCheckDigit(int lgPatternFound) throws NotFoundException { for (int d = 0; d < 10; d++) { if (lgPatternFound == CHECK_DIGIT_ENCODINGS[d]) { return d; } } throw NotFoundException.getNotFoundInstance(); }
/** * Skip all whitespace until we get to the first black line. * * @param row row of black/white values to search * @return index of the first black line. * @throws NotFoundException Throws exception if no black lines are found in the row */ private static int skipWhiteSpace(BitArray row) throws NotFoundException { int width = row.getSize(); int endStart = row.getNextSet(0); if (endStart == width) { throw NotFoundException.getNotFoundInstance(); } return endStart; }
int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) 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 < 5 && rowOffset < end; x++) { int bestMatch = UPCEANReader.decodeDigit(row, counters, rowOffset, UPCEANReader.L_AND_G_PATTERNS); resultString.append((char) ('0' + bestMatch % 10)); for (int counter : counters) { rowOffset += counter; } if (bestMatch >= 10) { lgPatternFound |= 1 << (4 - x); } if (x != 4) { // Read off separator if not last while (rowOffset < end && !row.get(rowOffset)) { rowOffset++; } while (rowOffset < end && row.get(rowOffset)) { rowOffset++; } } } if (resultString.length() != 5) { throw NotFoundException.getNotFoundInstance(); } int checkDigit = determineCheckDigit(lgPatternFound); if (extensionChecksum(resultString.toString()) != checkDigit) { throw NotFoundException.getNotFoundInstance(); } return rowOffset; }
private static int estimateBlackPoint(int[] buckets) throws NotFoundException { // Find the tallest peak in the histogram. int numBuckets = buckets.length; int maxBucketCount = 0; int firstPeak = 0; int firstPeakSize = 0; for (int x = 0; x < numBuckets; x++) { if (buckets[x] > firstPeakSize) { firstPeak = x; firstPeakSize = buckets[x]; } if (buckets[x] > maxBucketCount) { maxBucketCount = buckets[x]; } } // Find the second-tallest peak which is somewhat far from the tallest peak. int secondPeak = 0; int secondPeakScore = 0; for (int x = 0; x < numBuckets; x++) { int distanceToBiggest = x - firstPeak; // Encourage more distant second peaks by multiplying by square of distance. int score = buckets[x] * distanceToBiggest * distanceToBiggest; if (score > secondPeakScore) { secondPeak = x; secondPeakScore = score; } } // Make sure firstPeak corresponds to the black peak. if (firstPeak > secondPeak) { int temp = firstPeak; firstPeak = secondPeak; secondPeak = temp; } // If there is too little contrast in the image to pick a meaningful black point, throw rather // than waste time trying to decode the image, and risk false positives. if (secondPeak - firstPeak <= numBuckets >> 4) { throw NotFoundException.getNotFoundInstance(); } // Find a valley between them that is low and closer to the white peak. int bestValley = secondPeak - 1; int bestValleyScore = -1; for (int x = secondPeak - 1; x > firstPeak; x--) { int fromFirst = x - firstPeak; int score = fromFirst * fromFirst * (secondPeak - x) * (maxBucketCount - buckets[x]); if (score > bestValleyScore) { bestValley = x; bestValleyScore = score; } } return bestValley << LUMINANCE_SHIFT; }
/** * @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are those * that have been detected at least {@link #CENTER_QUORUM} times, and whose module size * differs from the average among those patterns the least * @throws NotFoundException if 3 such finder patterns do not exist */ private FinderPattern[] selectBestPatterns() throws NotFoundException { int startSize = possibleCenters.size(); if (startSize < 3) { // Couldn't find enough finder patterns throw NotFoundException.getNotFoundInstance(); } // Filter outlier possibilities whose module size is too different if (startSize > 3) { // But we can only afford to do so if we have at least 4 possibilities to choose from float totalModuleSize = 0.0f; float square = 0.0f; for (FinderPattern center : possibleCenters) { float size = center.getEstimatedModuleSize(); totalModuleSize += size; square += size * size; } float average = totalModuleSize / (float) startSize; float stdDev = (float) Math.sqrt(square / startSize - average * average); Collections.sort(possibleCenters, new FurthestFromAverageComparator(average)); float limit = Math.max(0.2f * average, stdDev); for (int i = 0; i < possibleCenters.size() && possibleCenters.size() > 3; i++) { FinderPattern pattern = possibleCenters.get(i); if (Math.abs(pattern.getEstimatedModuleSize() - average) > limit) { possibleCenters.remove(i); i--; } } } if (possibleCenters.size() > 3) { // Throw away all but those first size candidate points we found. float totalModuleSize = 0.0f; for (FinderPattern possibleCenter : possibleCenters) { totalModuleSize += possibleCenter.getEstimatedModuleSize(); } float average = totalModuleSize / (float) possibleCenters.size(); Collections.sort(possibleCenters, new CenterComparator(average)); possibleCenters.subList(3, possibleCenters.size()).clear(); } return new FinderPattern[] { possibleCenters.get(0), possibleCenters.get(1), possibleCenters.get(2) }; }
/** * This method detects a code in a "pure" image -- that is, pure monochrome image which contains * only an unrotated, unskewed, image of a code, with some white border around it. This is a * specialized method that works exceptionally fast in this special case. * * @see com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix) * @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix) */ private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException { int[] leftTopBlack = image.getTopLeftOnBit(); int[] rightBottomBlack = image.getBottomRightOnBit(); if (leftTopBlack == null || rightBottomBlack == null) { throw NotFoundException.getNotFoundInstance(); } int moduleSize = moduleSize(leftTopBlack, image); int top = leftTopBlack[1]; int bottom = rightBottomBlack[1]; int left = leftTopBlack[0]; int right = rightBottomBlack[0]; int matrixWidth = (right - left + 1) / moduleSize; int matrixHeight = (bottom - top + 1) / moduleSize; if (matrixWidth == 0 || matrixHeight == 0) { throw NotFoundException.getNotFoundInstance(); } // Push in the "border" by half the module width so that we start // sampling in the middle of the module. Just in case the image is a // little off, this will help recover. int nudge = moduleSize >> 1; top += nudge; left += nudge; // Now just read off the bits BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight); for (int y = 0; y < matrixHeight; y++) { int iOffset = top + y * moduleSize; for (int x = 0; x < matrixWidth; x++) { if (image.get(left + x * moduleSize, iOffset)) { bits.set(x, y); } } } return bits; }
protected final DetectorResult a(FinderPatternInfo paramFinderPatternInfo) { FinderPattern localFinderPattern1 = paramFinderPatternInfo.b(); FinderPattern localFinderPattern2 = paramFinderPatternInfo.c(); FinderPattern localFinderPattern3 = paramFinderPatternInfo.a(); float f1 = a(localFinderPattern1, localFinderPattern2, localFinderPattern3); if (f1 < 1.0F) throw NotFoundException.a(); int i = a(localFinderPattern1, localFinderPattern2, localFinderPattern3, f1); Version localVersion = Version.a(i); int j = -7 + localVersion.d(); int k = localVersion.b().length; Object localObject = null; int m; int n; int i1; float f5; if (k > 0) { float f2 = localFinderPattern2.a() - localFinderPattern1.a() + localFinderPattern3.a(); float f3 = localFinderPattern2.b() - localFinderPattern1.b() + localFinderPattern3.b(); float f4 = 1.0F - 3.0F / j; m = (int)(localFinderPattern1.a() + f4 * (f2 - localFinderPattern1.a())); n = (int)(localFinderPattern1.b() + f4 * (f3 - localFinderPattern1.b())); i1 = 4; localObject = null; if (i1 <= 16) f5 = i1; } while (true) { try { AlignmentPattern localAlignmentPattern = a(f1, m, n, f5); localObject = localAlignmentPattern; PerspectiveTransform localPerspectiveTransform = a(localFinderPattern1, localFinderPattern2, localFinderPattern3, localObject, i); BitMatrix localBitMatrix = a(this.a, localPerspectiveTransform, i); if (localObject != null) break label270; arrayOfResultPoint = new ResultPoint[] { localFinderPattern3, localFinderPattern1, localFinderPattern2 }; return new DetectorResult(localBitMatrix, arrayOfResultPoint); } catch (NotFoundException localNotFoundException) { i1 <<= 1; } break; label270: ResultPoint[] arrayOfResultPoint = { localFinderPattern3, localFinderPattern1, localFinderPattern2, localObject }; } }
/** * Detects a PDF417 Code in an image. Only checks 0 and 180 degree rotations. * * @param hints optional hints to detector * @return {@link DetectorResult} encapsulating results of detecting a PDF417 Code * @throws NotFoundException if no PDF417 Code can be found */ public DetectorResult detect(Hashtable<?, ?> hints) throws NotFoundException { // Fetch the 1 bit matrix once up front. BitMatrix matrix = image.getBlackMatrix(); // Try to find the vertices assuming the image is upright. ResultPoint[] vertices = findVertices(matrix); if (vertices == null) { // Maybe the image is rotated 180 degrees? vertices = findVertices180(matrix); if (vertices != null) { correctCodeWordVertices(vertices, true); } } else { correctCodeWordVertices(vertices, false); } if (vertices == null) { throw NotFoundException.getNotFoundInstance(); } float moduleWidth = computeModuleWidth(vertices); if (moduleWidth < 1.0f) { throw NotFoundException.getNotFoundInstance(); } int dimension = computeDimension(vertices[4], vertices[6], vertices[5], vertices[7], moduleWidth); if (dimension < 1) { throw NotFoundException.getNotFoundInstance(); } // Deskew and sample image. BitMatrix bits = sampleGrid(matrix, vertices[4], vertices[5], vertices[6], vertices[7], dimension); return new DetectorResult( bits, new ResultPoint[] {vertices[4], vertices[5], vertices[6], vertices[7]}); }
@Override public Result[] decodeMultiple(BinaryBitmap image, @SuppressWarnings("rawtypes") Hashtable hints) throws NotFoundException { @SuppressWarnings("rawtypes") Vector results = new Vector(); doDecodeMultiple(image, hints, results, 0, 0); if (results.isEmpty()) { throw NotFoundException.getNotFoundInstance(); } int numResults = results.size(); Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result) results.elementAt(i); } return resultArray; }
private FinderPattern[] selectBestPatterns() throws NotFoundException { int i = this.possibleCenters.size(); if (i < 3) { throw NotFoundException.getNotFoundInstance(); } if (i > 3) { float f3 = 0.0F; float f4 = 0.0F; Iterator localIterator2 = this.possibleCenters.iterator(); while (localIterator2.hasNext()) { float f8 = ((FinderPattern)localIterator2.next()).getEstimatedModuleSize(); f3 += f8; f4 += f8 * f8; } float f5 = f3 / i; float f6 = (float)Math.sqrt(f4 / i - f5 * f5); Collections.sort(this.possibleCenters, new FurthestFromAverageComparator(f5, null)); float f7 = Math.max(0.2F * f5, f6); for (int j = 0; (j < this.possibleCenters.size()) && (this.possibleCenters.size() > 3); j++) { if (Math.abs(((FinderPattern)this.possibleCenters.get(j)).getEstimatedModuleSize() - f5) > f7) { this.possibleCenters.remove(j); j--; } } } if (this.possibleCenters.size() > 3) { float f1 = 0.0F; Iterator localIterator1 = this.possibleCenters.iterator(); while (localIterator1.hasNext()) { f1 += ((FinderPattern)localIterator1.next()).getEstimatedModuleSize(); } float f2 = f1 / this.possibleCenters.size(); Collections.sort(this.possibleCenters, new CenterComparator(f2, null)); this.possibleCenters.subList(3, this.possibleCenters.size()).clear(); } FinderPattern[] arrayOfFinderPattern = new FinderPattern[3]; arrayOfFinderPattern[0] = ((FinderPattern)this.possibleCenters.get(0)); arrayOfFinderPattern[1] = ((FinderPattern)this.possibleCenters.get(1)); arrayOfFinderPattern[2] = ((FinderPattern)this.possibleCenters.get(2)); return arrayOfFinderPattern; }
public WhiteRectangleDetector(BitMatrix bitmatrix, int i, int j, int k) throws NotFoundException { image = bitmatrix; height = bitmatrix.getHeight(); width = bitmatrix.getWidth(); i /= 2; leftInit = j - i; rightInit = j + i; upInit = k - i; downInit = k + i; if (upInit < 0 || leftInit < 0 || downInit >= height || rightInit >= width) { throw NotFoundException.getNotFoundInstance(); } else { return; } }
/** * 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 { int 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]; int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE); if (variance < bestVariance) { bestVariance = variance; bestMatch = i; } } if (bestMatch >= 0) { return bestMatch; } else { throw NotFoundException.getNotFoundInstance(); } }
/** * The start & end patterns must be pre/post fixed by a quiet zone. This zone must be at least 10 * times the width of a narrow line. Scan back until we either get to the start of the barcode or * match the necessary number of quiet zone pixels. * * <p>Note: Its assumed the row is reversed when using this method to find quiet zone after the * end pattern. * * <p>ref: http://www.barcode-1.net/i25code.html * * @param row bit array representing the scanned barcode. * @param startPattern index into row of the start or end pattern. * @throws NotFoundException if the quiet zone cannot be found, a ReaderException is thrown. */ private void validateQuietZone(BitArray row, int startPattern) throws NotFoundException { int quietCount = this.narrowLineWidth * 10; // expect to find this many // pixels of quiet zone // if there are not so many pixel at all let's try as many as possible quietCount = quietCount < startPattern ? quietCount : startPattern; for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) { if (row.get(i)) { break; } quietCount--; } if (quietCount != 0) { // Unable to find the necessary number of quiet zone pixels. throw NotFoundException.getNotFoundInstance(); } }
private static int a(ResultPoint paramResultPoint1, ResultPoint paramResultPoint2, ResultPoint paramResultPoint3, float paramFloat) { int i = 7 + (MathUtils.a(ResultPoint.a(paramResultPoint1, paramResultPoint2) / paramFloat) + MathUtils.a(ResultPoint.a(paramResultPoint1, paramResultPoint3) / paramFloat) >> 1); switch (i & 0x3) { case 1: default: case 0: case 2: while (true) { return i; i++; continue; i--; } case 3: } throw NotFoundException.a(); }
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; }
public String parseInformation() throws NotFoundException { if (getInformation().getSize() < 48) { throw NotFoundException.getNotFoundInstance(); } StringBuilder localStringBuilder = new StringBuilder(); encodeCompressedGtin(localStringBuilder, 8); int i = getGeneralDecoder().extractNumericValueFromBitArray(48, 2); localStringBuilder.append("(393"); localStringBuilder.append(i); localStringBuilder.append(')'); int j = getGeneralDecoder().extractNumericValueFromBitArray(50, 10); if (j / 100 == 0) { localStringBuilder.append('0'); } if (j / 10 == 0) { localStringBuilder.append('0'); } localStringBuilder.append(j); localStringBuilder.append( getGeneralDecoder().decodeGeneralPurposeField(60, null).getNewString()); return localStringBuilder.toString(); }
private static int[] findAsteriskPattern(BitArray row, int[] counters) throws NotFoundException { // Should not be needed, but appears to work around a Java 7 JIT bug? This comes in corrupted Arrays.fill(counters, 0); int width = row.getSize(); int rowOffset = row.getNextSet(0); int counterPosition = 0; int patternStart = rowOffset; boolean isWhite = false; int patternLength = counters.length; for (int i = rowOffset; i < width; i++) { if (row.get(i) ^ isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { // Look for whitespace before start pattern, >= 50% of width of start pattern if (toNarrowWidePattern(counters) == ASTERISK_ENCODING && row.isRange( Math.max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) { return new int[] {patternStart, i}; } patternStart += counters[0] + counters[1]; System.arraycopy(counters, 2, counters, 0, patternLength - 2); counters[patternLength - 2] = 0; counters[patternLength - 1] = 0; counterPosition--; } else { counterPosition++; } counters[counterPosition] = 1; isWhite = !isWhite; } } throw NotFoundException.getNotFoundInstance(); }