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; }
/** * 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; }
/** * 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; }
/** * 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.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(); } float moduleSize = moduleSize(leftTopBlack, image); int top = leftTopBlack[1]; int bottom = rightBottomBlack[1]; int left = leftTopBlack[0]; int right = rightBottomBlack[0]; // Sanity check! if (left >= right || top >= bottom) { throw NotFoundException.getNotFoundInstance(); } 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 = Math.round((right - left + 1) / moduleSize); int matrixHeight = Math.round((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 = (int) (moduleSize / 2.0f); top += nudge; left += nudge; // But careful that this does not sample off the edge int nudgedTooFarRight = left + (int) ((matrixWidth - 1) * moduleSize) - (right - 1); if (nudgedTooFarRight > 0) { if (nudgedTooFarRight > nudge) { // Neither way fits; abort throw NotFoundException.getNotFoundInstance(); } left -= nudgedTooFarRight; } int nudgedTooFarDown = top + (int) ((matrixHeight - 1) * moduleSize) - (bottom - 1); if (nudgedTooFarDown > 0) { if (nudgedTooFarDown > nudge) { // Neither way fits; abort throw NotFoundException.getNotFoundInstance(); } top -= nudgedTooFarDown; } // Now just read off the bits BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight); for (int y = 0; y < matrixHeight; y++) { int iOffset = top + (int) (y * moduleSize); for (int x = 0; x < matrixWidth; x++) { if (image.get(left + (int) (x * moduleSize), iOffset)) { bits.set(x, y); } } } return bits; }