diff --git a/src/multi_format_reader.rs b/src/multi_format_reader.rs index f1e273c..da1963e 100644 --- a/src/multi_format_reader.rs +++ b/src/multi_format_reader.rs @@ -18,8 +18,9 @@ use std::collections::HashMap; use crate::{ aztec::AztecReader, datamatrix::DataMatrixReader, maxicode::MaxiCodeReader, - oned::MultiFormatOneDReader, qrcode::QRCodeReader, BarcodeFormat, BinaryBitmap, DecodeHintType, - DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult, Reader, + oned::MultiFormatOneDReader, pdf417::PDF417Reader, qrcode::QRCodeReader, BarcodeFormat, + BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult, + Reader, }; /** @@ -136,8 +137,7 @@ impl MultiFormatReader { readers.push(Box::new(AztecReader {})); } if formats.contains(&BarcodeFormat::PDF_417) { - unimplemented!(""); - // readers.push(new PDF417Reader()); + readers.push(Box::new(PDF417Reader {})); } if formats.contains(&BarcodeFormat::MAXICODE) { readers.push(Box::new(MaxiCodeReader {})); @@ -150,19 +150,17 @@ impl MultiFormatReader { if readers.is_empty() { if !tryHarder { readers.push(Box::new(MultiFormatOneDReader::new(hints))); - //TODO: ADD MultiformatOneDReader here } readers.push(Box::new(QRCodeReader {})); readers.push(Box::new(DataMatrixReader {})); readers.push(Box::new(AztecReader {})); - // readers.push( PDF417Reader()); + readers.push(Box::new(PDF417Reader {})); readers.push(Box::new(MaxiCodeReader {})); // unimplemented!(""); if tryHarder { readers.push(Box::new(MultiFormatOneDReader::new(hints))); - //TODO: ADD MultiformatOneDReader here } } self.readers = readers; //Vec::new(); //readers.toArray(EMPTY_READER_ARRAY); diff --git a/src/pdf417/decoder/pdf_417_scanning_decoder.rs b/src/pdf417/decoder/pdf_417_scanning_decoder.rs index 282ec38..342f880 100644 --- a/src/pdf417/decoder/pdf_417_scanning_decoder.rs +++ b/src/pdf417/decoder/pdf_417_scanning_decoder.rs @@ -803,7 +803,7 @@ fn adjustCodewordStartColumn( { return codewordStartColumn; } - correctedStartColumn += increment as u32; + correctedStartColumn = (correctedStartColumn as i32 + increment) as u32; } increment = -increment; leftToRight = !leftToRight; @@ -893,7 +893,7 @@ fn getBitCountForCodeword(codeword: u32) -> [u32; 8] { let mut codeword = codeword; let mut result = [0; 8]; //new int[8]; let mut previousValue = 0; - let mut i = result.len() - 1; + let mut i = result.len() as isize - 1; loop { if (codeword & 0x1) != previousValue { previousValue = codeword & 0x1; @@ -902,7 +902,7 @@ fn getBitCountForCodeword(codeword: u32) -> [u32; 8] { break; } } - result[i] += 1; + result[i as usize ] += 1; codeword >>= 1; } diff --git a/tests/PDF417BlackBox1TestCase.java b/tests/PDF417BlackBox1TestCase.java deleted file mode 100644 index c5292b4..0000000 --- a/tests/PDF417BlackBox1TestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2008 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.pdf417; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.common.AbstractBlackBoxTestCase; - -/** - * This test consists of perfect, computer-generated images. We should have 100% passing. - * - * @author SITA Lab (kevin.osullivan@sita.aero) - */ -public final class PDF417BlackBox1TestCase extends AbstractBlackBoxTestCase { - - public PDF417BlackBox1TestCase() { - super("src/test/resources/blackbox/pdf417-1", new MultiFormatReader(), BarcodeFormat.PDF_417); - addTest(10, 10, 0.0f); - addTest(10, 10, 90.0f); - addTest(10, 10, 180.0f); - addTest(10, 10, 270.0f); - } - -} \ No newline at end of file diff --git a/tests/PDF417BlackBox2TestCase.java b/tests/PDF417BlackBox2TestCase.java deleted file mode 100644 index cb7a60d..0000000 --- a/tests/PDF417BlackBox2TestCase.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2009 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.pdf417; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.common.AbstractBlackBoxTestCase; - -/** - * This test contains 480x240 images captured from an Android device at preview resolution. - * - * @author dswitkin@google.com (Daniel Switkin) - */ -public final class PDF417BlackBox2TestCase extends AbstractBlackBoxTestCase { - - public PDF417BlackBox2TestCase() { - super("src/test/resources/blackbox/pdf417-2", new MultiFormatReader(), BarcodeFormat.PDF_417); - addTest(25, 25, 0, 0, 0.0f); - addTest(25, 25, 0, 0, 180.0f); - } - -} diff --git a/tests/PDF417BlackBox3TestCase.java b/tests/PDF417BlackBox3TestCase.java deleted file mode 100644 index 192b877..0000000 --- a/tests/PDF417BlackBox3TestCase.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2009 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.pdf417; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.common.AbstractBlackBoxTestCase; - -/** - * Tests {@link PDF417Reader} against more sample images. - */ -public final class PDF417BlackBox3TestCase extends AbstractBlackBoxTestCase { - - public PDF417BlackBox3TestCase() { - super("src/test/resources/blackbox/pdf417-3", new MultiFormatReader(), BarcodeFormat.PDF_417); - addTest(19, 19, 0, 0, 0.0f); - addTest(19, 19, 0, 0, 180.0f); - } - -} diff --git a/tests/common/abstract_black_box_test_case.rs b/tests/common/abstract_black_box_test_case.rs index f335480..a267795 100644 --- a/tests/common/abstract_black_box_test_case.rs +++ b/tests/common/abstract_black_box_test_case.rs @@ -23,7 +23,7 @@ use std::{ use rxing::{ common::HybridBinarizer, BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, - DecodeHintType, DecodeHintValue, RXingResultMetadataType, RXingResultMetadataValue, Reader, + DecodeHintType, DecodeHintValue, RXingResultMetadataType, RXingResultMetadataValue, Reader, pdf417::PDF417RXingResultMetadata, }; use super::TestRXingResult; @@ -208,7 +208,7 @@ impl AbstractBlackBoxTestCase { RXingResultMetadataValue::UpcEanExtension(v) } RXingResultMetadataType::PDF417_EXTRA_METADATA => { - RXingResultMetadataValue::Pdf417ExtraMetadata(v) + RXingResultMetadataValue::Pdf417ExtraMetadata(Rc::new(PDF417RXingResultMetadata::default())) } RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE => { RXingResultMetadataValue::StructuredAppendSequence( @@ -222,7 +222,7 @@ impl AbstractBlackBoxTestCase { } RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => { RXingResultMetadataValue::SymbologyIdentifier(v) - } + }, }; } diff --git a/tests/pdf_417_blackbox_tests.rs b/tests/pdf_417_blackbox_tests.rs new file mode 100644 index 0000000..b85b1e7 --- /dev/null +++ b/tests/pdf_417_blackbox_tests.rs @@ -0,0 +1,58 @@ +use rxing::{qrcode::QRCodeReader, BarcodeFormat, MultiFormatReader}; + +mod common; + +/** + * This test consists of perfect, computer-generated images. We should have 100% passing. + * + * @author SITA Lab (kevin.osullivan@sita.aero) + */ +#[test] +fn pdf417_black_box1_test_case() { + let mut tester = common::AbstractBlackBoxTestCase::new( + "test_resources/blackbox/pdf417-1", + MultiFormatReader::default(), + rxing::BarcodeFormat::PDF_417, + ); + // super("src/test/resources/blackbox/pdf417-1", new MultiFormatReader(), BarcodeFormat.PDF_417); + tester.add_test(10, 10, 0.0); + tester.add_test(10, 10, 90.0); + tester.add_test(10, 10, 180.0); + tester.add_test(10, 10, 270.0); + + tester.test_black_box() +} + +/** + * This test contains 480x240 images captured from an Android device at preview resolution. + * + * @author dswitkin@google.com (Daniel Switkin) + */ +#[test] +fn pdf417_black_box2_test_case() { + let mut tester = common::AbstractBlackBoxTestCase::new( + "test_resources/blackbox/pdf417-2", + MultiFormatReader::default(), + rxing::BarcodeFormat::PDF_417, + ); + // super("src/test/resources/blackbox/pdf417-2", new MultiFormatReader(), BarcodeFormat.PDF_417); + tester.add_test_complex(25, 25, 0, 0, 0.0); + tester.add_test_complex(25, 25, 0, 0, 180.0); + tester.test_black_box() +} + +/** + * Tests {@link PDF417Reader} against more sample images. + */ +#[test] +fn pdf417_black_box3_test_case() { + let mut tester = common::AbstractBlackBoxTestCase::new( + "test_resources/blackbox/pdf417-3", + MultiFormatReader::default(), + rxing::BarcodeFormat::PDF_417, + ); + // super("src/test/resources/blackbox/pdf417-3", new MultiFormatReader(), BarcodeFormat.PDF_417); + tester.add_test_complex(19, 19, 0, 0, 0.0); + tester.add_test_complex(19, 19, 0, 0, 180.0); + tester.test_black_box() +}