Files
Graphite/libraries/raw-rs/src/processing.rs
Elbert Ronnie 442937c13f Raw-rs: Refactor to run multiple steps in a single loop (#1972)
* Prevent extra allocation in convert to RGB step

* Run preprocessing steps in a single loop

* Create new API to call steps in pipeline

* Include transform and gamma correction step

* cargo fmt

* Split scale colors into two steps

* Code relocations

* cargo fmt

* Implement transform traits for all tuples

* Replace Captures trick with the new `use` keyword
2024-10-25 11:52:35 -07:00

67 lines
1.2 KiB
Rust

use crate::CHANNELS_IN_RGB;
use fortuples::fortuples;
#[derive(Clone, Copy)]
pub struct RawPixel {
pub value: u16,
pub row: usize,
pub column: usize,
}
#[derive(Clone, Copy)]
pub struct Pixel {
pub values: [u16; CHANNELS_IN_RGB],
pub row: usize,
pub column: usize,
}
pub trait RawPixelTransform {
fn apply(&mut self, pixel: RawPixel) -> u16;
}
impl<T: Fn(RawPixel) -> u16> RawPixelTransform for T {
fn apply(&mut self, pixel: RawPixel) -> u16 {
self(pixel)
}
}
fortuples! {
#[tuples::min_size(1)]
#[tuples::max_size(8)]
impl RawPixelTransform for #Tuple
where
#(#Member: RawPixelTransform),*
{
fn apply(&mut self, mut pixel: RawPixel) -> u16 {
#(pixel.value = #self.apply(pixel);)*
pixel.value
}
}
}
pub trait PixelTransform {
fn apply(&mut self, pixel: Pixel) -> [u16; CHANNELS_IN_RGB];
}
impl<T: Fn(Pixel) -> [u16; CHANNELS_IN_RGB]> PixelTransform for T {
fn apply(&mut self, pixel: Pixel) -> [u16; CHANNELS_IN_RGB] {
self(pixel)
}
}
fortuples! {
#[tuples::min_size(1)]
#[tuples::max_size(8)]
impl PixelTransform for #Tuple
where
#(#Member: PixelTransform),*
{
fn apply(&mut self, mut pixel: Pixel) -> [u16; CHANNELS_IN_RGB] {
#(pixel.values = #self.apply(pixel);)*
pixel.values
}
}
}