chore: clippy cleanup

This commit is contained in:
Henry Schimke
2024-01-13 14:02:02 -06:00
parent 693d1c25e4
commit 6a06762fd8
8 changed files with 41 additions and 50 deletions

View File

@@ -103,7 +103,7 @@ impl FormatInformation {
pub fn DecodeRMQR(formatInfoBits1: u32, formatInfoBits2: u32) -> Self { pub fn DecodeRMQR(formatInfoBits1: u32, formatInfoBits2: u32) -> Self {
//FormatInformation fi; //FormatInformation fi;
let mirror18Bits = |bits: u32| bits.reverse_bits() >> 14; let mirror18Bits = |bits: u32| bits.reverse_bits() >> 14;
let mut fi = if (formatInfoBits2 != 0) { let mut fi = if formatInfoBits2 != 0 {
Self::FindBestFormatInfoRMQR( Self::FindBestFormatInfoRMQR(
&[formatInfoBits1, mirror18Bits(formatInfoBits1)], &[formatInfoBits1, mirror18Bits(formatInfoBits1)],
&[formatInfoBits2, mirror18Bits(formatInfoBits2)], &[formatInfoBits2, mirror18Bits(formatInfoBits2)],
@@ -218,7 +218,7 @@ impl FormatInformation {
let pattern = l_pattern ^ mask; let pattern = l_pattern ^ mask;
// Find the pattern with fewest bits differing // Find the pattern with fewest bits differing
let hammingDist = ((bits[bitsIndex] ^ mask) ^ pattern).count_ones(); let hammingDist = ((bits[bitsIndex] ^ mask) ^ pattern).count_ones();
if (hammingDist < fi.hammingDistance) { if hammingDist < fi.hammingDistance {
fi.mask = mask; // store the used mask to discriminate between types/models fi.mask = mask; // store the used mask to discriminate between types/models
fi.data = pattern >> 12; // drop the 12 BCH error correction bits fi.data = pattern >> 12; // drop the 12 BCH error correction bits
fi.hammingDistance = hammingDist; fi.hammingDistance = hammingDist;
@@ -229,7 +229,7 @@ impl FormatInformation {
}; };
best(bits, &MASKED_PATTERNS, FORMAT_INFO_MASK_RMQR); best(bits, &MASKED_PATTERNS, FORMAT_INFO_MASK_RMQR);
if (!subbits.is_empty()) if !subbits.is_empty()
// TODO probably remove if `sampleRMQR()` done properly // TODO probably remove if `sampleRMQR()` done properly
{ {
best(subbits, &MASKED_PATTERNS_SUB, FORMAT_INFO_MASK_RMQR_SUB); best(subbits, &MASKED_PATTERNS_SUB, FORMAT_INFO_MASK_RMQR_SUB);

View File

@@ -77,10 +77,10 @@ impl Version {
pub fn rMQR(version_number: u32) -> Result<VersionRef> { pub fn rMQR(version_number: u32) -> Result<VersionRef> {
let version_number = version_number as usize; let version_number = version_number as usize;
if (version_number < 1 || version_number > (RMQR_VERSIONS.len())) { if version_number < 1 || version_number > (RMQR_VERSIONS.len()) {
Err(Exceptions::ILLEGAL_ARGUMENT) Err(Exceptions::ILLEGAL_ARGUMENT)
} else { } else {
Ok(&RMQR_VERSIONS[version_number as usize - 1]) Ok(&RMQR_VERSIONS[version_number - 1])
} }
} }
@@ -146,7 +146,7 @@ impl Version {
pub fn HasMicroSize(bitMatrix: &BitMatrix) -> bool { pub fn HasMicroSize(bitMatrix: &BitMatrix) -> bool {
let size = bitMatrix.height(); let size = bitMatrix.height();
size == bitMatrix.width() && size >= 11 && size <= 17 && (size % 2) == 1 size == bitMatrix.width() && (11..=17).contains(&size) && (size % 2) == 1
} }
pub fn HasRMQRSize(bitMatrix: &BitMatrix) -> bool { pub fn HasRMQRSize(bitMatrix: &BitMatrix) -> bool {
@@ -187,10 +187,8 @@ impl Version {
if width != height if width != height
&& width.is_odd() && width.is_odd()
&& height.is_odd() && height.is_odd()
&& width >= 27 && (27..=139).contains(&width)
&& width <= 139 && (7..=17).contains(&height)
&& height >= 7
&& height <= 17
{ {
for i in 0..dimsVersionRMQR.len() { for i in 0..dimsVersionRMQR.len() {
// for (int i = 0; i < Size(dimsVersionRMQR); i++){ // for (int i = 0; i < Size(dimsVersionRMQR); i++){
@@ -199,6 +197,6 @@ impl Version {
} }
} }
} }
return -1; -1
} }
} }

View File

@@ -52,7 +52,7 @@ pub fn ReadFormatInformation(bitMatrix: &BitMatrix) -> Result<FormatInformation>
return Ok(FormatInformation::DecodeMQR(formatInfoBits as u32)); return Ok(FormatInformation::DecodeMQR(formatInfoBits as u32));
} }
if (Version::HasRMQRSize(bitMatrix)) { if Version::HasRMQRSize(bitMatrix) {
// Read top-left format info bits // Read top-left format info bits
let mut formatInfoBits1 = 0; let mut formatInfoBits1 = 0;
for y in (1..=3).rev() { for y in (1..=3).rev() {
@@ -378,7 +378,7 @@ pub fn ReadRMQRCodewords(
// for (int col = 0; col < 2; col++) { // for (int col = 0; col < 2; col++) {
let xx = x - col; let xx = x - col;
// Ignore bits covered by the function pattern // Ignore bits covered by the function pattern
if (!functionPattern.get(xx as u32, y)) { if !functionPattern.get(xx as u32, y) {
// Read a bit // Read a bit
AppendBit( AppendBit(
&mut currentByte, &mut currentByte,
@@ -399,7 +399,7 @@ pub fn ReadRMQRCodewords(
x -= 2 x -= 2
} }
if ((result.len()) != version.getTotalCodewords() as usize) { if (result.len()) != version.getTotalCodewords() as usize {
return Err(Exceptions::FORMAT); return Err(Exceptions::FORMAT);
} }

View File

@@ -5,12 +5,12 @@ use crate::{
}, },
DefaultGridSampler, GridSampler, Result, SamplerControl, DefaultGridSampler, GridSampler, Result, SamplerControl,
}, },
point, point_i, point_i,
qrcode::{ qrcode::{
decoder::{FormatInformation, Version, VersionRef}, decoder::{FormatInformation, Version, VersionRef},
detector::QRCodeDetectorResult, detector::QRCodeDetectorResult,
}, },
Exceptions, PointF, Exceptions,
}; };
use multimap::MultiMap; use multimap::MultiMap;
use num::Integer; use num::Integer;
@@ -24,7 +24,7 @@ use crate::{
}, },
BitMatrix, PerspectiveTransform, Quadrilateral, BitMatrix, PerspectiveTransform, Quadrilateral,
}, },
point_f, Point, PointI, point_f, Point,
}; };
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
@@ -914,8 +914,7 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let moduleSize: f32 = (fpWidth as f32) / 7.0; let moduleSize: f32 = (fpWidth as f32) / 7.0;
let dimension = (width as f32 / moduleSize).floor() as u32; let dimension = (width as f32 / moduleSize).floor() as u32;
if dimension < MIN_MODULES if !(MIN_MODULES..=MAX_MODULES).contains(&dimension)
|| dimension > MAX_MODULES
|| !image.is_in(point_f( || !image.is_in(point_f(
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize, top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
@@ -969,7 +968,7 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let (found, left, top, width, height) = image.findBoundingBox(0, 0, 0, 0, MIN_MODULES); let (found, left, top, width, height) = image.findBoundingBox(0, 0, 0, 0, MIN_MODULES);
if (!found) { if !found {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }
let right = left + width - 1; let right = left + width - 1;
@@ -994,7 +993,7 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let mut subdiagonal: SubPattern = EdgeTracer::new(image, br, point_i(-1, -1)) let mut subdiagonal: SubPattern = EdgeTracer::new(image, br, point_i(-1, -1))
.readPatternFromBlack(1, None) .readPatternFromBlack(1, None)
.ok_or(Exceptions::ILLEGAL_STATE)?; .ok_or(Exceptions::ILLEGAL_STATE)?;
if (subdiagonal.len() == 5 && subdiagonal[4] > subdiagonal[3]) { if subdiagonal.len() == 5 && subdiagonal[4] > subdiagonal[3] {
// Sub pattern has no separator so can run off along the diagonal // Sub pattern has no separator so can run off along the diagonal
subdiagonal[4] = subdiagonal[3]; // Hack it back to previous subdiagonal[4] = subdiagonal[3]; // Hack it back to previous
} }
@@ -1024,23 +1023,21 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
let dimW = (width as f32 / moduleSize as f32).floor() as u32; let dimW = (width as f32 / moduleSize as f32).floor() as u32;
let dimH = (height as f32 / moduleSize as f32).floor() as u32; let dimH = (height as f32 / moduleSize as f32).floor() as u32;
if (dimW == dimH if dimW == dimH
|| dimW.is_even() || dimW.is_even()
|| dimH.is_even() || dimH.is_even()
|| dimW < MIN_MODULES_W || !(MIN_MODULES_W..=MAX_MODULES_W).contains(&dimW)
|| dimW > MAX_MODULES_W || !(MIN_MODULES_H..=MAX_MODULES_H).contains(&dimH)
|| dimH < MIN_MODULES_H
|| dimH > MAX_MODULES_H
|| !image.is_in(point_f( || !image.is_in(point_f(
left as f32 + moduleSize / 2.0 + (dimW as f32 - 1.0) * moduleSize, left as f32 + moduleSize / 2.0 + (dimW as f32 - 1.0) * moduleSize,
top as f32 + moduleSize / 2.0 + (dimH as f32 - 1.0) * moduleSize, top as f32 + moduleSize / 2.0 + (dimH as f32 - 1.0) * moduleSize,
))) ))
{ {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }
// Vertical corner finder patterns // Vertical corner finder patterns
if (dimH > 7) { if dimH > 7 {
// None for R7 // None for R7
let corner: CornerEdgePattern = EdgeTracer::new(image, tr, point_i(0, 1)) let corner: CornerEdgePattern = EdgeTracer::new(image, tr, point_i(0, 1))
.readPatternFromBlack(1, None) .readPatternFromBlack(1, None)
@@ -1050,7 +1047,7 @@ pub fn DetectPureRMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
if !(IsPattern::<E2E, 2, 4, false>(&view, &CORNER_EDGE_RMQR, None, 0.0, 0.0) != 0.0) { if !(IsPattern::<E2E, 2, 4, false>(&view, &CORNER_EDGE_RMQR, None, 0.0, 0.0) != 0.0) {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }
if (dimH > 9) { if dimH > 9 {
// No bottom left for R9 // No bottom left for R9
let corner: CornerEdgePattern = EdgeTracer::new(image, bl, point_i(0, -1)) let corner: CornerEdgePattern = EdgeTracer::new(image, bl, point_i(0, -1))
.readPatternFromBlack(1, None) .readPatternFromBlack(1, None)
@@ -1241,7 +1238,7 @@ pub fn SampleRMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDete
}; };
// check that we see top edge timing pattern modules // check that we see top edge timing pattern modules
if (!check(0, true) || !check(1, false) || !check(2, true) || !check(3, false)) { if !check(0, true) || !check(1, false) || !check(2, true) || !check(3, false) {
continue; continue;
} }
@@ -1255,13 +1252,13 @@ pub fn SampleRMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDete
} }
let fi = FormatInformation::DecodeRMQR(formatInfoBits as u32, 0 /*formatInfoBits2*/); let fi = FormatInformation::DecodeRMQR(formatInfoBits as u32, 0 /*formatInfoBits2*/);
if (fi.hammingDistance < bestFI.hammingDistance) { if fi.hammingDistance < bestFI.hammingDistance {
bestFI = fi; bestFI = fi;
bestPT = mod2Pix; bestPT = mod2Pix;
} }
} }
if (!bestFI.isValid()) { if !bestFI.isValid() {
return Err(Exceptions::NOT_FOUND); return Err(Exceptions::NOT_FOUND);
} }

View File

@@ -215,12 +215,10 @@ impl Reader for QrReader {
position, position,
if detectorResult.getBits().width() != detectorResult.getBits().height() { if detectorResult.getBits().width() != detectorResult.getBits().height() {
BarcodeFormat::RECTANGULAR_MICRO_QR_CODE BarcodeFormat::RECTANGULAR_MICRO_QR_CODE
} else { } else if detectorResult.getBits().width() < 21 {
if detectorResult.getBits().width() < 21 {
BarcodeFormat::MICRO_QR_CODE BarcodeFormat::MICRO_QR_CODE
} else { } else {
BarcodeFormat::QR_CODE BarcodeFormat::QR_CODE
}
}, },
)) ))
} }

View File

@@ -204,7 +204,7 @@ XXX X X X X X X X XXX X X X X X X X X XXX X X X X X X XXXXX
) )
.unwrap(); .unwrap();
let result = Decode(&bitMatrix).unwrap(); let _result = Decode(&bitMatrix).unwrap();
// assert!(result.isValid()); // assert!(result.isValid());
// assert!(result.content().type() == ContentType::GS1); // assert!(result.content().type() == ContentType::GS1);
// assert_eq!( // assert_eq!(

View File

@@ -149,13 +149,13 @@ impl Mode {
let qr_type = qr_type.unwrap_or(Type::Model2); let qr_type = qr_type.unwrap_or(Type::Model2);
let bits = bits as usize; let bits = bits as usize;
if (qr_type == Type::Micro) { if qr_type == Type::Micro {
const Bits2Mode: [Mode; 4] = const Bits2Mode: [Mode; 4] =
[Mode::NUMERIC, Mode::ALPHANUMERIC, Mode::BYTE, Mode::KANJI]; [Mode::NUMERIC, Mode::ALPHANUMERIC, Mode::BYTE, Mode::KANJI];
if (bits < (Bits2Mode.len())) { if bits < (Bits2Mode.len()) {
return Ok(Bits2Mode[bits]); return Ok(Bits2Mode[bits]);
} }
} else if (qr_type == Type::RectMicro) { } else if qr_type == Type::RectMicro {
const Bits2Mode: [Mode; 8] = [ const Bits2Mode: [Mode; 8] = [
Mode::TERMINATOR, Mode::TERMINATOR,
Mode::NUMERIC, Mode::NUMERIC,
@@ -166,14 +166,12 @@ impl Mode {
Mode::FNC1_SECOND_POSITION, Mode::FNC1_SECOND_POSITION,
Mode::ECI, Mode::ECI,
]; ];
if (bits < (Bits2Mode.len())) { if bits < (Bits2Mode.len()) {
return Ok(Bits2Mode[bits]); return Ok(Bits2Mode[bits]);
} }
} else { } else if (0x00..=0x05).contains(&bits) || (0x07..=0x09).contains(&bits) || bits == 0x0d {
if ((bits >= 0x00 && bits <= 0x05) || (bits >= 0x07 && bits <= 0x09) || bits == 0x0d) {
return Mode::try_from(bits as u32); return Mode::try_from(bits as u32);
} }
}
Err(Exceptions::format_with("Invalid codec mode")) Err(Exceptions::format_with("Invalid codec mode"))
} }
@@ -196,7 +194,7 @@ impl Mode {
} }
} }
if (version.isRMQR()) { if version.isRMQR() {
// See ISO/IEC 23941:2022 7.4.1, Table 3 - Number of bits of character count indicator // See ISO/IEC 23941:2022 7.4.1, Table 3 - Number of bits of character count indicator
const numeric: [u32; 32] = [ const numeric: [u32; 32] = [
4, 5, 6, 7, 7, 5, 6, 7, 7, 8, 4, 6, 7, 7, 8, 8, 5, 6, 7, 7, 8, 8, 7, 7, 8, 8, 9, 7, 4, 5, 6, 7, 7, 5, 6, 7, 7, 8, 4, 6, 7, 7, 8, 8, 5, 6, 7, 7, 8, 8, 7, 7, 8, 8, 9, 7,
@@ -214,7 +212,7 @@ impl Mode {
2, 3, 4, 5, 5, 3, 4, 5, 5, 6, 2, 4, 5, 5, 6, 6, 3, 5, 5, 6, 6, 7, 5, 5, 6, 6, 7, 5, 2, 3, 4, 5, 5, 3, 4, 5, 5, 6, 2, 4, 5, 5, 6, 6, 3, 5, 5, 6, 6, 7, 5, 5, 6, 6, 7, 5,
6, 6, 6, 7, 6, 6, 6, 7,
]; ];
match (self) { match self {
Mode::NUMERIC => return numeric[number - 1], Mode::NUMERIC => return numeric[number - 1],
Mode::ALPHANUMERIC => return alphanum[number - 1], Mode::ALPHANUMERIC => return alphanum[number - 1],
Mode::BYTE => return byte[number - 1], Mode::BYTE => return byte[number - 1],

View File

@@ -201,7 +201,7 @@ impl Version {
* See ISO 18004:2006 Annex E * See ISO 18004:2006 Annex E
*/ */
pub fn buildFunctionPattern(&self) -> Result<BitMatrix> { pub fn buildFunctionPattern(&self) -> Result<BitMatrix> {
if (self.isRMQR()) { if self.isRMQR() {
let dimension = Version::DimensionOfVersionRMQR(self.versionNumber); let dimension = Version::DimensionOfVersionRMQR(self.versionNumber);
let mut bitMatrix = BitMatrix::new(dimension.x as u32, dimension.y as u32)?; let mut bitMatrix = BitMatrix::new(dimension.x as u32, dimension.y as u32)?;
@@ -240,7 +240,7 @@ impl Version {
// Top right corner finder // Top right corner finder
bitMatrix.set((dimension.x - 2) as u32, 1); bitMatrix.set((dimension.x - 2) as u32, 1);
if (dimension.y > 9) { if dimension.y > 9 {
// Bottom left corner finder // Bottom left corner finder
bitMatrix.set(1, (dimension.y - 2) as u32); bitMatrix.set(1, (dimension.y - 2) as u32);
} }