mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 12:52:34 +00:00
refactor to use common result type
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
common::Result,
|
||||
oned::{one_d_reader, OneDReader},
|
||||
Exceptions,
|
||||
};
|
||||
@@ -30,7 +31,7 @@ pub trait AbstractRSSReaderTrait: OneDReader {
|
||||
const MIN_FINDER_PATTERN_RATIO: f32 = 9.5 / 12.0;
|
||||
const MAX_FINDER_PATTERN_RATIO: f32 = 12.5 / 14.0;
|
||||
|
||||
fn parseFinderValue(counters: &[u32], finderPatterns: &[[u32; 4]]) -> Result<u32, Exceptions> {
|
||||
fn parseFinderValue(counters: &[u32], finderPatterns: &[[u32; 4]]) -> Result<u32> {
|
||||
for (value, pattern) in finderPatterns.iter().enumerate() {
|
||||
if one_d_reader::patternMatchVariance(counters, pattern, Self::MAX_INDIVIDUAL_VARIANCE)
|
||||
< Self::MAX_AVG_VARIANCE
|
||||
|
||||
@@ -30,7 +30,10 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::{common::BitArray, Exceptions};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
static ONE: Lazy<Regex> = Lazy::new(|| Regex::new("1").unwrap());
|
||||
static ZERO: Lazy<Regex> = Lazy::new(|| Regex::new("0").unwrap());
|
||||
@@ -39,7 +42,7 @@ static SPACE: Lazy<Regex> = Lazy::new(|| Regex::new(" ").unwrap());
|
||||
/*
|
||||
* Constructs a BitArray from a String like the one returned from BitArray.toString()
|
||||
*/
|
||||
pub fn buildBitArrayFromString(data: &str) -> Result<BitArray, Exceptions> {
|
||||
pub fn buildBitArrayFromString(data: &str) -> Result<BitArray> {
|
||||
let dotsAndXs = ZERO
|
||||
.replace_all(&ONE.replace_all(data, "X"), ".")
|
||||
.to_string();
|
||||
@@ -75,7 +78,7 @@ pub fn buildBitArrayFromString(data: &str) -> Result<BitArray, Exceptions> {
|
||||
Ok(binary)
|
||||
}
|
||||
|
||||
pub fn buildBitArrayFromStringWithoutSpaces(data: &str) -> Result<BitArray, Exceptions> {
|
||||
pub fn buildBitArrayFromStringWithoutSpaces(data: &str) -> Result<BitArray> {
|
||||
let mut sb = String::new();
|
||||
|
||||
// let dotsAndXs = ZERO.matcher(ONE.matcher(data).replaceAll("X")).replaceAll(".");
|
||||
|
||||
@@ -24,7 +24,10 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::{common::BitArray, Exceptions};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
use super::{
|
||||
AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder,
|
||||
@@ -53,14 +56,14 @@ pub trait AbstractExpandedDecoder {
|
||||
// return generalDecoder;
|
||||
// }
|
||||
|
||||
fn parseInformation(&mut self) -> Result<String, Exceptions>;
|
||||
fn parseInformation(&mut self) -> Result<String>;
|
||||
fn getGeneralDecoder(&self) -> &GeneralAppIdDecoder;
|
||||
// fn new(information:&BitArray) -> Self where Self:Sized;
|
||||
}
|
||||
|
||||
pub fn createDecoder<'a>(
|
||||
information: &'a BitArray,
|
||||
) -> Result<Box<dyn AbstractExpandedDecoder + 'a>, Exceptions> {
|
||||
) -> Result<Box<dyn AbstractExpandedDecoder + 'a>> {
|
||||
if information.get(1) {
|
||||
return Ok(Box::new(AI01AndOtherAIs::new(information)));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI013x0xDecoder, AI01decoder, AI01weightDecoder, AbstractExpandedDecoder};
|
||||
|
||||
@@ -43,7 +43,7 @@ impl AI01weightDecoder for AI013103decoder<'_> {
|
||||
}
|
||||
}
|
||||
impl AbstractExpandedDecoder for AI013103decoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
self.0.parseInformation()
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI013x0xDecoder, AI01decoder, AI01weightDecoder, AbstractExpandedDecoder};
|
||||
|
||||
@@ -43,7 +43,7 @@ impl AI01weightDecoder for AI01320xDecoder<'_> {
|
||||
}
|
||||
}
|
||||
impl AbstractExpandedDecoder for AI01320xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
self.0.parseInformation()
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct AI01392xDecoder<'a> {
|
||||
}
|
||||
impl AI01decoder for AI01392xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct AI01393xDecoder<'a> {
|
||||
}
|
||||
impl AI01decoder for AI01393xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
|
||||
return Err(crate::Exceptions::NotFoundException(None));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI01decoder, AI01weightDecoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
|
||||
@@ -53,7 +53,7 @@ impl AI01weightDecoder for AI013x0x1xDecoder<'_> {
|
||||
}
|
||||
impl AI01decoder for AI013x0x1xDecoder<'_> {}
|
||||
impl AbstractExpandedDecoder for AI013x0x1xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
if self.information.getSize()
|
||||
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE + Self::DATE_SIZE
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI01decoder, AI01weightDecoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
|
||||
@@ -49,7 +49,7 @@ impl AI01weightDecoder for AI013x0xDecoder<'_> {
|
||||
}
|
||||
}
|
||||
impl AbstractExpandedDecoder for AI013x0xDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
if self.information.getSize()
|
||||
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
|
||||
@@ -35,7 +35,7 @@ use super::{AI01decoder, AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
pub struct AI01AndOtherAIs<'a>(&'a BitArray, GeneralAppIdDecoder<'a>);
|
||||
impl AI01decoder for AI01AndOtherAIs<'_> {}
|
||||
impl AbstractExpandedDecoder for AI01AndOtherAIs<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
let mut buff = String::new();
|
||||
|
||||
buff.push_str("(01)");
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
|
||||
use super::{AbstractExpandedDecoder, GeneralAppIdDecoder};
|
||||
|
||||
@@ -37,7 +37,7 @@ pub struct AnyAIDecoder<'a> {
|
||||
general_decoder: GeneralAppIdDecoder<'a>,
|
||||
}
|
||||
impl AbstractExpandedDecoder for AnyAIDecoder<'_> {
|
||||
fn parseInformation(&mut self) -> Result<String, crate::Exceptions> {
|
||||
fn parseInformation(&mut self) -> Result<String> {
|
||||
let buf = String::new();
|
||||
self.general_decoder.decodeAllCodes(buf, Self::HEADER_SIZE)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use super::DecodedObject;
|
||||
@@ -45,7 +46,7 @@ impl DecodedObject for DecodedNumeric {
|
||||
impl DecodedNumeric {
|
||||
pub const FNC1: u32 = 10;
|
||||
|
||||
pub fn new(newPosition: usize, firstDigit: u32, secondDigit: u32) -> Result<Self, Exceptions> {
|
||||
pub fn new(newPosition: usize, firstDigit: u32, secondDigit: u32) -> Result<Self> {
|
||||
// super(newPosition);
|
||||
|
||||
if
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
*/
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::Exceptions;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
@@ -137,7 +138,7 @@ static FOUR_DIGIT_DATA_LENGTH: Lazy<HashMap<String, DataLength>> = Lazy::new(||
|
||||
hm
|
||||
});
|
||||
|
||||
pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Exceptions> {
|
||||
pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
|
||||
if rawInformation.is_empty() {
|
||||
return Ok(String::default());
|
||||
}
|
||||
@@ -194,11 +195,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String, Excep
|
||||
Err(Exceptions::NotFoundException(None))
|
||||
}
|
||||
|
||||
fn processFixedAI(
|
||||
aiSize: usize,
|
||||
fieldSize: usize,
|
||||
rawInformation: &str,
|
||||
) -> Result<String, Exceptions> {
|
||||
fn processFixedAI(aiSize: usize, fieldSize: usize, rawInformation: &str) -> Result<String> {
|
||||
if rawInformation.chars().count() < aiSize {
|
||||
return Err(Exceptions::NotFoundException(None));
|
||||
}
|
||||
@@ -229,7 +226,7 @@ fn processVariableAI(
|
||||
aiSize: usize,
|
||||
variableFieldSize: usize,
|
||||
rawInformation: &str,
|
||||
) -> Result<String, Exceptions> {
|
||||
) -> Result<String> {
|
||||
let ai: String = rawInformation.chars().take(aiSize).collect();
|
||||
let maxSize = rawInformation
|
||||
.chars()
|
||||
|
||||
@@ -24,7 +24,10 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::{common::BitArray, Exceptions};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
Exceptions,
|
||||
};
|
||||
|
||||
use super::{
|
||||
field_parser, BlockParsedRXingResult, CurrentParsingState, DecodedChar, DecodedInformation,
|
||||
@@ -50,11 +53,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decodeAllCodes(
|
||||
&mut self,
|
||||
buff: String,
|
||||
initialPosition: usize,
|
||||
) -> Result<String, Exceptions> {
|
||||
pub fn decodeAllCodes(&mut self, buff: String, initialPosition: usize) -> Result<String> {
|
||||
let mut buff = buff;
|
||||
let mut currentPosition = initialPosition;
|
||||
let mut remaining = String::default();
|
||||
@@ -97,7 +96,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
self.information.get(pos + 3)
|
||||
}
|
||||
|
||||
fn decodeNumeric(&self, pos: usize) -> Result<DecodedNumeric, Exceptions> {
|
||||
fn decodeNumeric(&self, pos: usize) -> Result<DecodedNumeric> {
|
||||
if pos + 7 > self.information.getSize() {
|
||||
let numeric = self.extractNumericValueFromBitArray(pos, 4);
|
||||
if numeric == 0 {
|
||||
@@ -144,7 +143,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
&mut self,
|
||||
pos: usize,
|
||||
remaining: &str,
|
||||
) -> Result<DecodedInformation, Exceptions> {
|
||||
) -> Result<DecodedInformation> {
|
||||
self.buffer.clear();
|
||||
|
||||
if !remaining.is_empty() {
|
||||
@@ -168,7 +167,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
))
|
||||
}
|
||||
|
||||
fn parseBlocks(&mut self) -> Result<DecodedInformation, Exceptions> {
|
||||
fn parseBlocks(&mut self) -> Result<DecodedInformation> {
|
||||
let mut isFinished;
|
||||
let mut result: BlockParsedRXingResult;
|
||||
loop {
|
||||
@@ -203,7 +202,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
|
||||
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult> {
|
||||
while self.isStillNumeric(self.current.getPosition()) {
|
||||
let numeric = self.decodeNumeric(self.current.getPosition())?;
|
||||
self.current.setPosition(numeric.getNewPosition());
|
||||
@@ -244,7 +243,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
Ok(BlockParsedRXingResult::new())
|
||||
}
|
||||
|
||||
fn parseIsoIec646Block(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
|
||||
fn parseIsoIec646Block(&mut self) -> Result<BlockParsedRXingResult> {
|
||||
while self.isStillIsoIec646(self.current.getPosition()) {
|
||||
let iso = self.decodeIsoIec646(self.current.getPosition())?;
|
||||
self.current.setPosition(iso.getNewPosition());
|
||||
@@ -275,7 +274,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
Ok(BlockParsedRXingResult::new())
|
||||
}
|
||||
|
||||
fn parseAlphaBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {
|
||||
fn parseAlphaBlock(&mut self) -> Result<BlockParsedRXingResult> {
|
||||
while self.isStillAlpha(self.current.getPosition()) {
|
||||
let alpha = self.decodeAlphanumeric(self.current.getPosition())?;
|
||||
self.current.setPosition(alpha.getNewPosition());
|
||||
@@ -336,7 +335,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
(232..253).contains(&eightBitValue)
|
||||
}
|
||||
|
||||
fn decodeIsoIec646(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
|
||||
fn decodeIsoIec646(&self, pos: usize) -> Result<DecodedChar> {
|
||||
let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
|
||||
if fiveBitValue == 15 {
|
||||
return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1));
|
||||
@@ -415,7 +414,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
|
||||
(16..63).contains(&sixBitValue) // 63 not included
|
||||
}
|
||||
|
||||
fn decodeAlphanumeric(&self, pos: usize) -> Result<DecodedChar, Exceptions> {
|
||||
fn decodeAlphanumeric(&self, pos: usize) -> Result<DecodedChar> {
|
||||
let fiveBitValue = self.extractNumericValueFromBitArray(pos, 5);
|
||||
if fiveBitValue == 15 {
|
||||
return Ok(DecodedChar::new(pos + 5, DecodedChar::FNC1));
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::BitArray,
|
||||
common::{BitArray, Result},
|
||||
oned::{
|
||||
recordPattern, recordPatternInReverse,
|
||||
rss::{
|
||||
@@ -156,7 +156,7 @@ impl OneDReader for RSSExpandedReader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
_hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
// Rows can start with even pattern in case in prev rows there where odd number of patters.
|
||||
// So lets try twice
|
||||
self.pairs.clear();
|
||||
@@ -173,10 +173,7 @@ impl OneDReader for RSSExpandedReader {
|
||||
}
|
||||
}
|
||||
impl Reader for RSSExpandedReader {
|
||||
fn decode(
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult> {
|
||||
self.decode_with_hints(image, &HashMap::new())
|
||||
}
|
||||
|
||||
@@ -185,7 +182,7 @@ impl Reader for RSSExpandedReader {
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
if let Ok(res) = self.doDecode(image, hints) {
|
||||
Ok(res)
|
||||
} else {
|
||||
@@ -289,7 +286,7 @@ impl RSSExpandedReader {
|
||||
&mut self,
|
||||
rowNumber: u32,
|
||||
row: &BitArray,
|
||||
) -> Result<Vec<ExpandedPair>, Exceptions> {
|
||||
) -> Result<Vec<ExpandedPair>> {
|
||||
let mut done = false;
|
||||
while !done {
|
||||
let previousPairs = self.pairs.clone();
|
||||
@@ -372,7 +369,7 @@ impl RSSExpandedReader {
|
||||
&mut self,
|
||||
collectedRows: &mut Vec<ExpandedRow>,
|
||||
currentRow: usize,
|
||||
) -> Result<Vec<ExpandedPair>, Exceptions> {
|
||||
) -> Result<Vec<ExpandedPair>> {
|
||||
for i in currentRow..self.rows.len() {
|
||||
// for (int i = currentRow; i < rows.size(); i++) {
|
||||
let row = self
|
||||
@@ -535,7 +532,7 @@ impl RSSExpandedReader {
|
||||
}
|
||||
|
||||
// Not private for unit testing
|
||||
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult, Exceptions> {
|
||||
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult> {
|
||||
let binary = bit_array_builder::buildBitArray(&pairs.to_vec())
|
||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
||||
|
||||
@@ -625,7 +622,7 @@ impl RSSExpandedReader {
|
||||
row: &BitArray,
|
||||
previousPairs: &[ExpandedPair],
|
||||
rowNumber: u32,
|
||||
) -> Result<ExpandedPair, Exceptions> {
|
||||
) -> Result<ExpandedPair> {
|
||||
let mut isOddPattern = previousPairs.len() % 2 == 0;
|
||||
if self.startFromEven {
|
||||
isOddPattern = !isOddPattern;
|
||||
@@ -688,7 +685,7 @@ impl RSSExpandedReader {
|
||||
row: &BitArray,
|
||||
previousPairs: &[ExpandedPair],
|
||||
forcedOffset: i32,
|
||||
) -> Result<(), Exceptions> {
|
||||
) -> Result<()> {
|
||||
let counters = &mut self.decodeFinderCounters;
|
||||
counters.fill(0);
|
||||
// counters[0] = 0;
|
||||
@@ -830,7 +827,7 @@ impl RSSExpandedReader {
|
||||
pattern: &FinderPattern,
|
||||
isOddPattern: bool,
|
||||
leftChar: bool,
|
||||
) -> Result<DataCharacter, Exceptions> {
|
||||
) -> Result<DataCharacter> {
|
||||
let counters = &mut self.dataCharacterCounters;
|
||||
counters.fill(0);
|
||||
|
||||
@@ -934,7 +931,7 @@ impl RSSExpandedReader {
|
||||
!(pattern.getValue() == 0 && isOddPattern && leftChar)
|
||||
}
|
||||
|
||||
fn adjustOddEvenCounts(&mut self, numModules: u32) -> Result<(), Exceptions> {
|
||||
fn adjustOddEvenCounts(&mut self, numModules: u32) -> Result<()> {
|
||||
let oddSum = self.oddCounts.iter().sum::<u32>();
|
||||
let evenSum = self.evenCounts.iter().sum::<u32>();
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
* http://www.piramidepse.com/
|
||||
*/
|
||||
|
||||
use crate::{oned::rss::expanded::ExpandedPair, Exceptions, Reader};
|
||||
use crate::common::Result;
|
||||
use crate::{oned::rss::expanded::ExpandedPair, Reader};
|
||||
|
||||
use super::{test_case_util, RSSExpandedReader};
|
||||
|
||||
@@ -43,7 +44,7 @@ fn testDecodingRowByRow() {
|
||||
|
||||
// let tester = ;
|
||||
|
||||
assert!(|| -> Result<Vec<ExpandedPair>, Exceptions> {
|
||||
assert!(|| -> Result<Vec<ExpandedPair>> {
|
||||
rssExpandedReader.decodeRow2pairs(firstRowNumber as u32, &firstRow)
|
||||
// fail(NotFoundException.class.getName() + " expected");
|
||||
}()
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::BitArray,
|
||||
common::{BitArray, Result},
|
||||
oned::{one_d_reader, OneDReader},
|
||||
BarcodeFormat, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions,
|
||||
RXingResult, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader,
|
||||
@@ -50,7 +50,7 @@ impl OneDReader for RSS14Reader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let mut row = row.clone();
|
||||
let leftPair = self.decodePair(&row, false, rowNumber, hints);
|
||||
Self::addOrTally(&mut self.possibleLeftPairs, leftPair);
|
||||
@@ -73,10 +73,7 @@ impl OneDReader for RSS14Reader {
|
||||
}
|
||||
}
|
||||
impl Reader for RSS14Reader {
|
||||
fn decode(
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult> {
|
||||
self.decode_with_hints(image, &HashMap::new())
|
||||
}
|
||||
|
||||
@@ -85,7 +82,7 @@ impl Reader for RSS14Reader {
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
if let Ok(res) = self.doDecode(image, hints) {
|
||||
Ok(res)
|
||||
} else {
|
||||
@@ -249,7 +246,7 @@ impl RSS14Reader {
|
||||
rowNumber: u32,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Option<Pair> {
|
||||
let pos_pair = || -> Result<Pair, Exceptions> {
|
||||
let pos_pair = || -> Result<Pair> {
|
||||
let startEnd = self.findFinderPattern(row, right)?;
|
||||
let pattern = self.parseFoundFinderPattern(row, rowNumber, right, &startEnd)?;
|
||||
|
||||
@@ -285,7 +282,7 @@ impl RSS14Reader {
|
||||
row: &BitArray,
|
||||
pattern: &FinderPattern,
|
||||
outsideChar: bool,
|
||||
) -> Result<DataCharacter, Exceptions> {
|
||||
) -> Result<DataCharacter> {
|
||||
let counters = &mut self.dataCharacterCounters;
|
||||
counters.fill(0);
|
||||
|
||||
@@ -378,7 +375,7 @@ impl RSS14Reader {
|
||||
&mut self,
|
||||
row: &BitArray,
|
||||
rightFinderPattern: bool,
|
||||
) -> Result<[usize; 2], Exceptions> {
|
||||
) -> Result<[usize; 2]> {
|
||||
let counters = &mut self.decodeFinderCounters;
|
||||
counters.fill(0);
|
||||
|
||||
@@ -426,7 +423,7 @@ impl RSS14Reader {
|
||||
rowNumber: u32,
|
||||
right: bool,
|
||||
startEnd: &[usize],
|
||||
) -> Result<FinderPattern, Exceptions> {
|
||||
) -> Result<FinderPattern> {
|
||||
// Actually we found elements 2-5
|
||||
let firstIsBlack = row.get(startEnd[0]);
|
||||
let mut firstElementStart = startEnd[0] as isize - 1;
|
||||
@@ -461,11 +458,7 @@ impl RSS14Reader {
|
||||
))
|
||||
}
|
||||
|
||||
fn adjustOddEvenCounts(
|
||||
&mut self,
|
||||
outsideChar: bool,
|
||||
numModules: u32,
|
||||
) -> Result<(), Exceptions> {
|
||||
fn adjustOddEvenCounts(&mut self, outsideChar: bool, numModules: u32) -> Result<()> {
|
||||
let oddSum = self.oddCounts.iter().sum::<u32>();
|
||||
let evenSum = self.evenCounts.iter().sum::<u32>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user