diff --git a/src/datamatrix/decoder/BitMatrixParser.java b/src/datamatrix/decoder/BitMatrixParser.java deleted file mode 100644 index 225df65..0000000 --- a/src/datamatrix/decoder/BitMatrixParser.java +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright 2007 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.datamatrix.decoder; - -import com.google.zxing.FormatException; -import com.google.zxing.common.BitMatrix; - -/** - * @author bbrown@google.com (Brian Brown) - */ -final class BitMatrixParser { - - private final BitMatrix mappingBitMatrix; - private final BitMatrix readMappingMatrix; - private final Version version; - - /** - * @param bitMatrix {@link BitMatrix} to parse - * @throws FormatException if dimension is < 8 or > 144 or not 0 mod 2 - */ - BitMatrixParser(BitMatrix bitMatrix) throws FormatException { - int dimension = bitMatrix.getHeight(); - if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) { - throw FormatException.getFormatInstance(); - } - - version = readVersion(bitMatrix); - this.mappingBitMatrix = extractDataRegion(bitMatrix); - this.readMappingMatrix = new BitMatrix(this.mappingBitMatrix.getWidth(), this.mappingBitMatrix.getHeight()); - } - - Version getVersion() { - return version; - } - - /** - *
Creates the version object based on the dimension of the original bit matrix from - * the datamatrix code.
- * - *See ISO 16022:2006 Table 7 - ECC 200 symbol attributes
- * - * @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. - */ - private static Version readVersion(BitMatrix bitMatrix) throws FormatException { - int numRows = bitMatrix.getHeight(); - int numColumns = bitMatrix.getWidth(); - return Version.getVersionForDimensions(numRows, numColumns); - } - - /** - *Reads the bits in the {@link BitMatrix} representing the mapping matrix (No alignment patterns) - * in the correct order in order to reconstitute the codewords bytes contained within the - * Data Matrix Code.
- * - * @return bytes encoded within the Data Matrix Code - * @throws FormatException if the exact number of bytes expected is not read - */ - byte[] readCodewords() throws FormatException { - - byte[] result = new byte[version.getTotalCodewords()]; - int resultOffset = 0; - - int row = 4; - int column = 0; - - int numRows = mappingBitMatrix.getHeight(); - int numColumns = mappingBitMatrix.getWidth(); - - boolean corner1Read = false; - boolean corner2Read = false; - boolean corner3Read = false; - boolean corner4Read = false; - - // Read all of the codewords - do { - // Check the four corner cases - if ((row == numRows) && (column == 0) && !corner1Read) { - result[resultOffset++] = (byte) readCorner1(numRows, numColumns); - row -= 2; - column += 2; - corner1Read = true; - } else if ((row == numRows - 2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) { - result[resultOffset++] = (byte) readCorner2(numRows, numColumns); - row -= 2; - column += 2; - corner2Read = true; - } else if ((row == numRows + 4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) { - result[resultOffset++] = (byte) readCorner3(numRows, numColumns); - row -= 2; - column += 2; - corner3Read = true; - } else if ((row == numRows - 2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) { - result[resultOffset++] = (byte) readCorner4(numRows, numColumns); - row -= 2; - column += 2; - corner4Read = true; - } else { - // Sweep upward diagonally to the right - do { - if ((row < numRows) && (column >= 0) && !readMappingMatrix.get(column, row)) { - result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns); - } - row -= 2; - column += 2; - } while ((row >= 0) && (column < numColumns)); - row += 1; - column += 3; - - // Sweep downward diagonally to the left - do { - if ((row >= 0) && (column < numColumns) && !readMappingMatrix.get(column, row)) { - result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns); - } - row += 2; - column -= 2; - } while ((row < numRows) && (column >= 0)); - row += 3; - column += 1; - } - } while ((row < numRows) || (column < numColumns)); - - if (resultOffset != version.getTotalCodewords()) { - throw FormatException.getFormatInstance(); - } - return result; - } - - /** - *Reads a bit of the mapping matrix accounting for boundary wrapping.
- * - * @param row Row to read in the mapping matrix - * @param column Column to read in the mapping matrix - * @param numRows Number of rows in the mapping matrix - * @param numColumns Number of columns in the mapping matrix - * @return value of the given bit in the mapping matrix - */ - private boolean 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); - } - if (row >= numRows) { - row -= numRows; - } - readMappingMatrix.set(column, row); - return mappingBitMatrix.get(column, row); - } - - /** - *Reads the 8 bits of the standard Utah-shaped pattern.
- * - *See ISO 16022:2006, 5.8.1 Figure 6
- * - * @param row Current row in the mapping matrix, anchored at the 8th bit (LSB) of the pattern - * @param column Current column in the mapping matrix, anchored at the 8th bit (LSB) of the pattern - * @param numRows Number of rows in the mapping matrix - * @param numColumns Number of columns in the mapping matrix - * @return byte from the utah shape - */ - private int readUtah(int row, int column, int numRows, int numColumns) { - int currentByte = 0; - if (readModule(row - 2, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 2, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 1, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 1, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 1, column, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row, column, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - - /** - *Reads the 8 bits of the special corner condition 1.
- * - *See ISO 16022:2006, Figure F.3
- * - * @param numRows Number of rows in the mapping matrix - * @param numColumns Number of columns in the mapping matrix - * @return byte from the Corner condition 1 - */ - private int readCorner1(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(2, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(3, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - - /** - *Reads the 8 bits of the special corner condition 2.
- * - *See ISO 16022:2006, Figure F.4
- * - * @param numRows Number of rows in the mapping matrix - * @param numColumns Number of columns in the mapping matrix - * @return byte from the Corner condition 2 - */ - private int readCorner2(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 3, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 2, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 4, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - - /** - *Reads the 8 bits of the special corner condition 3.
- * - *See ISO 16022:2006, Figure F.5
- * - * @param numRows Number of rows in the mapping matrix - * @param numColumns Number of columns in the mapping matrix - * @return byte from the Corner condition 3 - */ - private int readCorner3(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - - /** - *Reads the 8 bits of the special corner condition 4.
- * - *See ISO 16022:2006, Figure F.6
- * - * @param numRows Number of rows in the mapping matrix - * @param numColumns Number of columns in the mapping matrix - * @return byte from the Corner condition 4 - */ - private int readCorner4(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 3, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 2, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(2, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(3, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - - /** - *Extracts the data region from a {@link BitMatrix} that contains - * alignment patterns.
- * - * @param bitMatrix Original {@link BitMatrix} with alignment patterns - * @return BitMatrix that has the alignment patterns removed - */ - private BitMatrix extractDataRegion(BitMatrix bitMatrix) { - int symbolSizeRows = version.getSymbolSizeRows(); - int symbolSizeColumns = version.getSymbolSizeColumns(); - - if (bitMatrix.getHeight() != symbolSizeRows) { - throw new IllegalArgumentException("Dimension of bitMatrix must match the version size"); - } - - int dataRegionSizeRows = version.getDataRegionSizeRows(); - int dataRegionSizeColumns = version.getDataRegionSizeColumns(); - - 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; - } - -} diff --git a/src/datamatrix/decoder/bit_matrix_parser.rs b/src/datamatrix/decoder/bit_matrix_parser.rs new file mode 100644 index 0000000..9f88587 --- /dev/null +++ b/src/datamatrix/decoder/bit_matrix_parser.rs @@ -0,0 +1,495 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use crate::{common::BitMatrix, Exceptions}; + +use super::{Version, VersionRef}; + +/** + * @author bbrown@google.com (Brian Brown) + */ +pub struct BitMatrixParser { + mappingBitMatrix: BitMatrix, + readMappingMatrix: BitMatrix, + version: VersionRef, +} +impl BitMatrixParser { + /** + * @param bitMatrix {@link BitMatrix} to parse + * @throws FormatException if dimension is < 8 or > 144 or not 0 mod 2 + */ + pub fn new(bitMatrix: &BitMatrix) -> ResultCreates the version object based on the dimension of the original bit matrix from + * the datamatrix code.
+ * + *See ISO 16022:2006 Table 7 - ECC 200 symbol attributes
+ * + * @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. + */ + fn readVersion(bitMatrix: &BitMatrix) -> ResultReads the bits in the {@link BitMatrix} representing the mapping matrix (No alignment patterns) + * in the correct order in order to reconstitute the codewords bytes contained within the + * Data Matrix Code.
+ * + * @return bytes encoded within the Data Matrix Code + * @throws FormatException if the exact number of bytes expected is not read + */ + pub fn readCodewords(&self) -> ResultReads a bit of the mapping matrix accounting for boundary wrapping.
+ * + * @param row Row to read in the mapping matrix + * @param column Column to read in the mapping matrix + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix + * @return value of the given bit in the mapping matrix + */ + fn readModule(&self, row: usize, column: usize, numRows: usize, numColumns: usize) -> bool { + // 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); + } + if row >= numRows { + row -= numRows; + } + self.readMappingMatrix.set(column as u32, row as u32); + + self.mappingBitMatrix.get(column as u32, row as u32) + } + + /** + *Reads the 8 bits of the standard Utah-shaped pattern.
+ * + *See ISO 16022:2006, 5.8.1 Figure 6
+ * + * @param row Current row in the mapping matrix, anchored at the 8th bit (LSB) of the pattern + * @param column Current column in the mapping matrix, anchored at the 8th bit (LSB) of the pattern + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix + * @return byte from the utah shape + */ + fn readUtah(&self, row: usize, column: usize, numRows: usize, numColumns: usize) -> u32 { + let mut currentByte = 0; + if self.readModule(row - 2, column - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row - 2, column - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row - 1, column - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row - 1, column - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row - 1, column, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row, column - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row, column - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(row, column, numRows, numColumns) { + currentByte |= 1; + } + return currentByte; + } + + /** + *Reads the 8 bits of the special corner condition 1.
+ * + *See ISO 16022:2006, Figure F.3
+ * + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix + * @return byte from the Corner condition 1 + */ + fn readCorner1(&self, numRows: usize, numColumns: usize) -> u32 { + let mut currentByte = 0; + if self.readModule(numRows - 1, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 1, 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 1, 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(1, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(2, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(3, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + return currentByte; + } + + /** + *Reads the 8 bits of the special corner condition 2.
+ * + *See ISO 16022:2006, Figure F.4
+ * + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix + * @return byte from the Corner condition 2 + */ + fn readCorner2(&self, numRows: usize, numColumns: usize) -> u32 { + let mut currentByte = 0; + if self.readModule(numRows - 3, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 2, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 1, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 4, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 3, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(1, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + return currentByte; + } + + /** + *Reads the 8 bits of the special corner condition 3.
+ * + *See ISO 16022:2006, Figure F.5
+ * + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix + * @return byte from the Corner condition 3 + */ + fn readCorner3(&self, numRows: usize, numColumns: usize) -> u32 { + let mut currentByte = 0; + if self.readModule(numRows - 1, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 1, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 3, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(1, numColumns - 3, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(1, numColumns - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(1, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + return currentByte; + } + + /** + *Reads the 8 bits of the special corner condition 4.
+ * + *See ISO 16022:2006, Figure F.6
+ * + * @param numRows Number of rows in the mapping matrix + * @param numColumns Number of columns in the mapping matrix + * @return byte from the Corner condition 4 + */ + fn readCorner4(&self, numRows: usize, numColumns: usize) -> u32 { + let mut currentByte = 0; + if self.readModule(numRows - 3, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 2, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(numRows - 1, 0, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 2, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(0, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(1, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(2, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + currentByte <<= 1; + if self.readModule(3, numColumns - 1, numRows, numColumns) { + currentByte |= 1; + } + return currentByte; + } + + /** + *Extracts the data region from a {@link BitMatrix} that contains + * alignment patterns.
+ * + * @param bitMatrix Original {@link BitMatrix} with alignment patterns + * @return BitMatrix that has the alignment patterns removed + */ + fn extractDataRegion( + bitMatrix: &BitMatrix, + version: VersionRef, + ) -> ResultData Matrix Codes can encode text as bits in one of several modes, and can use multiple modes
@@ -37,9 +28,9 @@ import java.util.Set;
* @author bbrown@google.com (Brian Brown)
* @author Sean Owen
*/
-final class DecodedBitStreamParser {
- private enum Mode {
+ #[derive(Debug,PartialEq, Eq,Clone, Copy)]
+ enum Mode {
PAD_ENCODE, // Not really a mode
ASCII_ENCODE,
C40_ENCODE,
@@ -54,78 +45,71 @@ final class DecodedBitStreamParser {
* See ISO 16022:2006, Annex C Table C.1
* The C40 Basic Character Set (*'s used for placeholders for the shift values)
*/
- private static final char[] C40_BASIC_SET_CHARS = {
+ const C40_BASIC_SET_CHARS : [char;40]= [
'*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
- };
+ ];
- private static final char[] C40_SHIFT2_SET_CHARS = {
+ const C40_SHIFT2_SET_CHARS :[char;27] = [
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.',
'/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_'
- };
+ ];
/**
* See ISO 16022:2006, Annex C Table C.2
* The Text Basic Character Set (*'s used for placeholders for the shift values)
*/
- private static final char[] TEXT_BASIC_SET_CHARS = {
- '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ const TEXT_BASIC_SET_CHARS : [char;40]=
+ ['*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
- };
+ ];
// Shift 2 for Text is the same encoding as C40
- private static final char[] TEXT_SHIFT2_SET_CHARS = C40_SHIFT2_SET_CHARS;
+ const TEXT_SHIFT2_SET_CHARS : [char;27]= C40_SHIFT2_SET_CHARS;
- private static final char[] TEXT_SHIFT3_SET_CHARS = {
+ const TEXT_SHIFT3_SET_CHARS : [char;32]= [
'`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (char) 127
- };
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 127 as char
+ ];
- private DecodedBitStreamParser() {
- }
-
- static DecoderRXingResult decode(byte[] bytes) throws FormatException {
- BitSource bits = new BitSource(bytes);
- ECIStringBuilder result = new ECIStringBuilder(100);
- StringBuilder resultTrailer = new StringBuilder(0);
- List The main class which implements Data Matrix Code decoding -- as opposed to locating and extracting
@@ -30,12 +25,14 @@ import com.google.zxing.common.reedsolomon.ReedSolomonException;
*
* @author bbrown@google.com (Brian Brown)
*/
-public final class Decoder {
+pub struct Decoder(ReedSolomonDecoder);
- private final ReedSolomonDecoder rsDecoder;
+impl Decoder {
- public Decoder() {
- rsDecoder = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
+ pub fn new() -> Self {
+
+ Self(ReedSolomonDecoder::new(get_predefined_genericgf(PredefinedGenericGF::DataMatrixField256)))
+ // rsDecoder = new ReedSolomonDecoder(GenericGF.DATA_MATRIX_FIELD_256);
}
/**
@@ -47,8 +44,8 @@ public final class Decoder {
* @throws FormatException if the Data Matrix Code cannot be decoded
* @throws ChecksumException if error correction fails
*/
- public DecoderRXingResult decode(boolean[][] image) throws FormatException, ChecksumException {
- return decode(BitMatrix.parse(image));
+ pub fn decode_bools(&self, image:&Vec