swap to struct from tuple

This commit is contained in:
Henry
2023-01-04 19:00:29 -06:00
parent 9a5d6a704b
commit e0ab98d9a5

View File

@@ -1,34 +1,40 @@
use crate::LuminanceSource;
pub struct Luma8LuminanceSource((u32, u32), (u32, u32), Vec<u8>, bool, (u32, u32));
pub struct Luma8LuminanceSource {
dimensions: (u32, u32),
origin: (u32, u32),
data: Vec<u8>,
inverted: bool,
original_dimension: (u32, u32),
}
impl LuminanceSource for Luma8LuminanceSource {
fn getRow(&self, y: usize) -> Vec<u8> {
self.2
.chunks_exact(y * self.0 .0 as usize)
self.data
.chunks_exact(y * self.dimensions.0 as usize)
.skip(y)
.take(1)
.flatten()
.map(|byte| Self::invert_if_should(*byte, self.3))
.map(|byte| Self::invert_if_should(*byte, self.inverted))
.collect()
}
fn getMatrix(&self) -> Vec<u8> {
self.2
self.data
.iter()
.map(|byte| Self::invert_if_should(*byte, self.3))
.map(|byte| Self::invert_if_should(*byte, self.inverted))
.collect()
}
fn getWidth(&self) -> usize {
self.0 .0 as usize
self.dimensions.0 as usize
}
fn getHeight(&self) -> usize {
self.0 .1 as usize
self.dimensions.1 as usize
}
fn invert(&mut self) {
self.3 = !self.3;
self.inverted = !self.inverted;
}
fn isCropSupported(&self) -> bool {
@@ -42,18 +48,24 @@ impl LuminanceSource for Luma8LuminanceSource {
width: usize,
height: usize,
) -> Result<Box<dyn LuminanceSource>, crate::Exceptions> {
Ok(Box::new(Self(
(width as u32, height as u32),
(left as u32, top as u32),
self.2.clone(),
self.3,
self.4,
)))
Ok(Box::new(Self {
dimensions: (width as u32, height as u32),
origin: (left as u32, top as u32),
data: self.data.clone(),
inverted: self.inverted,
original_dimension: self.original_dimension,
}))
}
}
impl Luma8LuminanceSource {
pub fn new(source: Vec<u8>, width: u32, height: u32) -> Self {
Self((width, height), (0, 0), source, false, (width, height))
Self {
dimensions: (width, height),
origin: (0, 0),
data: source,
inverted: false,
original_dimension: (width, height),
}
}
#[inline(always)]