Filter 2d adding additional traits
authorRadzivon Bartoshyk <[email protected]>
Sun, 20 Jul 2025 15:47:55 +0000 (20 16:47 +0100)
committerRadzivon Bartoshyk <[email protected]>
Sun, 20 Jul 2025 15:52:02 +0000 (20 16:52 +0100)
src/filter1d/color_group.rs [deleted file]
src/filter1d/mod.rs
src/filter2d/filter_2d_handler.rs

diff --git a/src/filter1d/color_group.rs b/src/filter1d/color_group.rs
deleted file mode 100644 (file)
index e6b4308..0000000
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- * // Copyright (c) Radzivon Bartoshyk. All rights reserved.
- * //
- * // Redistribution and use in source and binary forms, with or without modification,
- * // are permitted provided that the following conditions are met:
- * //
- * // 1.  Redistributions of source code must retain the above copyright notice, this
- * // list of conditions and the following disclaimer.
- * //
- * // 2.  Redistributions in binary form must reproduce the above copyright notice,
- * // this list of conditions and the following disclaimer in the documentation
- * // and/or other materials provided with the distribution.
- * //
- * // 3.  Neither the name of the copyright holder nor the names of its
- * // contributors may be used to endorse or promote products derived from
- * // this software without specific prior written permission.
- * //
- * // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-use crate::mlaf::mlaf;
-use num_traits::{FromPrimitive, MulAdd};
-use std::ops::{Add, AddAssign, Mul, Shr, Sub, SubAssign};
-
-#[repr(C)]
-#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Copy)]
-pub(crate) struct ColorGroup<const COMPS: usize, J: Copy> {
-    pub r: J,
-    pub g: J,
-    pub b: J,
-    pub a: J,
-}
-
-impl<const COMPS: usize, J> ColorGroup<COMPS, J>
-where
-    J: Copy + Default,
-{
-    #[inline]
-    pub fn new() -> ColorGroup<COMPS, J> {
-        ColorGroup {
-            r: J::default(),
-            g: J::default(),
-            b: J::default(),
-            a: J::default(),
-        }
-    }
-
-    #[inline]
-    pub fn from_components(r: J, g: J, b: J, a: J) -> ColorGroup<COMPS, J> {
-        ColorGroup { r, g, b, a }
-    }
-}
-
-impl<const COMPS: usize, J> Mul<J> for ColorGroup<COMPS, J>
-where
-    J: Copy + Mul<Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn mul(self, rhs: J) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r * rhs, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r * rhs, self.g * rhs, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r * rhs, self.g * rhs, self.b * rhs, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(self.r * rhs, self.g * rhs, self.b * rhs, self.a * rhs)
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Mul<ColorGroup<COMPS, J>> for ColorGroup<COMPS, J>
-where
-    J: Copy + Mul<Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn mul(self, rhs: ColorGroup<COMPS, J>) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r * rhs.r, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r * rhs.r, self.g * rhs.g, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r * rhs.r, self.g * rhs.g, self.b * rhs.b, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(
-                self.r * rhs.r,
-                self.g * rhs.g,
-                self.b * rhs.b,
-                self.a * rhs.b,
-            )
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Sub<J> for ColorGroup<COMPS, J>
-where
-    J: Copy + Sub<Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn sub(self, rhs: J) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r - rhs, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r - rhs, self.g - rhs, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r - rhs, self.g - rhs, self.b - rhs, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(self.r - rhs, self.g - rhs, self.b - rhs, self.a - rhs)
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Sub<ColorGroup<COMPS, J>> for ColorGroup<COMPS, J>
-where
-    J: Copy + Sub<Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn sub(self, rhs: ColorGroup<COMPS, J>) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r - rhs.r, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r - rhs.r, self.g - rhs.g, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r - rhs.r, self.g - rhs.g, self.b - rhs.b, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(
-                self.r - rhs.r,
-                self.g - rhs.g,
-                self.b - rhs.b,
-                self.a - rhs.a,
-            )
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Add<ColorGroup<COMPS, J>> for ColorGroup<COMPS, J>
-where
-    J: Copy + Add<Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn add(self, rhs: ColorGroup<COMPS, J>) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r + rhs.r, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r + rhs.r, self.g + rhs.g, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r + rhs.r, self.g + rhs.g, self.b + rhs.b, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(
-                self.r + rhs.r,
-                self.g + rhs.g,
-                self.b + rhs.b,
-                self.a + rhs.a,
-            )
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Add<J> for ColorGroup<COMPS, J>
-where
-    J: Copy + Add<Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn add(self, rhs: J) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r + rhs, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r + rhs, self.g + rhs, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r + rhs, self.g + rhs, self.b + rhs, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(self.r + rhs, self.g + rhs, self.b + rhs, self.a + rhs)
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Shr<J> for ColorGroup<COMPS, J>
-where
-    J: Copy + Shr<J, Output = J> + Default + 'static,
-{
-    type Output = Self;
-
-    #[inline]
-    fn shr(self, rhs: J) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(self.r >> rhs, self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(self.r >> rhs, self.g >> rhs, self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(self.r >> rhs, self.g >> rhs, self.b >> rhs, self.a)
-        } else if COMPS == 4 {
-            ColorGroup::from_components(self.r >> rhs, self.g >> rhs, self.b >> rhs, self.a >> rhs)
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> MulAdd<ColorGroup<COMPS, J>, J> for ColorGroup<COMPS, J>
-where
-    J: Copy + MulAdd<J, Output = J> + Default + 'static + Mul<J, Output = J> + Add<J, Output = J>,
-{
-    type Output = Self;
-
-    #[inline]
-    fn mul_add(self, a: ColorGroup<COMPS, J>, b: J) -> Self::Output {
-        if COMPS == 1 {
-            ColorGroup::from_components(mlaf(a.r, self.r, b), self.g, self.b, self.a)
-        } else if COMPS == 2 {
-            ColorGroup::from_components(mlaf(a.r, self.r, b), mlaf(a.g, self.g, b), self.b, self.a)
-        } else if COMPS == 3 {
-            ColorGroup::from_components(
-                mlaf(a.r, self.r, b),
-                mlaf(a.g, self.g, b),
-                mlaf(a.b, self.b, b),
-                self.a,
-            )
-        } else if COMPS == 4 {
-            ColorGroup::from_components(
-                mlaf(a.r, self.r, b),
-                mlaf(a.g, self.g, b),
-                mlaf(a.b, self.b, b),
-                mlaf(a.a, self.a, b),
-            )
-        } else {
-            unimplemented!("Not implemented.");
-        }
-    }
-}
-
-impl<const COMPS: usize, J> AddAssign<ColorGroup<COMPS, J>> for ColorGroup<COMPS, J>
-where
-    J: Copy + AddAssign,
-{
-    #[inline]
-    fn add_assign(&mut self, rhs: ColorGroup<COMPS, J>) {
-        if COMPS == 1 {
-            self.r += rhs.r;
-        } else if COMPS == 2 {
-            self.r += rhs.r;
-            self.g += rhs.g;
-        } else if COMPS == 3 {
-            self.r += rhs.r;
-            self.g += rhs.g;
-            self.b += rhs.b;
-        } else if COMPS == 4 {
-            self.r += rhs.r;
-            self.g += rhs.g;
-            self.b += rhs.b;
-            self.a += rhs.a;
-        }
-    }
-}
-
-impl<const COMPS: usize, J> SubAssign<ColorGroup<COMPS, J>> for ColorGroup<COMPS, J>
-where
-    J: Copy + SubAssign,
-{
-    #[inline]
-    fn sub_assign(&mut self, rhs: ColorGroup<COMPS, J>) {
-        if COMPS == 1 {
-            self.r -= rhs.r;
-        } else if COMPS == 2 {
-            self.r -= rhs.r;
-            self.g -= rhs.g;
-        } else if COMPS == 3 {
-            self.r -= rhs.r;
-            self.g -= rhs.g;
-            self.b -= rhs.b;
-        } else if COMPS == 4 {
-            self.r -= rhs.r;
-            self.g -= rhs.g;
-            self.b -= rhs.b;
-            self.a -= rhs.a;
-        }
-    }
-}
-
-impl<const COMPS: usize, J> Default for ColorGroup<COMPS, J>
-where
-    J: Copy + FromPrimitive + Default,
-{
-    #[inline]
-    fn default() -> Self {
-        ColorGroup::new()
-    }
-}
index 8d6c9dc..2a7c75b 100644 (file)
@@ -33,7 +33,6 @@ mod arena_roi;
 mod avx;
 #[cfg(all(target_arch = "x86_64", feature = "nightly_avx512"))]
 mod avx512;
-mod color_group;
 mod filter;
 mod filter_1d_approx;
 mod filter_1d_column_handler;
index 222a0ad..449bb66 100644 (file)
@@ -186,3 +186,7 @@ default_2d_column_handler!(u32, f32, true);
 default_2d_column_handler!(u32, f64, true);
 default_2d_column_handler!(u64, f32, true);
 default_2d_column_handler!(u64, f64, true);
+default_2d_column_handler!(f32, f32, false);
+default_2d_column_handler!(f32, f64, false);
+default_2d_column_handler!(f64, f32, false);
+default_2d_column_handler!(f64, f64, false);