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

@@ -203,7 +203,7 @@ impl GlobalHistogramBinarizer {
let mut secondPeakScore = 0;
for x in 0..numBuckets {
// for (int x = 0; x < numBuckets; x++) {
let distanceToBiggest = x - firstPeak;
let distanceToBiggest = (x as i32 - firstPeak as i32).abs() as u32;
// Encourage more distant second peaks by multiplying by square of distance.
let score = buckets[x] * distanceToBiggest as u32 * distanceToBiggest as u32;
if score > secondPeakScore {

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

View File

@@ -17,9 +17,9 @@
use std::collections::HashMap;
use crate::{
aztec::AztecReader, maxicode::MaxiCodeReader, qrcode::QRCodeReader, BarcodeFormat,
BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult,
Reader,
aztec::AztecReader, datamatrix::DataMatrixReader, maxicode::MaxiCodeReader,
qrcode::QRCodeReader, BarcodeFormat, BinaryBitmap, DecodeHintType, DecodeHintValue,
DecodingHintDictionary, Exceptions, RXingResult, Reader,
};
/**
@@ -133,8 +133,7 @@ impl MultiFormatReader {
readers.push(Box::new(QRCodeReader {}));
}
if formats.contains(&BarcodeFormat::DATA_MATRIX) {
unimplemented!("");
// readers.push(DataMatrixReader{});
readers.push(Box::new(DataMatrixReader {}));
}
if formats.contains(&BarcodeFormat::AZTEC) {
readers.push(Box::new(AztecReader {}));
@@ -155,11 +154,11 @@ impl MultiFormatReader {
if readers.is_empty() {
if !tryHarder {
// readers.push( MultiFormatOneDReader::new(hints));
unimplemented!("");
//TODO: ADD MultiformatOneDReader here
}
readers.push(Box::new(QRCodeReader {}));
// readers.push( Box::new(DataMatrixReader{}));
readers.push(Box::new(DataMatrixReader {}));
readers.push(Box::new(AztecReader {}));
// readers.push( PDF417Reader());
readers.push(Box::new(MaxiCodeReader {}));
@@ -167,10 +166,10 @@ impl MultiFormatReader {
if tryHarder {
// readers.push( Box::new(MultiFormatOneDReader::new(hints)));
unimplemented!("");
//TODO: ADD MultiformatOneDReader here
}
}
self.readers = Vec::new(); //readers.toArray(EMPTY_READER_ARRAY);
self.readers = readers;//Vec::new(); //readers.toArray(EMPTY_READER_ARRAY);
}
pub fn decodeInternal(&mut self, image: &BinaryBitmap) -> Result<RXingResult, Exceptions> {
@@ -212,3 +211,12 @@ impl MultiFormatReader {
return Err(Exceptions::NotFoundException("".to_owned()));
}
}
impl Default for MultiFormatReader {
fn default() -> Self {
Self {
hints: HashMap::new(),
readers: Vec::new(),
}
}
}

View File

@@ -16,7 +16,7 @@
use std::collections::HashMap;
use crate::{aztec::AztecWriter, qrcode::QRCodeWriter, BarcodeFormat, Exceptions, Writer};
use crate::{aztec::AztecWriter, qrcode::QRCodeWriter, BarcodeFormat, Exceptions, Writer, datamatrix::DataMatrixWriter};
/**
* This is a factory class which finds the appropriate Writer subclass for the BarcodeFormat
@@ -67,8 +67,8 @@ impl Writer for MultiFormatWriter {
// writer = PDF417Writer(),
BarcodeFormat::CODABAR => unimplemented!(""),
// writer = CodaBarWriter(),
BarcodeFormat::DATA_MATRIX => unimplemented!(""),
// DataMatrixWriter{},
BarcodeFormat::DATA_MATRIX =>
Box::new(DataMatrixWriter{}),
BarcodeFormat::AZTEC => Box::new(AztecWriter {}),
_ => {
return Err(Exceptions::IllegalArgumentException(format!(

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2008 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;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
* @author bbrown@google.com (Brian Brown)
*/
public final class DataMatrixBlackBox1TestCase extends AbstractBlackBoxTestCase {
public DataMatrixBlackBox1TestCase() {
super("src/test/resources/blackbox/datamatrix-1", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
addTest(21, 21, 0.0f);
addTest(21, 21, 90.0f);
addTest(21, 21, 180.0f);
addTest(21, 21, 270.0f);
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2008 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;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class DataMatrixBlackBox2TestCase extends AbstractBlackBoxTestCase {
public DataMatrixBlackBox2TestCase() {
super("src/test/resources/blackbox/datamatrix-2", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
addTest(13, 13, 0, 1, 0.0f);
addTest(15, 15, 0, 1, 90.0f);
addTest(17, 16, 0, 1, 180.0f);
addTest(15, 15, 0, 1, 270.0f);
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2008 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;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.common.AbstractBlackBoxTestCase;
/**
* @author gitlost
*/
public final class DataMatrixBlackBox3TestCase extends AbstractBlackBoxTestCase {
public DataMatrixBlackBox3TestCase() {
super("src/test/resources/blackbox/datamatrix-3", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
addTest(18, 18, 0.0f);
addTest(17, 17, 90.0f);
addTest(18, 18, 180.0f);
addTest(18, 18, 270.0f);
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2008 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 rxing::MultiFormatReader;
mod common;
/**
* @author bbrown@google.com (Brian Brown)
*/
#[test]
fn data_matrix_black_box1_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/datamatrix-1",
MultiFormatReader::default(),
rxing::BarcodeFormat::DATA_MATRIX,
);
// super("src/test/resources/blackbox/datamatrix-1", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
tester.add_test(21, 21, 0.0);
tester.add_test(21, 21, 90.0);
tester.add_test(21, 21, 180.0);
tester.add_test(21, 21, 270.0);
tester.test_black_box();
}
/**
* @author dswitkin@google.com (Daniel Switkin)
*/
#[test]
fn data_matrix_black_box2_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/datamatrix-2",
MultiFormatReader::default(),
rxing::BarcodeFormat::DATA_MATRIX,
);
// super("src/test/resources/blackbox/datamatrix-2", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
tester.add_test_complex(13, 13, 0, 1, 0.0);
tester.add_test_complex(15, 15, 0, 1, 90.0);
tester.add_test_complex(17, 16, 0, 1, 180.0);
tester.add_test_complex(15, 15, 0, 1, 270.0);
tester.test_black_box();
}
/**
* @author gitlost
*/
#[test]
fn data_matrix_black_box3_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/datamatrix-3",
MultiFormatReader::default(),
rxing::BarcodeFormat::DATA_MATRIX,
);
// super("src/test/resources/blackbox/datamatrix-3", new MultiFormatReader(), BarcodeFormat.DATA_MATRIX);
tester.add_test(18, 18, 0.0);
tester.add_test(17, 17, 90.0);
tester.add_test(18, 18, 180.0);
tester.add_test(18, 18, 270.0);
tester.test_black_box();
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
use rxing::{maxicode::MaxiCodeReader, BarcodeFormat, DecodeHintType};
use rxing::{maxicode::MaxiCodeReader, BarcodeFormat, DecodeHintType, MultiFormatReader};
mod common;
@@ -25,7 +25,7 @@ mod common;
fn maxicode1_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/maxicode-1",
MaxiCodeReader {},
MultiFormatReader::default(),
BarcodeFormat::MAXICODE,
);
// super("src/test/resources/blackbox/maxicode-1", new MultiFormatReader(), BarcodeFormat.MAXICODE);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
use rxing::{qrcode::QRCodeReader, BarcodeFormat};
use rxing::{qrcode::QRCodeReader, BarcodeFormat, MultiFormatReader};
mod common;
@@ -26,7 +26,7 @@ mod common;
fn qrcode_black_box1_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/qrcode-1",
QRCodeReader {},
MultiFormatReader::default(),
rxing::BarcodeFormat::QR_CODE,
);
// super("src/test/resources/blackbox/qrcode-1", new MultiFormatReader(), BarcodeFormat.QR_CODE);
@@ -46,6 +46,7 @@ fn qrcode_black_box1_test_case() {
fn qrcode_black_box2_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/qrcode-2",
// MultiFormatReader::default(),
QRCodeReader {},
BarcodeFormat::QR_CODE,
);
@@ -65,7 +66,7 @@ fn qrcode_black_box2_test_case() {
fn qrcode_black_box3_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/qrcode-3",
QRCodeReader {},
MultiFormatReader::default(),
BarcodeFormat::QR_CODE,
);
tester.add_test(38, 38, 0.0);
@@ -86,7 +87,7 @@ fn qrcode_black_box3_test_case() {
fn qrcode_black_box4_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/qrcode-4",
QRCodeReader {},
MultiFormatReader::default(),
BarcodeFormat::QR_CODE,
);
tester.add_test(36, 36, 0.0);
@@ -109,7 +110,7 @@ fn qrcode_black_box4_test_case() {
fn qrcode_black_box5_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/qrcode-5",
QRCodeReader {},
MultiFormatReader::default(),
BarcodeFormat::QR_CODE,
);
tester.add_test(19, 19, 0.0);
@@ -129,7 +130,7 @@ fn qrcode_black_box5_test_case() {
fn qrcode_black_box6_test_case() {
let mut tester = common::AbstractBlackBoxTestCase::new(
"test_resources/blackbox/qrcode-6",
QRCodeReader {},
MultiFormatReader::default(),
BarcodeFormat::QR_CODE,
);
tester.add_test(15, 15, 0.0);