basic luma8 source

This commit is contained in:
Henry
2023-01-04 17:50:27 -06:00
parent 8481cb4542
commit 6e81b22054
4 changed files with 118 additions and 10 deletions

View File

@@ -8,7 +8,8 @@ use crate::{
common::HybridBinarizer,
multi::{GenericMultipleBarcodeReader, MultipleBarcodeReader},
BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, DecodeHintType, DecodeHintValue,
DecodingHintDictionary, Exceptions, MultiFormatReader, RXingResult, Reader,
DecodingHintDictionary, Exceptions, Luma8LuminanceSource, MultiFormatReader, RXingResult,
Reader,
};
#[cfg(feature = "image")]
@@ -74,27 +75,67 @@ pub fn detect_multiple_in_file_with_hints(
}
pub fn detect_in_luma(
luma: &[u8],
luma: Vec<u8>,
width: u32,
height: u32,
barcode_type: Option<BarcodeFormat>,
) -> Result<RXingResult, Exceptions> {
detect_in_luma_with_hints(luma, barcode_type, &mut HashMap::new())
detect_in_luma_with_hints(luma, height, width, barcode_type, &mut HashMap::new())
}
pub fn detect_in_luma_with_hints(
luma: &[u8],
luma: Vec<u8>,
width: u32,
height: u32,
barcode_type: Option<BarcodeFormat>,
hints: &mut DecodingHintDictionary,
) -> Result<RXingResult, Exceptions> {
Err(Exceptions::NotFoundException(None))
let mut multi_format_reader = MultiFormatReader::default();
if let Some(bc_type) = barcode_type {
hints.insert(
DecodeHintType::POSSIBLE_FORMATS,
DecodeHintValue::PossibleFormats(HashSet::from([bc_type])),
);
}
if !hints.contains_key(&DecodeHintType::TRY_HARDER) {
hints.insert(DecodeHintType::TRY_HARDER, DecodeHintValue::TryHarder(true));
}
multi_format_reader.decode_with_hints(
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
Luma8LuminanceSource::new(luma, width, height),
))))),
&hints,
)
}
pub fn detect_multiple_in_luma(luma: &[u8]) -> Result<Vec<RXingResult>, Exceptions> {
detect_multiple_in_luma_with_hints(luma, &mut HashMap::new())
pub fn detect_multiple_in_luma(
luma: Vec<u8>,
width: u32,
height: u32,
) -> Result<Vec<RXingResult>, Exceptions> {
detect_multiple_in_luma_with_hints(luma, width, height, &mut HashMap::new())
}
pub fn detect_multiple_in_luma_with_hints(
file_name: &[u8],
luma: Vec<u8>,
width: u32,
height: u32,
hints: &mut DecodingHintDictionary,
) -> Result<Vec<RXingResult>, Exceptions> {
Err(Exceptions::NotFoundException(None))
let multi_format_reader = MultiFormatReader::default();
let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader);
if !hints.contains_key(&DecodeHintType::TRY_HARDER) {
hints.insert(DecodeHintType::TRY_HARDER, DecodeHintValue::TryHarder(true));
}
scanner.decode_multiple_with_hints(
&mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new(
Luma8LuminanceSource::new(luma, width, height),
))))),
&hints,
)
}