mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
basic luma8 source
This commit is contained in:
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user