/// <summary> /// <p>Convenience method that can decode a PDF417 Code represented as a 2D array of booleans. /// "true" is taken to mean a black module.</p> /// </summary> /// <param name="image"> booleans representing white/black PDF417 modules </param> /// <returns> text and bytes encoded within the PDF417 Code </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.common.DecoderResult decode(boolean[][] image) throws com.google.zxing.FormatException, com.google.zxing.ChecksumException public DecoderResult decode(bool[][] image) { int dimension = image.Length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { if (image[j][i]) { bits.set(j, i); } } } return decode(bits); }
/// <summary> /// <p>Reads a bit of the mapping matrix accounting for boundary wrapping.</p> /// </summary> /// <param name="row"> Row to read in the mapping matrix </param> /// <param name="column"> Column to read in the mapping matrix </param> /// <param name="numRows"> Number of rows in the mapping matrix </param> /// <param name="numColumns"> Number of columns in the mapping matrix </param> /// <returns> value of the given bit in the mapping matrix </returns> internal bool readModule(int row, int column, int numRows, int numColumns) { // Adjust the row and column indices based on boundary wrapping if (row < 0) { row += numRows; column += 4 - ((numRows + 4) & 0x07); } if (column < 0) { column += numColumns; row += 4 - ((numColumns + 4) & 0x07); } readMappingMatrix.set(column, row); return(mappingBitMatrix.get(column, row)); }
/// <summary> /// <p>Convenience method that can decode a Data Matrix Code represented as a 2D array of booleans. /// "true" is taken to mean a black module.</p> /// </summary> /// <param name="image"> booleans representing white/black Data Matrix Code modules </param> /// <returns> text and bytes encoded within the Data Matrix Code </returns> /// <exception cref="FormatException"> if the Data Matrix Code cannot be decoded </exception> /// <exception cref="ChecksumException"> if error correction fails </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.common.DecoderResult decode(boolean[][] image) throws com.google.zxing.FormatException, com.google.zxing.ChecksumException public DecoderResult decode(bool[][] image) { int dimension = image.Length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { if (image[i][j]) { bits.set(j, i); } } } return(decode(bits)); }
/// <summary> /// <p>Extracts the data region from a <seealso cref="BitMatrix"/> that contains /// alignment patterns.</p> /// </summary> /// <param name="bitMatrix"> Original <seealso cref="BitMatrix"/> with alignment patterns </param> /// <returns> BitMatrix that has the alignment patterns removed </returns> internal BitMatrix extractDataRegion(BitMatrix bitMatrix) { int symbolSizeRows = version.SymbolSizeRows; int symbolSizeColumns = version.SymbolSizeColumns; if (bitMatrix.Height != symbolSizeRows) { throw new System.ArgumentException("Dimension of bitMarix must match the version size"); } int dataRegionSizeRows = version.DataRegionSizeRows; int dataRegionSizeColumns = version.DataRegionSizeColumns; int numDataRegionsRow = symbolSizeRows / dataRegionSizeRows; int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow); for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; for (int i = 0; i < dataRegionSizeRows; ++i) { int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; int writeRowOffset = dataRegionRowOffset + i; for (int j = 0; j < dataRegionSizeColumns; ++j) { int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; if (bitMatrix.get(readColumnOffset, readRowOffset)) { int writeColumnOffset = dataRegionColumnOffset + j; bitMatrixWithoutAlignment.set(writeColumnOffset, writeRowOffset); } } } } } return(bitMatrixWithoutAlignment); }
/// <summary> /// 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. /// </summary> /// <seealso cref= com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix) </seealso> /// <seealso cref= com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix) </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static com.google.zxing.common.BitMatrix extractPureBits(com.google.zxing.common.BitMatrix image) throws com.google.zxing.NotFoundException private static BitMatrix extractPureBits(BitMatrix image) { int[] leftTopBlack = image.TopLeftOnBit; int[] rightBottomBlack = image.BottomRightOnBit; if (leftTopBlack == null || rightBottomBlack == null) { throw NotFoundException.NotFoundInstance; } int moduleSize = getModuleSize(leftTopBlack, image); int top = leftTopBlack[1]; int bottom = rightBottomBlack[1]; int left = findPatternStart(leftTopBlack[0], top, image); int right = findPatternEnd(leftTopBlack[0], top, image); int matrixWidth = (right - left + 1) / moduleSize; int matrixHeight = (bottom - top + 1) / moduleSize; if (matrixWidth <= 0 || matrixHeight <= 0) { throw NotFoundException.NotFoundInstance; } // 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; }
/// <summary> /// <p>Convenience method that can decode a QR Code represented as a 2D array of booleans. /// "true" is taken to mean a black module.</p> /// </summary> /// <param name="image"> booleans representing white/black QR Code modules </param> /// <returns> text and bytes encoded within the QR Code </returns> /// <exception cref="FormatException"> if the QR Code cannot be decoded </exception> /// <exception cref="ChecksumException"> if error correction fails </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public com.google.zxing.common.DecoderResult decode(boolean[][] image, java.util.Map<com.google.zxing.DecodeHintType,?> hints) throws com.google.zxing.ChecksumException, com.google.zxing.FormatException public DecoderResult decode(bool[][] image, IDictionary<DecodeHintType, object> hints) { int dimension = image.Length; BitMatrix bits = new BitMatrix(dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { if (image[i][j]) { bits.set(j, i); } } } return decode(bits, hints); }
/// <summary> /// 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. /// </summary> /// <seealso cref= com.google.zxing.pdf417.PDF417Reader#extractPureBits(BitMatrix) </seealso> /// <seealso cref= com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix) </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static com.google.zxing.common.BitMatrix extractPureBits(com.google.zxing.common.BitMatrix image) throws com.google.zxing.NotFoundException private static BitMatrix extractPureBits(BitMatrix image) { int[] leftTopBlack = image.TopLeftOnBit; int[] rightBottomBlack = image.BottomRightOnBit; if (leftTopBlack == null || rightBottomBlack == null) { throw NotFoundException.NotFoundInstance; } float moduleSize = getModuleSize(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 = (int)Math.Round((right - left + 1) / moduleSize); int matrixHeight = (int) Math.Round((bottom - top + 1) / moduleSize); if (matrixWidth <= 0 || matrixHeight <= 0) { throw NotFoundException.NotFoundInstance; } if (matrixHeight != matrixWidth) { // Only possibly decode square regions throw NotFoundException.NotFoundInstance; } // 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; // 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; }
/// <summary> /// <p>Extracts the data region from a <seealso cref="BitMatrix"/> that contains /// alignment patterns.</p> /// </summary> /// <param name="bitMatrix"> Original <seealso cref="BitMatrix"/> with alignment patterns </param> /// <returns> BitMatrix that has the alignment patterns removed </returns> internal BitMatrix extractDataRegion(BitMatrix bitMatrix) { int symbolSizeRows = version.SymbolSizeRows; int symbolSizeColumns = version.SymbolSizeColumns; if (bitMatrix.Height != symbolSizeRows) { throw new System.ArgumentException("Dimension of bitMarix must match the version size"); } int dataRegionSizeRows = version.DataRegionSizeRows; int dataRegionSizeColumns = version.DataRegionSizeColumns; int numDataRegionsRow = symbolSizeRows / dataRegionSizeRows; int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; BitMatrix bitMatrixWithoutAlignment = new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow); for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; for (int i = 0; i < dataRegionSizeRows; ++i) { int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; int writeRowOffset = dataRegionRowOffset + i; for (int j = 0; j < dataRegionSizeColumns; ++j) { int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; if (bitMatrix.get(readColumnOffset, readRowOffset)) { int writeColumnOffset = dataRegionColumnOffset + j; bitMatrixWithoutAlignment.set(writeColumnOffset, writeRowOffset); } } } } } return bitMatrixWithoutAlignment; }