diff --git a/src/aztec/DetectorTest.rs b/src/aztec/DetectorTest.rs index fbfae1b..236ebc6 100644 --- a/src/aztec/DetectorTest.rs +++ b/src/aztec/DetectorTest.rs @@ -70,7 +70,7 @@ fn test_error_in_parameter_locator_not_compact() { #[test] fn test_aztec_rxing_result_sample() { let matrix = BitMatrix::parse_strings(TEST_BARCODE, "X ", " ").expect("string parse success"); - let r = Detector::new(matrix).detect(false); + let r = Detector::new(&matrix).detect(false); assert!(r.is_ok()); let r = r.expect("result already tested as ok"); let res = decoder::decode(&r).expect("decode success"); @@ -114,7 +114,7 @@ fn test_error_in_parameter_locator(data: &str) { // dbg!(copy.to_string()); // dbg!(make_larger(©, 3).to_string()); // The detector doesn't seem to work when matrix bits are only 1x1. So magnify. - let r = Detector::new(make_larger(©, 3)).detect(isMirror); + let r = Detector::new(&make_larger(©, 3)).detect(isMirror); assert!(r.is_ok()); let r = r.expect("result already tested as ok"); assert_eq!(r.getNbLayers(), layers); @@ -144,14 +144,14 @@ fn test_error_in_parameter_locator(data: &str) { // ); } // try { - if let Err(res) = detector::Detector::new(make_larger(©, 3)).detect(false) { + if let Err(res) = detector::Detector::new(&make_larger(©, 3)).detect(false) { if let Exceptions::NotFoundException(_msg) = res { // all ok } else { panic!("Only Exceptions::NotFoundException allowed, got {}", res); } } else { - let r = Detector::new(make_larger(©, 3)).detect(false); + let r = Detector::new(&make_larger(©, 3)).detect(false); assert!(r.is_ok()); let r = r.expect("result already tested as ok"); assert_eq!(r.getNbLayers(), layers); diff --git a/src/aztec/aztec_reader.rs b/src/aztec/aztec_reader.rs index 074e765..9faad3f 100644 --- a/src/aztec/aztec_reader.rs +++ b/src/aztec/aztec_reader.rs @@ -51,7 +51,7 @@ impl Reader for AztecReader { ) -> Result { // let notFoundException = None; // let formatException = None; - let mut detector = Detector::new(image.getBlackMatrix().clone()); + let mut detector = Detector::new(image.getBlackMatrix()); let points; let decoderRXingResult: DecoderRXingResult; // try { diff --git a/src/aztec/detector.rs b/src/aztec/detector.rs index acd4578..8b6935f 100644 --- a/src/aztec/detector.rs +++ b/src/aztec/detector.rs @@ -42,8 +42,8 @@ const EXPECTED_CORNER_BITS: [u32; 4] = [ * @author David Olivier * @author Frank Yellin */ -pub struct Detector { - image: BitMatrix, +pub struct Detector<'a> { + image: &'a BitMatrix, compact: bool, nb_layers: u32, @@ -52,9 +52,9 @@ pub struct Detector { shift: u32, } -impl Detector { - pub fn new(image: BitMatrix) -> Self { - Self { +impl<'a> Detector<'_> { + pub fn new(image: &'a BitMatrix) -> Detector<'a> { + Detector { image, compact: false, nb_layers: 0, diff --git a/src/datamatrix/data_matrix_reader.rs b/src/datamatrix/data_matrix_reader.rs index c4e25af..1d66beb 100644 --- a/src/datamatrix/data_matrix_reader.rs +++ b/src/datamatrix/data_matrix_reader.rs @@ -77,7 +77,7 @@ impl Reader for DataMatrixReader { decoderRXingResult = DECODER.decode(&bits)?; points.clear(); } else { - let detectorRXingResult = Detector::new(image.getBlackMatrix().clone())?.detect()?; + let detectorRXingResult = Detector::new(image.getBlackMatrix())?.detect()?; decoderRXingResult = DECODER.decode(detectorRXingResult.getBits())?; points = detectorRXingResult.getPoints().clone(); } diff --git a/src/datamatrix/detector/detector.rs b/src/datamatrix/detector/detector.rs index 19b9680..ed9d285 100644 --- a/src/datamatrix/detector/detector.rs +++ b/src/datamatrix/detector/detector.rs @@ -27,14 +27,14 @@ use super::DatamatrixDetectorResult; * * @author Sean Owen */ -pub struct Detector { - image: BitMatrix, +pub struct Detector<'a> { + image: &'a BitMatrix, rectangleDetector: WhiteRectangleDetector, } -impl Detector { - pub fn new(image: BitMatrix) -> Result { - Ok(Self { - rectangleDetector: WhiteRectangleDetector::new_from_image(&image)?, +impl<'a> Detector<'_> { + pub fn new(image: &'a BitMatrix) -> Result, Exceptions> { + Ok(Detector { + rectangleDetector: WhiteRectangleDetector::new_from_image(image)?, image, }) } diff --git a/src/multi/qrcode/detector/multi_detector.rs b/src/multi/qrcode/detector/multi_detector.rs index 2c5bd88..00b840b 100644 --- a/src/multi/qrcode/detector/multi_detector.rs +++ b/src/multi/qrcode/detector/multi_detector.rs @@ -29,10 +29,10 @@ use super::MultiFinderPatternFinder; * @author Sean Owen * @author Hannes Erven */ -pub struct MultiDetector(Detector); -impl MultiDetector { - pub fn new(image: BitMatrix) -> Self { - Self(Detector::new(image)) +pub struct MultiDetector<'a>(Detector<'a>); +impl<'a> MultiDetector<'_> { + pub fn new(image: &'a BitMatrix) -> MultiDetector<'a> { + MultiDetector(Detector::new(image)) } // private static final DetectorRXingResult[] EMPTY_DETECTOR_RESULTS = new DetectorRXingResult[0]; diff --git a/src/multi/qrcode/qr_code_multi_reader.rs b/src/multi/qrcode/qr_code_multi_reader.rs index 87ab788..44c0522 100644 --- a/src/multi/qrcode/qr_code_multi_reader.rs +++ b/src/multi/qrcode/qr_code_multi_reader.rs @@ -50,7 +50,7 @@ impl MultipleBarcodeReader for QRCodeMultiReader { ) -> Result, crate::Exceptions> { let mut results = Vec::new(); let detectorRXingResults = - MultiDetector::new(image.getBlackMatrix().clone()).detectMulti(hints)?; + MultiDetector::new(image.getBlackMatrix()).detectMulti(hints)?; for detectorRXingResult in detectorRXingResults { let mut proc = || -> Result<(), Exceptions> { let decoderRXingResult = decoder::decoder::decode_bitmatrix_with_hints( diff --git a/src/qrcode/detector/detector.rs b/src/qrcode/detector/detector.rs index 796acb1..d4e9514 100644 --- a/src/qrcode/detector/detector.rs +++ b/src/qrcode/detector/detector.rs @@ -36,14 +36,14 @@ use super::{ * * @author Sean Owen */ -pub struct Detector { - image: BitMatrix, +pub struct Detector<'a> { + image: &'a BitMatrix, resultPointCallback: Option, } -impl Detector { - pub fn new(image: BitMatrix) -> Self { - Self { +impl<'a> Detector<'_> { + pub fn new(image: &'a BitMatrix) -> Detector<'a> { + Detector { image, resultPointCallback: None, } diff --git a/src/qrcode/detector/cetector_test.rs b/src/qrcode/detector/detector_test.rs similarity index 94% rename from src/qrcode/detector/cetector_test.rs rename to src/qrcode/detector/detector_test.rs index 34e4204..109fb10 100644 --- a/src/qrcode/detector/cetector_test.rs +++ b/src/qrcode/detector/detector_test.rs @@ -32,7 +32,8 @@ fn test_encode_decode(value: &str) { let byt_matrix = qr_code.getMatrix().as_ref().unwrap().clone(); // dbg!(BitMatrix::from(byt_matrix.clone()).to_string()); // let mut detector = Detector::new(make_larger(&byt_matrix.into(),5)); - let mut detector = Detector::new(byt_matrix.into()); + let new_matrix : &BitMatrix = &byt_matrix.into(); + let mut detector = Detector::new(new_matrix); let detected_points = detector.detect().expect("must detect"); let decoded = decoder::decode_bitmatrix(detected_points.getBits()).expect("must decode"); assert_eq!(decoded.getText(), value); diff --git a/src/qrcode/detector/mod.rs b/src/qrcode/detector/mod.rs index eee527e..be21fa4 100644 --- a/src/qrcode/detector/mod.rs +++ b/src/qrcode/detector/mod.rs @@ -15,4 +15,4 @@ pub use finder_pattern_info::*; pub use qrcode_detector_result::*; #[cfg(test)] -mod cetector_test; +mod detector_test; diff --git a/src/qrcode/qr_code_reader.rs b/src/qrcode/qr_code_reader.rs index 5be7777..4b9ce70 100644 --- a/src/qrcode/qr_code_reader.rs +++ b/src/qrcode/qr_code_reader.rs @@ -67,7 +67,7 @@ impl Reader for QRCodeReader { points = Vec::new(); } else { let detectorRXingResult = - Detector::new(image.getBlackMatrix().clone()).detect_with_hints(&hints)?; + Detector::new(image.getBlackMatrix()).detect_with_hints(&hints)?; decoderRXingResult = decoder::decode_bitmatrix_with_hints(detectorRXingResult.getBits(), &hints)?; points = detectorRXingResult.getPoints().clone();