mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
port FastEdgeToEdgeCounter::new
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::Point;
|
||||
use crate::{common::BitMatrix, Point};
|
||||
|
||||
use super::{util::opposite, Direction, Value};
|
||||
|
||||
@@ -165,6 +165,8 @@ pub trait BitMatrixCursorTrait {
|
||||
|
||||
fn d(&self) -> Point;
|
||||
|
||||
fn img(&self) -> &BitMatrix;
|
||||
|
||||
fn readPattern<const LEN: usize, T: TryFrom<i32> + Default + Copy + Clone>(
|
||||
&mut self,
|
||||
range: Option<i32>,
|
||||
|
||||
@@ -170,6 +170,10 @@ impl BitMatrixCursorTrait for EdgeTracer<'_> {
|
||||
fn d(&self) -> Point {
|
||||
self.d
|
||||
}
|
||||
|
||||
fn img(&self) -> &BitMatrix {
|
||||
self.img
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> EdgeTracer<'_> {
|
||||
|
||||
@@ -1,23 +1,48 @@
|
||||
use crate::common::BitArray;
|
||||
|
||||
use super::BitMatrixCursorTrait;
|
||||
|
||||
pub struct FastEdgeToEdgeCounter {
|
||||
// const uint8_t* p = nullptr;
|
||||
// int stride = 0;
|
||||
// int stepsToBorder = 0;
|
||||
p: usize,
|
||||
stride: usize, // = 0;
|
||||
stepsToBorder: usize, // = 0;
|
||||
p: u32, // = nullptr;
|
||||
stride: u32, // = 0;
|
||||
stepsToBorder: u32, // = 0;
|
||||
arr: BitArray,
|
||||
}
|
||||
|
||||
impl FastEdgeToEdgeCounter {
|
||||
pub fn new<T: BitMatrixCursorTrait>(_cur: &T) -> Self {
|
||||
todo!()
|
||||
// stride = cur.d.y * cur.img->width() + cur.d.x;
|
||||
// p = cur.img->row(cur.p.y).begin() + cur.p.x;
|
||||
pub fn new<T: BitMatrixCursorTrait>(cur: &T) -> Self {
|
||||
let stride = cur.d().y as u32 * cur.img().width() as u32 + cur.d().x as u32;
|
||||
let p = /*cur.img().getRow(cur.p().y).begin()*/ 0 + cur.p().x as u32;
|
||||
|
||||
// int maxStepsX = cur.d.x ? (cur.d.x > 0 ? cur.img->width() - 1 - cur.p.x : cur.p.x) : INT_MAX;
|
||||
// int maxStepsY = cur.d.y ? (cur.d.y > 0 ? cur.img->height() - 1 - cur.p.y : cur.p.y) : INT_MAX;
|
||||
// stepsToBorder = std::min(maxStepsX, maxStepsY);
|
||||
let maxStepsX = if cur.d().x != 0.0 {
|
||||
(if cur.d().x > 0.0 {
|
||||
cur.img().width() - 1 - cur.p().x as u32
|
||||
} else {
|
||||
cur.p().x as u32
|
||||
})
|
||||
} else {
|
||||
u32::MAX
|
||||
};
|
||||
let maxStepsY = if cur.d().y != 0.0 {
|
||||
(if cur.d().y > 0.0 {
|
||||
cur.img().height() - 1 - cur.p().y as u32
|
||||
} else {
|
||||
cur.p().y as u32
|
||||
})
|
||||
} else {
|
||||
u32::MAX
|
||||
};
|
||||
let stepsToBorder = std::cmp::min(maxStepsX, maxStepsY);
|
||||
|
||||
Self {
|
||||
p,
|
||||
stride,
|
||||
stepsToBorder,
|
||||
arr: cur.img().getRow(cur.p().y as u32),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stepToNextEdge(&self, _range: i32) -> i32 {
|
||||
|
||||
Reference in New Issue
Block a user