mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 03:18:06 +08:00
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
This commit is contained in:
66
libraries/raw-rs/src/processing.rs
Normal file
66
libraries/raw-rs/src/processing.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user