mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
code cleanup
This commit is contained in:
@@ -9,8 +9,7 @@ use crate::common::reedsolomon::{
|
||||
get_predefined_genericgf, PredefinedGenericGF, ReedSolomonDecoder,
|
||||
};
|
||||
use crate::common::{
|
||||
AIFlag, BitMatrix, BitSource, CharacterSet, ECIStringBuilder, Eci, Result,
|
||||
SymbologyIdentifier,
|
||||
AIFlag, BitMatrix, BitSource, CharacterSet, ECIStringBuilder, Eci, Result, SymbologyIdentifier,
|
||||
};
|
||||
use crate::qrcode::cpp_port::bitmatrix_parser::{
|
||||
ReadCodewords, ReadFormatInformation, ReadVersion,
|
||||
|
||||
@@ -4,7 +4,8 @@ use crate::{
|
||||
CenterOfRing, DMRegressionLine, FindConcentricPatternCorners, FindLeftGuardBy, Matrix,
|
||||
},
|
||||
DefaultGridSampler, GridSampler, Result, SamplerControl,
|
||||
}, point_i,
|
||||
},
|
||||
point_i,
|
||||
qrcode::{
|
||||
decoder::{FormatInformation, Version, VersionRef},
|
||||
detector::QRCodeDetectorResult,
|
||||
@@ -16,10 +17,9 @@ use multimap::MultiMap;
|
||||
use crate::{
|
||||
common::{
|
||||
cpp_essentials::{
|
||||
BitMatrixCursorTrait, ConcentricPattern, Direction, EdgeTracer,
|
||||
FixedPattern, GetPatternRowTP, IsPattern, LocateConcentricPattern,
|
||||
PatternRow, PatternType, PatternView, ReadSymmetricPattern, RegressionLine,
|
||||
RegressionLineTrait,
|
||||
BitMatrixCursorTrait, ConcentricPattern, Direction, EdgeTracer, FixedPattern,
|
||||
GetPatternRowTP, IsPattern, LocateConcentricPattern, PatternRow, PatternType,
|
||||
PatternView, ReadSymmetricPattern, RegressionLine, RegressionLineTrait,
|
||||
},
|
||||
BitMatrix, PerspectiveTransform, Quadrilateral,
|
||||
},
|
||||
@@ -502,8 +502,16 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
}
|
||||
|
||||
let best = if top.err == left.err {
|
||||
if top.dim > left.dim { top } else { left }
|
||||
} else if top.err < left.err { top } else { left };
|
||||
if top.dim > left.dim {
|
||||
top
|
||||
} else {
|
||||
left
|
||||
}
|
||||
} else if top.err < left.err {
|
||||
top
|
||||
} else {
|
||||
left
|
||||
};
|
||||
let mut dimension = best.dim;
|
||||
let moduleSize = (best.ms + 1.0) as i32;
|
||||
|
||||
|
||||
@@ -120,8 +120,8 @@
|
||||
use crate::{
|
||||
common::{cpp_essentials::ConcentricPattern, DetectorRXingResult},
|
||||
multi::MultipleBarcodeReader,
|
||||
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
|
||||
Exceptions, RXingResult, Reader,
|
||||
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
|
||||
RXingResult, Reader,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -132,8 +132,6 @@ use super::{
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct QrReader;
|
||||
|
||||
|
||||
@@ -8,86 +8,62 @@ use crate::{common::BitMatrix, qrcode::cpp_port::data_mask::GetMaskedBit};
|
||||
|
||||
#[test]
|
||||
fn Mask0() {
|
||||
TestMaskAcrossDimensions(0, |i, j| {
|
||||
(i + j) % 2 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(0, |i, j| (i + j) % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask1() {
|
||||
TestMaskAcrossDimensions(1, |i, _| {
|
||||
i % 2 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(1, |i, _| i % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask2() {
|
||||
TestMaskAcrossDimensions(2, |_, j| {
|
||||
j % 3 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(2, |_, j| j % 3 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask3() {
|
||||
TestMaskAcrossDimensions(3, |i, j| {
|
||||
(i + j) % 3 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(3, |i, j| (i + j) % 3 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask4() {
|
||||
TestMaskAcrossDimensions(4, |i, j| {
|
||||
(i / 2 + j / 3) % 2 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(4, |i, j| (i / 2 + j / 3) % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask5() {
|
||||
TestMaskAcrossDimensions(5, |i, j| {
|
||||
(i * j) % 2 + (i * j) % 3 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(5, |i, j| (i * j) % 2 + (i * j) % 3 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask6() {
|
||||
TestMaskAcrossDimensions(6, |i, j| {
|
||||
((i * j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(6, |i, j| ((i * j) % 2 + (i * j) % 3) % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask7() {
|
||||
TestMaskAcrossDimensions(7, |i, j| {
|
||||
((i + j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
TestMaskAcrossDimensions(7, |i, j| ((i + j) % 2 + (i * j) % 3) % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask0() {
|
||||
TestMicroMaskAcrossDimensions(0, |i, _| {
|
||||
i % 2 == 0
|
||||
});
|
||||
TestMicroMaskAcrossDimensions(0, |i, _| i % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask1() {
|
||||
TestMicroMaskAcrossDimensions(1, |i, j| {
|
||||
(i / 2 + j / 3) % 2 == 0
|
||||
});
|
||||
TestMicroMaskAcrossDimensions(1, |i, j| (i / 2 + j / 3) % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask2() {
|
||||
TestMicroMaskAcrossDimensions(2, |i, j| {
|
||||
((i * j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
TestMicroMaskAcrossDimensions(2, |i, j| ((i * j) % 2 + (i * j) % 3) % 2 == 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask3() {
|
||||
TestMicroMaskAcrossDimensions(3, |i, j| {
|
||||
((i + j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
TestMicroMaskAcrossDimensions(3, |i, j| ((i + j) % 2 + (i * j) % 3) % 2 == 0);
|
||||
}
|
||||
|
||||
fn TestMaskAcrossDimensionsImpl<F>(
|
||||
|
||||
@@ -23,10 +23,8 @@
|
||||
// using namespace ZXing;
|
||||
// using namespace ZXing::QRCode;
|
||||
|
||||
|
||||
|
||||
use crate::{
|
||||
common::{BitArray},
|
||||
common::BitArray,
|
||||
qrcode::{
|
||||
cpp_port::decoder::DecodeBitStream,
|
||||
decoder::{ErrorCorrectionLevel, Version},
|
||||
|
||||
@@ -43,8 +43,8 @@ fn VersionForNumber() {
|
||||
fn GetProvisionalVersionForDimension() {
|
||||
for i in 1..=40 {
|
||||
// for (int i = 1; i <= 40; i++) {
|
||||
let prov =
|
||||
Version::FromDimension(4 * i + 17).unwrap_or_else(|_| panic!("version should exist for {i}"));
|
||||
let prov = Version::FromDimension(4 * i + 17)
|
||||
.unwrap_or_else(|_| panic!("version should exist for {i}"));
|
||||
// assert_ne!(prov, nullptr);
|
||||
assert_eq!(i, prov.getVersionNumber());
|
||||
}
|
||||
|
||||
@@ -151,10 +151,10 @@ impl Mode {
|
||||
return Mode::try_from(bits);
|
||||
}
|
||||
} else {
|
||||
const Bits2Mode: [Mode; BITS_2_MODE_LEN] =
|
||||
const BITS_2_MODE: [Mode; BITS_2_MODE_LEN] =
|
||||
[Mode::NUMERIC, Mode::ALPHANUMERIC, Mode::BYTE, Mode::KANJI];
|
||||
if (bits as usize) < BITS_2_MODE_LEN {
|
||||
return Ok(Bits2Mode[bits as usize]);
|
||||
return Ok(BITS_2_MODE[bits as usize]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user