mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
many small rustifications
This commit is contained in:
@@ -56,11 +56,10 @@ impl DataBlock {
|
||||
let ecBlocks = version.getECBlocks();
|
||||
|
||||
// First count the total number of data blocks
|
||||
let mut totalBlocks = 0_usize;
|
||||
let ecBlockArray = ecBlocks.getECBlocks();
|
||||
for ecBlock in ecBlockArray {
|
||||
totalBlocks += ecBlock.getCount() as usize;
|
||||
}
|
||||
let totalBlocks = ecBlockArray.iter().fold(0, |acc, ecBlock| {
|
||||
acc + ecBlock.getCount() as usize
|
||||
});
|
||||
|
||||
// Now establish DataBlocks of the appropriate size and number of data codewords
|
||||
let mut result = Vec::with_capacity(totalBlocks);
|
||||
|
||||
@@ -106,6 +106,10 @@ const TEXT_SHIFT3_SET_CHARS: [char; 32] = [
|
||||
127 as char,
|
||||
];
|
||||
|
||||
const INSERT_STRING_CONST: &str = "\u{001E}\u{0004}";
|
||||
const VALUE_236: &str = "[)>\u{001E}05\u{001D}";
|
||||
const VALUE_237: &str = "[)>\u{001E}06\u{001D}";
|
||||
|
||||
pub fn decode(bytes: &[u8]) -> Result<DecoderRXingResult, Exceptions> {
|
||||
let mut bits = BitSource::new(bytes.to_vec());
|
||||
let mut result = ECIStringBuilder::with_capacity(100);
|
||||
@@ -233,13 +237,13 @@ fn decodeAsciiSegment(
|
||||
235=> // Upper Shift (shift to Extended ASCII)
|
||||
upperShift = true,
|
||||
236=> {// 05 Macro
|
||||
result.append_string("[)>\u{001E}05\u{001D}");
|
||||
resultTrailer.replace_range(0..0, "\u{001E}\u{0004}");
|
||||
result.append_string(VALUE_236);
|
||||
resultTrailer.replace_range(0..0, INSERT_STRING_CONST);
|
||||
// resultTrailer.insert(0, "\u{001E}\u{0004}");
|
||||
},
|
||||
237=>{ // 06 Macro
|
||||
result.append_string("[)>\u{001E}06\u{001D}");
|
||||
resultTrailer.replace_range(0..0, "\u{001E}\u{0004}");
|
||||
result.append_string(VALUE_237);
|
||||
resultTrailer.replace_range(0..0, INSERT_STRING_CONST);
|
||||
// resultTrailer.insert(0, "\u{001E}\u{0004}");
|
||||
},
|
||||
238=> // Latch to ANSI X12 encodation
|
||||
|
||||
@@ -75,10 +75,10 @@ impl Decoder {
|
||||
let dataBlocks = DataBlock::getDataBlocks(&codewords, version)?;
|
||||
|
||||
// Count total number of data bytes
|
||||
let mut totalBytes = 0;
|
||||
for db in &dataBlocks {
|
||||
totalBytes += db.getNumDataCodewords();
|
||||
}
|
||||
let totalBytes = dataBlocks
|
||||
.iter()
|
||||
.fold(0, |acc, db| acc + db.getNumDataCodewords());
|
||||
|
||||
let mut resultBytes = vec![0u8; totalBytes as usize];
|
||||
|
||||
let dataBlocksCount = dataBlocks.len();
|
||||
|
||||
@@ -54,16 +54,23 @@ impl Version {
|
||||
dataRegionSizeRows,
|
||||
dataRegionSizeColumns,
|
||||
totalCodewords: {
|
||||
// Calculate the total number of codewords
|
||||
let mut total = 0;
|
||||
let ecCodewords = &ecBlocks.getECCodewords();
|
||||
let ecbArray = ecBlocks.getECBlocks();
|
||||
for ecBlock in ecbArray {
|
||||
total += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords);
|
||||
}
|
||||
|
||||
total
|
||||
ecbArray.iter().fold(0, |acc, ecBlock| {
|
||||
acc + ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords)
|
||||
})
|
||||
},
|
||||
// totalCodewords: {
|
||||
// // Calculate the total number of codewords
|
||||
// let mut total = 0;
|
||||
// let ecCodewords = &ecBlocks.getECCodewords();
|
||||
// let ecbArray = ecBlocks.getECBlocks();
|
||||
// for ecBlock in ecbArray {
|
||||
// total += ecBlock.getCount() * (ecBlock.getDataCodewords() + ecCodewords);
|
||||
// }
|
||||
|
||||
// total
|
||||
// },
|
||||
ecBlocks,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use super::DatamatrixDetectorResult;
|
||||
*/
|
||||
pub struct Detector<'a> {
|
||||
image: &'a BitMatrix,
|
||||
rectangleDetector: WhiteRectangleDetector,
|
||||
rectangleDetector: WhiteRectangleDetector<'a>,
|
||||
}
|
||||
impl<'a> Detector<'_> {
|
||||
pub fn new(image: &'a BitMatrix) -> Result<Detector<'a>, Exceptions> {
|
||||
@@ -127,7 +127,7 @@ impl<'a> Detector<'_> {
|
||||
/**
|
||||
* Detect a solid side which has minimum transition.
|
||||
*/
|
||||
fn detectSolid1(&self, cornerPoints: Vec<RXingResultPoint>) -> [RXingResultPoint; 4] {
|
||||
fn detectSolid1(&self, cornerPoints: [RXingResultPoint; 4]) -> [RXingResultPoint; 4] {
|
||||
// 0 2
|
||||
// 1 3
|
||||
let pointA = cornerPoints[0];
|
||||
|
||||
Reference in New Issue
Block a user