From 6a1c5c568a0f744eb7d80992e8ab276bf8faf566 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Wed, 29 Mar 2023 12:10:58 -0500 Subject: [PATCH] continued removal of todo!() --- .../base_extentions/qr_formatinformation.rs | 25 +++++- src/qrcode/cpp_port/bitmatrix_parser.rs | 81 +++++++++++-------- 2 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs index 149c838..720abcb 100644 --- a/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs +++ b/src/common/cpp_essentials/base_extentions/qr_formatinformation.rs @@ -1,8 +1,28 @@ use crate::qrcode::decoder::FormatInformation; impl FormatInformation { + /** + * @param formatInfoBits1 format info indicator, with mask still applied + * @param formatInfoBits2 second copy of same info; both are checked at the same time to establish best match + */ + pub fn DecodeQR(formatInfoBits1: u32, formatInfoBits2: u32) -> Self { + todo!() + // // maks out the 'Dark Module' for mirrored and non-mirrored case (see Figure 25 in ISO/IEC 18004:2015) + // uint32_t mirroredFormatInfoBits2 = MirrorBits(((formatInfoBits2 >> 1) & 0b111111110000000) | (formatInfoBits2 & 0b1111111)); + // formatInfoBits2 = ((formatInfoBits2 >> 1) & 0b111111100000000) | (formatInfoBits2 & 0b11111111); + // auto fi = FindBestFormatInfo(FORMAT_INFO_MASK_QR, FORMAT_INFO_DECODE_LOOKUP, + // {formatInfoBits1, formatInfoBits2, MirrorBits(formatInfoBits1), mirroredFormatInfoBits2}); + + // // Use bits 3/4 for error correction, and 0-2 for mask. + // fi.ecLevel = ECLevelFromBits((fi.index >> 3) & 0x03); + // fi.dataMask = static_cast(fi.index & 0x07); + // fi.isMirrored = fi.bitsIndex > 1; + + // return fi; + } + pub fn DecodeMQR(formatInfoBits: u32) -> Self { - unimplemented!() + todo!() // // We don't use the additional masking (with 0x4445) to work around potentially non complying MicroQRCode encoders // auto fi = FindBestFormatInfo(0, FORMAT_INFO_DECODE_LOOKUP_MICRO, {formatInfoBits, MirrorBits(formatInfoBits)}); @@ -16,7 +36,8 @@ impl FormatInformation { // return fi; } + pub fn isValid(&self) -> bool { - unimplemented!() + todo!() } } diff --git a/src/qrcode/cpp_port/bitmatrix_parser.rs b/src/qrcode/cpp_port/bitmatrix_parser.rs index 3c33ac8..2eafb77 100644 --- a/src/qrcode/cpp_port/bitmatrix_parser.rs +++ b/src/qrcode/cpp_port/bitmatrix_parser.rs @@ -61,44 +61,59 @@ pub fn ReadVersion(bitMatrix: &BitMatrix) -> Result { } pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result { - todo!() - // if (!hasValidDimension(bitMatrix, isMicro)) - // return {}; + if (!hasValidDimension(bitMatrix, isMicro)) { + return Err(Exceptions::FORMAT); + } - // if (isMicro) { - // // Read top-left format info bits - // int formatInfoBits = 0; - // for (int x = 1; x < 9; x++) - // AppendBit(formatInfoBits, getBit(bitMatrix, x, 8)); - // for (int y = 7; y >= 1; y--) - // AppendBit(formatInfoBits, getBit(bitMatrix, 8, y)); + if (isMicro) { + // Read top-left format info bits + let mut formatInfoBits = 0; + for x in 1..9 { + // for (int x = 1; x < 9; x++) + AppendBit(&mut formatInfoBits, getBit(bitMatrix, x, 8, None)); + } + for y in (1..=7).rev() { + // for (int y = 7; y >= 1; y--) + AppendBit(&mut formatInfoBits, getBit(bitMatrix, 8, y, None)); + } - // return FormatInformation::DecodeMQR(formatInfoBits); - // } + return Ok(FormatInformation::DecodeMQR(formatInfoBits as u32)); + } - // // Read top-left format info bits - // int formatInfoBits1 = 0; - // for (int x = 0; x < 6; x++) - // AppendBit(formatInfoBits1, getBit(bitMatrix, x, 8)); - // // .. and skip a bit in the timing pattern ... - // AppendBit(formatInfoBits1, getBit(bitMatrix, 7, 8)); - // AppendBit(formatInfoBits1, getBit(bitMatrix, 8, 8)); - // AppendBit(formatInfoBits1, getBit(bitMatrix, 8, 7)); - // // .. and skip a bit in the timing pattern ... - // for (int y = 5; y >= 0; y--) - // AppendBit(formatInfoBits1, getBit(bitMatrix, 8, y)); + // Read top-left format info bits + let mut formatInfoBits1 = 0; + for x in 0..6 { + // for (int x = 0; x < 6; x++) + AppendBit(&mut formatInfoBits1, getBit(bitMatrix, x, 8, None)); + } + // .. and skip a bit in the timing pattern ... + AppendBit(&mut formatInfoBits1, getBit(bitMatrix, 7, 8, None)); + AppendBit(&mut formatInfoBits1, getBit(bitMatrix, 8, 8, None)); + AppendBit(&mut formatInfoBits1, getBit(bitMatrix, 8, 7, None)); + // .. and skip a bit in the timing pattern ... + for y in (0..=6).rev() { + // for (int y = 5; y >= 0; y--) + AppendBit(&mut formatInfoBits1, getBit(bitMatrix, 8, y, None)); + } - // // Read the top-right/bottom-left pattern including the 'Dark Module' from the bottom-left - // // part that has to be considered separately when looking for mirrored symbols. - // // See also FormatInformation::DecodeQR - // int dimension = bitMatrix.height(); - // int formatInfoBits2 = 0; - // for (int y = dimension - 1; y >= dimension - 8; y--) - // AppendBit(formatInfoBits2, getBit(bitMatrix, 8, y)); - // for (int x = dimension - 8; x < dimension; x++) - // AppendBit(formatInfoBits2, getBit(bitMatrix, x, 8)); + // Read the top-right/bottom-left pattern including the 'Dark Module' from the bottom-left + // part that has to be considered separately when looking for mirrored symbols. + // See also FormatInformation::DecodeQR + let dimension = bitMatrix.height(); + let mut formatInfoBits2 = 0; + for y in ((dimension - 8)..=(dimension - 1)).rev() { + // for (int y = dimension - 1; y >= dimension - 8; y--) + AppendBit(&mut formatInfoBits2, getBit(bitMatrix, 8, y, None)); + } + for x in (dimension - 8)..dimension { + // for (int x = dimension - 8; x < dimension; x++) + AppendBit(&mut formatInfoBits2, getBit(bitMatrix, x, 8, None)); + } - // return FormatInformation::DecodeQR(formatInfoBits1, formatInfoBits2); + return Ok(FormatInformation::DecodeQR( + formatInfoBits1 as u32, + formatInfoBits2 as u32, + )); } pub fn ReadQRCodewords(