port integration for pdf 417 1-3

This commit is contained in:
Henry Schimke
2022-12-26 14:22:37 -06:00
parent 3021c163d4
commit cba6a10c4b
7 changed files with 69 additions and 121 deletions

View File

@@ -18,8 +18,9 @@ use std::collections::HashMap;
use crate::{ use crate::{
aztec::AztecReader, datamatrix::DataMatrixReader, maxicode::MaxiCodeReader, aztec::AztecReader, datamatrix::DataMatrixReader, maxicode::MaxiCodeReader,
oned::MultiFormatOneDReader, qrcode::QRCodeReader, BarcodeFormat, BinaryBitmap, DecodeHintType, oned::MultiFormatOneDReader, pdf417::PDF417Reader, qrcode::QRCodeReader, BarcodeFormat,
DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult, Reader, BinaryBitmap, DecodeHintType, DecodeHintValue, DecodingHintDictionary, Exceptions, RXingResult,
Reader,
}; };
/** /**
@@ -136,8 +137,7 @@ impl MultiFormatReader {
readers.push(Box::new(AztecReader {})); readers.push(Box::new(AztecReader {}));
} }
if formats.contains(&BarcodeFormat::PDF_417) { if formats.contains(&BarcodeFormat::PDF_417) {
unimplemented!(""); readers.push(Box::new(PDF417Reader {}));
// readers.push(new PDF417Reader());
} }
if formats.contains(&BarcodeFormat::MAXICODE) { if formats.contains(&BarcodeFormat::MAXICODE) {
readers.push(Box::new(MaxiCodeReader {})); readers.push(Box::new(MaxiCodeReader {}));
@@ -150,19 +150,17 @@ impl MultiFormatReader {
if readers.is_empty() { if readers.is_empty() {
if !tryHarder { if !tryHarder {
readers.push(Box::new(MultiFormatOneDReader::new(hints))); readers.push(Box::new(MultiFormatOneDReader::new(hints)));
//TODO: ADD MultiformatOneDReader here
} }
readers.push(Box::new(QRCodeReader {})); readers.push(Box::new(QRCodeReader {}));
readers.push(Box::new(DataMatrixReader {})); readers.push(Box::new(DataMatrixReader {}));
readers.push(Box::new(AztecReader {})); readers.push(Box::new(AztecReader {}));
// readers.push( PDF417Reader()); readers.push(Box::new(PDF417Reader {}));
readers.push(Box::new(MaxiCodeReader {})); readers.push(Box::new(MaxiCodeReader {}));
// unimplemented!(""); // unimplemented!("");
if tryHarder { if tryHarder {
readers.push(Box::new(MultiFormatOneDReader::new(hints))); readers.push(Box::new(MultiFormatOneDReader::new(hints)));
//TODO: ADD MultiformatOneDReader here
} }
} }
self.readers = readers; //Vec::new(); //readers.toArray(EMPTY_READER_ARRAY); self.readers = readers; //Vec::new(); //readers.toArray(EMPTY_READER_ARRAY);

View File

@@ -803,7 +803,7 @@ fn adjustCodewordStartColumn(
{ {
return codewordStartColumn; return codewordStartColumn;
} }
correctedStartColumn += increment as u32; correctedStartColumn = (correctedStartColumn as i32 + increment) as u32;
} }
increment = -increment; increment = -increment;
leftToRight = !leftToRight; leftToRight = !leftToRight;
@@ -893,7 +893,7 @@ fn getBitCountForCodeword(codeword: u32) -> [u32; 8] {
let mut codeword = codeword; let mut codeword = codeword;
let mut result = [0; 8]; //new int[8]; let mut result = [0; 8]; //new int[8];
let mut previousValue = 0; let mut previousValue = 0;
let mut i = result.len() - 1; let mut i = result.len() as isize - 1;
loop { loop {
if (codeword & 0x1) != previousValue { if (codeword & 0x1) != previousValue {
previousValue = codeword & 0x1; previousValue = codeword & 0x1;
@@ -902,7 +902,7 @@ fn getBitCountForCodeword(codeword: u32) -> [u32; 8] {
break; break;
} }
} }
result[i] += 1; result[i as usize ] += 1;
codeword >>= 1; codeword >>= 1;
} }

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -23,7 +23,7 @@ use std::{
use rxing::{ use rxing::{
common::HybridBinarizer, BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource, common::HybridBinarizer, BarcodeFormat, BinaryBitmap, BufferedImageLuminanceSource,
DecodeHintType, DecodeHintValue, RXingResultMetadataType, RXingResultMetadataValue, Reader, DecodeHintType, DecodeHintValue, RXingResultMetadataType, RXingResultMetadataValue, Reader, pdf417::PDF417RXingResultMetadata,
}; };
use super::TestRXingResult; use super::TestRXingResult;
@@ -208,7 +208,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
RXingResultMetadataValue::UpcEanExtension(v) RXingResultMetadataValue::UpcEanExtension(v)
} }
RXingResultMetadataType::PDF417_EXTRA_METADATA => { RXingResultMetadataType::PDF417_EXTRA_METADATA => {
RXingResultMetadataValue::Pdf417ExtraMetadata(v) RXingResultMetadataValue::Pdf417ExtraMetadata(Rc::new(PDF417RXingResultMetadata::default()))
} }
RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE => { RXingResultMetadataType::STRUCTURED_APPEND_SEQUENCE => {
RXingResultMetadataValue::StructuredAppendSequence( RXingResultMetadataValue::StructuredAppendSequence(
@@ -222,7 +222,7 @@ impl<T: Reader> AbstractBlackBoxTestCase<T> {
} }
RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => { RXingResultMetadataType::SYMBOLOGY_IDENTIFIER => {
RXingResultMetadataValue::SymbologyIdentifier(v) RXingResultMetadataValue::SymbologyIdentifier(v)
} },
}; };
} }

View File

@@ -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()
}