Merge branch 'main' into pr/exception_helpers

This commit is contained in:
Vukašin Stepanović
2023-02-16 07:15:51 +00:00
161 changed files with 900 additions and 933 deletions

View File

@@ -16,7 +16,10 @@
use std::rc::Rc;
use crate::{common::BitMatrix, Exceptions, RXingResultPoint, ResultPoint};
use crate::{
common::{BitMatrix, Result},
Exceptions, RXingResultPoint, ResultPoint,
};
/**
* @author Guenther Grau
@@ -40,7 +43,7 @@ impl BoundingBox {
bottomLeft: Option<RXingResultPoint>,
topRight: Option<RXingResultPoint>,
bottomRight: Option<RXingResultPoint>,
) -> Result<BoundingBox, Exceptions> {
) -> Result<BoundingBox> {
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
if leftUnspecified && rightUnspecified {
@@ -100,7 +103,7 @@ impl BoundingBox {
pub fn merge(
leftBox: Option<BoundingBox>,
rightBox: Option<BoundingBox>,
) -> Result<BoundingBox, Exceptions> {
) -> Result<BoundingBox> {
if leftBox.is_none() {
return Ok(rightBox.as_ref().ok_or(Exceptions::illegalState)?.clone());
}
@@ -124,7 +127,7 @@ impl BoundingBox {
missingStartRows: u32,
missingEndRows: u32,
isLeft: bool,
) -> Result<BoundingBox, Exceptions> {
) -> Result<BoundingBox> {
let mut newTopLeft = self.topLeft;
let mut newBottomLeft = self.bottomLeft;
let mut newTopRight = self.topRight;

View File

@@ -19,7 +19,7 @@ use num::{self, bigint::ToBigUint, BigUint};
use std::rc::Rc;
use crate::{
common::{DecoderRXingResult, ECIStringBuilder},
common::{DecoderRXingResult, ECIStringBuilder, Result},
pdf417::PDF417RXingResultMetadata,
Exceptions,
};
@@ -106,7 +106,7 @@ static EXP900: Lazy<Vec<BigUint>> = Lazy::new(|| {
const NUMBER_OF_SEQUENCE_CODEWORDS: usize = 2;
pub fn decode(codewords: &[u32], ecLevel: &str) -> Result<DecoderRXingResult, Exceptions> {
pub fn decode(codewords: &[u32], ecLevel: &str) -> Result<DecoderRXingResult> {
let mut result = ECIStringBuilder::with_capacity(codewords.len() * 2);
let mut codeIndex = textCompaction(codewords, 1, &mut result)?;
let mut resultMetadata = PDF417RXingResultMetadata::default();
@@ -180,7 +180,7 @@ pub fn decodeMacroBlock(
codewords: &[u32],
codeIndex: usize,
resultMetadata: &mut PDF417RXingResultMetadata,
) -> Result<usize, Exceptions> {
) -> Result<usize> {
let mut codeIndex = codeIndex;
if codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0] as usize {
// we must have at least two bytes left for the segment index
@@ -330,7 +330,7 @@ fn textCompaction(
codewords: &[u32],
codeIndex: usize,
result: &mut ECIStringBuilder,
) -> Result<usize, Exceptions> {
) -> Result<usize> {
let mut codeIndex = codeIndex;
// 2 character per codeword
let mut textCompactionData = vec![0; (codewords[0] as usize - codeIndex) * 2];
@@ -608,7 +608,7 @@ fn byteCompaction(
codewords: &[u32],
codeIndex: usize,
result: &mut ECIStringBuilder,
) -> Result<usize, Exceptions> {
) -> Result<usize> {
let mut end = false;
let mut codeIndex = codeIndex;
@@ -679,7 +679,7 @@ fn numericCompaction(
codewords: &[u32],
codeIndex: usize,
result: &mut ECIStringBuilder,
) -> Result<usize, Exceptions> {
) -> Result<usize> {
let mut count = 0;
let mut end = false;
let mut codeIndex = codeIndex;
@@ -767,8 +767,10 @@ fn numericCompaction(
Remove leading 1 => RXingResult is 000213298174000
*/
fn decodeBase900toBase10(codewords: &[u32], count: usize) -> Result<String, Exceptions> {
let mut result = 0.to_biguint().ok_or(Exceptions::arithmetic)?;
fn decodeBase900toBase10(codewords: &[u32], count: usize) -> Result<String> {
let mut result = 0
.to_biguint()
.ok_or(Exceptions::ArithmeticException(None))?;
for i in 0..count {
result +=
&EXP900[count - i - 1] * (codewords[i].to_biguint().ok_or(Exceptions::arithmetic)?);

View File

@@ -17,6 +17,7 @@
use std::rc::Rc;
use crate::{
common::Result,
pdf417::{decoder::ec::ModulusGF, pdf_417_common::NUMBER_OF_CODEWORDS},
Exceptions,
};
@@ -45,11 +46,7 @@ static FLD_INTERIOR: Lazy<ModulusGF> = Lazy::new(|| ModulusGF::new(NUMBER_OF_COD
* @return number of errors
* @throws ChecksumException if errors cannot be corrected, maybe because of too many errors
*/
pub fn decode(
received: &mut [u32],
numECCodewords: u32,
erasures: &mut [u32],
) -> Result<usize, Exceptions> {
pub fn decode(received: &mut [u32], numECCodewords: u32, erasures: &mut [u32]) -> Result<usize> {
let field: &'static ModulusGF = &FLD_INTERIOR;
let poly = ModulusPoly::new(field, received.to_vec())?;
let mut S = vec![0u32; numECCodewords as usize];
@@ -117,7 +114,7 @@ fn runEuclideanAlgorithm(
b: Rc<ModulusPoly>,
R: u32,
field: &'static ModulusGF,
) -> Result<[Rc<ModulusPoly>; 2], Exceptions> {
) -> Result<[Rc<ModulusPoly>; 2]> {
// Assume a's degree is >= b's
let mut a = a;
let mut b = b;
@@ -172,10 +169,7 @@ fn runEuclideanAlgorithm(
Ok([sigma, omega])
}
fn findErrorLocations(
errorLocator: Rc<ModulusPoly>,
field: &ModulusGF,
) -> Result<Vec<u32>, Exceptions> {
fn findErrorLocations(errorLocator: Rc<ModulusPoly>, field: &ModulusGF) -> Result<Vec<u32>> {
// This is a direct application of Chien's search
let numErrors = errorLocator.getDegree();
let mut result = vec![0u32; numErrors as usize];

View File

@@ -16,7 +16,7 @@
use rand::Rng;
use crate::Exceptions;
use crate::common::Result;
use super::{
abstract_error_correction_test_case::{corrupt, getRandom},
@@ -99,11 +99,11 @@ fn testTooManyErrors() {
// }
}
fn checkDecode(received: &mut [u32]) -> Result<(), Exceptions> {
fn checkDecode(received: &mut [u32]) -> Result<()> {
checkDecodeErasures(received, &mut [0_u32; 0])
}
fn checkDecodeErasures(received: &mut [u32], erasures: &mut [u32]) -> Result<(), Exceptions> {
fn checkDecodeErasures(received: &mut [u32], erasures: &mut [u32]) -> Result<()> {
decode(received, ECC_BYTES as u32, erasures)?;
// ec.decode(received, ECC_BYTES, erasures);
for i in 0..PDF417_TEST.len() {

View File

@@ -16,6 +16,7 @@
//public static final ModulusGF PDF417_GF = new ModulusGF(PDF417Common.NUMBER_OF_CODEWORDS, 3);
use crate::common::Result;
use crate::Exceptions;
/**
@@ -75,7 +76,7 @@ impl ModulusGF {
self.expTable[a as usize]
}
pub fn log(&self, a: u32) -> Result<u32, Exceptions> {
pub fn log(&self, a: u32) -> Result<u32> {
if a == 0 {
Err(Exceptions::arithmetic)
} else {
@@ -83,7 +84,7 @@ impl ModulusGF {
}
}
pub fn inverse(&self, a: u32) -> Result<u32, Exceptions> {
pub fn inverse(&self, a: u32) -> Result<u32> {
if a == 0 {
Err(Exceptions::arithmetic)
} else {

View File

@@ -16,6 +16,7 @@
use std::rc::Rc;
use crate::common::Result;
use crate::Exceptions;
use super::ModulusGF;
@@ -31,10 +32,7 @@ pub struct ModulusPoly {
// one: Option<Rc<ModulusPoly>>,
}
impl ModulusPoly {
pub fn new(
field: &'static ModulusGF,
coefficients: Vec<u32>,
) -> Result<ModulusPoly, Exceptions> {
pub fn new(field: &'static ModulusGF, coefficients: Vec<u32>) -> Result<ModulusPoly> {
if coefficients.is_empty() {
return Err(Exceptions::illegalArgument);
}
@@ -124,7 +122,7 @@ impl ModulusPoly {
result
}
pub fn add(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>, Exceptions> {
pub fn add(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>> {
if self.field != other.field {
return Err(Exceptions::illegalArgumentWith(
"ModulusPolys do not have same ModulusGF field",
@@ -158,7 +156,7 @@ impl ModulusPoly {
Ok(Rc::new(ModulusPoly::new(self.field, sumDiff)?))
}
pub fn subtract(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>, Exceptions> {
pub fn subtract(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>> {
if self.field != other.field {
return Err(Exceptions::illegalArgumentWith(
"ModulusPolys do not have same ModulusGF field",
@@ -170,7 +168,7 @@ impl ModulusPoly {
self.add(other.negative())
}
pub fn multiply(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>, Exceptions> {
pub fn multiply(&self, other: Rc<ModulusPoly>) -> Result<Rc<ModulusPoly>> {
if !(self.field == other.field) {
return Err(Exceptions::illegalArgumentWith(
"ModulusPolys do not have same ModulusGF field",

View File

@@ -17,7 +17,7 @@
use std::rc::Rc;
use crate::{
common::{BitMatrix, DecoderRXingResult},
common::{BitMatrix, DecoderRXingResult, Result},
pdf417::pdf_417_common,
Exceptions, RXingResultPoint, ResultPoint,
};
@@ -50,7 +50,7 @@ pub fn decode(
imageBottomRight: Option<RXingResultPoint>,
minCodewordWidth: u32,
maxCodewordWidth: u32,
) -> Result<DecoderRXingResult, Exceptions> {
) -> Result<DecoderRXingResult> {
let mut minCodewordWidth = minCodewordWidth;
let mut maxCodewordWidth = maxCodewordWidth;
let mut boundingBox = Rc::new(BoundingBox::new(
@@ -180,7 +180,7 @@ pub fn decode(
fn merge<'a, T: DetectionRXingResultRowIndicatorColumn>(
leftRowIndicatorColumn: &'a mut Option<T>,
rightRowIndicatorColumn: &'a mut Option<T>,
) -> Result<Option<DetectionRXingResult>, Exceptions> {
) -> Result<Option<DetectionRXingResult>> {
if leftRowIndicatorColumn.is_none() && rightRowIndicatorColumn.is_none() {
return Ok(None);
}
@@ -201,7 +201,7 @@ fn merge<'a, T: DetectionRXingResultRowIndicatorColumn>(
fn adjustBoundingBox<T: DetectionRXingResultRowIndicatorColumn>(
rowIndicatorColumn: &mut Option<T>,
) -> Result<Option<BoundingBox>, Exceptions> {
) -> Result<Option<BoundingBox>> {
if rowIndicatorColumn.is_none() {
return Ok(None);
}
@@ -403,7 +403,7 @@ fn getRowIndicatorColumn<'a>(
fn adjustCodewordCount(
detectionRXingResult: &DetectionRXingResult,
barcodeMatrix: &mut [Vec<BarcodeValue>],
) -> Result<(), Exceptions> {
) -> Result<()> {
let barcodeMatrix01 = &mut barcodeMatrix[0][1];
let numberOfCodewords = barcodeMatrix01.getValue();
let calculatedNumberOfCodewords = (detectionRXingResult.getBarcodeColumnCount() as isize
@@ -426,7 +426,7 @@ fn adjustCodewordCount(
fn createDecoderRXingResult(
detectionRXingResult: &mut DetectionRXingResult,
) -> Result<DecoderRXingResult, Exceptions> {
) -> Result<DecoderRXingResult> {
let mut barcodeMatrix = createBarcodeMatrix(detectionRXingResult);
adjustCodewordCount(detectionRXingResult, &mut barcodeMatrix)?;
let mut erasures = Vec::new();
@@ -488,7 +488,7 @@ fn createDecoderRXingResultFromAmbiguousValues(
erasureArray: &mut [u32],
ambiguousIndexes: &mut [u32],
ambiguousIndexValues: &[Vec<u32>],
) -> Result<DecoderRXingResult, Exceptions> {
) -> Result<DecoderRXingResult> {
let mut ambiguousIndexCount = vec![0; ambiguousIndexes.len()];
let mut tries = 100;
@@ -843,7 +843,7 @@ fn decodeCodewords(
codewords: &mut [u32],
ecLevel: u32,
erasures: &mut [u32],
) -> Result<DecoderRXingResult, Exceptions> {
) -> Result<DecoderRXingResult> {
if codewords.is_empty() {
return Err(Exceptions::format);
}
@@ -874,7 +874,7 @@ fn correctErrors(
codewords: &mut [u32],
erasures: &mut [u32],
numECCodewords: u32,
) -> Result<usize, Exceptions> {
) -> Result<usize> {
if !erasures.is_empty() && erasures.len() as u32 > numECCodewords / 2 + MAX_ERRORS
/*|| numECCodewords < 0*/
|| numECCodewords > MAX_EC_CODEWORDS
@@ -888,7 +888,7 @@ fn correctErrors(
/**
* Verify that all is OK with the codeword array.
*/
fn verifyCodewordCount(codewords: &mut [u32], numECCodewords: u32) -> Result<(), Exceptions> {
fn verifyCodewordCount(codewords: &mut [u32], numECCodewords: u32) -> Result<()> {
if codewords.len() < 4 {
// Codeword array size should be at least 4 allowing for
// Count CW, At least one Data CW, Error Correction CW, Error Correction CW

View File

@@ -15,8 +15,8 @@
*/
use crate::{
common::BitMatrix, BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResultPoint,
ResultPoint,
common::{BitMatrix, Result},
BinaryBitmap, DecodingHintDictionary, Exceptions, RXingResultPoint, ResultPoint,
};
use std::borrow::Cow;
@@ -68,7 +68,7 @@ pub fn detect_with_hints(
image: &mut BinaryBitmap,
_hints: &DecodingHintDictionary,
multiple: bool,
) -> Result<PDF417DetectorRXingResult, Exceptions> {
) -> Result<PDF417DetectorRXingResult> {
// TODO detection improvement, tryHarder could try several different luminance thresholds/blackpoints or even
// different binarizers
//boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
@@ -100,7 +100,7 @@ pub fn detect_with_hints(
* @param rotation the degrees of rotation to apply
* @return BitMatrix with applied rotation
*/
fn applyRotation(matrix: &BitMatrix, rotation: u32) -> Result<Cow<BitMatrix>, Exceptions> {
fn applyRotation(matrix: &BitMatrix, rotation: u32) -> Result<Cow<BitMatrix>> {
if rotation % 360 == 0 {
Ok(Cow::Borrowed(matrix))
} else {

View File

@@ -20,6 +20,7 @@
use encoding::EncodingRef;
use crate::common::Result;
use crate::Exceptions;
use super::{
@@ -133,7 +134,7 @@ impl PDF417 {
r: u32,
errorCorrectionLevel: u32,
logic: &mut BarcodeMatrix,
) -> Result<(), Exceptions> {
) -> Result<()> {
let mut idx = 0;
for y in 0..r {
let cluster = y as usize % 3;
@@ -184,11 +185,7 @@ impl PDF417 {
* @param errorCorrectionLevel PDF417 error correction level to use
* @throws WriterException if the contents cannot be encoded in this format
*/
pub fn generateBarcodeLogic(
&mut self,
msg: &str,
errorCorrectionLevel: u32,
) -> Result<(), Exceptions> {
pub fn generateBarcodeLogic(&mut self, msg: &str, errorCorrectionLevel: u32) -> Result<()> {
self.generateBarcodeLogicWithAutoECI(msg, errorCorrectionLevel, false)
}
@@ -203,7 +200,7 @@ impl PDF417 {
msg: &str,
errorCorrectionLevel: u32,
autoECI: bool,
) -> Result<(), Exceptions> {
) -> Result<()> {
//1. step: High-level encoding
let errorCorrectionCodeWords =
pdf_417_error_correction::getErrorCorrectionCodewordCount(errorCorrectionLevel)?;
@@ -272,7 +269,7 @@ impl PDF417 {
&self,
sourceCodeWords: u32,
errorCorrectionCodeWords: u32,
) -> Result<[u32; 2], Exceptions> {
) -> Result<[u32; 2]> {
let mut ratio = 0.0;
let mut dimension = None;

View File

@@ -24,6 +24,7 @@
*/
use once_cell::sync::Lazy;
use crate::common::Result;
use crate::Exceptions;
/**
@@ -117,7 +118,7 @@ static EC_COEFFICIENTS: Lazy<[Vec<u32>; 9]> = Lazy::new(|| {
* @param errorCorrectionLevel the error correction level (0-8)
* @return the number of codewords generated for error correction
*/
pub fn getErrorCorrectionCodewordCount(errorCorrectionLevel: u32) -> Result<u32, Exceptions> {
pub fn getErrorCorrectionCodewordCount(errorCorrectionLevel: u32) -> Result<u32> {
if errorCorrectionLevel > 8 {
return Err(Exceptions::illegalArgumentWith(
"Error correction level must be between 0 and 8!",
@@ -133,7 +134,7 @@ pub fn getErrorCorrectionCodewordCount(errorCorrectionLevel: u32) -> Result<u32,
* @param n the number of data codewords
* @return the recommended minimum error correction level
*/
pub fn getRecommendedMinimumErrorCorrectionLevel(n: u32) -> Result<u32, Exceptions> {
pub fn getRecommendedMinimumErrorCorrectionLevel(n: u32) -> Result<u32> {
if n == 0 {
Err(Exceptions::illegalArgumentWith("n must be > 0"))
} else if n <= 40 {
@@ -156,10 +157,7 @@ pub fn getRecommendedMinimumErrorCorrectionLevel(n: u32) -> Result<u32, Exceptio
* @param errorCorrectionLevel the error correction level (0-8)
* @return the String representing the error correction codewords
*/
pub fn generateErrorCorrection(
dataCodewords: &str,
errorCorrectionLevel: u32,
) -> Result<String, Exceptions> {
pub fn generateErrorCorrection(dataCodewords: &str, errorCorrectionLevel: u32) -> Result<String> {
let k = getErrorCorrectionCodewordCount(errorCorrectionLevel)?;
let mut e = vec![0 as char; k as usize]; //new char[k];
let sld = dataCodewords.chars().count();

View File

@@ -23,7 +23,7 @@ use std::{any::TypeId, fmt::Display, str::FromStr};
use encoding::EncodingRef;
use crate::{
common::{CharacterSetECI, ECIInput, MinimalECIInput},
common::{CharacterSetECI, ECIInput, MinimalECIInput, Result},
Exceptions,
};
@@ -176,7 +176,7 @@ pub fn encodeHighLevel(
compaction: Compaction,
encoding: Option<EncodingRef>,
autoECI: bool,
) -> Result<String, Exceptions> {
) -> Result<String> {
let mut encoding = encoding;
if msg.is_empty() {
return Err(Exceptions::writerWith("Empty message not allowed"));
@@ -351,7 +351,7 @@ fn encodeText<T: ECIInput + ?Sized>(
count: u32,
sb: &mut String,
initialSubmode: u32,
) -> Result<u32, Exceptions> {
) -> Result<u32> {
let mut tmp = String::with_capacity(count as usize);
let mut submode = initialSubmode;
let mut idx = 0;
@@ -496,7 +496,7 @@ fn encodeMultiECIBinary<T: ECIInput + ?Sized>(
count: u32,
startmode: u32,
sb: &mut String,
) -> Result<(), Exceptions> {
) -> Result<()> {
let end = (startpos + count).min(input.length() as u32);
let mut localStart = startpos;
loop {
@@ -535,11 +535,7 @@ fn encodeMultiECIBinary<T: ECIInput + ?Sized>(
Ok(())
}
pub fn subBytes<T: ECIInput + ?Sized>(
input: &Box<T>,
start: u32,
end: u32,
) -> Result<Vec<u8>, Exceptions> {
pub fn subBytes<T: ECIInput + ?Sized>(input: &Box<T>, start: u32, end: u32) -> Result<Vec<u8>> {
let count = (end - start) as usize;
let mut result = vec![0_u8; count];
for i in start as usize..end as usize {
@@ -565,7 +561,7 @@ fn encodeBinary(
count: u32,
startmode: u32,
sb: &mut String,
) -> Result<(), Exceptions> {
) -> Result<()> {
if count == 1 && startmode == TEXT_COMPACTION {
sb.push(char::from_u32(SHIFT_TO_BYTE).ok_or(Exceptions::parse)?);
} else if (count % 6) == 0 {
@@ -606,7 +602,7 @@ fn encodeNumeric<T: ECIInput + ?Sized>(
startpos: u32,
count: u32,
sb: &mut String,
) -> Result<(), Exceptions> {
) -> Result<()> {
let mut idx = 0;
let mut tmp = String::with_capacity(count as usize / 3 + 1);
let NUM900: num::BigUint = num::BigUint::from(900_u16); //.ok_or(Exceptions::parseEmpty())?;
@@ -686,7 +682,7 @@ fn isText(ch: char) -> bool {
fn determineConsecutiveDigitCount<T: ECIInput + ?Sized>(
input: &Box<T>,
startpos: u32,
) -> Result<u32, Exceptions> {
) -> Result<u32> {
let mut count = 0;
let len = input.length();
let mut idx = startpos as usize;
@@ -710,7 +706,7 @@ fn determineConsecutiveDigitCount<T: ECIInput + ?Sized>(
fn determineConsecutiveTextCount<T: ECIInput + ?Sized>(
input: &Box<T>,
startpos: u32,
) -> Result<u32, Exceptions> {
) -> Result<u32> {
let len = input.length();
let mut idx = startpos as usize;
while idx < len {
@@ -752,7 +748,7 @@ fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
input: &Box<T>,
startpos: u32,
encoding: Option<EncodingRef>,
) -> Result<u32, Exceptions> {
) -> Result<u32> {
let len = input.length();
let mut idx = startpos as usize;
while idx < len {
@@ -795,7 +791,7 @@ fn determineConsecutiveBinaryCount<T: ECIInput + ?Sized + 'static>(
Ok(idx as u32 - startpos)
}
fn encodingECI(eci: i32, sb: &mut String) -> Result<(), Exceptions> {
fn encodingECI(eci: i32, sb: &mut String) -> Result<()> {
if (0..900).contains(&eci) {
sb.push(char::from_u32(ECI_CHARSET).ok_or(Exceptions::parse)?);
sb.push(char::from_u32(eci as u32).ok_or(Exceptions::parse)?);
@@ -820,27 +816,27 @@ impl ECIInput for NoECIInput {
self.0.chars().count()
}
fn charAt(&self, index: usize) -> Result<char, Exceptions> {
fn charAt(&self, index: usize) -> Result<char> {
self.0
.chars()
.nth(index)
.ok_or(Exceptions::indexOutOfBounds)
}
fn subSequence(&self, start: usize, end: usize) -> Result<Vec<char>, Exceptions> {
fn subSequence(&self, start: usize, end: usize) -> Result<Vec<char>> {
let res: Vec<char> = self.0.chars().skip(start).take(end - start).collect();
Ok(res)
}
fn isECI(&self, _index: u32) -> Result<bool, Exceptions> {
fn isECI(&self, _index: u32) -> Result<bool> {
Ok(false)
}
fn getECIValue(&self, _index: usize) -> Result<i32, Exceptions> {
fn getECIValue(&self, _index: usize) -> Result<i32> {
Ok(-1)
}
fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool, Exceptions> {
fn haveNCharacters(&self, index: usize, n: usize) -> Result<bool> {
Ok(index + n <= self.0.len())
}
}

View File

@@ -16,7 +16,7 @@
use encoding::EncodingRef;
use crate::Exceptions;
use crate::common::Result;
use super::{pdf_417_high_level_encoder, Compaction};
@@ -29,6 +29,6 @@ pub fn encodeHighLevel(
compaction: Compaction,
encoding: Option<EncodingRef>,
autoECI: bool,
) -> Result<String, Exceptions> {
) -> Result<String> {
pdf_417_high_level_encoder::encodeHighLevel(msg, compaction, encoding, autoECI)
}

View File

@@ -17,9 +17,9 @@
use std::collections::HashMap;
use crate::{
multi::MultipleBarcodeReader, BarcodeFormat, BinaryBitmap, DecodingHintDictionary, Exceptions,
RXingResult, RXingResultMetadataType, RXingResultMetadataValue, RXingResultPoint, Reader,
ResultPoint,
common::Result, multi::MultipleBarcodeReader, BarcodeFormat, BinaryBitmap,
DecodingHintDictionary, Exceptions, RXingResult, RXingResultMetadataType,
RXingResultMetadataValue, RXingResultPoint, Reader, ResultPoint,
};
use super::{
@@ -43,10 +43,7 @@ impl Reader for PDF417Reader {
* @throws NotFoundException if a PDF417 code cannot be found,
* @throws FormatException if a PDF417 cannot be decoded
*/
fn decode(
&mut self,
image: &mut crate::BinaryBitmap,
) -> Result<crate::RXingResult, crate::Exceptions> {
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult> {
self.decode_with_hints(image, &HashMap::new())
}
@@ -54,7 +51,7 @@ impl Reader for PDF417Reader {
&mut self,
image: &mut crate::BinaryBitmap,
hints: &crate::DecodingHintDictionary,
) -> Result<crate::RXingResult, crate::Exceptions> {
) -> Result<crate::RXingResult> {
let result = Self::decode(image, hints, false)?;
if result.is_empty() {
return Err(Exceptions::notFound);
@@ -67,7 +64,7 @@ impl MultipleBarcodeReader for PDF417Reader {
fn decode_multiple(
&mut self,
image: &mut crate::BinaryBitmap,
) -> Result<Vec<crate::RXingResult>, crate::Exceptions> {
) -> Result<Vec<crate::RXingResult>> {
self.decode_multiple_with_hints(image, &HashMap::new())
}
@@ -75,7 +72,7 @@ impl MultipleBarcodeReader for PDF417Reader {
&mut self,
image: &mut crate::BinaryBitmap,
hints: &crate::DecodingHintDictionary,
) -> Result<Vec<crate::RXingResult>, crate::Exceptions> {
) -> Result<Vec<crate::RXingResult>> {
Self::decode(image, hints, true)
}
}
@@ -89,7 +86,7 @@ impl PDF417Reader {
image: &mut BinaryBitmap,
hints: &DecodingHintDictionary,
multiple: bool,
) -> Result<Vec<RXingResult>, Exceptions> {
) -> Result<Vec<RXingResult>> {
let mut results = Vec::new();
let detectorRXingResult = pdf_417_detector::detect_with_hints(image, hints, multiple)?;

View File

@@ -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 super::encoder::PDF417;
@@ -46,7 +47,7 @@ impl Writer for PDF417Writer {
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())
}
@@ -57,7 +58,7 @@ impl Writer for PDF417Writer {
width: i32,
height: i32,
hints: &crate::EncodingHintDictionary,
) -> Result<crate::common::BitMatrix, crate::Exceptions> {
) -> Result<crate::common::BitMatrix> {
if format != &BarcodeFormat::PDF_417 {
return Err(Exceptions::illegalArgumentWith(format!(
"Can only encode PDF_417, but got {format}"
@@ -142,7 +143,7 @@ impl PDF417Writer {
height: u32,
margin: u32,
autoECI: bool,
) -> Result<BitMatrix, Exceptions> {
) -> Result<BitMatrix> {
encoder.generateBarcodeLogicWithAutoECI(contents, errorCorrectionLevel, autoECI)?;
let aspectRatio = 4;