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:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
// import java.util.Arrays;
|
// import java.util.Arrays;
|
||||||
|
|
||||||
|
use std::ops::Index;
|
||||||
use std::{cmp, fmt};
|
use std::{cmp, fmt};
|
||||||
|
|
||||||
use crate::common::Result;
|
use crate::common::Result;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::Point;
|
use crate::{common::BitMatrix, Point};
|
||||||
|
|
||||||
use super::{util::opposite, Direction, Value};
|
use super::{util::opposite, Direction, Value};
|
||||||
|
|
||||||
@@ -165,6 +165,8 @@ pub trait BitMatrixCursorTrait {
|
|||||||
|
|
||||||
fn d(&self) -> Point;
|
fn d(&self) -> Point;
|
||||||
|
|
||||||
|
fn img(&self) -> &BitMatrix;
|
||||||
|
|
||||||
fn readPattern<const LEN: usize, T: TryFrom<i32> + Default + Copy + Clone>(
|
fn readPattern<const LEN: usize, T: TryFrom<i32> + Default + Copy + Clone>(
|
||||||
&mut self,
|
&mut self,
|
||||||
range: Option<i32>,
|
range: Option<i32>,
|
||||||
|
|||||||
@@ -170,6 +170,10 @@ impl BitMatrixCursorTrait for EdgeTracer<'_> {
|
|||||||
fn d(&self) -> Point {
|
fn d(&self) -> Point {
|
||||||
self.d
|
self.d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn img(&self) -> &BitMatrix {
|
||||||
|
self.img
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> EdgeTracer<'_> {
|
impl<'a> EdgeTracer<'_> {
|
||||||
|
|||||||
@@ -1,23 +1,48 @@
|
|||||||
|
use crate::common::BitArray;
|
||||||
|
|
||||||
use super::BitMatrixCursorTrait;
|
use super::BitMatrixCursorTrait;
|
||||||
|
|
||||||
pub struct FastEdgeToEdgeCounter {
|
pub struct FastEdgeToEdgeCounter {
|
||||||
// const uint8_t* p = nullptr;
|
// const uint8_t* p = nullptr;
|
||||||
// int stride = 0;
|
// int stride = 0;
|
||||||
// int stepsToBorder = 0;
|
// int stepsToBorder = 0;
|
||||||
p: usize,
|
p: u32, // = nullptr;
|
||||||
stride: usize, // = 0;
|
stride: u32, // = 0;
|
||||||
stepsToBorder: usize, // = 0;
|
stepsToBorder: u32, // = 0;
|
||||||
|
arr: BitArray,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FastEdgeToEdgeCounter {
|
impl FastEdgeToEdgeCounter {
|
||||||
pub fn new<T: BitMatrixCursorTrait>(_cur: &T) -> Self {
|
pub fn new<T: BitMatrixCursorTrait>(cur: &T) -> Self {
|
||||||
todo!()
|
let stride = cur.d().y as u32 * cur.img().width() as u32 + cur.d().x as u32;
|
||||||
// stride = cur.d.y * cur.img->width() + cur.d.x;
|
let p = /*cur.img().getRow(cur.p().y).begin()*/ 0 + cur.p().x as u32;
|
||||||
// p = cur.img->row(cur.p.y).begin() + cur.p.x;
|
|
||||||
|
|
||||||
// int maxStepsX = cur.d.x ? (cur.d.x > 0 ? cur.img->width() - 1 - cur.p.x : cur.p.x) : INT_MAX;
|
let maxStepsX = if cur.d().x != 0.0 {
|
||||||
// int maxStepsY = cur.d.y ? (cur.d.y > 0 ? cur.img->height() - 1 - cur.p.y : cur.p.y) : INT_MAX;
|
(if cur.d().x > 0.0 {
|
||||||
// stepsToBorder = std::min(maxStepsX, maxStepsY);
|
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 {
|
pub fn stepToNextEdge(&self, _range: i32) -> i32 {
|
||||||
|
|||||||
Reference in New Issue
Block a user