datamatrix integration passes

This commit is contained in:
Henry Schimke
2022-11-28 11:51:26 -06:00
parent ba02512695
commit 75e69bc498
14 changed files with 131 additions and 150 deletions

View File

@@ -139,13 +139,16 @@ impl DataMatrixReader {
let mut left = leftTopBlack[0];
let right = rightBottomBlack[0];
let matrixWidth = (right - left + 1) / moduleSize;
let matrixHeight = (bottom - top + 1) / moduleSize;
let matrixWidth = (right as i32 - left as i32 + 1) / moduleSize as i32;
let matrixHeight = (bottom as i32 - top as i32 + 1) / moduleSize as i32;
if matrixWidth <= 0 || matrixHeight <= 0 {
return Err(Exceptions::NotFoundException("".to_owned()));
// throw NotFoundException.getNotFoundInstance();
}
let matrixWidth = matrixWidth as u32;
let matrixHeight = matrixHeight as u32;
// 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.

View File

@@ -83,10 +83,10 @@ impl BitMatrixParser {
let mut resultOffset = 0;
let mut row = 4;
let mut column = 0_usize;
let mut column = 0;
let numRows = self.mappingBitMatrix.getHeight() as usize;
let numColumns = self.mappingBitMatrix.getWidth() as usize;
let numRows = self.mappingBitMatrix.getHeight().try_into().unwrap();
let numColumns = self.mappingBitMatrix.getWidth().try_into().unwrap();
let mut corner1Read = false;
let mut corner2Read = false;
@@ -193,7 +193,7 @@ impl BitMatrixParser {
* @param numColumns Number of columns in the mapping matrix
* @return value of the given bit in the mapping matrix
*/
fn readModule(&mut self, row: usize, column: usize, numRows: usize, numColumns: usize) -> bool {
fn readModule(&mut self, row: isize, column: isize, numRows: isize, numColumns: isize) -> bool {
let mut row = row;
let mut column = column;
// Adjust the row and column indices based on boundary wrapping
@@ -224,7 +224,7 @@ impl BitMatrixParser {
* @param numColumns Number of columns in the mapping matrix
* @return byte from the utah shape
*/
fn readUtah(&mut self, row: usize, column: usize, numRows: usize, numColumns: usize) -> u32 {
fn readUtah(&mut self, row: isize, column: isize, numRows: isize, numColumns: isize) -> u32 {
let mut currentByte = 0;
if self.readModule(row - 2, column - 2, numRows, numColumns) {
currentByte |= 1;
@@ -269,7 +269,7 @@ impl BitMatrixParser {
* @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 1
*/
fn readCorner1(&mut self, numRows: usize, numColumns: usize) -> u32 {
fn readCorner1(&mut self, numRows: isize, numColumns: isize) -> u32 {
let mut currentByte = 0;
if self.readModule(numRows - 1, 0, numRows, numColumns) {
currentByte |= 1;
@@ -314,7 +314,7 @@ impl BitMatrixParser {
* @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 2
*/
fn readCorner2(&mut self, numRows: usize, numColumns: usize) -> u32 {
fn readCorner2(&mut self, numRows: isize, numColumns: isize) -> u32 {
let mut currentByte = 0;
if self.readModule(numRows - 3, 0, numRows, numColumns) {
currentByte |= 1;
@@ -359,7 +359,7 @@ impl BitMatrixParser {
* @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 3
*/
fn readCorner3(&mut self, numRows: usize, numColumns: usize) -> u32 {
fn readCorner3(&mut self, numRows: isize, numColumns: isize) -> u32 {
let mut currentByte = 0;
if self.readModule(numRows - 1, 0, numRows, numColumns) {
currentByte |= 1;
@@ -404,7 +404,7 @@ impl BitMatrixParser {
* @param numColumns Number of columns in the mapping matrix
* @return byte from the Corner condition 4
*/
fn readCorner4(&mut self, numRows: usize, numColumns: usize) -> u32 {
fn readCorner4(&mut self, numRows: isize, numColumns: isize) -> u32 {
let mut currentByte = 0;
if self.readModule(numRows - 3, 0, numRows, numColumns) {
currentByte |= 1;

View File

@@ -64,7 +64,7 @@ impl DataBlock {
// Now establish DataBlocks of the appropriate size and number of data codewords
let mut result = Vec::with_capacity(totalBlocks);
let numRXingResultBlocks = 0;
let mut numRXingResultBlocks = 0;
for ecBlock in ecBlockArray {
for _i in 0..ecBlock.getCount() {
// for (int i = 0; i < ecBlock.getCount(); i++) {
@@ -75,6 +75,7 @@ impl DataBlock {
numDataCodewords as u32,
vec![0; numBlockCodewords],
));
numRXingResultBlocks +=1;
}
}

View File

@@ -693,12 +693,12 @@ fn decodeECISegment(bits: &mut BitSource, result: &mut ECIStringBuilder) -> Resu
*/
fn unrandomize255State(randomizedBase256Codeword: u32, base256CodewordPosition: usize) -> u32 {
let pseudoRandomNumber = ((149 * base256CodewordPosition as u32) % 255) + 1;
let tempVariable = randomizedBase256Codeword - pseudoRandomNumber;
let tempVariable = randomizedBase256Codeword as i32 - pseudoRandomNumber as i32;
if tempVariable >= 0 {
tempVariable
tempVariable as u32
} else {
tempVariable + 256
(tempVariable + 256) as u32
}
}

View File

@@ -48,8 +48,8 @@ impl Detector {
pub fn detect(&self) -> Result<DatamatrixDetectorResult, Exceptions> {
let cornerPoints = self.rectangleDetector.detect()?;
let mut points = self.detectSolid1(&cornerPoints);
points = self.detectSolid2(&points);
let mut points = self.detectSolid1(cornerPoints);
points = self.detectSolid2(points);
if let Some(point) = self.correctTopRight(&points) {
points[3] = point;
} else {
@@ -59,7 +59,7 @@ impl Detector {
// if points[3] == null {
// throw NotFoundException.getNotFoundInstance();
// }
points = self.shiftToModuleCenter(&points);
points = self.shiftToModuleCenter(points);
let topLeft = points[0];
let bottomLeft = points[1];
@@ -125,7 +125,7 @@ impl Detector {
/**
* Detect a solid side which has minimum transition.
*/
fn detectSolid1(&self, cornerPoints: &[RXingResultPoint]) -> [RXingResultPoint; 4] {
fn detectSolid1(&self, cornerPoints: Vec<RXingResultPoint>) -> [RXingResultPoint; 4] {
// 0 2
// 1 3
let pointA = cornerPoints[0];
@@ -170,7 +170,7 @@ impl Detector {
/**
* Detect a second solid side next to first solid side.
*/
fn detectSolid2(&self, points: &[RXingResultPoint]) -> [RXingResultPoint; 4] {
fn detectSolid2(&self, points: [RXingResultPoint;4]) -> [RXingResultPoint; 4] {
// A..D
// : :
// B--C
@@ -262,7 +262,7 @@ impl Detector {
/**
* Shift the edge points to the module center.
*/
fn shiftToModuleCenter(&self, points: &[RXingResultPoint]) -> [RXingResultPoint; 4] {
fn shiftToModuleCenter(&self, points: [RXingResultPoint;4]) -> [RXingResultPoint; 4] {
// A..D
// | :
// B--C