mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Merge branch 'main' into pr/exception_helpers
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDReader;
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
use crate::BarcodeFormat;
|
||||
use crate::DecodeHintValue;
|
||||
use crate::Exceptions;
|
||||
@@ -54,7 +54,7 @@ impl OneDReader for CodaBarReader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
self.counters.fill(0);
|
||||
// Arrays.fill(counters, 0);
|
||||
self.setCounters(row)?;
|
||||
@@ -227,7 +227,7 @@ impl CodaBarReader {
|
||||
}
|
||||
}
|
||||
|
||||
fn validatePattern(&self, start: usize) -> Result<(), Exceptions> {
|
||||
fn validatePattern(&self, start: usize) -> Result<()> {
|
||||
// First, sum up the total size of our four categories of stripe sizes;
|
||||
let mut sizes = [0, 0, 0, 0];
|
||||
let mut counts = [0, 0, 0, 0];
|
||||
@@ -304,7 +304,7 @@ impl CodaBarReader {
|
||||
* uses our builtin "counters" member for storage.
|
||||
* @param row row to count from
|
||||
*/
|
||||
fn setCounters(&mut self, row: &BitArray) -> Result<(), Exceptions> {
|
||||
fn setCounters(&mut self, row: &BitArray) -> Result<()> {
|
||||
self.counterLength = 0;
|
||||
// Start from the first white bit.
|
||||
let mut i = row.getNextUnset(0);
|
||||
@@ -338,7 +338,7 @@ impl CodaBarReader {
|
||||
}
|
||||
}
|
||||
|
||||
fn findStartPattern(&mut self) -> Result<u32, Exceptions> {
|
||||
fn findStartPattern(&mut self) -> Result<u32> {
|
||||
let mut i = 1;
|
||||
while i < self.counterLength {
|
||||
// for (int i = 1; i < counterLength; i += 2) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::{CodaBarReader, OneDimensionalCodeWriter};
|
||||
@@ -34,7 +35,7 @@ const DEFAULT_GUARD: char = START_END_CHARS[0];
|
||||
pub struct CodaBarWriter;
|
||||
|
||||
impl OneDimensionalCodeWriter for CodaBarWriter {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, crate::Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let contents = if contents.chars().count() < 2 {
|
||||
// Can't have a start/end guard, so tentatively add default guards
|
||||
format!("{DEFAULT_GUARD}{contents}{DEFAULT_GUARD}")
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDReader;
|
||||
|
||||
use crate::{common::BitArray, BarcodeFormat, Exceptions, RXingResult};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
BarcodeFormat, Exceptions, RXingResult,
|
||||
};
|
||||
|
||||
use super::{one_d_reader, OneDReader};
|
||||
|
||||
@@ -34,7 +37,7 @@ impl OneDReader for Code128Reader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let convertFNC1 = hints.contains_key(&DecodeHintType::ASSUME_GS1);
|
||||
|
||||
let mut symbologyModifier = 0;
|
||||
@@ -350,7 +353,7 @@ impl OneDReader for Code128Reader {
|
||||
}
|
||||
}
|
||||
impl Code128Reader {
|
||||
fn findStartPattern(&self, row: &BitArray) -> Result<[usize; 3], Exceptions> {
|
||||
fn findStartPattern(&self, row: &BitArray) -> Result<[usize; 3]> {
|
||||
let width = row.getSize();
|
||||
let rowOffset = row.getNextSet(0);
|
||||
|
||||
@@ -406,12 +409,7 @@ impl Code128Reader {
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn decodeCode(
|
||||
&self,
|
||||
row: &BitArray,
|
||||
counters: &mut [u32; 6],
|
||||
rowOffset: usize,
|
||||
) -> Result<u8, Exceptions> {
|
||||
fn decodeCode(&self, row: &BitArray, counters: &mut [u32; 6], rowOffset: usize) -> Result<u8> {
|
||||
one_d_reader::recordPattern(row, rowOffset, counters)?;
|
||||
let mut bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
let mut bestMatch = -1_isize;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::{code_128_reader, OneDimensionalCodeWriter};
|
||||
@@ -58,7 +59,7 @@ enum CType {
|
||||
pub struct Code128Writer;
|
||||
|
||||
impl OneDimensionalCodeWriter for Code128Writer {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
self.encode_oned_with_hints(contents, &HashMap::new())
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ impl OneDimensionalCodeWriter for Code128Writer {
|
||||
&self,
|
||||
contents: &str,
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<Vec<bool>, Exceptions> {
|
||||
) -> Result<Vec<bool>> {
|
||||
let forcedCodeSet = check(contents, hints)?;
|
||||
|
||||
let hasCompactionHint = matches!(
|
||||
@@ -95,7 +96,7 @@ impl OneDimensionalCodeWriter for Code128Writer {
|
||||
}
|
||||
}
|
||||
|
||||
fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, Exceptions> {
|
||||
fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32> {
|
||||
let length = contents.chars().count();
|
||||
// Check length
|
||||
if !(1..=80).contains(&length) {
|
||||
@@ -183,7 +184,7 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result<i32, E
|
||||
Ok(forcedCodeSet)
|
||||
}
|
||||
|
||||
fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encodeFast(contents: &str, forcedCodeSet: i32) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
|
||||
let mut patterns: Vec<Vec<usize>> = Vec::new(); //new ArrayList<>(); // temporary storage for patterns
|
||||
@@ -441,7 +442,7 @@ fn chooseCode(value: &str, start: usize, oldCode: usize) -> Option<usize> {
|
||||
// minPath:Vec<Vec<Latch>>,
|
||||
// }
|
||||
mod MinimalEncoder {
|
||||
use crate::{oned::code_128_reader, Exceptions};
|
||||
use crate::{common::Result, oned::code_128_reader, Exceptions};
|
||||
|
||||
use super::{
|
||||
produceRXingResult, CODE_CODE_A, CODE_CODE_B, CODE_CODE_C, CODE_FNC_1, CODE_FNC_2,
|
||||
@@ -475,7 +476,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
|
||||
const CODE_SHIFT: usize = 98;
|
||||
|
||||
pub fn encode(contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
pub fn encode(contents: &str) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
let mut memoizedCost = vec![vec![0_u32; length]; 4]; //new int[4][contents.length()];
|
||||
let mut minPath = vec![vec![Latch::None; length]; 4]; //new Latch[4][contents.length()];
|
||||
@@ -678,7 +679,7 @@ stuvwxyz{|}~\u{007F}\u{00FF}";
|
||||
position: usize,
|
||||
memoizedCost: &mut Vec<Vec<u32>>,
|
||||
minPath: &mut Vec<Vec<Latch>>,
|
||||
) -> Result<u32, Exceptions> {
|
||||
) -> Result<u32> {
|
||||
if position >= contents.chars().count() {
|
||||
return Err(Exceptions::illegalState);
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ use std::collections::HashMap;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::{
|
||||
common::{bit_matrix_test_case, BitMatrix},
|
||||
common::{bit_matrix_test_case, BitMatrix, Result},
|
||||
oned::{Code128Reader, OneDReader},
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, EncodingHintDictionary, Exceptions, Writer,
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, EncodingHintDictionary, Writer,
|
||||
};
|
||||
|
||||
use super::Code128Writer;
|
||||
@@ -469,7 +469,7 @@ fn testEncodeWithForcedCodeSetFailureCodeSetB() {
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
fn encode(toEncode: &str, compact: bool, expectedLoopback: &str) -> Result<BitMatrix, Exceptions> {
|
||||
fn encode(toEncode: &str, compact: bool, expectedLoopback: &str) -> Result<BitMatrix> {
|
||||
let mut reader = Code128Reader::default();
|
||||
|
||||
let mut hints: EncodingHintDictionary = HashMap::new();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDReader;
|
||||
|
||||
use crate::common::BitArray;
|
||||
use crate::common::{BitArray, Result};
|
||||
use crate::{BarcodeFormat, Exceptions, RXingResult};
|
||||
|
||||
use super::{one_d_reader, OneDReader};
|
||||
@@ -45,7 +45,7 @@ impl OneDReader for Code39Reader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
_hints: &DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let mut counters = [0_u32; 9];
|
||||
self.decodeRowRXingResult.clear();
|
||||
|
||||
@@ -204,7 +204,7 @@ impl Code39Reader {
|
||||
}
|
||||
}
|
||||
|
||||
fn findAsteriskPattern(row: &BitArray, counters: &mut [u32]) -> Result<Vec<u32>, Exceptions> {
|
||||
fn findAsteriskPattern(row: &BitArray, counters: &mut [u32]) -> Result<Vec<u32>> {
|
||||
let width = row.getSize();
|
||||
let rowOffset = row.getNextSet(0);
|
||||
|
||||
@@ -300,7 +300,7 @@ impl Code39Reader {
|
||||
-1
|
||||
}
|
||||
|
||||
fn patternToChar(pattern: u32) -> Result<char, Exceptions> {
|
||||
fn patternToChar(pattern: u32) -> Result<char> {
|
||||
for i in 0..Self::CHARACTER_ENCODINGS.len() {
|
||||
if Self::CHARACTER_ENCODINGS[i] == pattern {
|
||||
return Self::ALPHABET_STRING
|
||||
@@ -315,7 +315,7 @@ impl Code39Reader {
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn decodeExtended(encoded: &str) -> Result<String, Exceptions> {
|
||||
fn decodeExtended(encoded: &str) -> Result<String> {
|
||||
let length = encoded.chars().count();
|
||||
let mut decoded = String::with_capacity(length); //new StringBuilder(length);
|
||||
let mut i = 0;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::{Code39Reader, OneDimensionalCodeWriter};
|
||||
@@ -29,7 +30,7 @@ use super::{Code39Reader, OneDimensionalCodeWriter};
|
||||
pub struct Code39Writer;
|
||||
|
||||
impl OneDimensionalCodeWriter for Code39Writer {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let mut contents = contents.to_owned();
|
||||
let mut length = contents.chars().count();
|
||||
if length > 80 {
|
||||
@@ -99,7 +100,7 @@ impl Code39Writer {
|
||||
}
|
||||
}
|
||||
|
||||
fn tryToConvertToExtendedMode(contents: &str) -> Result<String, Exceptions> {
|
||||
fn tryToConvertToExtendedMode(contents: &str) -> Result<String> {
|
||||
// let length = contents.chars().count();
|
||||
let mut extendedContent = String::new(); //new StringBuilder();
|
||||
for character in contents.chars() {
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDReader;
|
||||
|
||||
use crate::{common::BitArray, BarcodeFormat, Exceptions, RXingResult};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
BarcodeFormat, Exceptions, RXingResult,
|
||||
};
|
||||
|
||||
use super::{one_d_reader, OneDReader};
|
||||
|
||||
@@ -47,7 +50,7 @@ impl OneDReader for Code93Reader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
_hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let start = self.findAsteriskPattern(row)?;
|
||||
// Read off white space
|
||||
let mut nextStart = row.getNextSet(start[1]);
|
||||
@@ -159,7 +162,7 @@ impl Code93Reader {
|
||||
}
|
||||
}
|
||||
|
||||
fn findAsteriskPattern(&mut self, row: &BitArray) -> Result<[usize; 2], Exceptions> {
|
||||
fn findAsteriskPattern(&mut self, row: &BitArray) -> Result<[usize; 2]> {
|
||||
let width = row.getSize();
|
||||
let rowOffset = row.getNextSet(0);
|
||||
|
||||
@@ -215,7 +218,7 @@ impl Code93Reader {
|
||||
pattern
|
||||
}
|
||||
|
||||
fn patternToChar(pattern: u32) -> Result<char, Exceptions> {
|
||||
fn patternToChar(pattern: u32) -> Result<char> {
|
||||
for i in 0..Self::CHARACTER_ENCODINGS.len() {
|
||||
if Self::CHARACTER_ENCODINGS[i] == pattern {
|
||||
return Ok(Self::ALPHABET[i]);
|
||||
@@ -224,7 +227,7 @@ impl Code93Reader {
|
||||
Err(Exceptions::notFound)
|
||||
}
|
||||
|
||||
fn decodeExtended(encoded: &str) -> Result<String, Exceptions> {
|
||||
fn decodeExtended(encoded: &str) -> Result<String> {
|
||||
let length = encoded.chars().count();
|
||||
let mut decoded = String::with_capacity(length);
|
||||
let mut i = 0;
|
||||
@@ -318,18 +321,14 @@ impl Code93Reader {
|
||||
Ok(decoded)
|
||||
}
|
||||
|
||||
fn checkChecksums(result: &str) -> Result<(), Exceptions> {
|
||||
fn checkChecksums(result: &str) -> Result<()> {
|
||||
let length = result.chars().count();
|
||||
Self::checkOneChecksum(result, length - 2, 20)?;
|
||||
Self::checkOneChecksum(result, length - 1, 15)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn checkOneChecksum(
|
||||
result: &str,
|
||||
checkPosition: usize,
|
||||
weightMax: u32,
|
||||
) -> Result<(), Exceptions> {
|
||||
fn checkOneChecksum(result: &str, checkPosition: usize, weightMax: u32) -> Result<()> {
|
||||
let mut weight = 1;
|
||||
let mut total = 0;
|
||||
for i in (0..checkPosition).rev() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::{Code93Reader, OneDimensionalCodeWriter};
|
||||
@@ -31,7 +32,7 @@ impl OneDimensionalCodeWriter for Code93Writer {
|
||||
* @param contents barcode contents to encode. It should not be encoded for extended characters.
|
||||
* @return a {@code boolean[]} of horizontal pixels (false = white, true = black)
|
||||
*/
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let mut contents = Self::convertToExtended(contents)?;
|
||||
let length = contents.chars().count();
|
||||
if length > 80 {
|
||||
@@ -142,7 +143,7 @@ impl Code93Writer {
|
||||
total as usize % 47
|
||||
}
|
||||
|
||||
fn convertToExtended(contents: &str) -> Result<String, Exceptions> {
|
||||
fn convertToExtended(contents: &str) -> Result<String> {
|
||||
let length = contents.chars().count();
|
||||
let mut extendedContent = String::with_capacity(length * 2);
|
||||
for character in contents.chars() {
|
||||
|
||||
@@ -21,6 +21,7 @@ use super::UPCEANReader;
|
||||
use super::upc_ean_reader;
|
||||
use super::OneDReader;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
use crate::Exceptions;
|
||||
|
||||
@@ -43,7 +44,7 @@ impl UPCEANReader for EAN13Reader {
|
||||
row: &crate::common::BitArray,
|
||||
startRange: &[usize; 2],
|
||||
resultString: &mut String,
|
||||
) -> Result<usize, crate::Exceptions> {
|
||||
) -> Result<usize> {
|
||||
let mut counters = [0_u32; 4]; //decodeMiddleCounters;
|
||||
// counters[0] = 0;
|
||||
// counters[1] = 0;
|
||||
@@ -141,10 +142,7 @@ impl EAN13Reader {
|
||||
* encode digits
|
||||
* @throws NotFoundException if first digit cannot be determined
|
||||
*/
|
||||
fn determineFirstDigit(
|
||||
resultString: &mut String,
|
||||
lgPatternFound: usize,
|
||||
) -> Result<(), Exceptions> {
|
||||
fn determineFirstDigit(resultString: &mut String, lgPatternFound: usize) -> Result<()> {
|
||||
for d in 0..10 {
|
||||
// for (int d = 0; d < 10; d++) {
|
||||
if lgPatternFound == Self::FIRST_DIGIT_ENCODINGS[d] {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::{
|
||||
common::Result,
|
||||
oned::{upc_ean_reader, EAN13Reader},
|
||||
BarcodeFormat,
|
||||
};
|
||||
@@ -33,7 +34,7 @@ pub struct EAN13Writer;
|
||||
impl UPCEANWriter for EAN13Writer {}
|
||||
|
||||
impl OneDimensionalCodeWriter for EAN13Writer {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, crate::Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let reader: EAN13Reader = EAN13Reader::default();
|
||||
let mut contents = contents.to_owned();
|
||||
let length = contents.chars().count();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
use super::OneDReader;
|
||||
use crate::common::Result;
|
||||
use crate::{BarcodeFormat, Exceptions};
|
||||
use rxing_one_d_proc_derive::{EANReader, OneDReader};
|
||||
|
||||
@@ -39,7 +40,7 @@ impl UPCEANReader for EAN8Reader {
|
||||
row: &crate::common::BitArray,
|
||||
startRange: &[usize; 2],
|
||||
resultString: &mut String,
|
||||
) -> Result<usize, Exceptions> {
|
||||
) -> Result<usize> {
|
||||
let mut counters = [0_u32; 4]; //decodeMiddleCounters;
|
||||
// counters[0] = 0;
|
||||
// counters[1] = 0;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::{
|
||||
common::Result,
|
||||
oned::{EAN8Reader, UPCEANReader},
|
||||
BarcodeFormat,
|
||||
};
|
||||
@@ -42,7 +43,7 @@ impl OneDimensionalCodeWriter for EAN8Writer {
|
||||
/**
|
||||
* @return a byte array of horizontal pixels (false = white, true = black)
|
||||
*/
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
let reader = EAN8Reader::default();
|
||||
let mut contents = contents.to_owned();
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDReader;
|
||||
|
||||
use crate::{common::BitArray, BarcodeFormat, DecodeHintValue, Exceptions, RXingResult};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
BarcodeFormat, DecodeHintValue, Exceptions, RXingResult,
|
||||
};
|
||||
|
||||
use super::{one_d_reader, OneDReader};
|
||||
|
||||
@@ -106,7 +109,7 @@ impl OneDReader for ITFReader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
// Find out where the Middle section (payload) starts & ends
|
||||
let mut row = row.clone();
|
||||
let startRange = self.decodeStart(&row)?;
|
||||
@@ -174,7 +177,7 @@ impl ITFReader {
|
||||
payloadStart: usize,
|
||||
payloadEnd: usize,
|
||||
resultString: &mut String,
|
||||
) -> Result<(), Exceptions> {
|
||||
) -> Result<()> {
|
||||
let mut payloadStart = payloadStart;
|
||||
// Digits are interleaved in pairs - 5 black lines for one digit, and the
|
||||
// 5 interleaved white lines for the second digit.
|
||||
@@ -212,7 +215,7 @@ impl ITFReader {
|
||||
* @return Array, containing index of start of 'start block' and end of
|
||||
* 'start block'
|
||||
*/
|
||||
fn decodeStart(&mut self, row: &BitArray) -> Result<[usize; 2], Exceptions> {
|
||||
fn decodeStart(&mut self, row: &BitArray) -> Result<[usize; 2]> {
|
||||
let endStart = Self::skipWhiteSpace(row)?;
|
||||
let startPattern = self.findGuardPattern(row, endStart, &START_PATTERN)?;
|
||||
|
||||
@@ -241,7 +244,7 @@ impl ITFReader {
|
||||
* @param startPattern index into row of the start or end pattern.
|
||||
* @throws NotFoundException if the quiet zone cannot be found
|
||||
*/
|
||||
fn validateQuietZone(&self, row: &BitArray, startPattern: usize) -> Result<(), Exceptions> {
|
||||
fn validateQuietZone(&self, row: &BitArray, startPattern: usize) -> Result<()> {
|
||||
let mut quietCount = self.narrowLineWidth * 10; // expect to find this many pixels of quiet zone
|
||||
|
||||
// if there are not so many pixel at all let's try as many as possible
|
||||
@@ -271,7 +274,7 @@ impl ITFReader {
|
||||
* @return index of the first black line.
|
||||
* @throws NotFoundException Throws exception if no black lines are found in the row
|
||||
*/
|
||||
fn skipWhiteSpace(row: &BitArray) -> Result<usize, Exceptions> {
|
||||
fn skipWhiteSpace(row: &BitArray) -> Result<usize> {
|
||||
let width = row.getSize();
|
||||
let endStart = row.getNextSet(0);
|
||||
if endStart == width {
|
||||
@@ -288,11 +291,11 @@ impl ITFReader {
|
||||
* @return Array, containing index of start of 'end block' and end of 'end
|
||||
* block'
|
||||
*/
|
||||
fn decodeEnd(&self, row: &mut BitArray) -> Result<[usize; 2], Exceptions> {
|
||||
fn decodeEnd(&self, row: &mut BitArray) -> Result<[usize; 2]> {
|
||||
// For convenience, reverse the row and then
|
||||
// search from 'the start' for the end block
|
||||
row.reverse();
|
||||
let interim_function = || -> Result<[usize; 2], Exceptions> {
|
||||
let interim_function = || -> Result<[usize; 2]> {
|
||||
let endStart = Self::skipWhiteSpace(row)?;
|
||||
let mut endPattern =
|
||||
if let Ok(ptrn) = self.findGuardPattern(row, endStart, &END_PATTERN_REVERSED[0]) {
|
||||
@@ -335,7 +338,7 @@ impl ITFReader {
|
||||
row: &BitArray,
|
||||
rowOffset: usize,
|
||||
pattern: &[u32],
|
||||
) -> Result<[usize; 2], Exceptions> {
|
||||
) -> Result<[usize; 2]> {
|
||||
let patternLength = pattern.len();
|
||||
let mut counters = vec![0u32; patternLength]; //new int[patternLength];
|
||||
let width = row.getSize();
|
||||
@@ -381,7 +384,7 @@ impl ITFReader {
|
||||
* @return The decoded digit
|
||||
* @throws NotFoundException if digit cannot be decoded
|
||||
*/
|
||||
fn decodeDigit(&self, counters: &[u32]) -> Result<u32, Exceptions> {
|
||||
fn decodeDigit(&self, counters: &[u32]) -> Result<u32> {
|
||||
let mut bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
let mut bestMatch = -1_isize;
|
||||
let max = PATTERNS.len();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::OneDimensionalCodeWriter;
|
||||
@@ -29,7 +30,7 @@ use super::OneDimensionalCodeWriter;
|
||||
pub struct ITFWriter;
|
||||
|
||||
impl OneDimensionalCodeWriter for ITFWriter {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
if length % 2 != 0 {
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
|
||||
@@ -23,6 +23,7 @@ use super::Code93Reader;
|
||||
use super::ITFReader;
|
||||
use super::MultiFormatUPCEANReader;
|
||||
use super::OneDReader;
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
use crate::DecodeHintValue;
|
||||
use crate::Exceptions;
|
||||
@@ -39,7 +40,7 @@ impl OneDReader for MultiFormatOneDReader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
for reader in self.0.iter_mut() {
|
||||
if let Ok(res) = reader.decodeRow(rowNumber, row, hints) {
|
||||
return Ok(res);
|
||||
@@ -113,10 +114,7 @@ use crate::Reader;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl Reader for MultiFormatOneDReader {
|
||||
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())
|
||||
}
|
||||
|
||||
@@ -125,7 +123,7 @@ impl Reader for MultiFormatOneDReader {
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let first_try = self.doDecode(image, hints);
|
||||
if first_try.is_ok() {
|
||||
return first_try;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
use crate::DecodeHintValue;
|
||||
use crate::Exceptions;
|
||||
@@ -74,7 +75,7 @@ impl MultiFormatUPCEANReader {
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
startGuardPattern: &[usize; 2],
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let result = reader.decodeRowWithGuardRange(rowNumber, row, startGuardPattern, hints)?;
|
||||
// Special case: a 12-digit code encoded in UPC-A is identical to a "0"
|
||||
// followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
|
||||
@@ -122,7 +123,7 @@ impl OneDReader for MultiFormatUPCEANReader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, crate::Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
// Compute this location once and reuse it on multiple implementations
|
||||
let startGuardPattern = STAND_IN.findStartGuardPattern(row)?;
|
||||
for reader in &self.0 {
|
||||
@@ -145,10 +146,7 @@ use crate::RXingResultMetadataValue;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl Reader for MultiFormatUPCEANReader {
|
||||
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())
|
||||
}
|
||||
|
||||
@@ -157,7 +155,7 @@ impl Reader for MultiFormatUPCEANReader {
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
let first_try = self.doDecode(image, hints);
|
||||
if first_try.is_ok() {
|
||||
return first_try;
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::BitMatrix, BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||
common::{BitMatrix, Result},
|
||||
BarcodeFormat, EncodeHintType, EncodeHintValue, Exceptions, Writer,
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
@@ -40,7 +41,7 @@ pub trait OneDimensionalCodeWriter: Writer {
|
||||
* @param contents barcode contents to encode
|
||||
* @return a {@code boolean[]} of horizontal pixels (false = white, true = black)
|
||||
*/
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions>;
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>>;
|
||||
|
||||
/**
|
||||
* Can be overwritten if the encode requires to read the hints map. Otherwise it defaults to {@code encode}.
|
||||
@@ -52,7 +53,7 @@ pub trait OneDimensionalCodeWriter: Writer {
|
||||
&self,
|
||||
contents: &str,
|
||||
_hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<Vec<bool>, Exceptions> {
|
||||
) -> Result<Vec<bool>> {
|
||||
self.encode_oned(contents)
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ pub trait OneDimensionalCodeWriter: Writer {
|
||||
width: i32,
|
||||
height: i32,
|
||||
sidesMargin: u32,
|
||||
) -> Result<BitMatrix, Exceptions> {
|
||||
) -> Result<BitMatrix> {
|
||||
let inputWidth = code.len();
|
||||
// Add quiet zone on both sides.
|
||||
let fullWidth = inputWidth + sidesMargin as usize;
|
||||
@@ -98,7 +99,7 @@ pub trait OneDimensionalCodeWriter: Writer {
|
||||
* @param contents string to check for numeric characters
|
||||
* @throws IllegalArgumentException if input contains characters other than digits 0-9.
|
||||
*/
|
||||
fn checkNumeric(contents: &str) -> Result<(), Exceptions> {
|
||||
fn checkNumeric(contents: &str) -> Result<()> {
|
||||
if !NUMERIC.is_match(contents) {
|
||||
Err(Exceptions::illegalArgumentWith(
|
||||
"Input should only contain digits 0-9",
|
||||
@@ -150,7 +151,7 @@ impl Writer for L {
|
||||
format: &crate::BarcodeFormat,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
self.encode_with_hints(contents, format, width, height, &HashMap::new())
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ impl Writer for L {
|
||||
width: i32,
|
||||
height: i32,
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
if contents.is_empty() {
|
||||
return Err(Exceptions::illegalArgumentWith("Found empty contents"));
|
||||
}
|
||||
@@ -193,7 +194,7 @@ impl Writer for L {
|
||||
}
|
||||
|
||||
impl OneDimensionalCodeWriter for L {
|
||||
fn encode_oned(&self, _contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, _contents: &str) -> Result<Vec<bool>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
common::BitArray, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
|
||||
Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint,
|
||||
Reader, ResultPoint,
|
||||
common::{BitArray, Result},
|
||||
BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult,
|
||||
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ pub trait OneDReader: Reader {
|
||||
&mut self,
|
||||
image: &mut BinaryBitmap,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let mut hints = hints.clone();
|
||||
let width = image.getWidth();
|
||||
let height = image.getHeight();
|
||||
@@ -151,7 +151,7 @@ pub trait OneDReader: Reader {
|
||||
rowNumber: u32,
|
||||
row: &BitArray,
|
||||
hints: &DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions>;
|
||||
) -> Result<RXingResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +212,7 @@ pub fn patternMatchVariance(counters: &[u32], pattern: &[u32], maxIndividualVari
|
||||
* @throws NotFoundException if counters cannot be filled entirely from row before running out
|
||||
* of pixels
|
||||
*/
|
||||
pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Result<(), Exceptions> {
|
||||
pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Result<()> {
|
||||
let numCounters = counters.len();
|
||||
counters.fill(0);
|
||||
|
||||
@@ -246,11 +246,7 @@ pub fn recordPattern(row: &BitArray, start: usize, counters: &mut [u32]) -> Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn recordPatternInReverse(
|
||||
row: &BitArray,
|
||||
start: usize,
|
||||
counters: &mut [u32],
|
||||
) -> Result<(), Exceptions> {
|
||||
pub fn recordPatternInReverse(row: &BitArray, start: usize, counters: &mut [u32]) -> Result<()> {
|
||||
let mut start = start;
|
||||
// This could be more efficient I guess
|
||||
let mut numTransitionsLeft = counters.len() as isize;
|
||||
|
||||
@@ -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();
|
||||
@@ -65,7 +68,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::notFound);
|
||||
}
|
||||
|
||||
@@ -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::notFound);
|
||||
}
|
||||
|
||||
@@ -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::notFound)
|
||||
}
|
||||
|
||||
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::notFound);
|
||||
}
|
||||
@@ -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));
|
||||
@@ -414,7 +413,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();
|
||||
@@ -370,7 +367,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.rows.get(i).ok_or(Exceptions::indexOutOfBounds)?;
|
||||
@@ -530,9 +527,9 @@ impl RSSExpandedReader {
|
||||
}
|
||||
|
||||
// Not private for unit testing
|
||||
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult, Exceptions> {
|
||||
let binary =
|
||||
bit_array_builder::buildBitArray(&pairs.to_vec()).ok_or(Exceptions::illegalState)?;
|
||||
pub(crate) fn constructRXingResult(pairs: &[ExpandedPair]) -> Result<RXingResult> {
|
||||
let binary = bit_array_builder::buildBitArray(&pairs.to_vec())
|
||||
.ok_or(Exceptions::IllegalStateException(None))?;
|
||||
|
||||
let mut decoder = abstract_expanded_decoder::createDecoder(&binary)?;
|
||||
let resultingString = decoder.parseInformation()?;
|
||||
@@ -620,7 +617,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;
|
||||
@@ -679,7 +676,7 @@ impl RSSExpandedReader {
|
||||
row: &BitArray,
|
||||
previousPairs: &[ExpandedPair],
|
||||
forcedOffset: i32,
|
||||
) -> Result<(), Exceptions> {
|
||||
) -> Result<()> {
|
||||
let counters = &mut self.decodeFinderCounters;
|
||||
counters.fill(0);
|
||||
// counters[0] = 0;
|
||||
@@ -819,7 +816,7 @@ impl RSSExpandedReader {
|
||||
pattern: &FinderPattern,
|
||||
isOddPattern: bool,
|
||||
leftChar: bool,
|
||||
) -> Result<DataCharacter, Exceptions> {
|
||||
) -> Result<DataCharacter> {
|
||||
let counters = &mut self.dataCharacterCounters;
|
||||
counters.fill(0);
|
||||
|
||||
@@ -923,7 +920,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>();
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::{BarcodeFormat, Exceptions, RXingResult, Reader};
|
||||
use crate::{common::Result, BarcodeFormat, Exceptions, RXingResult, Reader};
|
||||
|
||||
use super::{EAN13Reader, OneDReader, UPCEANReader};
|
||||
|
||||
@@ -28,10 +28,7 @@ use super::{EAN13Reader, OneDReader, UPCEANReader};
|
||||
pub struct UPCAReader(EAN13Reader);
|
||||
|
||||
impl Reader for UPCAReader {
|
||||
fn decode(
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult> {
|
||||
Self::maybeReturnRXingResult(self.0.decode(image)?)
|
||||
}
|
||||
|
||||
@@ -39,7 +36,7 @@ impl Reader for UPCAReader {
|
||||
&mut self,
|
||||
image: &mut crate::BinaryBitmap,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
Self::maybeReturnRXingResult(self.0.decode_with_hints(image, hints)?)
|
||||
}
|
||||
}
|
||||
@@ -50,7 +47,7 @@ impl OneDReader for UPCAReader {
|
||||
rowNumber: u32,
|
||||
row: &crate::common::BitArray,
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions> {
|
||||
) -> Result<crate::RXingResult> {
|
||||
Self::maybeReturnRXingResult(self.0.decodeRow(rowNumber, row, hints)?)
|
||||
}
|
||||
}
|
||||
@@ -65,7 +62,7 @@ impl UPCEANReader for UPCAReader {
|
||||
row: &crate::common::BitArray,
|
||||
startRange: &[usize; 2],
|
||||
resultString: &mut String,
|
||||
) -> Result<usize, Exceptions> {
|
||||
) -> Result<usize> {
|
||||
self.0.decodeMiddle(row, startRange, resultString)
|
||||
}
|
||||
|
||||
@@ -75,7 +72,7 @@ impl UPCEANReader for UPCAReader {
|
||||
row: &crate::common::BitArray,
|
||||
startGuardRange: &[usize; 2],
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<crate::RXingResult, Exceptions>
|
||||
) -> Result<crate::RXingResult>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
@@ -91,7 +88,7 @@ impl UPCEANReader for UPCAReader {
|
||||
impl UPCAReader {
|
||||
// private final UPCEANReader ean13Reader = new EAN13Reader();
|
||||
|
||||
fn maybeReturnRXingResult(result: RXingResult) -> Result<RXingResult, Exceptions> {
|
||||
fn maybeReturnRXingResult(result: RXingResult) -> Result<RXingResult> {
|
||||
let text = result.getText();
|
||||
if let Some(stripped_text) = text.strip_prefix('0') {
|
||||
let mut upcaRXingResult = RXingResult::new(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{BarcodeFormat, Exceptions, Writer};
|
||||
use crate::{common::Result, BarcodeFormat, Exceptions, Writer};
|
||||
|
||||
use super::EAN13Writer;
|
||||
|
||||
@@ -35,7 +35,7 @@ impl Writer for UPCAWriter {
|
||||
format: &crate::BarcodeFormat,
|
||||
width: i32,
|
||||
height: i32,
|
||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
self.encode_with_hints(contents, format, width, height, &HashMap::new())
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Writer for UPCAWriter {
|
||||
width: i32,
|
||||
height: i32,
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
if format != &BarcodeFormat::UPC_A {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
"Can only encode UPC-A, but got {format:?}"
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
use super::{OneDReader, UPCEANReader, L_AND_G_PATTERNS};
|
||||
use crate::{BarcodeFormat, Exceptions};
|
||||
use crate::{common::Result, BarcodeFormat, Exceptions};
|
||||
use rxing_one_d_proc_derive::{EANReader, OneDReader};
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ impl UPCEANReader for UPCEReader {
|
||||
row: &crate::common::BitArray,
|
||||
startRange: &[usize; 2],
|
||||
resultString: &mut String,
|
||||
) -> Result<usize, Exceptions> {
|
||||
) -> Result<usize> {
|
||||
let mut counters = [0_u32; 4];
|
||||
|
||||
let end = row.getSize();
|
||||
@@ -65,15 +65,13 @@ impl UPCEANReader for UPCEReader {
|
||||
Ok(rowOffset)
|
||||
}
|
||||
|
||||
fn checkChecksum(&self, s: &str) -> Result<bool, Exceptions> {
|
||||
self.checkStandardUPCEANChecksum(&convertUPCEtoUPCA(s).ok_or(Exceptions::illegalArgument)?)
|
||||
fn checkChecksum(&self, s: &str) -> Result<bool> {
|
||||
self.checkStandardUPCEANChecksum(
|
||||
&convertUPCEtoUPCA(s).ok_or(Exceptions::IllegalArgumentException(None))?,
|
||||
)
|
||||
}
|
||||
|
||||
fn decodeEnd(
|
||||
&self,
|
||||
row: &crate::common::BitArray,
|
||||
endStart: usize,
|
||||
) -> Result<[usize; 2], Exceptions> {
|
||||
fn decodeEnd(&self, row: &crate::common::BitArray, endStart: usize) -> Result<[usize; 2]> {
|
||||
self.findGuardPattern(row, endStart, true, &Self::MIDDLE_END_PATTERN)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +120,7 @@ impl UPCEReader {
|
||||
fn determineNumSysAndCheckDigit(
|
||||
resultString: &mut String,
|
||||
lgPatternFound: usize,
|
||||
) -> Result<(), Exceptions> {
|
||||
) -> Result<()> {
|
||||
for numSys in 0..=1 {
|
||||
for d in 0..10 {
|
||||
if lgPatternFound == Self::NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d] {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
use rxing_one_d_proc_derive::OneDWriter;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::BarcodeFormat;
|
||||
|
||||
use super::{
|
||||
@@ -37,7 +38,7 @@ pub struct UPCEWriter;
|
||||
impl UPCEANWriter for UPCEWriter {}
|
||||
|
||||
impl OneDimensionalCodeWriter for UPCEWriter {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>, Exceptions> {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
let mut contents = contents.to_owned();
|
||||
let reader = UPCEReader::default();
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::BitArray, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType,
|
||||
RXingResultMetadataValue, RXingResultPoint,
|
||||
common::{BitArray, Result},
|
||||
BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue,
|
||||
RXingResultPoint,
|
||||
};
|
||||
|
||||
use super::{upc_ean_reader, UPCEANReader, STAND_IN};
|
||||
@@ -37,7 +38,7 @@ impl UPCEANExtension2Support {
|
||||
rowNumber: u32,
|
||||
row: &BitArray,
|
||||
extensionStartRange: &[u32; 3],
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let mut result = String::new();
|
||||
let end = self.decodeMiddle(row, extensionStartRange, &mut result)?;
|
||||
|
||||
@@ -68,7 +69,7 @@ impl UPCEANExtension2Support {
|
||||
row: &BitArray,
|
||||
startRange: &[u32; 3],
|
||||
resultString: &mut String,
|
||||
) -> Result<u32, Exceptions> {
|
||||
) -> Result<u32> {
|
||||
let mut counters = self.decodeMiddleCounters;
|
||||
counters.fill(0);
|
||||
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
common::BitArray, BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType,
|
||||
RXingResultMetadataValue, RXingResultPoint,
|
||||
common::{BitArray, Result},
|
||||
BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue,
|
||||
RXingResultPoint,
|
||||
};
|
||||
|
||||
use super::{upc_ean_reader, UPCEANReader, STAND_IN};
|
||||
@@ -38,7 +39,7 @@ impl UPCEANExtension5Support {
|
||||
rowNumber: u32,
|
||||
row: &BitArray,
|
||||
extensionStartRange: &[usize; 2],
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let mut result = String::new();
|
||||
|
||||
let end = Self::decodeMiddle(row, extensionStartRange, &mut result)?;
|
||||
@@ -70,7 +71,7 @@ impl UPCEANExtension5Support {
|
||||
row: &BitArray,
|
||||
startRange: &[usize; 2],
|
||||
resultString: &mut String,
|
||||
) -> Result<u32, Exceptions> {
|
||||
) -> Result<u32> {
|
||||
let mut counters = [0_u32; 4];
|
||||
let end = row.getSize();
|
||||
let mut rowOffset = startRange[1];
|
||||
@@ -139,7 +140,7 @@ impl UPCEANExtension5Support {
|
||||
Some(sum % 10)
|
||||
}
|
||||
|
||||
fn determineCheckDigit(lgPatternFound: usize) -> Result<usize, Exceptions> {
|
||||
fn determineCheckDigit(lgPatternFound: usize) -> Result<usize> {
|
||||
for d in 0..10 {
|
||||
if lgPatternFound == Self::CHECK_DIGIT_ENCODINGS[d] {
|
||||
return Ok(d);
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use crate::{common::BitArray, Exceptions, RXingResult};
|
||||
use crate::{
|
||||
common::{BitArray, Result},
|
||||
RXingResult,
|
||||
};
|
||||
|
||||
use super::{UPCEANExtension2Support, UPCEANExtension5Support, UPCEANReader, STAND_IN};
|
||||
|
||||
@@ -32,7 +35,7 @@ impl UPCEANExtensionSupport {
|
||||
rowNumber: u32,
|
||||
row: &BitArray,
|
||||
rowOffset: usize,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let extensionStartRange =
|
||||
STAND_IN.findGuardPattern(row, rowOffset, false, &Self::EXTENSION_START_PATTERN)?;
|
||||
if let Ok(res_1) = self
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
common::BitArray, BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
|
||||
common::{BitArray, Result},
|
||||
BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
|
||||
RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader,
|
||||
};
|
||||
|
||||
@@ -100,7 +101,7 @@ pub const L_AND_G_PATTERNS: [[u32; 4]; 20] = {
|
||||
* @author alasdair@google.com (Alasdair Mackintosh)
|
||||
*/
|
||||
pub trait UPCEANReader: OneDReader {
|
||||
fn findStartGuardPattern(&self, row: &BitArray) -> Result<[usize; 2], Exceptions> {
|
||||
fn findStartGuardPattern(&self, row: &BitArray) -> Result<[usize; 2]> {
|
||||
let mut foundStart = false;
|
||||
let mut startRange = [0; 2];
|
||||
let mut nextStart = 0;
|
||||
@@ -150,7 +151,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
row: &BitArray,
|
||||
startGuardRange: &[usize; 2],
|
||||
hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let resultPointCallback = hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK);
|
||||
let mut symbologyIdentifier = 0;
|
||||
|
||||
@@ -211,7 +212,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
|
||||
let mut extensionLength = 0;
|
||||
|
||||
let mut attempt = || -> Result<(), Exceptions> {
|
||||
let mut attempt = || -> Result<()> {
|
||||
let extensionRXingResult =
|
||||
UPC_EAN_EXTENSION_SUPPORT.decodeRow(rowNumber, row, endRange[1])?;
|
||||
|
||||
@@ -272,7 +273,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
* @return {@link #checkStandardUPCEANChecksum(CharSequence)}
|
||||
* @throws FormatException if the string does not contain only digits
|
||||
*/
|
||||
fn checkChecksum(&self, s: &str) -> Result<bool, Exceptions> {
|
||||
fn checkChecksum(&self, s: &str) -> Result<bool> {
|
||||
self.checkStandardUPCEANChecksum(s)
|
||||
}
|
||||
|
||||
@@ -284,7 +285,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
* @return true iff string of digits passes the UPC/EAN checksum algorithm
|
||||
* @throws FormatException if the string does not contain only digits
|
||||
*/
|
||||
fn checkStandardUPCEANChecksum(&self, s: &str) -> Result<bool, Exceptions> {
|
||||
fn checkStandardUPCEANChecksum(&self, s: &str) -> Result<bool> {
|
||||
let length = s.len();
|
||||
if length == 0 {
|
||||
return Ok(false);
|
||||
@@ -306,7 +307,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
})
|
||||
}
|
||||
|
||||
fn getStandardUPCEANChecksum(&self, s: &str) -> Result<u32, Exceptions> {
|
||||
fn getStandardUPCEANChecksum(&self, s: &str) -> Result<u32> {
|
||||
let length = s.chars().count();
|
||||
let mut sum = 0;
|
||||
let mut i = length as isize - 1;
|
||||
@@ -343,7 +344,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
Ok(((1000 - sum) % 10) as u32)
|
||||
}
|
||||
|
||||
fn decodeEnd(&self, row: &BitArray, endStart: usize) -> Result<[usize; 2], Exceptions> {
|
||||
fn decodeEnd(&self, row: &BitArray, endStart: usize) -> Result<[usize; 2]> {
|
||||
self.findGuardPattern(row, endStart, false, &START_END_PATTERN)
|
||||
}
|
||||
|
||||
@@ -353,7 +354,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
rowOffset: usize,
|
||||
whiteFirst: bool,
|
||||
pattern: &[u32],
|
||||
) -> Result<[usize; 2], Exceptions> {
|
||||
) -> Result<[usize; 2]> {
|
||||
self.findGuardPatternWithCounters(
|
||||
row,
|
||||
rowOffset,
|
||||
@@ -381,7 +382,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
whiteFirst: bool,
|
||||
pattern: &[u32],
|
||||
counters: &mut [u32],
|
||||
) -> Result<[usize; 2], Exceptions> {
|
||||
) -> Result<[usize; 2]> {
|
||||
let width = row.getSize();
|
||||
let rowOffset = if whiteFirst {
|
||||
row.getNextUnset(rowOffset)
|
||||
@@ -442,7 +443,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
counters: &mut [u32; 4],
|
||||
rowOffset: usize,
|
||||
patterns: &[[u32; 4]],
|
||||
) -> Result<usize, Exceptions> {
|
||||
) -> Result<usize> {
|
||||
one_d_reader::recordPattern(row, rowOffset, counters)?;
|
||||
let mut bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
let mut bestMatch = -1_isize;
|
||||
@@ -484,7 +485,7 @@ pub trait UPCEANReader: OneDReader {
|
||||
row: &BitArray,
|
||||
startRange: &[usize; 2],
|
||||
resultString: &mut String,
|
||||
) -> Result<usize, Exceptions>;
|
||||
) -> Result<usize>;
|
||||
}
|
||||
|
||||
pub(crate) struct StandInStruct;
|
||||
@@ -498,7 +499,7 @@ impl UPCEANReader for StandInStruct {
|
||||
_row: &BitArray,
|
||||
_startRange: &[usize; 2],
|
||||
_resultString: &mut String,
|
||||
) -> Result<usize, Exceptions> {
|
||||
) -> Result<usize> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -508,13 +509,13 @@ impl OneDReader for StandInStruct {
|
||||
_rowNumber: u32,
|
||||
_row: &BitArray,
|
||||
_hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Reader for StandInStruct {
|
||||
fn decode(&mut self, _image: &mut crate::BinaryBitmap) -> Result<RXingResult, Exceptions> {
|
||||
fn decode(&mut self, _image: &mut crate::BinaryBitmap) -> Result<RXingResult> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -522,7 +523,7 @@ impl Reader for StandInStruct {
|
||||
&mut self,
|
||||
_image: &mut crate::BinaryBitmap,
|
||||
_hints: &crate::DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user