refactor to use common result type

This commit is contained in:
Vukašin Stepanović
2023-02-14 22:56:03 +00:00
parent 145cf704fe
commit 8ee616d96b
160 changed files with 829 additions and 901 deletions

View File

@@ -16,7 +16,10 @@
use unicode_segmentation::UnicodeSegmentation;
use crate::{common::DecoderRXingResult, Exceptions};
use crate::{
common::{DecoderRXingResult, Result},
Exceptions,
};
use once_cell::sync::Lazy;
/**
@@ -78,7 +81,7 @@ static SETS: Lazy<[String; 5]> = Lazy::new(|| {
]
});
pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult, Exceptions> {
pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult> {
let mut result = String::with_capacity(144);
match mode {
2 | 3 => {

View File

@@ -21,7 +21,7 @@ use once_cell::sync::Lazy;
use crate::{
common::{
reedsolomon::{get_predefined_genericgf, PredefinedGenericGF, ReedSolomonDecoder},
BitMatrix, DecoderRXingResult,
BitMatrix, DecoderRXingResult, Result,
},
DecodingHintDictionary, Exceptions,
};
@@ -45,14 +45,14 @@ static RS_DECODER: Lazy<ReedSolomonDecoder> = Lazy::new(|| {
))
});
pub fn decode(bits: &BitMatrix) -> Result<DecoderRXingResult, Exceptions> {
pub fn decode(bits: &BitMatrix) -> Result<DecoderRXingResult> {
decode_with_hints(bits, &HashMap::new())
}
pub fn decode_with_hints(
bits: &BitMatrix,
_hints: &DecodingHintDictionary,
) -> Result<DecoderRXingResult, Exceptions> {
) -> Result<DecoderRXingResult> {
let parser = BitMatrixParser::new(bits);
let mut codewords = parser.readCodewords();
@@ -88,7 +88,7 @@ fn correctErrors(
dataCodewords: u32,
ecCodewords: u32,
mode: u32,
) -> Result<(), Exceptions> {
) -> Result<()> {
let codewords = dataCodewords + ecCodewords;
// in EVEN or ODD mode only half the codewords

View File

@@ -4,6 +4,7 @@ use num::integer::Roots;
use crate::{
common::{
detector::MathUtils, BitMatrix, DefaultGridSampler, DetectorRXingResult, GridSampler,
Result,
},
Exceptions, RXingResultPoint,
};
@@ -315,7 +316,7 @@ impl Circle<'_> {
}
}
pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionResult, Exceptions> {
pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionResult> {
// find concentric circles
let Some( mut circles) = find_concentric_circles(image) else {
return Err(Exceptions::NotFoundException(None));
@@ -711,10 +712,7 @@ const LEFT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
const RIGHT_SHIFT_PERCENT_ADJUST: f32 = 0.03;
const ACCEPTED_SCALES: [f64; 5] = [0.065, 0.069, 0.07, 0.075, 0.08];
fn box_symbol(
image: &BitMatrix,
circle: &mut Circle,
) -> Result<([(f32, f32); 4], f32), Exceptions> {
fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4], f32)> {
let (left_boundary, right_boundary, top_boundary, bottom_boundary) =
calculate_simple_boundary(circle, Some(image), None, false);
@@ -1051,7 +1049,7 @@ fn compare_circle(a: &Circle, b: &Circle) -> std::cmp::Ordering {
}
/// Read appropriate bits from a bitmatrix for the maxicode decoder
pub fn read_bits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
pub fn read_bits(image: &BitMatrix) -> Result<BitMatrix> {
let enclosingRectangle = image
.getEnclosingRectangle()
.ok_or(Exceptions::NotFoundException(None))?;

View File

@@ -17,7 +17,7 @@
use std::collections::HashMap;
use crate::{
common::{BitMatrix, DetectorRXingResult},
common::{BitMatrix, DetectorRXingResult, Result},
BarcodeFormat, DecodeHintType, DecodeHintValue, Exceptions, RXingResult,
RXingResultMetadataType, Reader,
};
@@ -41,10 +41,7 @@ impl Reader for MaxiCodeReader {
* @throws FormatException if a MaxiCode cannot be decoded
* @throws ChecksumException if error correction fails
*/
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())
}
@@ -60,7 +57,7 @@ impl Reader for MaxiCodeReader {
&mut self,
image: &mut crate::BinaryBitmap,
hints: &crate::DecodingHintDictionary,
) -> Result<crate::RXingResult, crate::Exceptions> {
) -> Result<crate::RXingResult> {
// Note that MaxiCode reader effectively always assumes PURE_BARCODE mode
// and can't detect it in an image
let try_harder = matches!(
@@ -123,7 +120,7 @@ impl MaxiCodeReader {
* around it. This is a specialized method that works exceptionally fast in this special
* case.
*/
fn extractPureBits(image: &BitMatrix) -> Result<BitMatrix, Exceptions> {
fn extractPureBits(image: &BitMatrix) -> Result<BitMatrix> {
let enclosingRectangleOption = image.getEnclosingRectangle();
if enclosingRectangleOption.is_none() {
return Err(Exceptions::NotFoundException(None));