all pass but test case 3

This commit is contained in:
Henry Schimke
2022-10-14 08:58:18 -05:00
parent f9ea8b97f9
commit 7244075501

View File

@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
use std::{fs::File, io::Write};
use crate::{ use crate::{
common::BitMatrix, result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions, common::BitMatrix, result_point_utils, DecodeHintType, DecodingHintDictionary, Exceptions,
RXingResultPoint, RXingResultPointCallback, ResultPoint, RXingResultPoint, RXingResultPointCallback, ResultPoint,
@@ -76,6 +78,7 @@ impl FinderPatternFinder {
&mut self, &mut self,
hints: &DecodingHintDictionary, hints: &DecodingHintDictionary,
) -> Result<FinderPatternInfo, Exceptions> { ) -> Result<FinderPatternInfo, Exceptions> {
let tryHarder = hints.contains_key(&DecodeHintType::TRY_HARDER); let tryHarder = hints.contains_key(&DecodeHintType::TRY_HARDER);
let maxI = self.image.getHeight(); let maxI = self.image.getHeight();
let maxJ = self.image.getWidth(); let maxJ = self.image.getWidth();
@@ -93,8 +96,8 @@ impl FinderPatternFinder {
let mut done = false; let mut done = false;
let mut stateCount = [0u32; 5]; let mut stateCount = [0u32; 5];
let mut i = iSkip - 1; let mut i = iSkip as i32 - 1;
while i < maxI && !done { while i < maxI as i32 && !done {
// for (int i = iSkip - 1; i < maxI && !done; i += iSkip) { // for (int i = iSkip - 1; i < maxI && !done; i += iSkip) {
// Get a row of black/white values // Get a row of black/white values
FinderPatternFinder::doClearCounts(&mut stateCount); FinderPatternFinder::doClearCounts(&mut stateCount);
@@ -102,7 +105,7 @@ impl FinderPatternFinder {
let mut j = 0; let mut j = 0;
while j < maxJ { while j < maxJ {
// for (int j = 0; j < maxJ; j++) { // for (int j = 0; j < maxJ; j++) {
if self.image.get(j, i) { if self.image.get(j, i as u32) {
// Black pixel // Black pixel
if (currentState & 1) == 1 { if (currentState & 1) == 1 {
// Counting white pixels // Counting white pixels
@@ -117,7 +120,7 @@ impl FinderPatternFinder {
// A winner? // A winner?
if FinderPatternFinder::foundPatternCross(&stateCount) { if FinderPatternFinder::foundPatternCross(&stateCount) {
// Yes // Yes
let confirmed = self.handlePossibleCenter(&stateCount, i, j); let confirmed = self.handlePossibleCenter(&stateCount, i as u32, j);
if confirmed { if confirmed {
// Start examining every other line. Checking each line turned out to be too // Start examining every other line. Checking each line turned out to be too
// expensive and didn't improve performance. // expensive and didn't improve performance.
@@ -135,7 +138,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 as i32 - stateCount[2] as i32 - iSkip as i32).max(0) as u32; i += rowSkip as i32 - stateCount[2] as i32 - iSkip as i32;
// i += rowSkip - stateCount[2] - iSkip ; // i += rowSkip - stateCount[2] - iSkip ;
j = maxJ - 1; j = maxJ - 1;
} }
@@ -143,6 +146,7 @@ impl FinderPatternFinder {
} else { } else {
FinderPatternFinder::doShiftCounts2(&mut stateCount); FinderPatternFinder::doShiftCounts2(&mut stateCount);
currentState = 3; currentState = 3;
j+=1;
continue; continue;
} }
// Clear state to start looking again // Clear state to start looking again
@@ -165,7 +169,7 @@ impl FinderPatternFinder {
j+=1; j+=1;
} }
if FinderPatternFinder::foundPatternCross(&stateCount) { if FinderPatternFinder::foundPatternCross(&stateCount) {
let confirmed = self.handlePossibleCenter(&stateCount, i, maxJ); let confirmed = self.handlePossibleCenter(&stateCount, i as u32, maxJ);
if confirmed { if confirmed {
iSkip = stateCount[0]; iSkip = stateCount[0];
if self.hasSkipped { if self.hasSkipped {
@@ -175,7 +179,7 @@ impl FinderPatternFinder {
} }
} }
i += iSkip; i += iSkip as i32;
} }
let mut patternInfo = self.selectBestPatterns()?; let mut patternInfo = self.selectBestPatterns()?;