mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
wip: incomplete port checking
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
// import java.util.Arrays;
|
||||
|
||||
use std::ops::Index;
|
||||
use std::{cmp, fmt};
|
||||
|
||||
use crate::common::Result;
|
||||
@@ -420,6 +421,19 @@ impl From<BitArray> for Vec<u8> {
|
||||
|
||||
impl From<BitArray> for Vec<bool> {
|
||||
fn from(value: BitArray) -> Self {
|
||||
// let mut array = vec![false; value.size];
|
||||
|
||||
// for (pixel, element) in array.iter_mut().enumerate().take(value.size) {
|
||||
// *element = value.get(pixel);
|
||||
// }
|
||||
|
||||
// array
|
||||
Self::from(&value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&BitArray> for Vec<bool> {
|
||||
fn from(value: &BitArray) -> Self {
|
||||
let mut array = vec![false; value.size];
|
||||
|
||||
for (pixel, element) in array.iter_mut().enumerate().take(value.size) {
|
||||
@@ -429,3 +443,11 @@ impl From<BitArray> for Vec<bool> {
|
||||
array
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<usize> for BitArray {
|
||||
type Output = bool;
|
||||
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.get(index)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::common::cpp_essentials::PatternRow;
|
||||
use crate::common::BitMatrix;
|
||||
use crate::common::Result;
|
||||
use crate::point_f;
|
||||
|
||||
@@ -51,6 +51,10 @@ impl PatternRow {
|
||||
pub fn sum(&self) -> PatternType {
|
||||
self.0.iter().sum()
|
||||
}
|
||||
|
||||
pub fn rev(&mut self) {
|
||||
self.0.reverse()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for PatternRow {
|
||||
|
||||
@@ -51,6 +51,7 @@ pub struct GlobalHistogramBinarizer<LS: LuminanceSource> {
|
||||
source: LS,
|
||||
black_matrix: OnceCell<BitMatrix>,
|
||||
black_row_cache: Vec<OnceCell<BitArray>>,
|
||||
black_column_cache: Vec<OnceCell<BitArray>>,
|
||||
}
|
||||
|
||||
impl<LS: LuminanceSource> Binarizer for GlobalHistogramBinarizer<LS> {
|
||||
@@ -106,6 +107,10 @@ impl<LS: LuminanceSource> Binarizer for GlobalHistogramBinarizer<LS> {
|
||||
Ok(Cow::Borrowed(row))
|
||||
}
|
||||
|
||||
fn get_black_line(&self, l: usize, lt: super::LineOrientation) -> Result<Cow<BitArray>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// Does not sharpen the data, as this call is intended to only be used by 2D Readers.
|
||||
fn get_black_matrix(&self) -> Result<&BitMatrix> {
|
||||
let matrix = self
|
||||
@@ -137,6 +142,7 @@ impl<LS: LuminanceSource> GlobalHistogramBinarizer<LS> {
|
||||
height: source.get_height(),
|
||||
black_matrix: OnceCell::new(),
|
||||
black_row_cache: vec![OnceCell::default(); source.get_height()],
|
||||
black_column_cache: vec![OnceCell::default(); source.get_width()],
|
||||
source,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,10 @@ impl<LS: LuminanceSource> Binarizer for HybridBinarizer<LS> {
|
||||
self.ghb.get_black_row(y)
|
||||
}
|
||||
|
||||
fn get_black_line(&self, l: usize, lt: super::LineOrientation) -> Result<Cow<BitArray>> {
|
||||
self.ghb.get_black_line(l, lt)
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the final BitMatrix once for all requests. This could be called once from the
|
||||
* constructor instead, but there are some advantages to doing it lazily, such as making
|
||||
|
||||
5
src/common/line_orientation.rs
Normal file
5
src/common/line_orientation.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum LineOrientation {
|
||||
Row,
|
||||
Column,
|
||||
}
|
||||
@@ -114,6 +114,9 @@ pub use quad::*;
|
||||
|
||||
pub mod cpp_essentials;
|
||||
|
||||
mod line_orientation;
|
||||
pub use line_orientation::LineOrientation;
|
||||
|
||||
#[cfg(feature = "otsu_level")]
|
||||
mod otsu_level_binarizer;
|
||||
#[cfg(feature = "otsu_level")]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{point_f, Point};
|
||||
use crate::{point_f, Exceptions, Point};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Quadrilateral(pub [Point; 4]);
|
||||
@@ -272,3 +272,19 @@ impl From<[Point; 4]> for Quadrilateral {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&Vec<Point>> for Quadrilateral {
|
||||
type Error = Exceptions;
|
||||
|
||||
fn try_from(value: &Vec<Point>) -> Result<Self, Self::Error> {
|
||||
if value.len() == 4 {
|
||||
Ok(
|
||||
Self(
|
||||
[value[0], value[1], value[2], value[3]]
|
||||
)
|
||||
)
|
||||
}else{
|
||||
Err(Exceptions::INDEX_OUT_OF_BOUNDS)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user