DetectPureQR ported

This commit is contained in:
Henry Schimke
2023-03-20 11:09:06 -05:00
parent 75313c26f8
commit 3d75de7183
8 changed files with 168 additions and 86 deletions

View File

@@ -0,0 +1,61 @@
use crate::common::BitMatrix;
use crate::common::Result;
use crate::point;
impl BitMatrix {
pub fn Deflate(
&self,
width: u32,
height: u32,
top: f32,
left: f32,
subSampling: f32,
) -> Result<Self> {
let mut result = BitMatrix::new(width, height)?;
for y in 0..result.height() {
// for (int y = 0; y < result.height(); y++) {
let yOffset = top + y as f32 * subSampling;
for x in 0..result.width() {
// for (int x = 0; x < result.width(); x++) {
if (self.get_point(point(left + x as f32 * subSampling, yOffset))) {
result.set(x, y);
}
}
}
Ok(result)
}
pub fn findBoundingBox(
&self,
left: &mut u32,
top: &mut u32,
width: &mut u32,
height: &mut u32,
minSize: u32,
) -> bool {
todo!()
// let right;
// let bottom;
// if (!self.getTopLeftOnBitWithPosition(left, top) || !self.getBottomRightOnBitWithPosition(right, bottom) || bottom - top + 1 < minSize)
// {return false;}
// for (int y = top; y <= bottom; y++ ) {
// for (int x = 0; x < left; ++x)
// if (get(x, y)) {
// left = x;
// break;
// }
// for (int x = _width-1; x > right; x--)
// if (get(x, y)) {
// right = x;
// break;
// }
// }
// width = right - left + 1;
// height = bottom - top + 1;
// return width >= minSize && height >= minSize;
}
}

View File

@@ -165,27 +165,27 @@ pub trait BitMatrixCursorTrait {
fn d(&self) -> Point;
fn readPattern<T>(&self, range : Option<u32>) -> Option<T>
{
fn readPattern<T>(&self, range: Option<u32>) -> Option<T> {
// let range = range.unwrap_or(0);
// let mut res :T;
// let mut res :T;
// for i in res.into_iter() {
// i = self.stepToEdge(1, range);
// }
// // for (auto& i : res)
// // i = stepToEdge(1, range);
// return res;
// // for (auto& i : res)
// // i = stepToEdge(1, range);
// return res;
todo!()
}
fn readPatternFromBlack<T>(&self, maxWhitePrefix:i32, range: Option<u32>) -> Option<T>
{
fn readPatternFromBlack<T>(&self, maxWhitePrefix: i32, range: Option<u32>) -> Option<T> {
let range = range.unwrap_or(0);
if (maxWhitePrefix != 0 && self.isWhite() && !self.stepToEdge(Some(1), Some(maxWhitePrefix), None) > 0)
{return None;}
// return readPattern<ARRAY>(range);
if (maxWhitePrefix != 0
&& self.isWhite()
&& !self.stepToEdge(Some(1), Some(maxWhitePrefix), None) > 0)
{
return None;
}
// return readPattern<ARRAY>(range);
self.readPattern(Some(range))
}
}

View File

@@ -1,3 +1,4 @@
mod bitmatrix;
pub mod bitmatrix_cursor;
pub mod bitmatrix_cursor_trait;
pub mod concentric_finder;

View File

@@ -54,6 +54,12 @@ impl std::ops::IndexMut<usize> for PatternRow {
}
}
impl From<Vec<PatternType>> for PatternRow {
fn from(value: Vec<PatternType>) -> Self {
Self(value)
}
}
impl<'a> Iterator for PatternView<'_> {
type Item = PatternType;