Initial generics

This commit is contained in:
Steve Cook
2023-03-01 22:08:12 -05:00
parent 26325928e7
commit a9bc58108c
65 changed files with 1013 additions and 883 deletions

View File

@@ -17,7 +17,7 @@
use std::collections::HashMap;
use crate::common::Result;
use crate::{point, Exceptions, Point, RXingResult, Reader};
use crate::{point, Binarizer, Exceptions, Point, RXingResult, Reader};
/**
* This class attempts to decode a barcode from an image, not by scanning the whole image,
@@ -30,17 +30,17 @@ use crate::{point, Exceptions, Point, RXingResult, Reader};
*/
pub struct ByQuadrantReader<T: Reader>(T);
impl<T: Reader> Reader for ByQuadrantReader<T> {
fn decode(&mut self, image: &mut crate::BinaryBitmap) -> Result<crate::RXingResult> {
fn decode<B: Binarizer>(&mut self, image: &mut crate::BinaryBitmap<B>) -> Result<RXingResult> {
self.decode_with_hints(image, &HashMap::new())
}
fn decode_with_hints(
fn decode_with_hints<B: Binarizer>(
&mut self,
image: &mut crate::BinaryBitmap,
image: &mut crate::BinaryBitmap<B>,
hints: &crate::DecodingHintDictionary,
) -> Result<crate::RXingResult> {
let width = image.getWidth();
let height = image.getHeight();
let width = image.get_width();
let height = image.get_height();
let halfWidth = width / 2;
let halfHeight = height / 2;

View File

@@ -17,8 +17,8 @@
use std::collections::HashMap;
use crate::{
common::Result, point, BinaryBitmap, DecodingHintDictionary, Exceptions, Point, RXingResult,
Reader,
common::Result, point, Binarizer, BinaryBitmap, DecodingHintDictionary, Exceptions, Point,
RXingResult, Reader,
};
use super::MultipleBarcodeReader;
@@ -41,20 +41,20 @@ use super::MultipleBarcodeReader;
pub struct GenericMultipleBarcodeReader<T: Reader>(T);
impl<T: Reader> MultipleBarcodeReader for GenericMultipleBarcodeReader<T> {
fn decode_multiple(
fn decode_multiple<B: Binarizer>(
&mut self,
image: &mut crate::BinaryBitmap,
) -> Result<Vec<crate::RXingResult>> {
image: &mut BinaryBitmap<B>,
) -> Result<Vec<RXingResult>> {
self.decode_multiple_with_hints(image, &HashMap::new())
}
fn decode_multiple_with_hints(
fn decode_multiple_with_hints<B: Binarizer>(
&mut self,
image: &mut crate::BinaryBitmap,
hints: &crate::DecodingHintDictionary,
) -> Result<Vec<crate::RXingResult>> {
image: &mut BinaryBitmap<B>,
hints: &DecodingHintDictionary,
) -> Result<Vec<RXingResult>> {
let mut results = Vec::new();
self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0);
self.do_decode_multiple(image, hints, &mut results, 0, 0, 0);
if results.is_empty() {
return Err(Exceptions::NOT_FOUND);
}
@@ -69,9 +69,9 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
Self(delegate)
}
fn doDecodeMultiple(
fn do_decode_multiple<B: Binarizer>(
&mut self,
image: &mut BinaryBitmap,
image: &mut BinaryBitmap<B>,
hints: &DecodingHintDictionary,
results: &mut Vec<RXingResult>,
xOffset: u32,
@@ -105,8 +105,8 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
return;
}
let width = image.getWidth();
let height = image.getHeight();
let width = image.get_width();
let height = image.get_height();
let mut minX: f32 = width as f32;
let mut minY: f32 = height as f32;
let mut maxX: f32 = 0.0;
@@ -133,7 +133,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
// Decode left of barcode
if minX > Self::MIN_DIMENSION_TO_RECUR {
self.doDecodeMultiple(
self.do_decode_multiple(
&mut image.crop(0, 0, minX as usize, height),
hints,
results,
@@ -144,7 +144,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
}
// Decode above barcode
if minY > Self::MIN_DIMENSION_TO_RECUR {
self.doDecodeMultiple(
self.do_decode_multiple(
&mut image.crop(0, 0, width, minY as usize),
hints,
results,
@@ -155,7 +155,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
}
// Decode right of barcode
if maxX < (width as f32) - Self::MIN_DIMENSION_TO_RECUR {
self.doDecodeMultiple(
self.do_decode_multiple(
&mut image.crop(maxX as usize, 0, width - maxX as usize, height),
hints,
results,
@@ -166,7 +166,7 @@ impl<T: Reader> GenericMultipleBarcodeReader<T> {
}
// Decode below barcode
if maxY < (height as f32) - Self::MIN_DIMENSION_TO_RECUR {
self.doDecodeMultiple(
self.do_decode_multiple(
&mut image.crop(0, maxY as usize, width, height - maxY as usize),
hints,
results,

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
use crate::{common::Result, BinaryBitmap, DecodingHintDictionary, RXingResult};
use crate::{common::Result, Binarizer, BinaryBitmap, DecodingHintDictionary, RXingResult};
/**
* Implementation of this interface attempt to read several barcodes from one image.
@@ -23,11 +23,14 @@ use crate::{common::Result, BinaryBitmap, DecodingHintDictionary, RXingResult};
* @author Sean Owen
*/
pub trait MultipleBarcodeReader {
fn decode_multiple(&mut self, image: &mut BinaryBitmap) -> Result<Vec<RXingResult>>;
fn decode_multiple_with_hints(
fn decode_multiple<B: Binarizer>(
&mut self,
image: &mut BinaryBitmap,
image: &mut BinaryBitmap<B>,
) -> Result<Vec<RXingResult>>;
fn decode_multiple_with_hints<B: Binarizer>(
&mut self,
image: &mut BinaryBitmap<B>,
hints: &DecodingHintDictionary,
) -> Result<Vec<RXingResult>>;
}

View File

@@ -23,7 +23,8 @@ use crate::{
decoder::{self, QRCodeDecoderMetaData},
QRCodeReader,
},
BarcodeFormat, Exceptions, RXingResult, RXingResultMetadataType, RXingResultMetadataValue,
BarcodeFormat, Binarizer, Exceptions, RXingResult, RXingResultMetadataType,
RXingResultMetadataValue,
};
use super::detector::MultiDetector;
@@ -37,20 +38,21 @@ use super::detector::MultiDetector;
#[derive(Default)]
pub struct QRCodeMultiReader(QRCodeReader);
impl MultipleBarcodeReader for QRCodeMultiReader {
fn decode_multiple(
fn decode_multiple<B: Binarizer>(
&mut self,
image: &mut crate::BinaryBitmap,
) -> Result<Vec<crate::RXingResult>> {
image: &mut crate::BinaryBitmap<B>,
) -> Result<Vec<RXingResult>> {
self.decode_multiple_with_hints(image, &HashMap::new())
}
fn decode_multiple_with_hints(
fn decode_multiple_with_hints<B: Binarizer>(
&mut self,
image: &mut crate::BinaryBitmap,
image: &mut crate::BinaryBitmap<B>,
hints: &crate::DecodingHintDictionary,
) -> Result<Vec<crate::RXingResult>> {
) -> Result<Vec<RXingResult>> {
let mut results = Vec::new();
let detectorRXingResults = MultiDetector::new(image.getBlackMatrix()).detectMulti(hints)?;
let detectorRXingResults =
MultiDetector::new(image.get_black_matrix()).detectMulti(hints)?;
for detectorRXingResult in detectorRXingResults {
let mut proc = || -> Result<()> {
let decoderRXingResult = decoder::qrcode_decoder::decode_bitmatrix_with_hints(