From bec7c99dbbf6e87c29423e2ef8db7f64599c4e02 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sat, 22 Apr 2023 16:17:05 -0500 Subject: [PATCH] partial success on parse, missing symbology id --- src/aztec/detector.rs | 4 +++- src/common/bit_matrix.rs | 11 +++++++++-- .../cpp_essentials/fast_edge_to_edge_counter.rs | 9 ++++++--- src/common/default_grid_sampler.rs | 2 +- src/datamatrix/detector/datamatrix_detector.rs | 3 ++- .../detector/zxing_cpp_detector/cpp_new_detector.rs | 4 +++- src/maxicode/detector.rs | 2 +- src/qrcode/cpp_port/bitmatrix_parser.rs | 6 +++--- src/qrcode/cpp_port/decoder.rs | 2 +- src/qrcode/cpp_port/detector.rs | 4 ++-- src/qrcode/detector/qrcode_detector.rs | 5 +++-- 11 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/aztec/detector.rs b/src/aztec/detector.rs index b0bc4a2..3bb8766 100644 --- a/src/aztec/detector.rs +++ b/src/aztec/detector.rs @@ -469,7 +469,9 @@ impl<'a> Detector<'_> { point(low, high), ); - sampler.sample_grid_detailed(image, dimension, dimension, dst, quad) + let (res, _) = sampler.sample_grid_detailed(image, dimension, dimension, dst, quad)?; + + Ok(res) } /** diff --git a/src/common/bit_matrix.rs b/src/common/bit_matrix.rs index f73d5d1..197e12b 100644 --- a/src/common/bit_matrix.rs +++ b/src/common/bit_matrix.rs @@ -21,7 +21,7 @@ use std::fmt; use crate::common::Result; -use crate::{point, Exceptions, Point}; +use crate::{point, Exceptions, Point, point_i}; use super::BitArray; @@ -223,7 +223,14 @@ impl BitMatrix { } pub fn get_index>(&self, index: T) -> bool { - todo!() + self.get_point(self.calculate_point_from_index(index.into())) + } + + #[inline(always)] + fn calculate_point_from_index(&self, index: usize) -> Point { + let row = index / (self.getWidth() as usize); + let column = index % (self.getWidth() as usize); + point_i(column as u32, row as u32) } #[inline(always)] diff --git a/src/common/cpp_essentials/fast_edge_to_edge_counter.rs b/src/common/cpp_essentials/fast_edge_to_edge_counter.rs index d1226c5..95ad6a2 100644 --- a/src/common/cpp_essentials/fast_edge_to_edge_counter.rs +++ b/src/common/cpp_essentials/fast_edge_to_edge_counter.rs @@ -1,3 +1,5 @@ +use crate::common::BitMatrix; + use super::BitMatrixCursorTrait; pub struct FastEdgeToEdgeCounter { @@ -9,11 +11,11 @@ pub struct FastEdgeToEdgeCounter { stepsToBorder: i32, // = 0; //arr: BitArray, _arr: isize, - under_arry: Vec, + under_arry: Vec//&'a BitMatrix//, } impl FastEdgeToEdgeCounter { - pub fn new(cur: &T) -> Self { + pub fn new(cur: &T) -> FastEdgeToEdgeCounter { let stride = cur.d().y as isize * cur.img().width() as isize + cur.d().x as isize; let p = ((cur.p().y as isize * cur.img().width() as isize).abs() as i32 + cur.p().x as i32) as u32; // P IS SET WRONG IN REVERSE @@ -37,7 +39,7 @@ impl FastEdgeToEdgeCounter { }; let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY) as i32; - Self { + FastEdgeToEdgeCounter { p, stride, stepsToBorder, @@ -63,6 +65,7 @@ impl FastEdgeToEdgeCounter { if !(self.under_arry[idx_pt] == self.under_arry[self.p as usize]) + // if !(self.under_arry.get_index(idx_pt) == self.under_arry.get_index(self.p as usize)) { break true; } diff --git a/src/common/default_grid_sampler.rs b/src/common/default_grid_sampler.rs index d9bc061..2c0b36a 100644 --- a/src/common/default_grid_sampler.rs +++ b/src/common/default_grid_sampler.rs @@ -89,7 +89,7 @@ impl GridSampler for DefaultGridSampler { Point::default() }; - let tl = projectCorner(point(0.0, 0.0)); + let tl = projectCorner(Point::default()); let tr = projectCorner(Point::from((dimensionX, 0))); let bl = projectCorner(Point::from((dimensionX, dimensionY))); let br = projectCorner(Point::from((0, dimensionX))); diff --git a/src/datamatrix/detector/datamatrix_detector.rs b/src/datamatrix/detector/datamatrix_detector.rs index 88a973c..63a877e 100644 --- a/src/datamatrix/detector/datamatrix_detector.rs +++ b/src/datamatrix/detector/datamatrix_detector.rs @@ -343,7 +343,8 @@ impl<'a> Detector<'_> { ); let src = Quadrilateral::new(topRight, topLeft, bottomRight, bottomLeft); - sampler.sample_grid_detailed(image, dimensionX, dimensionY, dst, src) + let(res,_)=sampler.sample_grid_detailed(image, dimensionX, dimensionY, dst, src)?; + Ok(res) } /** diff --git a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs index 5d74e31..e09b8dc 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs @@ -233,8 +233,10 @@ fn Scan( CHECK!(res.is_ok()); + let (res, _) = res?; + return Ok(DatamatrixDetectorResult::new( - res?, + res, sourcePoints.points().to_vec(), )); } diff --git a/src/maxicode/detector.rs b/src/maxicode/detector.rs index 8f6546a..4294311 100644 --- a/src/maxicode/detector.rs +++ b/src/maxicode/detector.rs @@ -356,7 +356,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result Result= 0; y--) AppendBit(&mut formatInfoBits1, getBit(bitMatrix, 8, y, None)); } @@ -130,7 +130,7 @@ pub fn ReadQRCodewords( let mut bitsRead = 0; let dimension = bitMatrix.height(); // Read columns in pairs, from right to left - let mut x = dimension - 1; + let mut x = (dimension as i32) - 1; while x > 0 { // for (int x = dimension - 1; x > 0; x -= 2) { // Skip whole column with vertical timing pattern. @@ -143,7 +143,7 @@ pub fn ReadQRCodewords( let y = if readingUp { dimension - 1 - row } else { row }; for col in 0..2 { // for (int col = 0; col < 2; col++) { - let xx = x - col; + let xx = (x - col) as u32; // Ignore bits covered by the function pattern if (!functionPattern.get(xx, y)) { // Read a bit diff --git a/src/qrcode/cpp_port/decoder.rs b/src/qrcode/cpp_port/decoder.rs index c6637bf..0e6c14d 100644 --- a/src/qrcode/cpp_port/decoder.rs +++ b/src/qrcode/cpp_port/decoder.rs @@ -428,7 +428,7 @@ pub fn Decode(bits: &BitMatrix) -> Result> { } // resultIterator = std::copy_n(codewordBytes.begin(), numDataCodewords, resultIterator); - resultBytes[resultIterator..numDataCodewords] + resultBytes[resultIterator..(resultIterator+numDataCodewords)] .copy_from_slice(&codewordBytes[..numDataCodewords]); resultIterator += numDataCodewords; } diff --git a/src/qrcode/cpp_port/detector.rs b/src/qrcode/cpp_port/detector.rs index 4324283..a407b7a 100644 --- a/src/qrcode/cpp_port/detector.rs +++ b/src/qrcode/cpp_port/detector.rs @@ -747,8 +747,8 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result Detector<'_> { dimension: u32, ) -> Result { let sampler = DefaultGridSampler::default(); - sampler.sample_grid( + let (res, _) = sampler.sample_grid( image, dimension, dimension, &[SamplerControl::new(dimension, dimension, transform)], - ) + )?; + Ok(res) } /**