mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Cargo clippy --all-features
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn;
|
|
||||||
|
|
||||||
#[proc_macro_derive(OneDReader)]
|
#[proc_macro_derive(OneDReader)]
|
||||||
pub fn one_d_reader_derive(input: TokenStream) -> TokenStream {
|
pub fn one_d_reader_derive(input: TokenStream) -> TokenStream {
|
||||||
|
|||||||
@@ -142,10 +142,10 @@ impl<B: Binarizer> BinaryBitmap<B> {
|
|||||||
.binarizer
|
.binarizer
|
||||||
.get_luminance_source()
|
.get_luminance_source()
|
||||||
.crop(left, top, width, height);
|
.crop(left, top, width, height);
|
||||||
return BinaryBitmap::new(
|
BinaryBitmap::new(
|
||||||
self.binarizer
|
self.binarizer
|
||||||
.create_binarizer(newSource.expect("new lum source expected")),
|
.create_binarizer(newSource.expect("new lum source expected")),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,10 +168,10 @@ impl<B: Binarizer> BinaryBitmap<B> {
|
|||||||
.binarizer
|
.binarizer
|
||||||
.get_luminance_source()
|
.get_luminance_source()
|
||||||
.rotate_counter_clockwise();
|
.rotate_counter_clockwise();
|
||||||
return BinaryBitmap::new(
|
BinaryBitmap::new(
|
||||||
self.binarizer
|
self.binarizer
|
||||||
.create_binarizer(newSource.expect("new lum source expected")),
|
.create_binarizer(newSource.expect("new lum source expected")),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,10 +187,10 @@ impl<B: Binarizer> BinaryBitmap<B> {
|
|||||||
.binarizer
|
.binarizer
|
||||||
.get_luminance_source()
|
.get_luminance_source()
|
||||||
.rotate_counter_clockwise_45();
|
.rotate_counter_clockwise_45();
|
||||||
return BinaryBitmap::new(
|
BinaryBitmap::new(
|
||||||
self.binarizer
|
self.binarizer
|
||||||
.create_binarizer(newSource.expect("new lum source expected")),
|
.create_binarizer(newSource.expect("new lum source expected")),
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use super::{BoundingBox, Codeword, DetectionRXingResultRowIndicatorColumn};
|
|||||||
const MAX_NEARBY_DISTANCE: u32 = 5;
|
const MAX_NEARBY_DISTANCE: u32 = 5;
|
||||||
|
|
||||||
pub trait DetectionRXingResultColumnTrait {
|
pub trait DetectionRXingResultColumnTrait {
|
||||||
fn new(boundingBox: Rc<BoundingBox>) -> DetectionRXingResultColumn
|
fn new_column(boundingBox: Rc<BoundingBox>) -> DetectionRXingResultColumn
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
fn new_with_is_left(boundingBox: Rc<BoundingBox>, isLeft: bool) -> DetectionRXingResultColumn
|
fn new_with_is_left(boundingBox: Rc<BoundingBox>, isLeft: bool) -> DetectionRXingResultColumn
|
||||||
@@ -48,7 +48,7 @@ pub struct DetectionRXingResultColumn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DetectionRXingResultColumnTrait for DetectionRXingResultColumn {
|
impl DetectionRXingResultColumnTrait for DetectionRXingResultColumn {
|
||||||
fn new(boundingBox: Rc<BoundingBox>) -> DetectionRXingResultColumn {
|
fn new_column(boundingBox: Rc<BoundingBox>) -> DetectionRXingResultColumn {
|
||||||
DetectionRXingResultColumn {
|
DetectionRXingResultColumn {
|
||||||
boundingBox: BoundingBox::from_other(boundingBox.clone()),
|
boundingBox: BoundingBox::from_other(boundingBox.clone()),
|
||||||
codewords: vec![None; (boundingBox.getMaxY() - boundingBox.getMinY() + 1) as usize],
|
codewords: vec![None; (boundingBox.getMaxY() - boundingBox.getMinY() + 1) as usize],
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ const MAX_EC_CODEWORDS: u32 = 512;
|
|||||||
// than it should be. This can happen if the scanner used a bad blackpoint.
|
// than it should be. This can happen if the scanner used a bad blackpoint.
|
||||||
pub fn decode(
|
pub fn decode(
|
||||||
image: &BitMatrix,
|
image: &BitMatrix,
|
||||||
imageTopLeft: Option<Point>,
|
image_top_left: Option<Point>,
|
||||||
imageBottomLeft: Option<Point>,
|
imageBottomLeft: Option<Point>,
|
||||||
imageTopRight: Option<Point>,
|
image_top_right: Option<Point>,
|
||||||
imageBottomRight: Option<Point>,
|
imageBottomRight: Option<Point>,
|
||||||
minCodewordWidth: u32,
|
minCodewordWidth: u32,
|
||||||
maxCodewordWidth: u32,
|
maxCodewordWidth: u32,
|
||||||
@@ -55,30 +55,30 @@ pub fn decode(
|
|||||||
let mut maxCodewordWidth = maxCodewordWidth;
|
let mut maxCodewordWidth = maxCodewordWidth;
|
||||||
let mut boundingBox = Rc::new(BoundingBox::new(
|
let mut boundingBox = Rc::new(BoundingBox::new(
|
||||||
Rc::new(image.clone()),
|
Rc::new(image.clone()),
|
||||||
imageTopLeft,
|
image_top_left,
|
||||||
imageBottomLeft,
|
imageBottomLeft,
|
||||||
imageTopRight,
|
image_top_right,
|
||||||
imageBottomRight,
|
imageBottomRight,
|
||||||
)?);
|
)?);
|
||||||
let mut leftRowIndicatorColumn = None;
|
let mut leftRowIndicatorColumn = None;
|
||||||
let mut rightRowIndicatorColumn = None;
|
let mut rightRowIndicatorColumn = None;
|
||||||
let mut detectionRXingResult = None;
|
let mut detectionRXingResult = None;
|
||||||
for firstPass in [true, false] {
|
for firstPass in [true, false] {
|
||||||
if imageTopLeft.is_some() {
|
if let Some(image_top_left) = image_top_left {
|
||||||
leftRowIndicatorColumn = Some(getRowIndicatorColumn(
|
leftRowIndicatorColumn = Some(getRowIndicatorColumn(
|
||||||
image,
|
image,
|
||||||
boundingBox.clone(),
|
boundingBox.clone(),
|
||||||
imageTopLeft.unwrap(),
|
image_top_left,
|
||||||
true,
|
true,
|
||||||
minCodewordWidth,
|
minCodewordWidth,
|
||||||
maxCodewordWidth,
|
maxCodewordWidth,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if imageTopRight.is_some() {
|
if let Some(image_top_right) = image_top_right {
|
||||||
rightRowIndicatorColumn = Some(getRowIndicatorColumn(
|
rightRowIndicatorColumn = Some(getRowIndicatorColumn(
|
||||||
image,
|
image,
|
||||||
boundingBox.clone(),
|
boundingBox.clone(),
|
||||||
imageTopRight.unwrap(),
|
image_top_right,
|
||||||
false,
|
false,
|
||||||
minCodewordWidth,
|
minCodewordWidth,
|
||||||
maxCodewordWidth,
|
maxCodewordWidth,
|
||||||
@@ -129,7 +129,7 @@ pub fn decode(
|
|||||||
{
|
{
|
||||||
DetectionRXingResultColumn::new_with_is_left(boundingBox.clone(), barcodeColumn == 0)
|
DetectionRXingResultColumn::new_with_is_left(boundingBox.clone(), barcodeColumn == 0)
|
||||||
} else {
|
} else {
|
||||||
DetectionRXingResultColumn::new(boundingBox.clone())
|
DetectionRXingResultColumn::new_column(boundingBox.clone())
|
||||||
};
|
};
|
||||||
|
|
||||||
detectionRXingResult
|
detectionRXingResult
|
||||||
|
|||||||
@@ -217,11 +217,15 @@ pub fn encodeHighLevel(
|
|||||||
// User selected encoding mode
|
// User selected encoding mode
|
||||||
match compaction {
|
match compaction {
|
||||||
Compaction::TEXT => {
|
Compaction::TEXT => {
|
||||||
encodeText(&input, p, len as u32, &mut sb, textSubMode)?;
|
encodeText(input.as_ref(), p, len as u32, &mut sb, textSubMode)?;
|
||||||
}
|
|
||||||
Compaction::BYTE if autoECI => {
|
|
||||||
encodeMultiECIBinary(&input, 0, input.length() as u32, TEXT_COMPACTION, &mut sb)?
|
|
||||||
}
|
}
|
||||||
|
Compaction::BYTE if autoECI => encodeMultiECIBinary(
|
||||||
|
input.as_ref(),
|
||||||
|
0,
|
||||||
|
input.length() as u32,
|
||||||
|
TEXT_COMPACTION,
|
||||||
|
&mut sb,
|
||||||
|
)?,
|
||||||
Compaction::BYTE => {
|
Compaction::BYTE => {
|
||||||
let msgBytes = encoding
|
let msgBytes = encoding
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -238,7 +242,7 @@ pub fn encodeHighLevel(
|
|||||||
}
|
}
|
||||||
Compaction::NUMERIC => {
|
Compaction::NUMERIC => {
|
||||||
sb.push(char::from_u32(LATCH_TO_NUMERIC).ok_or(Exceptions::PARSE)?);
|
sb.push(char::from_u32(LATCH_TO_NUMERIC).ok_or(Exceptions::PARSE)?);
|
||||||
encodeNumeric(&input, p, len as u32, &mut sb)?;
|
encodeNumeric(input.as_ref(), p, len as u32, &mut sb)?;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let mut encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
|
let mut encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
|
||||||
@@ -250,26 +254,26 @@ pub fn encodeHighLevel(
|
|||||||
if p >= len as u32 {
|
if p >= len as u32 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let n = determineConsecutiveDigitCount(&input, p)?;
|
let n = determineConsecutiveDigitCount(input.as_ref(), p)?;
|
||||||
if n >= 13 {
|
if n >= 13 {
|
||||||
sb.push(char::from_u32(LATCH_TO_NUMERIC).ok_or(Exceptions::PARSE)?);
|
sb.push(char::from_u32(LATCH_TO_NUMERIC).ok_or(Exceptions::PARSE)?);
|
||||||
encodingMode = NUMERIC_COMPACTION;
|
encodingMode = NUMERIC_COMPACTION;
|
||||||
textSubMode = SUBMODE_ALPHA; //Reset after latch
|
textSubMode = SUBMODE_ALPHA; //Reset after latch
|
||||||
encodeNumeric(&input, p, n, &mut sb)?;
|
encodeNumeric(input.as_ref(), p, n, &mut sb)?;
|
||||||
p += n;
|
p += n;
|
||||||
} else {
|
} else {
|
||||||
let t = determineConsecutiveTextCount(&input, p)?;
|
let t = determineConsecutiveTextCount(input.as_ref(), p)?;
|
||||||
if t >= 5 || n == len as u32 {
|
if t >= 5 || n == len as u32 {
|
||||||
if encodingMode != TEXT_COMPACTION {
|
if encodingMode != TEXT_COMPACTION {
|
||||||
sb.push(char::from_u32(LATCH_TO_TEXT).ok_or(Exceptions::PARSE)?);
|
sb.push(char::from_u32(LATCH_TO_TEXT).ok_or(Exceptions::PARSE)?);
|
||||||
encodingMode = TEXT_COMPACTION;
|
encodingMode = TEXT_COMPACTION;
|
||||||
textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
|
textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
|
||||||
}
|
}
|
||||||
textSubMode = encodeText(&input, p, t, &mut sb, textSubMode)?;
|
textSubMode = encodeText(input.as_ref(), p, t, &mut sb, textSubMode)?;
|
||||||
p += t;
|
p += t;
|
||||||
} else {
|
} else {
|
||||||
let mut b = determineConsecutiveBinaryCount(
|
let mut b = determineConsecutiveBinaryCount(
|
||||||
&input,
|
input.as_ref(),
|
||||||
p,
|
p,
|
||||||
if autoECI { None } else { encoding },
|
if autoECI { None } else { encoding },
|
||||||
)?;
|
)?;
|
||||||
@@ -298,7 +302,13 @@ pub fn encodeHighLevel(
|
|||||||
if (bytes_ok && b == 1) && (encodingMode == TEXT_COMPACTION) {
|
if (bytes_ok && b == 1) && (encodingMode == TEXT_COMPACTION) {
|
||||||
//Switch for one byte (instead of latch)
|
//Switch for one byte (instead of latch)
|
||||||
if autoECI {
|
if autoECI {
|
||||||
encodeMultiECIBinary(&input, p, 1, TEXT_COMPACTION, &mut sb)?;
|
encodeMultiECIBinary(
|
||||||
|
input.as_ref(),
|
||||||
|
p,
|
||||||
|
1,
|
||||||
|
TEXT_COMPACTION,
|
||||||
|
&mut sb,
|
||||||
|
)?;
|
||||||
} else {
|
} else {
|
||||||
encodeBinary(
|
encodeBinary(
|
||||||
bytes.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?,
|
bytes.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?,
|
||||||
@@ -311,7 +321,13 @@ pub fn encodeHighLevel(
|
|||||||
} else {
|
} else {
|
||||||
//Mode latch performed by encodeBinary()
|
//Mode latch performed by encodeBinary()
|
||||||
if autoECI {
|
if autoECI {
|
||||||
encodeMultiECIBinary(&input, p, p + b, encodingMode, &mut sb)?;
|
encodeMultiECIBinary(
|
||||||
|
input.as_ref(),
|
||||||
|
p,
|
||||||
|
p + b,
|
||||||
|
encodingMode,
|
||||||
|
&mut sb,
|
||||||
|
)?;
|
||||||
} else {
|
} else {
|
||||||
encodeBinary(
|
encodeBinary(
|
||||||
bytes.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?,
|
bytes.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?,
|
||||||
@@ -346,7 +362,7 @@ pub fn encodeHighLevel(
|
|||||||
* @return the text submode in which this method ends
|
* @return the text submode in which this method ends
|
||||||
*/
|
*/
|
||||||
fn encodeText<T: ECIInput + ?Sized>(
|
fn encodeText<T: ECIInput + ?Sized>(
|
||||||
input: &Box<T>,
|
input: &T,
|
||||||
startpos: u32,
|
startpos: u32,
|
||||||
count: u32,
|
count: u32,
|
||||||
sb: &mut String,
|
sb: &mut String,
|
||||||
@@ -491,7 +507,7 @@ fn encodeText<T: ECIInput + ?Sized>(
|
|||||||
* @param sb receives the encoded codewords
|
* @param sb receives the encoded codewords
|
||||||
*/
|
*/
|
||||||
fn encodeMultiECIBinary<T: ECIInput + ?Sized>(
|
fn encodeMultiECIBinary<T: ECIInput + ?Sized>(
|
||||||
input: &Box<T>,
|
input: &T,
|
||||||
startpos: u32,
|
startpos: u32,
|
||||||
count: u32,
|
count: u32,
|
||||||
startmode: u32,
|
startmode: u32,
|
||||||
@@ -535,7 +551,7 @@ fn encodeMultiECIBinary<T: ECIInput + ?Sized>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subBytes<T: ECIInput + ?Sized>(input: &Box<T>, start: u32, end: u32) -> Result<Vec<u8>> {
|
pub fn subBytes<T: ECIInput + ?Sized>(input: &T, start: u32, end: u32) -> Result<Vec<u8>> {
|
||||||
let count = (end - start) as usize;
|
let count = (end - start) as usize;
|
||||||
let mut result = vec![0_u8; count];
|
let mut result = vec![0_u8; count];
|
||||||
for i in start as usize..end as usize {
|
for i in start as usize..end as usize {
|
||||||
@@ -598,7 +614,7 @@ fn encodeBinary(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn encodeNumeric<T: ECIInput + ?Sized>(
|
fn encodeNumeric<T: ECIInput + ?Sized>(
|
||||||
input: &Box<T>,
|
input: &T,
|
||||||
startpos: u32,
|
startpos: u32,
|
||||||
count: u32,
|
count: u32,
|
||||||
sb: &mut String,
|
sb: &mut String,
|
||||||
@@ -679,10 +695,7 @@ fn isText(ch: char) -> bool {
|
|||||||
* @param startpos the start position within the input
|
* @param startpos the start position within the input
|
||||||
* @return the requested character count
|
* @return the requested character count
|
||||||
*/
|
*/
|
||||||
fn determineConsecutiveDigitCount<T: ECIInput + ?Sized>(
|
fn determineConsecutiveDigitCount<T: ECIInput + ?Sized>(input: &T, startpos: u32) -> Result<u32> {
|
||||||
input: &Box<T>,
|
|
||||||
startpos: u32,
|
|
||||||
) -> Result<u32> {
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let len = input.length();
|
let len = input.length();
|
||||||
let mut idx = startpos as usize;
|
let mut idx = startpos as usize;
|
||||||
@@ -703,10 +716,7 @@ fn determineConsecutiveDigitCount<T: ECIInput + ?Sized>(
|
|||||||
* @param startpos the start position within the input
|
* @param startpos the start position within the input
|
||||||
* @return the requested character count
|
* @return the requested character count
|
||||||
*/
|
*/
|
||||||
fn determineConsecutiveTextCount<T: ECIInput + ?Sized>(
|
fn determineConsecutiveTextCount<T: ECIInput + ?Sized>(input: &T, startpos: u32) -> Result<u32> {
|
||||||
input: &Box<T>,
|
|
||||||
startpos: u32,
|
|
||||||
) -> Result<u32> {
|
|
||||||
let len = input.length();
|
let len = input.length();
|
||||||
let mut idx = startpos as usize;
|
let mut idx = startpos as usize;
|
||||||
while idx < len {
|
while idx < len {
|
||||||
@@ -745,7 +755,7 @@ fn determineConsecutiveTextCount<T: ECIInput + ?Sized>(
|
|||||||
* @return the requested character count
|
* @return the requested character count
|
||||||
*/
|
*/
|
||||||
fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
|
||||||
input: &Box<T>,
|
input: &T,
|
||||||
startpos: u32,
|
startpos: u32,
|
||||||
encoding: Option<EncodingRef>,
|
encoding: Option<EncodingRef>,
|
||||||
) -> Result<u32> {
|
) -> Result<u32> {
|
||||||
|
|||||||
@@ -846,7 +846,7 @@ impl RXingResultList {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn internal_static_get_size(version: VersionRef, list: &Vec<RXingResultNode>) -> u32 {
|
fn internal_static_get_size(version: VersionRef, list: &[RXingResultNode]) -> u32 {
|
||||||
let result = list.iter().fold(0, |acc, node| acc + node.getSize(version));
|
let result = list.iter().fold(0, |acc, node| acc + node.getSize(version));
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl LuminanceSource for SVGLuminanceSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn crop(&self, left: usize, top: usize, width: usize, height: usize) -> Result<Self> {
|
fn crop(&self, left: usize, top: usize, width: usize, height: usize) -> Result<Self> {
|
||||||
self.0.crop(left, top, width, height).map(|src| Self(src))
|
self.0.crop(left, top, width, height).map(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_rotate_supported(&self) -> bool {
|
fn is_rotate_supported(&self) -> bool {
|
||||||
@@ -39,11 +39,11 @@ impl LuminanceSource for SVGLuminanceSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_counter_clockwise(&self) -> Result<Self> {
|
fn rotate_counter_clockwise(&self) -> Result<Self> {
|
||||||
self.0.rotate_counter_clockwise().map(|src| Self(src))
|
self.0.rotate_counter_clockwise().map(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_counter_clockwise_45(&self) -> Result<Self> {
|
fn rotate_counter_clockwise_45(&self) -> Result<Self> {
|
||||||
self.0.rotate_counter_clockwise_45().map(|src| Self(src))
|
self.0.rotate_counter_clockwise_45().map(Self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user