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:
@@ -6,7 +6,7 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
common::{BitMatrix, HybridBinarizer},
|
||||
common::{BitMatrix, HybridBinarizer, Result},
|
||||
multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
|
||||
BarcodeFormat, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary,
|
||||
Exceptions, Luma8LuminanceSource, MultiFormatReader, RXingResult, Reader,
|
||||
@@ -16,10 +16,7 @@ use crate::{
|
||||
use crate::BufferedImageLuminanceSource;
|
||||
|
||||
#[cfg(feature = "svg_read")]
|
||||
pub fn detect_in_svg(
|
||||
file_name: &str,
|
||||
barcode_type: Option<BarcodeFormat>,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
pub fn detect_in_svg(file_name: &str, barcode_type: Option<BarcodeFormat>) -> Result<RXingResult> {
|
||||
detect_in_svg_with_hints(file_name, barcode_type, &mut HashMap::new())
|
||||
}
|
||||
|
||||
@@ -28,7 +25,7 @@ pub fn detect_in_svg_with_hints(
|
||||
file_name: &str,
|
||||
barcode_type: Option<BarcodeFormat>,
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
use crate::SVGLuminanceSource;
|
||||
@@ -69,7 +66,7 @@ pub fn detect_in_svg_with_hints(
|
||||
}
|
||||
|
||||
#[cfg(feature = "svg_read")]
|
||||
pub fn detect_multiple_in_svg(file_name: &str) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
pub fn detect_multiple_in_svg(file_name: &str) -> Result<Vec<RXingResult>> {
|
||||
detect_multiple_in_svg_with_hints(file_name, &mut HashMap::new())
|
||||
}
|
||||
|
||||
@@ -77,7 +74,7 @@ pub fn detect_multiple_in_svg(file_name: &str) -> Result<Vec<RXingResult>, Excep
|
||||
pub fn detect_multiple_in_svg_with_hints(
|
||||
file_name: &str,
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
) -> Result<Vec<RXingResult>> {
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
use crate::SVGLuminanceSource;
|
||||
@@ -112,10 +109,7 @@ pub fn detect_multiple_in_svg_with_hints(
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
pub fn detect_in_file(
|
||||
file_name: &str,
|
||||
barcode_type: Option<BarcodeFormat>,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
pub fn detect_in_file(file_name: &str, barcode_type: Option<BarcodeFormat>) -> Result<RXingResult> {
|
||||
detect_in_file_with_hints(file_name, barcode_type, &mut HashMap::new())
|
||||
}
|
||||
|
||||
@@ -124,7 +118,7 @@ pub fn detect_in_file_with_hints(
|
||||
file_name: &str,
|
||||
barcode_type: Option<BarcodeFormat>,
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let Ok(img) = image::open(file_name) else {
|
||||
return Err(Exceptions::illegalArgumentWith(format!("file '{file_name}' not found or cannot be opened")));
|
||||
};
|
||||
@@ -150,7 +144,7 @@ pub fn detect_in_file_with_hints(
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
pub fn detect_multiple_in_file(file_name: &str) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
pub fn detect_multiple_in_file(file_name: &str) -> Result<Vec<RXingResult>> {
|
||||
detect_multiple_in_file_with_hints(file_name, &mut HashMap::new())
|
||||
}
|
||||
|
||||
@@ -158,9 +152,10 @@ pub fn detect_multiple_in_file(file_name: &str) -> Result<Vec<RXingResult>, Exce
|
||||
pub fn detect_multiple_in_file_with_hints(
|
||||
file_name: &str,
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
let img = image::open(file_name)
|
||||
.map_err(|e| Exceptions::runtimeWith(format!("couldn't read {file_name}: {e}")))?;
|
||||
) -> Result<Vec<RXingResult>> {
|
||||
let img = image::open(file_name).map_err(|e| {
|
||||
Exceptions::RuntimeException(Some(format!("couldn't read {file_name}: {e}")))
|
||||
})?;
|
||||
let multi_format_reader = MultiFormatReader::default();
|
||||
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
||||
|
||||
@@ -181,7 +176,7 @@ pub fn detect_in_luma(
|
||||
width: u32,
|
||||
height: u32,
|
||||
barcode_type: Option<BarcodeFormat>,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
detect_in_luma_with_hints(luma, height, width, barcode_type, &mut HashMap::new())
|
||||
}
|
||||
|
||||
@@ -191,7 +186,7 @@ pub fn detect_in_luma_with_hints(
|
||||
height: u32,
|
||||
barcode_type: Option<BarcodeFormat>,
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<RXingResult, Exceptions> {
|
||||
) -> Result<RXingResult> {
|
||||
let mut multi_format_reader = MultiFormatReader::default();
|
||||
|
||||
if let Some(bc_type) = barcode_type {
|
||||
@@ -213,11 +208,7 @@ pub fn detect_in_luma_with_hints(
|
||||
)
|
||||
}
|
||||
|
||||
pub fn detect_multiple_in_luma(
|
||||
luma: Vec<u8>,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
pub fn detect_multiple_in_luma(luma: Vec<u8>, width: u32, height: u32) -> Result<Vec<RXingResult>> {
|
||||
detect_multiple_in_luma_with_hints(luma, width, height, &mut HashMap::new())
|
||||
}
|
||||
|
||||
@@ -226,7 +217,7 @@ pub fn detect_multiple_in_luma_with_hints(
|
||||
width: u32,
|
||||
height: u32,
|
||||
hints: &mut DecodingHintDictionary,
|
||||
) -> Result<Vec<RXingResult>, Exceptions> {
|
||||
) -> Result<Vec<RXingResult>> {
|
||||
let multi_format_reader = MultiFormatReader::default();
|
||||
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
|
||||
|
||||
@@ -243,7 +234,7 @@ pub fn detect_multiple_in_luma_with_hints(
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
pub fn save_image(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exceptions> {
|
||||
pub fn save_image(file_name: &str, bit_matrix: &BitMatrix) -> Result<()> {
|
||||
let image: image::DynamicImage = bit_matrix.into();
|
||||
match image.save(file_name) {
|
||||
Ok(_) => Ok(()),
|
||||
@@ -254,7 +245,7 @@ pub fn save_image(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Excepti
|
||||
}
|
||||
|
||||
#[cfg(feature = "svg_write")]
|
||||
pub fn save_svg(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exceptions> {
|
||||
pub fn save_svg(file_name: &str, bit_matrix: &BitMatrix) -> Result<()> {
|
||||
let svg: svg::Document = bit_matrix.into();
|
||||
|
||||
match svg::save(file_name, &svg) {
|
||||
@@ -266,7 +257,7 @@ pub fn save_svg(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exception
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_file(file_name: &str, bit_matrix: &BitMatrix) -> Result<(), Exceptions> {
|
||||
pub fn save_file(file_name: &str, bit_matrix: &BitMatrix) -> Result<()> {
|
||||
let path = PathBuf::from(file_name);
|
||||
|
||||
#[allow(unused_variables)]
|
||||
|
||||
Reference in New Issue
Block a user