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

View File

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

View File

@@ -197,8 +197,11 @@ fn correctErrors(codewordBytes: &mut [u8], numDataCodewords: usize) -> Result<()
// for (int i = 0; i < numCodewords; i++) { // for (int i = 0; i < numCodewords; i++) {
codewordsInts[i] = codewordBytes[i]; // & 0xFF; codewordsInts[i] = codewordBytes[i]; // & 0xFF;
} }
let mut sending_code_words : Vec<i32> = codewordsInts.iter().map(|x| *x as i32).collect();
if let Err(e) = rsDecoder.decode( if let Err(e) = rsDecoder.decode(
&mut codewordsInts.iter().map(|x| *x as i32).collect(), &mut sending_code_words,
(codewordBytes.len() - numDataCodewords) as i32, (codewordBytes.len() - numDataCodewords) as i32,
) { ) {
if let Exceptions::ReedSolomonException(error_str) = e { if let Exceptions::ReedSolomonException(error_str) = e {
@@ -210,7 +213,7 @@ fn correctErrors(codewordBytes: &mut [u8], numDataCodewords: usize) -> Result<()
// We don't care about errors in the error-correction codewords // We don't care about errors in the error-correction codewords
for i in 0..numDataCodewords { for i in 0..numDataCodewords {
// for (int i = 0; i < numDataCodewords; i++) { // for (int i = 0; i < numDataCodewords; i++) {
codewordBytes[i] = codewordsInts[i]; codewordBytes[i] = sending_code_words[i] as u8;
} }
Ok(()) Ok(())
} }

View File

@@ -290,7 +290,7 @@ impl AlignmentPatternFinder {
let centerJ = Self::centerFromEnd(stateCount, j); let centerJ = Self::centerFromEnd(stateCount, j);
let centerI = self.crossCheckVertical( let centerI = self.crossCheckVertical(
i, i,
centerJ.floor() as u32, centerJ.round() as u32,
2 * stateCount[1], 2 * stateCount[1],
stateCountTotal, stateCountTotal,
); );

View File

@@ -462,13 +462,13 @@ impl Detector {
// Look for an alignment pattern (3 modules in size) around where it // Look for an alignment pattern (3 modules in size) around where it
// should be // should be
let allowance = (allowanceFactor * overallEstModuleSize) as u32; let allowance = (allowanceFactor * overallEstModuleSize) as u32;
let alignmentAreaLeftX = 0.max(estAlignmentX - allowance); let alignmentAreaLeftX = 0.max(estAlignmentX as i32- allowance as i32) as u32;
let alignmentAreaRightX = (self.image.getWidth() - 1).min(estAlignmentX + allowance); let alignmentAreaRightX = (self.image.getWidth() - 1).min(estAlignmentX + allowance);
if ((alignmentAreaRightX - alignmentAreaLeftX) as f32) < overallEstModuleSize * 3.0 { if ((alignmentAreaRightX - alignmentAreaLeftX) as f32) < overallEstModuleSize * 3.0 {
return Err(Exceptions::NotFoundException("not found".to_owned())); return Err(Exceptions::NotFoundException("not found".to_owned()));
} }
let alignmentAreaTopY = 0.max(estAlignmentY - allowance); let alignmentAreaTopY = 0.max(estAlignmentY as i32 - allowance as i32) as u32;
let alignmentAreaBottomY = (self.image.getHeight() - 1).min(estAlignmentY + allowance); let alignmentAreaBottomY = (self.image.getHeight() - 1).min(estAlignmentY + allowance);
if alignmentAreaBottomY - alignmentAreaTopY < overallEstModuleSize as u32 * 3 { if alignmentAreaBottomY - alignmentAreaTopY < overallEstModuleSize as u32 * 3 {
return Err(Exceptions::NotFoundException("not found".to_owned())); return Err(Exceptions::NotFoundException("not found".to_owned()));

View File

@@ -92,7 +92,7 @@ impl FinderPattern {
combinedX, combinedX,
combinedY, combinedY,
combinedModuleSize, combinedModuleSize,
combinedCount.floor() as usize, combinedCount.round() as usize,
) )
} }
} }

View File

@@ -135,7 +135,7 @@ impl FinderPatternFinder {
// Skip by rowSkip, but back off by stateCount[2] (size of last center // Skip by rowSkip, but back off by stateCount[2] (size of last center
// of pattern we saw) to be conservative, and also back off by iSkip which // of pattern we saw) to be conservative, and also back off by iSkip which
// is about to be re-added // is about to be re-added
i += rowSkip - stateCount[2] - iSkip; i += (rowSkip as i32 - stateCount[2] as i32 - iSkip as i32).max(0) as u32;
j = maxJ - 1; j = maxJ - 1;
} }
} }
@@ -620,7 +620,7 @@ impl FinderPatternFinder {
return (((fnp.getX() - center.getX().abs()) return (((fnp.getX() - center.getX().abs())
- (fnp.getY() - center.getY()).abs()) - (fnp.getY() - center.getY()).abs())
/ 2.0) / 2.0)
.floor() as u32; .round() as u32;
} }
} }
} }

View File

@@ -38,9 +38,8 @@ fn QRCodeBlackBox1TestCase() {
tester.testBlackBox(); tester.testBlackBox();
} }
// 15 - 180 should pass // 16 - 0
// 19 - 180 should pass // 19 - 0
// 20 - 90 should pass
// TEST CASE 15 FAILING AT allignment patter finder! (line 88) FROM detector 486 // TEST CASE 15 FAILING AT allignment patter finder! (line 88) FROM detector 486