mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
clippy fix
This commit is contained in:
@@ -127,8 +127,7 @@ impl LuminanceSource for BufferedImageLuminanceSource {
|
||||
.collect::<Vec<&u8>>(); // get all the rows we want to look at
|
||||
|
||||
let data = unmanaged
|
||||
.chunks_exact(self.image.width() as usize)
|
||||
.into_iter() // Get rows
|
||||
.chunks_exact(self.image.width() as usize) // Get rows
|
||||
.flat_map(|f| {
|
||||
f.iter()
|
||||
.skip(row_skip as usize)
|
||||
|
||||
@@ -63,7 +63,6 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
} else {
|
||||
COMMA
|
||||
.split(hostEmail)
|
||||
.into_iter()
|
||||
.map(|s| s.to_owned())
|
||||
.collect()
|
||||
};
|
||||
@@ -81,7 +80,6 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
if let Some(tosString) = nv.get("to") {
|
||||
tos = COMMA
|
||||
.split(tosString)
|
||||
.into_iter()
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
}
|
||||
@@ -92,7 +90,6 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
if let Some(ccString) = nv.get("cc") {
|
||||
ccs = COMMA
|
||||
.split(ccString)
|
||||
.into_iter()
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
}
|
||||
@@ -102,7 +99,6 @@ pub fn parse(result: &RXingResult) -> Option<ParsedClientResult> {
|
||||
if let Some(bccString) = nv.get("bcc") {
|
||||
bccs = COMMA
|
||||
.split(bccString)
|
||||
.into_iter()
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ fn findAIvalue(i: usize, rawText: &str) -> Option<String> {
|
||||
if currentChar == ')' {
|
||||
return Some(buf);
|
||||
}
|
||||
if !('0'..='9').contains(¤tChar) {
|
||||
if !currentChar.is_ascii_digit() {
|
||||
return None;
|
||||
}
|
||||
buf.push(currentChar);
|
||||
|
||||
@@ -227,7 +227,7 @@ pub fn unescapeBackslash(escaped: &str) -> String {
|
||||
}
|
||||
|
||||
pub fn parseHexDigit(c: char) -> i32 {
|
||||
if ('0'..='9').contains(&c) {
|
||||
if c.is_ascii_digit() {
|
||||
return (c as u8 - b'0') as i32;
|
||||
}
|
||||
if ('a'..='f').contains(&c) {
|
||||
|
||||
@@ -431,7 +431,7 @@ impl Into<Vec<bool>> for BitArray {
|
||||
let mut array = vec![false; self.size];
|
||||
|
||||
for pixel in 0..self.size {
|
||||
array[pixel] = bool::from(self.get(pixel));
|
||||
array[pixel] = self.get(pixel);
|
||||
}
|
||||
|
||||
array
|
||||
|
||||
@@ -22,7 +22,7 @@ impl ErrorCorrectionLevel {
|
||||
ErrorCorrectionLevel::H,
|
||||
ErrorCorrectionLevel::Q,
|
||||
];
|
||||
return LEVEL_FOR_BITS[bits as usize & 0x3];
|
||||
LEVEL_FOR_BITS[bits as usize & 0x3]
|
||||
}
|
||||
|
||||
pub fn ECLevelFromBits(bits: u8, isMicro: bool) -> Self {
|
||||
|
||||
@@ -88,7 +88,7 @@ impl Version {
|
||||
return Self::getVersionForNumber(bestVersion);
|
||||
}
|
||||
// If we didn't find a close enough match, fail
|
||||
return Err(Exceptions::ILLEGAL_STATE);
|
||||
Err(Exceptions::ILLEGAL_STATE)
|
||||
}
|
||||
|
||||
pub const fn isMicroQRCode(&self) -> bool {
|
||||
|
||||
@@ -38,13 +38,13 @@ impl<'a> FastEdgeToEdgeCounter<'a> {
|
||||
} else {
|
||||
i32::MAX
|
||||
};
|
||||
let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY) as i32;
|
||||
let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY);
|
||||
|
||||
FastEdgeToEdgeCounter {
|
||||
p,
|
||||
stride,
|
||||
stepsToBorder,
|
||||
_arr: cur.p().y as isize * stride as isize, //cur.img().getRow(cur.p().y as u32),
|
||||
_arr: cur.p().y as isize * stride, //cur.img().getRow(cur.p().y as u32),
|
||||
under_arry: cur.img(), //.into(),
|
||||
}
|
||||
}
|
||||
@@ -66,15 +66,15 @@ impl<'a> FastEdgeToEdgeCounter<'a> {
|
||||
|
||||
// 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)) {
|
||||
if self.under_arry.get_index(idx_pt) != self.under_arry.get_index(self.p as usize) {
|
||||
break;
|
||||
}
|
||||
} // while (p[steps * stride] == p[0]);
|
||||
|
||||
self.p = (self.p as isize + (steps as isize * self.stride)).abs() as u32;
|
||||
self.p = (self.p as isize + (steps as isize * self.stride)).unsigned_abs() as u32;
|
||||
self.stepsToBorder -= steps;
|
||||
|
||||
return steps as u32;
|
||||
steps as u32
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct Matrix<T: Default + Clone + Copy> {
|
||||
|
||||
impl<T: Default + Clone + Copy> Matrix<T> {
|
||||
pub fn with_data(width: usize, height: usize, data: Vec<Option<T>>) -> Result<Matrix<T>> {
|
||||
if width != 0 && data.len() / width as usize != height as usize {
|
||||
if width != 0 && data.len() / width != height {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"invalid size: width * height is too big",
|
||||
));
|
||||
@@ -23,7 +23,7 @@ impl<T: Default + Clone + Copy> Matrix<T> {
|
||||
}
|
||||
|
||||
pub fn new(width: usize, height: usize) -> Result<Matrix<T>> {
|
||||
if width != 0 && (width * height) / width as usize != height as usize {
|
||||
if width != 0 && (width * height) / width != height {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"invalid size: width * height is too big",
|
||||
));
|
||||
@@ -60,7 +60,7 @@ impl<T: Default + Clone + Copy> Matrix<T> {
|
||||
// }
|
||||
|
||||
fn get_offset(x: usize, y: usize, width: usize) -> usize {
|
||||
(y * width + x) as usize
|
||||
y * width + x
|
||||
}
|
||||
|
||||
pub fn get(&self, x: usize, y: usize) -> Option<T> {
|
||||
|
||||
@@ -310,7 +310,7 @@ impl<'a> std::ops::Index<isize> for PatternView<'_> {
|
||||
|
||||
fn index(&self, index: isize) -> &Self::Output {
|
||||
if self.count == self.data.len() {
|
||||
return &self.data[index.abs() as usize];
|
||||
return &self.data[index.unsigned_abs()];
|
||||
}
|
||||
|
||||
if index > self.data.0.len() as isize {
|
||||
@@ -353,7 +353,7 @@ impl<'a> std::ops::Index<i32> for PatternView<'_> {
|
||||
|
||||
impl<'a> Into<Vec<PatternType>> for &PatternView<'a> {
|
||||
fn into(self) -> Vec<PatternType> {
|
||||
let mut v = vec![PatternType::default(); self.count as usize];
|
||||
let mut v = vec![PatternType::default(); self.count];
|
||||
for i in 0..self.count {
|
||||
v[i] = self[i];
|
||||
}
|
||||
@@ -420,11 +420,11 @@ pub struct FixedPattern<const N: usize, const SUM: usize, const IS_SPARCE: bool
|
||||
data: [PatternType; N],
|
||||
}
|
||||
|
||||
impl<const N: usize, const SUM: usize, const IS_SPARCE: bool> Into<Pattern<N>>
|
||||
for FixedPattern<N, SUM, IS_SPARCE>
|
||||
impl<const N: usize, const SUM: usize, const IS_SPARCE: bool> From<FixedPattern<N, SUM, IS_SPARCE>>
|
||||
for Pattern<N>
|
||||
{
|
||||
fn into(self) -> Pattern<N> {
|
||||
self.data
|
||||
fn from(val: FixedPattern<N, SUM, IS_SPARCE>) -> Self {
|
||||
val.data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ impl<const N: usize, const SUM: usize, const IS_SPARCE: bool> FixedPattern<N, SU
|
||||
}
|
||||
|
||||
fn sums(&self) -> BarAndSpace<PatternType> {
|
||||
return BarAndSpaceSum::<N, PatternType, PatternType>(&self.data);
|
||||
BarAndSpaceSum::<N, PatternType, PatternType>(&self.data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,11 +584,11 @@ pub fn IsRightGuard<const N: usize, const SUM: usize, const IS_SPARCE: bool>(
|
||||
) != 0.0
|
||||
}
|
||||
|
||||
pub fn FindLeftGuardBy<'a, const LEN: usize, Pred: Fn(&PatternView, Option<f32>) -> bool>(
|
||||
view: PatternView<'a>,
|
||||
pub fn FindLeftGuardBy<const LEN: usize, Pred: Fn(&PatternView, Option<f32>) -> bool>(
|
||||
view: PatternView<'_>,
|
||||
minSize: usize,
|
||||
isGuard: Pred,
|
||||
) -> Result<PatternView<'a>> {
|
||||
) -> Result<PatternView<'_>> {
|
||||
const PREV_IDX: isize = -1;
|
||||
|
||||
if view.size() < minSize {
|
||||
@@ -601,11 +601,7 @@ pub fn FindLeftGuardBy<'a, const LEN: usize, Pred: Fn(&PatternView, Option<f32>)
|
||||
}
|
||||
let end = Into::<usize>::into(view.end().ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?) - minSize;
|
||||
while (window.start + window.current) < end {
|
||||
let prev = if let Some(v) = window.try_get_index(PREV_IDX) {
|
||||
Some(v as f32)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let prev = window.try_get_index(PREV_IDX).map(|v| v as f32);
|
||||
if isGuard(&window, prev) {
|
||||
return Ok(window);
|
||||
}
|
||||
@@ -631,18 +627,18 @@ pub fn FindLeftGuard<'a, const LEN: usize, const SUM: usize, const IS_SPARCE: bo
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return IsPattern::<false, LEN, SUM, IS_SPARCE>(
|
||||
IsPattern::<false, LEN, SUM, IS_SPARCE>(
|
||||
window,
|
||||
pattern,
|
||||
spaceInPixel,
|
||||
minQuietZone,
|
||||
0.0,
|
||||
) != 0.0;
|
||||
) != 0.0
|
||||
})
|
||||
}
|
||||
|
||||
pub fn NormalizedE2EPattern<'a, const LEN: usize, const LEN_MINUS_2: usize, const SUM: usize>(
|
||||
view: &'a PatternView,
|
||||
pub fn NormalizedE2EPattern<const LEN: usize, const LEN_MINUS_2: usize, const SUM: usize>(
|
||||
view: &PatternView,
|
||||
) -> [PatternType; LEN_MINUS_2] {
|
||||
let moduleSize: f32 = Into::<f32>::into(view.sum(Some(LEN))) / SUM as f32;
|
||||
|
||||
@@ -656,8 +652,8 @@ pub fn NormalizedE2EPattern<'a, const LEN: usize, const LEN_MINUS_2: usize, cons
|
||||
e2e
|
||||
}
|
||||
|
||||
pub fn NormalizedPattern<'a, const LEN: usize, const SUM: usize>(
|
||||
view: &'a PatternView,
|
||||
pub fn NormalizedPattern<const LEN: usize, const SUM: usize>(
|
||||
view: &PatternView,
|
||||
) -> Result<[PatternType; LEN]> {
|
||||
let moduleSize: f32 = (Into::<usize>::into(view.sum(Some(LEN))) / SUM) as f32;
|
||||
let mut err = SUM as isize;
|
||||
|
||||
@@ -113,7 +113,9 @@ impl<LS: LuminanceSource> HybridBinarizer<LS> {
|
||||
let source = ghb.get_luminance_source();
|
||||
let width = source.get_width();
|
||||
let height = source.get_height();
|
||||
let matrix = if width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION {
|
||||
|
||||
// dbg!(matrix.to_string());
|
||||
if width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION {
|
||||
let luminances = source.get_matrix();
|
||||
let mut sub_width = width >> BLOCK_SIZE_POWER;
|
||||
if (width & BLOCK_SIZE_MASK) != 0 {
|
||||
@@ -146,9 +148,7 @@ impl<LS: LuminanceSource> HybridBinarizer<LS> {
|
||||
// If the image is too small, fall back to the global histogram approach.
|
||||
let m = ghb.get_black_matrix()?;
|
||||
Ok(m.clone())
|
||||
};
|
||||
// dbg!(matrix.to_string());
|
||||
matrix
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,20 +58,20 @@ impl Quadrilateral {
|
||||
|
||||
Quadrilateral([
|
||||
Point {
|
||||
x: margin as f32,
|
||||
y: margin as f32,
|
||||
x: margin,
|
||||
y: margin,
|
||||
},
|
||||
Point {
|
||||
x: width as f32 - margin as f32,
|
||||
y: margin as f32,
|
||||
x: width as f32 - margin,
|
||||
y: margin,
|
||||
},
|
||||
Point {
|
||||
x: width as f32 - margin as f32,
|
||||
y: height as f32 - margin as f32,
|
||||
x: width as f32 - margin,
|
||||
y: height as f32 - margin,
|
||||
},
|
||||
Point {
|
||||
x: margin as f32,
|
||||
y: height as f32 - margin as f32,
|
||||
x: margin,
|
||||
y: height as f32 - margin,
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ impl DataMatrixReader {
|
||||
let iOffset = top + y as f32 * moduleSize as f32;
|
||||
for x in 0..matrixWidth {
|
||||
// for (int x = 0; x < matrixWidth; x++) {
|
||||
if image.get_point(point(left as f32 + x as f32 * moduleSize as f32, iOffset)) {
|
||||
if image.get_point(point(left + x as f32 * moduleSize as f32, iOffset)) {
|
||||
bits.set(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,11 +246,11 @@ impl C40Encoder {
|
||||
sb.push('\u{3}');
|
||||
return 1;
|
||||
}
|
||||
if ('0'..='9').contains(&c) {
|
||||
if c.is_ascii_digit() {
|
||||
sb.push((c as u8 - 48 + 4) as char);
|
||||
return 1;
|
||||
}
|
||||
if ('A'..='Z').contains(&c) {
|
||||
if c.is_ascii_uppercase() {
|
||||
sb.push((c as u8 - 65 + 14) as char);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -551,7 +551,7 @@ fn getMinimumCount(mins: &[u8]) -> u32 {
|
||||
}
|
||||
|
||||
pub fn isDigit(ch: char) -> bool {
|
||||
('0'..='9').contains(&ch)
|
||||
ch.is_ascii_digit()
|
||||
}
|
||||
|
||||
pub fn isExtendedASCII(ch: char) -> bool {
|
||||
@@ -559,15 +559,15 @@ pub fn isExtendedASCII(ch: char) -> bool {
|
||||
}
|
||||
|
||||
pub fn isNativeC40(ch: char) -> bool {
|
||||
(ch == ' ') || ('0'..='9').contains(&ch) || ('A'..='Z').contains(&ch)
|
||||
(ch == ' ') || ch.is_ascii_digit() || ch.is_ascii_uppercase()
|
||||
}
|
||||
|
||||
pub fn isNativeText(ch: char) -> bool {
|
||||
(ch == ' ') || ('0'..='9').contains(&ch) || ('a'..='z').contains(&ch)
|
||||
(ch == ' ') || ch.is_ascii_digit() || ch.is_ascii_lowercase()
|
||||
}
|
||||
|
||||
pub fn isNativeX12(ch: char) -> bool {
|
||||
isX12TermSep(ch) || (ch == ' ') || ('0'..='9').contains(&ch) || ('A'..='Z').contains(&ch)
|
||||
isX12TermSep(ch) || (ch == ' ') || ch.is_ascii_digit() || ch.is_ascii_uppercase()
|
||||
}
|
||||
|
||||
fn isX12TermSep(ch: char) -> bool {
|
||||
|
||||
@@ -41,11 +41,11 @@ impl TextEncoder {
|
||||
sb.push('\u{3}');
|
||||
return 1;
|
||||
}
|
||||
if ('0'..='9').contains(&c) {
|
||||
if c.is_ascii_digit() {
|
||||
sb.push((c as u8 - 48 + 4) as char);
|
||||
return 1;
|
||||
}
|
||||
if ('a'..='z').contains(&c) {
|
||||
if c.is_ascii_lowercase() {
|
||||
sb.push((c as u8 - 97 + 14) as char);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -66,9 +66,9 @@ impl X12Encoder {
|
||||
'>' => sb.push('\u{2}'),
|
||||
' ' => sb.push('\u{3}'),
|
||||
_ => {
|
||||
if ('0'..='9').contains(&c) {
|
||||
if c.is_ascii_digit() {
|
||||
sb.push((c as u8 - 48 + 4) as char);
|
||||
} else if ('A'..='Z').contains(&c) {
|
||||
} else if c.is_ascii_uppercase() {
|
||||
sb.push((c as u8 - 65 + 14) as char);
|
||||
} else {
|
||||
high_level_encoder::illegalCharacter(c)?;
|
||||
|
||||
@@ -34,7 +34,6 @@ impl LuminanceSource for Luma8LuminanceSource {
|
||||
.take((self.dimensions.1 * self.original_dimension.0) as usize)
|
||||
.collect::<Vec<&u8>>()
|
||||
.chunks_exact(self.original_dimension.0 as usize)
|
||||
.into_iter()
|
||||
.flat_map(|f| {
|
||||
f.iter()
|
||||
.skip((self.origin.0) as usize)
|
||||
@@ -182,7 +181,7 @@ mod tests {
|
||||
|
||||
let square = Luma8LuminanceSource::new(src_square, 3, 3);
|
||||
let rect_tall = Luma8LuminanceSource::new(src_rect.clone(), 3, 4);
|
||||
let rect_wide = Luma8LuminanceSource::new(src_rect.clone(), 4, 3);
|
||||
let rect_wide = Luma8LuminanceSource::new(src_rect, 4, 3);
|
||||
|
||||
let rotated_square = square.rotate_counter_clockwise().expect("rotate");
|
||||
// print_matrix(&src_rect, 4, 3);
|
||||
|
||||
@@ -348,14 +348,14 @@ fn findCType(value: &str, start: usize) -> Option<CType> {
|
||||
if c == ESCAPE_FNC_1 {
|
||||
return Some(CType::Fnc1);
|
||||
}
|
||||
if !('0'..='9').contains(&c) {
|
||||
if !c.is_ascii_digit() {
|
||||
return Some(CType::Uncodable);
|
||||
}
|
||||
if start + 1 >= last {
|
||||
return Some(CType::OneDigit);
|
||||
}
|
||||
let c = value.chars().nth(start + 1)?;
|
||||
if !('0'..='9').contains(&c) {
|
||||
if !c.is_ascii_digit() {
|
||||
return Some(CType::OneDigit);
|
||||
}
|
||||
Some(CType::TwoDigits)
|
||||
@@ -638,7 +638,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
}
|
||||
|
||||
fn isDigit(c: char) -> bool {
|
||||
('0'..='9').contains(&c)
|
||||
c.is_ascii_digit()
|
||||
}
|
||||
|
||||
fn canEncode(contents: &str, charset: Charset, position: usize) -> bool {
|
||||
|
||||
@@ -335,7 +335,7 @@ impl Code39Reader {
|
||||
match c {
|
||||
'+' => {
|
||||
// +A to +Z map to a to z
|
||||
if ('A'..='Z').contains(&next) {
|
||||
if next.is_ascii_uppercase() {
|
||||
decodedChar = char::from_u32(next as u32 + 32)
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?;
|
||||
} else {
|
||||
@@ -344,7 +344,7 @@ impl Code39Reader {
|
||||
}
|
||||
'$' => {
|
||||
// $A to $Z map to control codes SH to SB
|
||||
if ('A'..='Z').contains(&next) {
|
||||
if next.is_ascii_uppercase() {
|
||||
decodedChar = char::from_u32(next as u32 - 64)
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?;
|
||||
} else {
|
||||
|
||||
@@ -250,7 +250,7 @@ impl Code93Reader {
|
||||
match c {
|
||||
'd' => {
|
||||
// +A to +Z map to a to z
|
||||
if ('A'..='Z').contains(&next) {
|
||||
if next.is_ascii_uppercase() {
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 + 32).ok_or(Exceptions::PARSE)?;
|
||||
} else {
|
||||
@@ -259,7 +259,7 @@ impl Code93Reader {
|
||||
}
|
||||
'a' => {
|
||||
// $A to $Z map to control codes SH to SB
|
||||
if ('A'..='Z').contains(&next) {
|
||||
if next.is_ascii_uppercase() {
|
||||
decodedChar =
|
||||
char::from_u32(next as u32 - 64).ok_or(Exceptions::PARSE)?;
|
||||
} else {
|
||||
|
||||
@@ -566,7 +566,7 @@ fn generateText(
|
||||
for j in 0..wordLength.ceil() as u32 {
|
||||
// for (int j = 0; j < wordLength; j++) {
|
||||
let mut c = chars[maxIndex];
|
||||
if j == 0 && ('a'..='z').contains(&c) && random.next_bool() {
|
||||
if j == 0 && c.is_ascii_lowercase() && random.next_bool() {
|
||||
c = char::from_u32(c as u32 - 'a' as u32 + 'A' as u32).unwrap();
|
||||
}
|
||||
result.push(c);
|
||||
|
||||
@@ -667,15 +667,15 @@ fn encodeNumeric<T: ECIInput + ?Sized>(
|
||||
}
|
||||
|
||||
fn isDigit(ch: char) -> bool {
|
||||
('0'..='9').contains(&ch)
|
||||
ch.is_ascii_digit()
|
||||
}
|
||||
|
||||
fn isAlphaUpper(ch: char) -> bool {
|
||||
ch == ' ' || ('A'..='Z').contains(&ch)
|
||||
ch == ' ' || ch.is_ascii_uppercase()
|
||||
}
|
||||
|
||||
fn isAlphaLower(ch: char) -> bool {
|
||||
ch == ' ' || ('a'..='z').contains(&ch)
|
||||
ch == ' ' || ch.is_ascii_lowercase()
|
||||
}
|
||||
|
||||
fn isMixed(ch: char) -> bool {
|
||||
|
||||
@@ -24,9 +24,9 @@ pub fn getBit(bitMatrix: &BitMatrix, x: u32, y: u32, mirrored: Option<bool>) ->
|
||||
pub fn hasValidDimension(bitMatrix: &BitMatrix, isMicro: bool) -> bool {
|
||||
let dimension = bitMatrix.height();
|
||||
if isMicro {
|
||||
dimension >= 11 && dimension <= 17 && (dimension % 2) == 1
|
||||
(11..=17).contains(&dimension) && (dimension % 2) == 1
|
||||
} else {
|
||||
dimension >= 21 && dimension <= 177 && (dimension % 4) == 1
|
||||
(21..=177).contains(&dimension) && (dimension % 4) == 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn ReadVersion(bitMatrix: &BitMatrix) -> Result<VersionRef> {
|
||||
}
|
||||
}
|
||||
|
||||
return Err(Exceptions::FORMAT);
|
||||
Err(Exceptions::FORMAT)
|
||||
}
|
||||
|
||||
pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result<FormatInformation> {
|
||||
@@ -110,10 +110,10 @@ pub fn ReadFormatInformation(bitMatrix: &BitMatrix, isMicro: bool) -> Result<For
|
||||
AppendBit(&mut formatInfoBits2, getBit(bitMatrix, x, 8, None));
|
||||
}
|
||||
|
||||
return Ok(FormatInformation::DecodeQR(
|
||||
Ok(FormatInformation::DecodeQR(
|
||||
formatInfoBits1 as u32,
|
||||
formatInfoBits2 as u32,
|
||||
));
|
||||
))
|
||||
}
|
||||
|
||||
pub fn ReadQRCodewords(
|
||||
@@ -184,12 +184,10 @@ pub fn ReadMQRCodewords(
|
||||
let hasD4mBlock = version.getVersionNumber() % 2 == 1;
|
||||
let d4mBlockIndex = if version.getVersionNumber() == 1 {
|
||||
3
|
||||
} else if formatInfo.error_correction_level == ErrorCorrectionLevel::L {
|
||||
11
|
||||
} else {
|
||||
if formatInfo.error_correction_level == ErrorCorrectionLevel::L {
|
||||
11
|
||||
} else {
|
||||
9
|
||||
}
|
||||
9
|
||||
};
|
||||
|
||||
let mut result = Vec::new();
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn GetDataMaskBit(maskIndex: u32, x: u32, y: u32, isMicro: Option<bool>) ->
|
||||
let isMicro = isMicro.unwrap_or(false);
|
||||
let mut maskIndex = maskIndex;
|
||||
if isMicro {
|
||||
if maskIndex < 0 || maskIndex >= 4 {
|
||||
if !(0..4).contains(&maskIndex) {
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"QRCode maskIndex out of range",
|
||||
));
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn CorrectErrors(codewordBytes: &mut [u8], numDataCodewords: u32) -> Result<
|
||||
// We don't care about errors in the error-correction codewords
|
||||
codewordBytes[..numDataCodewords as usize].copy_from_slice(
|
||||
&codewordsInts[..numDataCodewords as usize]
|
||||
.into_iter()
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|i| i as u8)
|
||||
.collect::<Vec<u8>>(),
|
||||
@@ -332,7 +332,7 @@ pub fn DecodeBitStream(
|
||||
{
|
||||
result +=
|
||||
crate::common::cpp_essentials::util::ToString(appInd as usize, 2)?;
|
||||
} else if (appInd >= 165 && appInd <= 190) || (appInd >= 197 && appInd <= 222)
|
||||
} else if (165..=190).contains(&appInd) || (197..=222).contains(&appInd)
|
||||
// "A-Za-z"
|
||||
{
|
||||
result += (appInd - 100) as u8;
|
||||
@@ -403,14 +403,14 @@ pub fn Decode(bits: &BitMatrix) -> Result<DecoderResult<bool>> {
|
||||
};
|
||||
|
||||
// Read codewords
|
||||
let codewords = ReadCodewords(bits, &version, &formatInfo)?;
|
||||
let codewords = ReadCodewords(bits, version, &formatInfo)?;
|
||||
if codewords.is_empty() {
|
||||
return Err(Exceptions::format_with("Failed to read codewords"));
|
||||
}
|
||||
|
||||
// Separate into data blocks
|
||||
let dataBlocks: Vec<DataBlock> =
|
||||
DataBlock::getDataBlocks(&codewords, &version, formatInfo.error_correction_level)?;
|
||||
DataBlock::getDataBlocks(&codewords, version, formatInfo.error_correction_level)?;
|
||||
if dataBlocks.is_empty() {
|
||||
return Err(Exceptions::format_with("Failed to get data blocks"));
|
||||
}
|
||||
@@ -438,7 +438,7 @@ pub fn Decode(bits: &BitMatrix) -> Result<DecoderResult<bool>> {
|
||||
|
||||
// Decode the contents of that stream of bytes
|
||||
Ok(
|
||||
DecodeBitStream(&resultBytes, &version, formatInfo.error_correction_level)?
|
||||
DecodeBitStream(&resultBytes, version, formatInfo.error_correction_level)?
|
||||
.withIsMirrored(formatInfo.isMirrored),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ const SUM: usize = 7;
|
||||
const PATTERN: FixedPattern<LEN, SUM, false> = FixedPattern::new([1, 1, 3, 1, 1]);
|
||||
const E2E: bool = true;
|
||||
|
||||
fn FindPattern<'a>(view: PatternView<'a>) -> Result<PatternView<'a>> {
|
||||
fn FindPattern(view: PatternView<'_>) -> Result<PatternView<'_>> {
|
||||
FindLeftGuardBy::<LEN, _>(
|
||||
view,
|
||||
LEN,
|
||||
@@ -162,7 +162,7 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern
|
||||
// for (int i = 0; i < nbPatterns - 2; i++) {
|
||||
for j in (i + 1)..(nbPatterns - 1) {
|
||||
// for (int j = i + 1; j < nbPatterns - 1; j++) {
|
||||
for k in (j + 1)..(nbPatterns - 0) {
|
||||
for k in (j + 1)..nbPatterns {
|
||||
// for (int k = j + 1; k < nbPatterns - 0; k++) {
|
||||
let mut a = &patterns[i];
|
||||
let mut b = &patterns[j];
|
||||
@@ -201,7 +201,7 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern
|
||||
let moduleCount = (distAB + distBC)
|
||||
/ (2.0 * (a.size + b.size + c.size) as f64 / (3.0 * 7.0))
|
||||
+ 7.0;
|
||||
if moduleCount < 21.0 * 0.9 || moduleCount > 177.0 * 1.5
|
||||
if !(21.0 * 0.9..=177.0 * 1.5).contains(&moduleCount)
|
||||
// moduleCount may be overestimated, see above
|
||||
{
|
||||
continue;
|
||||
@@ -399,7 +399,7 @@ pub fn Mod2Pix(
|
||||
) -> Result<PerspectiveTransform> {
|
||||
let mut quad = Quadrilateral::rectangle(dimension, dimension, Some(3.5));
|
||||
// let quad = Rectangle(dimension, dimension, 3.5);
|
||||
quad[2] = quad[2] - brOffset;
|
||||
quad[2] -= brOffset;
|
||||
|
||||
PerspectiveTransform::quadrilateralToQuadrilateral(quad, pix)
|
||||
// return {quad, pix};
|
||||
@@ -497,15 +497,13 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
let top = EstimateDimension(image, fp.tl, fp.tr);
|
||||
let left = EstimateDimension(image, fp.tl, fp.bl);
|
||||
|
||||
if !(top.dim != 0) && !(left.dim != 0) {
|
||||
if top.dim == 0 && left.dim == 0 {
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
}
|
||||
|
||||
let best = if top.err == left.err {
|
||||
if top.dim > left.dim { top } else { left }
|
||||
} else {
|
||||
if top.err < left.err { 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;
|
||||
|
||||
@@ -563,10 +561,10 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
)?;
|
||||
|
||||
if dimension >= Version::DimensionOfVersion(7, false) as i32 {
|
||||
let version = ReadVersion(image, dimension as u32, mod2Pix.clone());
|
||||
let version = ReadVersion(image, dimension as u32, mod2Pix);
|
||||
|
||||
// if the version bits are garbage -> discard the detection
|
||||
if !version.is_ok()
|
||||
if version.is_err()
|
||||
|| (version.as_ref().unwrap().getDimensionForVersion() as i32 - dimension).abs() > 8
|
||||
{
|
||||
/*return DetectorResult();*/
|
||||
@@ -609,7 +607,7 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
{
|
||||
return p;
|
||||
}
|
||||
return projectM2P(x, y, &mod2Pix);
|
||||
projectM2P(x, y, &mod2Pix)
|
||||
};
|
||||
|
||||
for y in 0..=N {
|
||||
@@ -847,7 +845,7 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
if dimension < MIN_MODULES as i32
|
||||
|| dimension > MAX_MODULES as i32
|
||||
|| !image.is_in(point(
|
||||
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize as f32,
|
||||
left as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
top as f32 + moduleSize / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
))
|
||||
{
|
||||
@@ -899,7 +897,7 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
let bottom = top + height - 1;
|
||||
|
||||
// allow corners be moved one pixel inside to accommodate for possible aliasing artifacts
|
||||
let diagonal: Pattern = EdgeTracer::new(&image, point_i(left, top), point_i(1, 1))
|
||||
let diagonal: Pattern = EdgeTracer::new(image, point_i(left, top), point_i(1, 1))
|
||||
.readPatternFromBlack(1, None)
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
let diag_hld = diagonal.to_vec().into();
|
||||
@@ -915,8 +913,8 @@ pub fn DetectPureMQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
if dimension < MIN_MODULES
|
||||
|| dimension > MAX_MODULES
|
||||
|| !image.is_in(point(
|
||||
left as f32 + moduleSize as f32 / 2.0 + (dimension - 1) as f32 * moduleSize,
|
||||
top as f32 + moduleSize as f32 / 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,
|
||||
))
|
||||
{
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
@@ -997,7 +995,7 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDetec
|
||||
|
||||
let check = |i, checkOne: bool| {
|
||||
let p = mod2Pix.transform_point(Point::centered(FORMAT_INFO_COORDS[i]));
|
||||
return image.is_in(p) && (!checkOne || image.get_point(p));
|
||||
image.is_in(p) && (!checkOne || image.get_point(p))
|
||||
};
|
||||
|
||||
// check that we see both innermost timing pattern modules
|
||||
@@ -1048,7 +1046,7 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDetec
|
||||
dim,
|
||||
dim,
|
||||
&[SamplerControl {
|
||||
p1: point_i(dim as u32, dim as u32),
|
||||
p1: point_i(dim, dim),
|
||||
p0: point_i(0, 0),
|
||||
transform: bestPT,
|
||||
}],
|
||||
|
||||
@@ -374,6 +374,6 @@ impl QrReader {
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(results);
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,84 +9,84 @@ use crate::{common::BitMatrix, qrcode::cpp_port::data_mask::GetMaskedBit};
|
||||
#[test]
|
||||
fn Mask0() {
|
||||
TestMaskAcrossDimensions(0, |i, j| {
|
||||
return (i + j) % 2 == 0;
|
||||
(i + j) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask1() {
|
||||
TestMaskAcrossDimensions(1, |i, _| {
|
||||
return i % 2 == 0;
|
||||
i % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask2() {
|
||||
TestMaskAcrossDimensions(2, |_, j| {
|
||||
return j % 3 == 0;
|
||||
j % 3 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask3() {
|
||||
TestMaskAcrossDimensions(3, |i, j| {
|
||||
return (i + j) % 3 == 0;
|
||||
(i + j) % 3 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask4() {
|
||||
TestMaskAcrossDimensions(4, |i, j| {
|
||||
return (i / 2 + j / 3) % 2 == 0;
|
||||
(i / 2 + j / 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask5() {
|
||||
TestMaskAcrossDimensions(5, |i, j| {
|
||||
return (i * j) % 2 + (i * j) % 3 == 0;
|
||||
(i * j) % 2 + (i * j) % 3 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask6() {
|
||||
TestMaskAcrossDimensions(6, |i, j| {
|
||||
return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i * j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn Mask7() {
|
||||
TestMaskAcrossDimensions(7, |i, j| {
|
||||
return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i + j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask0() {
|
||||
TestMicroMaskAcrossDimensions(0, |i, _| {
|
||||
return i % 2 == 0;
|
||||
i % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask1() {
|
||||
TestMicroMaskAcrossDimensions(1, |i, j| {
|
||||
return (i / 2 + j / 3) % 2 == 0;
|
||||
(i / 2 + j / 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask2() {
|
||||
TestMicroMaskAcrossDimensions(2, |i, j| {
|
||||
return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i * j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn MicroMask3() {
|
||||
TestMicroMaskAcrossDimensions(3, |i, j| {
|
||||
return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
|
||||
((i + j) % 2 + (i * j) % 3) % 2 == 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ fn GetProvisionalVersionForDimension() {
|
||||
for i in 1..=40 {
|
||||
// for (int i = 1; i <= 40; i++) {
|
||||
let prov =
|
||||
Version::FromDimension(4 * i + 17).expect(&format!("version should exist for {i}"));
|
||||
Version::FromDimension(4 * i + 17).unwrap_or_else(|_| panic!("version should exist for {i}"));
|
||||
// assert_ne!(prov, nullptr);
|
||||
assert_eq!(i, prov.getVersionNumber());
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fn MicroVersionForNumber() {
|
||||
for i in 1..=4 {
|
||||
// for (int i = 1; i <= 4; i++) {
|
||||
CheckVersion(
|
||||
Version::FromNumber(i, true).expect(&format!("version for {i} should exist")),
|
||||
Version::FromNumber(i, true).unwrap_or_else(|_| panic!("version for {i} should exist")),
|
||||
i,
|
||||
2 * i + 9,
|
||||
);
|
||||
@@ -81,7 +81,7 @@ fn GetProvisionalMicroVersionForDimension() {
|
||||
for i in 1..=4 {
|
||||
// for (int i = 1; i <= 4; i++) {
|
||||
let prov = Version::FromDimension(2 * i + 9)
|
||||
.expect(&format!("version for micro {i} should exist"));
|
||||
.unwrap_or_else(|_| panic!("version for micro {i} should exist"));
|
||||
// assert_ne!(prov, nullptr);
|
||||
assert_eq!(i, prov.getVersionNumber());
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ impl FromStr for ErrorCorrectionLevel {
|
||||
return number_possible.try_into();
|
||||
}
|
||||
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
Err(Exceptions::illegal_argument_with(format!(
|
||||
"could not parse {s} into an ec level"
|
||||
)));
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ impl Mode {
|
||||
const BITS_2_MODE_LEN: usize = 4;
|
||||
|
||||
if !isMicro {
|
||||
if (bits >= 0x00 && bits <= 0x05) || (bits >= 0x07 && bits <= 0x09) || bits == 0x0d {
|
||||
if (0x00..=0x05).contains(&bits) || (0x07..=0x09).contains(&bits) || bits == 0x0d {
|
||||
return Mode::try_from(bits);
|
||||
}
|
||||
} else {
|
||||
@@ -188,12 +188,12 @@ impl Mode {
|
||||
};
|
||||
|
||||
match self {
|
||||
Mode::NUMERIC=> return [10, 12, 14][i],
|
||||
Mode::ALPHANUMERIC=> return [9, 11, 13][i],
|
||||
Mode::BYTE=> return [8, 16, 16][i],
|
||||
Mode::NUMERIC=> [10, 12, 14][i],
|
||||
Mode::ALPHANUMERIC=> [9, 11, 13][i],
|
||||
Mode::BYTE=> [8, 16, 16][i],
|
||||
Mode::KANJI| // [[fallthrough]];
|
||||
Mode::HANZI=> return [8, 10, 12][i],
|
||||
_=> return 0,
|
||||
Mode::HANZI=> [8, 10, 12][i],
|
||||
_=> 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ impl MinimalEncoder {
|
||||
pub fn isNumeric(c: &str) -> bool {
|
||||
if c.len() == 1 {
|
||||
if let Some(ch) = c.chars().next() {
|
||||
return ('0'..='9').contains(&ch);
|
||||
return ch.is_ascii_digit();
|
||||
}
|
||||
}
|
||||
false
|
||||
|
||||
@@ -310,7 +310,7 @@ fn chooseModeWithEncoding(content: &str, encoding: CharacterSet) -> Mode {
|
||||
let mut has_numeric = false;
|
||||
let mut has_alphanumeric = false;
|
||||
for c in content.chars() {
|
||||
if ('0'..='9').contains(&c) {
|
||||
if c.is_ascii_digit() {
|
||||
has_numeric = true;
|
||||
} else if getAlphanumericCode(c as u32) != -1 {
|
||||
has_alphanumeric = true;
|
||||
|
||||
@@ -250,6 +250,6 @@ impl QRCodeReader {
|
||||
if x == width || y == height {
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
}
|
||||
Ok((x - leftTopBlack.x) as f32 / 7.0)
|
||||
Ok((x - leftTopBlack.x) / 7.0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user