fixed issue with ec results not being used

This commit is contained in:
Henry Schimke
2022-10-12 19:14:47 -05:00
parent 3602f9c2e8
commit 7395bb2c29
8 changed files with 51 additions and 37 deletions

View File

@@ -181,7 +181,7 @@ impl StringUtils {
break;
}
let value = bytes[i] & 0xFF;
let value = bytes[i];
// UTF-8 stuff
if can_be_utf8 {
@@ -1545,7 +1545,7 @@ impl BitSource {
return Err(Exceptions::IllegalArgumentException(numBits.to_string()));
}
let mut result:u32 = 0;
let mut result: u32 = 0;
let mut num_bits = numBits;
@@ -1850,7 +1850,12 @@ pub struct DecoderRXingResult {
}
impl DecoderRXingResult {
pub fn new(rawBytes: Vec<u8>, text: String, byteSegments: Vec<Vec<u8>>, ecLevel: String) -> Self {
pub fn new(
rawBytes: Vec<u8>,
text: String,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
) -> Self {
Self::with_all(rawBytes, text, byteSegments, ecLevel, -2, -2, 0)
}
@@ -1894,7 +1899,7 @@ impl DecoderRXingResult {
pub fn with_all(
rawBytes: Vec<u8>,
text: String,
byteSegments:Vec<Vec<u8>>,
byteSegments: Vec<Vec<u8>>,
ecLevel: String,
saSequence: i32,
saParity: i32,
@@ -2243,11 +2248,11 @@ pub trait GridSampler {
}
// Check and nudge points from end:
nudged = true;
let mut offset = points.len() - 2;
let mut offset = points.len() as isize - 2;
while offset >= 0 && nudged {
// for (int offset = points.length - 2; offset >= 0 && nudged; offset -= 2) {
let x = points[offset] as i32;
let y = points[offset + 1] as i32;
let x = points[offset as usize] as i32;
let y = points[offset as usize + 1] as i32;
if x < -1 || x > width.try_into().unwrap() || y < -1 || y > height.try_into().unwrap() {
return Err(Exceptions::NotFoundException(
"getNotFoundInstance".to_owned(),
@@ -2255,20 +2260,20 @@ pub trait GridSampler {
}
nudged = false;
if x == -1 {
points[offset] = 0.0f32;
points[offset as usize] = 0.0f32;
nudged = true;
} else if (x == width.try_into().unwrap()) {
points[offset] = width as f32 - 1f32;
} else if x == width.try_into().unwrap() {
points[offset as usize] = width as f32 - 1f32;
nudged = true;
}
if y == -1 {
points[offset + 1] = 0.0f32;
points[offset as usize + 1] = 0.0f32;
nudged = true;
} else if (y == height.try_into().unwrap()) {
points[offset + 1] = height as f32 - 1f32;
} else if y == height.try_into().unwrap() {
points[offset as usize + 1] = height as f32 - 1f32;
nudged = true;
}
offset += 2;
offset += -2;
}
Ok(())
}
@@ -2363,6 +2368,13 @@ impl GridSampler for DefaultGridSampler {
let mut x = 0;
while x < max {
// for (int x = 0; x < max; x += 2) {
if points[x].floor() as u32 >= image.getWidth()
|| points[x + 1].floor() as u32 >= image.getHeight()
{
return Err(Exceptions::NotFoundException(
"index out of bounds, see documentation in file for explanation".to_owned(),
));
}
if image.get(points[x].floor() as u32, points[x + 1].floor() as u32) {
// Black(-ish) pixel
bits.set(x as u32 / 2, y);
@@ -4127,4 +4139,4 @@ impl HybridBinarizer {
}
blackPoints
}
}
}

View File

@@ -701,7 +701,7 @@ impl ReedSolomonDecoder {
}
let syndrome = match GenericGFPoly::new(self.field, &syndromeCoefficients) {
Ok(res) => res,
Err(fail) => {
Err(_fail) => {
return Err(Exceptions::ReedSolomonException(
"IllegalArgumentException".to_owned(),
))
@@ -722,13 +722,13 @@ impl ReedSolomonDecoder {
if log_value > received.len() as i32 - 1 {
return Ok(());
}
let position: usize = received.len() - 1 - log_value as usize;
let position: isize = received.len() as isize - 1 - log_value as isize;
if position < 0 {
return Err(Exceptions::ReedSolomonException(
"Bad error location".to_owned(),
));
}
received[position] = GenericGF::addOrSubtract(received[position], errorMagnitudes[i]);
received[position as usize] = GenericGF::addOrSubtract(received[position as usize], errorMagnitudes[i]);
}
Ok(())
}
@@ -774,7 +774,7 @@ impl ReedSolomonDecoder {
let denominatorLeadingTerm = rLast.getCoefficient(rLast.getDegree());
let dltInverse = match self.field.inverse(denominatorLeadingTerm) {
Ok(inv) => inv,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"ArithmetricException".to_owned(),
))
@@ -787,7 +787,7 @@ impl ReedSolomonDecoder {
.multiply(r.getCoefficient(r.getDegree()), dltInverse);
q = match q.addOrSubtract(&GenericGF::buildMonomial(self.field, degreeDiff, scale)) {
Ok(res) => res,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"IllegalArgumentException".to_owned(),
))
@@ -795,14 +795,14 @@ impl ReedSolomonDecoder {
};
r = match r.addOrSubtract(&match rLast.multiply_by_monomial(degreeDiff, scale) {
Ok(res) => res,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"IllegalArgumentException".to_owned(),
))
}
}) {
Ok(res) => res,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"IllegalArgumentException".to_owned(),
))
@@ -812,7 +812,7 @@ impl ReedSolomonDecoder {
t = match (match q.multiply(&tLast) {
Ok(res) => res,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"IllegalArgumentException".to_owned(),
))
@@ -821,7 +821,7 @@ impl ReedSolomonDecoder {
.addOrSubtract(&tLastLast)
{
Ok(res) => res,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"IllegalArgumentException".to_owned(),
))
@@ -845,7 +845,7 @@ impl ReedSolomonDecoder {
let inverse = match self.field.inverse(sigmaTildeAtZero) {
Ok(res) => res,
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"ArithmetricException".to_owned(),
))
@@ -874,7 +874,7 @@ impl ReedSolomonDecoder {
if errorLocator.evaluateAt(i) == 0 {
result[e] = match self.field.inverse(i.try_into().unwrap()) {
Ok(res) => res.try_into().unwrap(),
Err(err) => {
Err(_err) => {
return Err(Exceptions::ReedSolomonException(
"ArithmetricException".to_owned(),
))