Skip to content

Commit

Permalink
Raw-rs: Remove fortuples dependency (#2082)
Browse files Browse the repository at this point in the history
Remove fortuples from Raw-rs
  • Loading branch information
elbertronnie authored Oct 28, 2024
1 parent 4df7803 commit b7ba2c3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 62 deletions.
49 changes: 13 additions & 36 deletions libraries/raw-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion libraries/raw-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ build-camera-data = { path = "build-camera-data" }
# Required dependencies
bitstream-io = "2.5.3"
num_enum = "0.7.3"
fortuples = "0.9.1"
thiserror = "1.0.64"

# Optional dependencies (should be dev dependencies, but Cargo currently doesn't allow optional dev dependencies)
Expand Down
67 changes: 42 additions & 25 deletions libraries/raw-rs/src/processing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::CHANNELS_IN_RGB;
use fortuples::fortuples;

#[derive(Clone, Copy)]
pub struct RawPixel {
Expand All @@ -25,21 +24,30 @@ impl<T: Fn(RawPixel) -> u16> RawPixelTransform for T {
}
}

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);)*
macro_rules! impl_raw_pixel_transform {
($($idx:tt $t:tt),+) => {
impl<$($t,)+> RawPixelTransform for ($($t,)+)
where
$($t: RawPixelTransform,)+
{
fn apply(&mut self, mut pixel: RawPixel) -> u16 {
$(pixel.value = self.$idx.apply(pixel);)*

pixel.value
}
}
pixel.value
}
}
};
}

impl_raw_pixel_transform!(0 A);
impl_raw_pixel_transform!(0 A, 1 B);
impl_raw_pixel_transform!(0 A, 1 B, 2 C);
impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D);
impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E);
impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F);
impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G);
impl_raw_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H);

pub trait PixelTransform {
fn apply(&mut self, pixel: Pixel) -> [u16; CHANNELS_IN_RGB];
}
Expand All @@ -50,17 +58,26 @@ impl<T: Fn(Pixel) -> [u16; CHANNELS_IN_RGB]> PixelTransform for T {
}
}

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);)*
macro_rules! impl_pixel_transform {
($($idx:tt $t:tt),+) => {
impl<$($t,)+> PixelTransform for ($($t,)+)
where
$($t: PixelTransform,)+
{
fn apply(&mut self, mut pixel: Pixel) -> [u16; CHANNELS_IN_RGB] {
$(pixel.values = self.$idx.apply(pixel);)*

pixel.values
}
}
pixel.values
}
}
};
}

impl_pixel_transform!(0 A);
impl_pixel_transform!(0 A, 1 B);
impl_pixel_transform!(0 A, 1 B, 2 C);
impl_pixel_transform!(0 A, 1 B, 2 C, 3 D);
impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E);
impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F);
impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G);
impl_pixel_transform!(0 A, 1 B, 2 C, 3 D, 4 E, 5 F, 6 G, 7 H);

0 comments on commit b7ba2c3

Please sign in to comment.