This commit is contained in:
Henry Schimke
2022-10-10 16:28:37 -05:00
parent 8785a7d0e7
commit 9b47d53f4b
2 changed files with 17 additions and 17 deletions

View File

@@ -172,7 +172,7 @@ impl AlignmentPatternFinder {
* figures the location of the center of this black/white/black run. * figures the location of the center of this black/white/black run.
*/ */
fn centerFromEnd(stateCount: &[u32], end: u32) -> f32 { fn centerFromEnd(stateCount: &[u32], end: u32) -> f32 {
(end - stateCount[2]) as f32 - stateCount[1] as f32 / 2.0 (end as f32 - stateCount[2] as f32) - stateCount[1] as f32 / 2.0
} }
/** /**
@@ -219,8 +219,8 @@ impl AlignmentPatternFinder {
self.crossCheckStateCount[2] = 0; self.crossCheckStateCount[2] = 0;
// Start counting up from center // Start counting up from center
let mut i = startI; let mut i = startI as i32;
while i >= 0 && image.get(centerJ, i) && self.crossCheckStateCount[1] <= maxCount { while i >= 0 && image.get(centerJ, i as u32) && self.crossCheckStateCount[1] <= maxCount {
self.crossCheckStateCount[1] += 1; self.crossCheckStateCount[1] += 1;
i -= 1; i -= 1;
} }
@@ -228,7 +228,7 @@ impl AlignmentPatternFinder {
if i < 0 || self.crossCheckStateCount[1] > maxCount { if i < 0 || self.crossCheckStateCount[1] > maxCount {
return f32::NAN; return f32::NAN;
} }
while i >= 0 && !image.get(centerJ, i) && self.crossCheckStateCount[0] <= maxCount { while i >= 0 && !image.get(centerJ, i as u32) && self.crossCheckStateCount[0] <= maxCount {
self.crossCheckStateCount[0] += 1; self.crossCheckStateCount[0] += 1;
i -= 1; i -= 1;
} }
@@ -237,15 +237,15 @@ impl AlignmentPatternFinder {
} }
// Now also count down from center // Now also count down from center
i = startI + 1; i = startI as i32+ 1;
while i < maxI && image.get(centerJ, i) && self.crossCheckStateCount[1] <= maxCount { while i < maxI as i32 && image.get(centerJ, i as u32) && self.crossCheckStateCount[1] <= maxCount {
self.crossCheckStateCount[1] += 1; self.crossCheckStateCount[1] += 1;
i += 1; i += 1;
} }
if i == maxI || self.crossCheckStateCount[1] > maxCount { if i == maxI as i32 || self.crossCheckStateCount[1] > maxCount {
return f32::NAN; return f32::NAN;
} }
while i < maxI && !image.get(centerJ, i) && self.crossCheckStateCount[2] <= maxCount { while i < maxI as i32 && !image.get(centerJ, i as u32) && self.crossCheckStateCount[2] <= maxCount {
self.crossCheckStateCount[2] += 1; self.crossCheckStateCount[2] += 1;
i += 1; i += 1;
} }
@@ -263,7 +263,7 @@ impl AlignmentPatternFinder {
} }
if self.foundPatternCross(&self.crossCheckStateCount) { if self.foundPatternCross(&self.crossCheckStateCount) {
Self::centerFromEnd(&self.crossCheckStateCount, i) Self::centerFromEnd(&self.crossCheckStateCount, i as u32)
} else { } else {
f32::NAN f32::NAN
} }

View File

@@ -235,14 +235,14 @@ impl AbstractBlackBoxTestCase {
let source = BufferedImageLuminanceSource::new(rotated_image); let source = BufferedImageLuminanceSource::new(rotated_image);
let bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source)))); let bitmap = BinaryBitmap::new(Box::new(HybridBinarizer::new(Box::new(source))));
#[cfg(test)] // #[cfg(test)]
if file_base_name == "13" { // if file_base_name == "13" {
let mut f = File::create("test_file_output.txt").unwrap(); // let mut f = File::create("test_file_output.txt").unwrap();
dbg!("dumb"); // dbg!("dumb");
write!(f,"{}", bitmap.getBlackMatrix().unwrap()); // write!(f,"{}", bitmap.getBlackMatrix().unwrap());
drop(f); // drop(f);
Self::rotate_image(&image, rotation).save("test_image.png").unwrap(); // Self::rotate_image(&image, rotation).save("test_image.png").unwrap();
} // }
if let Ok(decoded) = if let Ok(decoded) =
self.decode(&bitmap, rotation, &expected_text, &expected_metadata, false) self.decode(&bitmap, rotation, &expected_text, &expected_metadata, false)