pdf417 ec + test

This commit is contained in:
Henry Schimke
2022-12-19 12:01:11 -06:00
parent 5b616fe710
commit 75026d6936
14 changed files with 870 additions and 695 deletions

View File

@@ -340,7 +340,12 @@ fn test_aztec() {
test_encode_decode_random(azd12, 3072, 1023);
}
fn corrupt(received: &mut Vec<i32>, howMany: i32, random: &mut rand::rngs::ThreadRng, max: i32) {
pub(crate) fn corrupt(
received: &mut Vec<i32>,
howMany: i32,
random: &mut rand::rngs::ThreadRng,
max: i32,
) {
let mut corrupted = vec![false; received.len()];
//BitSet corrupted = new BitSet(received.length);
let mut j = 0isize;

View File

@@ -1,7 +1,7 @@
#[cfg(test)]
mod GenericGFPolyTestCase;
#[cfg(test)]
mod ReedSolomonTestCase;
pub(crate) mod ReedSolomonTestCase;
/*
* Copyright 2007 ZXing authors
@@ -26,12 +26,13 @@ pub type GenericGFRef = &'static GenericGF;
use lazy_static::lazy_static;
lazy_static! {
static ref AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
static ref AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
static ref AZTEC_DATA_10: GenericGF = GenericGF::new(0x409, 1024, 1); // x^10 + x^3 + 1
static ref AZTEC_DATA_6: GenericGF = GenericGF::new(0x43, 64, 1); // x^6 + x + 1
static ref AZTEC_PARAM: GenericGF = GenericGF::new(0x13, 16, 1); // x^4 + x + 1
static ref QR_CODE_FIELD_256: GenericGF = GenericGF::new(0x011D, 256, 0); // x^8 + x^4 + x^3 + x^2 + 1
static ref DATA_MATRIX_FIELD_256: GenericGF = GenericGF::new(0x012D, 256, 1); // x^8 + x^5 + x^3 + x^2 + 1
// static ref PDF_417_FIELD: GenericGF = GenericGF::new(3,crate::pdf417::pdf_417_common::NUMBER_OF_CODEWORDS as usize,1);
}
// pub const AZTEC_DATA_12: GenericGF = GenericGF::new(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1
@@ -52,6 +53,7 @@ pub enum PredefinedGenericGF {
DataMatrixField256,
AztecData8,
MaxicodeField64,
// PDF417,
}
/// Replacement for old const options, has the downside of generating new versions whenever one is requested.
@@ -65,6 +67,7 @@ pub fn get_predefined_genericgf(request: PredefinedGenericGF) -> GenericGFRef {
PredefinedGenericGF::DataMatrixField256 | PredefinedGenericGF::AztecData8 => {
&DATA_MATRIX_FIELD_256
} // x^8 + x^5 + x^3 + x^2 + 1
// PredefinedGenericGF::PDF417 => &PDF_417_FIELD,
}
}

View File

@@ -60,7 +60,7 @@ impl ReedSolomonDecoder {
* @param twoS number of error-correction codewords available
* @throws ReedSolomonException if decoding fails for any reason
*/
pub fn decode(&self, received: &mut Vec<i32>, twoS: i32) -> Result<(), Exceptions> {
pub fn decode(&self, received: &mut Vec<i32>, twoS: i32) -> Result<usize, Exceptions> {
let poly = GenericGFPoly::new(self.field, received).unwrap();
let mut syndromeCoefficients = vec![0; twoS as usize];
let mut noError = true;
@@ -74,7 +74,7 @@ impl ReedSolomonDecoder {
}
}
if noError {
return Ok(());
return Ok(0);
}
let syndrome = match GenericGFPoly::new(self.field, &syndromeCoefficients) {
Ok(res) => res,
@@ -97,7 +97,7 @@ impl ReedSolomonDecoder {
//for (int i = 0; i < errorLocations.length; i++) {
let log_value = self.field.log(errorLocations[i] as i32)?;
if log_value > received.len() as i32 - 1 {
return Ok(());
return Ok(0);
}
let position: isize = received.len() as isize - 1 - log_value as isize;
if position < 0 {
@@ -108,7 +108,7 @@ impl ReedSolomonDecoder {
received[position as usize] =
GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
}
Ok(())
Ok(errorLocations.len())
}
fn runEuclideanAlgorithm(