diff --git a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs index 2dd548d..1e2ca2d 100644 --- a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs +++ b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs @@ -102,12 +102,9 @@ impl FormatInformation { */ pub fn DecodeRMQR(formatInfoBits1: u32, formatInfoBits2: u32) -> Self { //FormatInformation fi; - + let mut fi = if formatInfoBits2 != 0 { - Self::FindBestFormatInfoRMQR( - &[formatInfoBits1], - &[formatInfoBits2], - ) + Self::FindBestFormatInfoRMQR(&[formatInfoBits1], &[formatInfoBits2]) } else { // TODO probably remove if `sampleRMQR()` done properly Self::FindBestFormatInfoRMQR(&[formatInfoBits1], &[]) diff --git a/src/common/cpp_essentials/base_extentions/qrcode_version.rs b/src/common/cpp_essentials/base_extentions/qrcode_version.rs index 0216f14..4700b1e 100644 --- a/src/common/cpp_essentials/base_extentions/qrcode_version.rs +++ b/src/common/cpp_essentials/base_extentions/qrcode_version.rs @@ -144,7 +144,7 @@ impl Version { Type::const_eq(self.qr_type, Type::RectMicro) } - pub fn SymbolSize(version: u32, qr_type: Type) -> PointI { + pub fn SymbolSize(version: u32, qr_type: Type) -> PointI { let version = version as i32; let square = |s: i32| point(s, s); @@ -216,7 +216,8 @@ impl Version { fn IndexOf(_points: &[PointI], search: PointI) -> i32 { RMQR_SIZES .iter() - .position(|p| *p == search).map(|x| x as i32) + .position(|p| *p == search) + .map(|x| x as i32) .unwrap_or(-1) } @@ -224,11 +225,11 @@ impl Version { if size.x != size.y { (Self::IndexOf(&RMQR_SIZES, size) + 1) as u32 } else if Self::IsValidSize(size, Type::Model2) { - ((size.x - 17) / 4) as u32 + ((size.x - 17) / 4) as u32 } else if Self::IsValidSize(size, Type::Micro) { - ((size.x - 9) / 2) as u32 + ((size.x - 9) / 2) as u32 } else { - 0 + 0 } } diff --git a/src/qrcode/cpp_port/detector.rs b/src/qrcode/cpp_port/detector.rs index 93d7ed7..dfd6118 100644 --- a/src/qrcode/cpp_port/detector.rs +++ b/src/qrcode/cpp_port/detector.rs @@ -5,16 +5,15 @@ use crate::{ }, DefaultGridSampler, GridSampler, Result, SamplerControl, }, - point_i, + point, point_i, qrcode::{ decoder::{FormatInformation, Version, VersionRef}, detector::QRCodeDetectorResult, }, - Exceptions, point, + Exceptions, }; use multimap::MultiMap; - use crate::{ common::{ cpp_essentials::{ @@ -799,7 +798,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result { // SaveAsPBM(image, "weg.pbm"); // #endif - let MIN_MODULES : i32 = Version::SymbolSize(1, Type::Model2).x; + let MIN_MODULES: i32 = Version::SymbolSize(1, Type::Model2).x; let (found, left, top, width, height) = image.findBoundingBox(0, 0, 0, 0, MIN_MODULES as u32); @@ -886,7 +885,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result { pub fn DetectPureMQR(image: &BitMatrix) -> Result { type Pattern = [PatternType; 5]; - let MIN_MODULES : i32= Version::SymbolSize(1, Type::Micro).x; + let MIN_MODULES: i32 = Version::SymbolSize(1, Type::Micro).x; let (found, left, top, width, height) = image.findBoundingBox(0, 0, 0, 0, MIN_MODULES as u32); @@ -949,25 +948,25 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result { } pub fn DetectPureRMQR(image: &BitMatrix) -> Result { - const SUBPATTERN : FixedPattern<4,4> = FixedPattern::new([1, 1, 1, 1]); - const TIMINGPATTERN : FixedPattern<10,10>= FixedPattern::new([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); + const SUBPATTERN: FixedPattern<4, 4> = FixedPattern::new([1, 1, 1, 1]); + const TIMINGPATTERN: FixedPattern<10, 10> = FixedPattern::new([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); type Pattern = [PatternType; 5]; //std::array; - // type SubPattern = [PatternType; 5]; //std::array; - // type CornerEdgePattern = [PatternType; 2]; //std::array; + // type SubPattern = [PatternType; 5]; //std::array; + // type CornerEdgePattern = [PatternType; 2]; //std::array; - type SubPattern = [PatternType;4]; - type TimingPattern = [PatternType;10]; + type SubPattern = [PatternType; 4]; + type TimingPattern = [PatternType; 10]; // #ifdef PRINT_DEBUG // SaveAsPBM(image, "weg.pbm"); // #endif - let MIN_MODULES : i32 = Version::SymbolSize(1, Type::RectMicro).y; + let MIN_MODULES: i32 = Version::SymbolSize(1, Type::RectMicro).y; let (found, left, top, width, height) = image.findBoundingBox(0, 0, 0, 0, MIN_MODULES as u32); - if !found || height >= width{ + if !found || height >= width { return Err(Exceptions::NOT_FOUND); } let right = left + width - 1; @@ -988,37 +987,43 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result { return Err(Exceptions::NOT_FOUND); } - - let fpWidth = (diagonal).into_iter().sum::(); let moduleSize = (fpWidth as f32) / 7.0; let dimW = (width as f32 / moduleSize as f32).floor() as u32; let dimH = (height as f32 / moduleSize as f32).floor() as u32; - if !Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro) - {return Err(Exceptions::NOT_FOUND);} + if !Version::IsValidSize(point(dimW as i32, dimH as i32), Type::RectMicro) { + return Err(Exceptions::NOT_FOUND); + } - // Finder sub pattern - let subdiagonal : SubPattern = EdgeTracer::new(image, br, point_i(-1, -1)).readPatternFromBlack(1,None).ok_or(Exceptions::ILLEGAL_STATE)?; + // Finder sub pattern + let subdiagonal: SubPattern = EdgeTracer::new(image, br, point_i(-1, -1)) + .readPatternFromBlack(1, None) + .ok_or(Exceptions::ILLEGAL_STATE)?; let subdiagonal_hld = subdiagonal.to_vec().into(); let view = PatternView::new(&subdiagonal_hld); - if IsPattern::(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0 - {return Err(Exceptions::NOT_FOUND);} + if IsPattern::(&view, &SUBPATTERN, None, 0.0, 0.0) != 0.0 { + return Err(Exceptions::NOT_FOUND); + } // Vertical corner finder patterns // Horizontal timing patterns - for (p, d) in [(tr, point(-1, 0)), (bl, point(1, 0)), (tl, point(1, 0)), (br, point(-1, 0))] { - let mut cur = EdgeTracer::new(image, p, d.into()); - // skip corner / finder / sub pattern edge - cur.stepToEdge(Some(2 + i32::from(cur.isWhite())), None, None); - let timing : TimingPattern = cur.readPattern(None).ok_or(Exceptions::ILLEGAL_STATE)?; + for (p, d) in [ + (tr, point(-1, 0)), + (bl, point(1, 0)), + (tl, point(1, 0)), + (br, point(-1, 0)), + ] { + let mut cur = EdgeTracer::new(image, p, d.into()); + // skip corner / finder / sub pattern edge + cur.stepToEdge(Some(2 + i32::from(cur.isWhite())), None, None); + let timing: TimingPattern = cur.readPattern(None).ok_or(Exceptions::ILLEGAL_STATE)?; let timing_hld = timing.to_vec().into(); - let view = PatternView::new(&timing_hld); - if !(IsPattern::(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0) - {return Err(Exceptions::NOT_FOUND);} + let view = PatternView::new(&timing_hld); + if !(IsPattern::(&view, &TIMINGPATTERN, None, 0.0, 0.0) != 0.0) { + return Err(Exceptions::NOT_FOUND); } - - + } // #ifdef PRINT_DEBUG // LogMatrix log; @@ -1162,10 +1167,24 @@ pub fn SampleRMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result