IDataBlock block = new DataBlock(); for (DataBlockDecorator extender : this.getExtenders()) { extender.extend(block); block = extender; }
private Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, int dataRegionSizeColumns, ECBlocks ecBlocks) { this.versionNumber = versionNumber; this.symbolSizeRows = symbolSizeRows; this.symbolSizeColumns = symbolSizeColumns; this.dataRegionSizeRows = dataRegionSizeRows; this.dataRegionSizeColumns = dataRegionSizeColumns; this.ecBlocks = ecBlocks; // Calculate the total number of codewords int total = 0; int ecCodewords = ecBlocks.getECCodewords(); ECB[] ecbArray = ecBlocks.getECBlocks(); for (int i = 0; i < ecbArray.length; i++) { ECB ecBlock = ecbArray[i]; total += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords); } this.totalCodewords = total; }
BitMatrixParser parser = new BitMatrixParser(bits); Version version = parser.readVersion(bits); byte[] codewords = parser.readCodewords(); DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version); totalBytes += dataBlocks[i].getNumDataCodewords(); byte[] codewordBytes = dataBlock.getCodewords(); int numDataCodewords = dataBlock.getNumDataCodewords(); correctErrors(codewordBytes, numDataCodewords); for (int i = 0; i < numDataCodewords; i++) { resultBytes[resultOffset++] = codewordBytes[i]; return DecodedBitStreamParser.decode(resultBytes);
Version version) { Version.ECBlocks ecBlocks = version.getECBlocks(); Version.ECB[] ecBlockArray = ecBlocks.getECBlocks(); for (int i = 0; i < ecBlockArray.length; i++) { totalBlocks += ecBlockArray[i].getCount(); for (int j = 0; j < ecBlockArray.length; j++) { Version.ECB ecBlock = ecBlockArray[j]; for (int i = 0; i < ecBlock.getCount(); i++) { int numDataCodewords = ecBlock.getDataCodewords(); int numBlockCodewords = ecBlocks.getECCodewords() + numDataCodewords; result[numResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]); int longerBlocksNumDataCodewords = longerBlocksTotalCodewords - ecBlocks.getECCodewords(); int shorterBlocksNumDataCodewords = longerBlocksNumDataCodewords - 1; boolean specialVersion = version.getVersionNumber() == 24; int numLongerBlocks = specialVersion ? 8 : numResultBlocks; for (int j = 0; j < numLongerBlocks; j++) {
new Version(1, 10, 10, 8, 8, new ECBlocks(5, new ECB(1, 3))), new Version(2, 12, 12, 10, 10, new ECBlocks(7, new ECB(1, 5))), new Version(3, 14, 14, 12, 12, new ECBlocks(10, new ECB(1, 8))), new Version(4, 16, 16, 14, 14, new ECBlocks(12, new ECB(1, 12))), new Version(5, 18, 18, 16, 16, new ECBlocks(14, new ECB(1, 18))), new Version(6, 20, 20, 18, 18, new ECBlocks(18, new ECB(1, 22))), new Version(7, 22, 22, 20, 20, new ECBlocks(20, new ECB(1, 30))), new Version(8, 24, 24, 22, 22, new ECBlocks(24, new ECB(1, 36))), new Version(9, 26, 26, 24, 24, new ECBlocks(28, new ECB(1, 44))), new Version(10, 32, 32, 14, 14, new ECBlocks(36, new ECB(1, 62))), new Version(11, 36, 36, 16, 16, new ECBlocks(42, new ECB(1, 86))), new Version(12, 40, 40, 18, 18, new ECBlocks(48, new ECB(1, 114))), new Version(13, 44, 44, 20, 20, new ECBlocks(56, new ECB(1, 144))), new Version(14, 48, 48, 22, 22, new ECBlocks(68, new ECB(1, 174))), new Version(15, 52, 52, 24, 24,
/** * @param bitMatrix {@link BitMatrix} to parse * @throws FormatException if dimension is < 10 or > 144 or not 0 mod 2 */ BitMatrixParser(BitMatrix bitMatrix) throws FormatException { int dimension = bitMatrix.getHeight(); if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) { throw FormatException.getFormatInstance(); } version = readVersion(bitMatrix); this.mappingBitMatrix = extractDataRegion(bitMatrix); // TODO(bbrown): Make this work for rectangular symbols this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getHeight()); }
if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, 1, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(2, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(3, numColumns - 1, numRows, numColumns)) { currentByte |= 1;
/** * <p>Creates the version object based on the dimension of the original bit matrix from * the datamatrix code.</p> * * <p>See ISO 16022:2006 Table 7 - ECC 200 symbol attributes</p> * * @param bitMatrix Original {@link BitMatrix} including alignment patterns * @return {@link Version} encapsulating the Data Matrix Code's "version" * @throws FormatException if the dimensions of the mapping matrix are not valid * Data Matrix dimensions. */ Version readVersion(BitMatrix bitMatrix) throws FormatException { if (version != null) { return version; } // TODO(bbrown): make this work for rectangular dimensions as well. int numRows = bitMatrix.getHeight(); int numColumns = numRows; return Version.getVersionForDimensions(numRows, numColumns); }
/** * <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> * * @param image booleans representing white/black Data Matrix Code modules * @return text and bytes encoded within the Data Matrix Code * @throws FormatException if the Data Matrix Code cannot be decoded * @throws ChecksumException if error correction fails */ public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumException { 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); }
private Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, int dataRegionSizeColumns, ECBlocks ecBlocks) { this.versionNumber = versionNumber; this.symbolSizeRows = symbolSizeRows; this.symbolSizeColumns = symbolSizeColumns; this.dataRegionSizeRows = dataRegionSizeRows; this.dataRegionSizeColumns = dataRegionSizeColumns; this.ecBlocks = ecBlocks; // Calculate the total number of codewords int total = 0; int ecCodewords = ecBlocks.getECCodewords(); ECB[] ecbArray = ecBlocks.getECBlocks(); for (int i = 0; i < ecbArray.length; i++) { ECB ecBlock = ecbArray[i]; total += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords); } this.totalCodewords = total; }
new Version(1, 10, 10, 8, 8, new ECBlocks(5, new ECB(1, 3))), new Version(2, 12, 12, 10, 10, new ECBlocks(7, new ECB(1, 5))), new Version(3, 14, 14, 12, 12, new ECBlocks(10, new ECB(1, 8))), new Version(4, 16, 16, 14, 14, new ECBlocks(12, new ECB(1, 12))), new Version(5, 18, 18, 16, 16, new ECBlocks(14, new ECB(1, 18))), new Version(6, 20, 20, 18, 18, new ECBlocks(18, new ECB(1, 22))), new Version(7, 22, 22, 20, 20, new ECBlocks(20, new ECB(1, 30))), new Version(8, 24, 24, 22, 22, new ECBlocks(24, new ECB(1, 36))), new Version(9, 26, 26, 24, 24, new ECBlocks(28, new ECB(1, 44))), new Version(10, 32, 32, 14, 14, new ECBlocks(36, new ECB(1, 62))), new Version(11, 36, 36, 16, 16, new ECBlocks(42, new ECB(1, 86))), new Version(12, 40, 40, 18, 18, new ECBlocks(48, new ECB(1, 114))), new Version(13, 44, 44, 20, 20, new ECBlocks(56, new ECB(1, 144))), new Version(14, 48, 48, 22, 22, new ECBlocks(68, new ECB(1, 174))), new Version(15, 52, 52, 24, 24,
/** * @param bitMatrix {@link BitMatrix} to parse * @throws FormatException if dimension is < 10 or > 144 or not 0 mod 2 */ BitMatrixParser(BitMatrix bitMatrix) throws FormatException { int dimension = bitMatrix.getHeight(); if (dimension < 10 || dimension > 144 || (dimension & 0x01) != 0) { throw FormatException.getFormatInstance(); } version = readVersion(bitMatrix); this.mappingBitMatrix = extractDataRegion(bitMatrix); // TODO(bbrown): Make this work for rectangular symbols this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getHeight()); }
if (readModule(numRows - 3, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 2, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(2, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(3, numColumns - 1, numRows, numColumns)) { currentByte |= 1;
/** * <p>Creates the version object based on the dimension of the original bit matrix from * the datamatrix code.</p> * * <p>See ISO 16022:2006 Table 7 - ECC 200 symbol attributes</p> * * @param bitMatrix Original {@link BitMatrix} including alignment patterns * @return {@link Version} encapsulating the Data Matrix Code's "version" * @throws FormatException if the dimensions of the mapping matrix are not valid * Data Matrix dimensions. */ Version readVersion(BitMatrix bitMatrix) throws FormatException { if (version != null) { return version; } // TODO(bbrown): make this work for rectangular dimensions as well. int numRows = bitMatrix.getHeight(); int numColumns = numRows; return Version.getVersionForDimensions(numRows, numColumns); }
if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 3, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 3, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1;
if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 3, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 3, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1;
if (readModule(numRows - 3, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 2, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 4, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 3, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1;
if (readModule(numRows - 3, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 2, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(2, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(3, numColumns - 1, numRows, numColumns)) { currentByte |= 1;
if (readModule(row - 2, column - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(row - 2, column - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(row - 1, column - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(row - 1, column - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(row - 1, column, numRows, numColumns)) { currentByte |= 1; if (readModule(row, column - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(row, column - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(row, column, numRows, numColumns)) { currentByte |= 1;
if (readModule(numRows - 3, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 2, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(numRows - 1, 0, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 4, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 3, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 2, numRows, numColumns)) { currentByte |= 1; if (readModule(0, numColumns - 1, numRows, numColumns)) { currentByte |= 1; if (readModule(1, numColumns - 1, numRows, numColumns)) { currentByte |= 1;