diff --git a/src/multi/MultiTestCase.java b/src/multi/MultiTestCase.java deleted file mode 100644 index 12aa067..0000000 --- a/src/multi/MultiTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.multi; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.nio.file.Path; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.BinaryBitmap; -import com.google.zxing.BufferedImageLuminanceSource; -import com.google.zxing.LuminanceSource; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.RXingResult; -import com.google.zxing.common.AbstractBlackBoxTestCase; -import com.google.zxing.common.HybridBinarizer; -import org.junit.Assert; -import org.junit.Test; - -/** - * Tests {@link MultipleBarcodeReader}. - */ -public final class MultiTestCase extends Assert { - - @Test - public void testMulti() throws Exception { - // Very basic test for now - Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-1"); - - Path testImage = testBase.resolve("1.png"); - BufferedImage image = ImageIO.read(testImage.toFile()); - LuminanceSource source = new BufferedImageLuminanceSource(image); - BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); - - MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader()); - RXingResult[] results = reader.decodeMultiple(bitmap); - assertNotNull(results); - assertEquals(2, results.length); - - assertEquals("031415926531", results[0].getText()); - assertEquals(BarcodeFormat.UPC_A, results[0].getBarcodeFormat()); - - assertEquals("www.airtable.com/jobs", results[1].getText()); - assertEquals(BarcodeFormat.QR_CODE, results[1].getBarcodeFormat()); - } - -} diff --git a/src/multi/generic_multiple_barcode_reader.rs b/src/multi/generic_multiple_barcode_reader.rs index dabdae7..da76189 100644 --- a/src/multi/generic_multiple_barcode_reader.rs +++ b/src/multi/generic_multiple_barcode_reader.rs @@ -53,7 +53,7 @@ impl MultipleBarcodeReader for GenericMultipleBarcodeReader { hints: &crate::DecodingHintDictionary, ) -> Result, crate::Exceptions> { let mut results = Vec::new(); - self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0); + self.doDecodeMultiple(image, hints, &mut results, 0, 0, 0)?; if results.is_empty() { return Err(Exceptions::NotFoundException("".to_owned())); } @@ -76,9 +76,9 @@ impl GenericMultipleBarcodeReader { xOffset: u32, yOffset: u32, currentDepth: u32, - ) { + ) -> Result<(),Exceptions>{ if currentDepth > Self::MAX_DEPTH { - return; + return Ok(()); } let result; @@ -88,7 +88,9 @@ impl GenericMultipleBarcodeReader { // return; //} if let Err(Exceptions::ReaderException(_)) = result { - return; + return Ok(()); + }else if result.is_err(){ + return Err(result.err().unwrap()) } let result = result.expect("must exist"); @@ -108,7 +110,7 @@ impl GenericMultipleBarcodeReader { } if resultPoints.is_empty() { - return; + return Ok(()); } let width = image.getWidth(); let height = image.getHeight(); @@ -145,7 +147,7 @@ impl GenericMultipleBarcodeReader { xOffset, yOffset, currentDepth + 1, - ); + )?; } // Decode above barcode if minY > Self::MIN_DIMENSION_TO_RECUR { @@ -156,7 +158,7 @@ impl GenericMultipleBarcodeReader { xOffset, yOffset, currentDepth + 1, - ); + )?; } // Decode right of barcode if maxX < (width as f32) - Self::MIN_DIMENSION_TO_RECUR { @@ -167,7 +169,7 @@ impl GenericMultipleBarcodeReader { xOffset + maxX as u32, yOffset, currentDepth + 1, - ); + )?; } // Decode below barcode if maxY < (height as f32) - Self::MIN_DIMENSION_TO_RECUR { @@ -178,8 +180,9 @@ impl GenericMultipleBarcodeReader { xOffset, yOffset + maxY as u32, currentDepth + 1, - ); + )?; } + Ok(()) } fn translateRXingResultPoints(result: RXingResult, xOffset: u32, yOffset: u32) -> RXingResult { diff --git a/src/multi/mod.rs b/src/multi/mod.rs index c79949c..1ec5bad 100644 --- a/src/multi/mod.rs +++ b/src/multi/mod.rs @@ -7,3 +7,6 @@ pub use by_quadrant_reader::*; mod generic_multiple_barcode_reader; pub use generic_multiple_barcode_reader::*; + +#[cfg(test)] +mod multi_test_case; \ No newline at end of file diff --git a/src/multi/multi_test_case.rs b/src/multi/multi_test_case.rs new file mode 100644 index 0000000..58cf2c1 --- /dev/null +++ b/src/multi/multi_test_case.rs @@ -0,0 +1,50 @@ +/* + * Copyright 2016 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use std::{path::PathBuf, rc::Rc}; + +use crate::{BufferedImageLuminanceSource, BinaryBitmap, common::HybridBinarizer, MultiFormatReader, BarcodeFormat}; + +use super::{GenericMultipleBarcodeReader, MultipleBarcodeReader}; + +/** + * Tests {@link MultipleBarcodeReader}. + */ + + #[test] + fn testMulti() { + // Very basic test for now + let mut testBase = PathBuf::from("test_resources/blackbox/multi-1"); + + testBase.push("1.png"); + let image = image::io::Reader::open(testBase) + .expect("image must open") + .decode() + .expect("must decode"); + let source = BufferedImageLuminanceSource::new(image); + let bitmap = BinaryBitmap::new( Rc::new(HybridBinarizer::new(Box::new(source)))); + + let mut reader = GenericMultipleBarcodeReader::new( MultiFormatReader::default()); + let results = reader.decodeMultiple(&bitmap).expect("must decode multi"); + // assertNotNull(results); + assert_eq!(2, results.len()); + + assert_eq!("031415926531", results[0].getText()); + assert_eq!(&BarcodeFormat::UPC_A, results[0].getBarcodeFormat()); + + assert_eq!("www.airtable.com/jobs", results[1].getText()); + assert_eq!(&BarcodeFormat::QR_CODE, results[1].getBarcodeFormat()); + } diff --git a/src/multi_format_reader.rs b/src/multi_format_reader.rs index 49cda3e..b6b8646 100644 --- a/src/multi_format_reader.rs +++ b/src/multi_format_reader.rs @@ -80,7 +80,6 @@ impl Reader for MultiFormatReader { } impl MultiFormatReader { - const EMPTY_READER_ARRAY: Vec> = Vec::new(); /** * Decode an image using the state set up by calling setHints() previously. Continuous scan