mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
add partial crop support
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
use crate::LuminanceSource;
|
use crate::LuminanceSource;
|
||||||
|
|
||||||
pub struct Luma8LuminanceSource(u32, u32, Vec<u8>, bool);
|
pub struct Luma8LuminanceSource((u32, u32), (u32, u32), Vec<u8>, bool, (u32, u32));
|
||||||
impl LuminanceSource for Luma8LuminanceSource {
|
impl LuminanceSource for Luma8LuminanceSource {
|
||||||
fn getRow(&self, y: usize) -> Vec<u8> {
|
fn getRow(&self, y: usize) -> Vec<u8> {
|
||||||
self.2
|
self.2
|
||||||
.chunks_exact(y * self.0 as usize)
|
.chunks_exact(y * self.0 .0 as usize)
|
||||||
.skip(y)
|
.skip(y)
|
||||||
.take(1)
|
.take(1)
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -20,11 +20,11 @@ impl LuminanceSource for Luma8LuminanceSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn getWidth(&self) -> usize {
|
fn getWidth(&self) -> usize {
|
||||||
self.0 as usize
|
self.0 .0 as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getHeight(&self) -> usize {
|
fn getHeight(&self) -> usize {
|
||||||
self.1 as usize
|
self.0 .1 as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invert(&mut self) {
|
fn invert(&mut self) {
|
||||||
@@ -37,19 +37,23 @@ impl LuminanceSource for Luma8LuminanceSource {
|
|||||||
|
|
||||||
fn crop(
|
fn crop(
|
||||||
&self,
|
&self,
|
||||||
_left: usize,
|
left: usize,
|
||||||
_top: usize,
|
top: usize,
|
||||||
_width: usize,
|
width: usize,
|
||||||
_height: usize,
|
height: usize,
|
||||||
) -> Result<Box<dyn LuminanceSource>, crate::Exceptions> {
|
) -> Result<Box<dyn LuminanceSource>, crate::Exceptions> {
|
||||||
Err(crate::Exceptions::UnsupportedOperationException(Some(
|
Ok(Box::new(Self(
|
||||||
"This luminance source does not support cropping.".to_owned(),
|
(width as u32, height as u32),
|
||||||
|
(left as u32, top as u32),
|
||||||
|
self.2.clone(),
|
||||||
|
self.3,
|
||||||
|
self.4,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Luma8LuminanceSource {
|
impl Luma8LuminanceSource {
|
||||||
pub fn new(source: Vec<u8>, width: u32, height: u32) -> Self {
|
pub fn new(source: Vec<u8>, width: u32, height: u32) -> Self {
|
||||||
Self(width, height, source, false)
|
Self((width, height), (0, 0), source, false, (width, height))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|||||||
Reference in New Issue
Block a user