diff --git a/src/image/srgb.rs b/src/image/srgb.rs index aeec0e6..f84a43b 100644 --- a/src/image/srgb.rs +++ b/src/image/srgb.rs @@ -2,6 +2,13 @@ use super::*; use ccvl_proc_macros::Pixel; +#[derive(Clone, Copy, Debug, PartialEq, Pixel)] +pub struct SRGB { + pub r: f32, + pub g: f32, + pub b: f32, +} + #[derive(Clone, Copy, Debug, PartialEq, Pixel)] pub struct SRGBA { pub r: f32, @@ -10,13 +17,6 @@ pub struct SRGBA { pub a: f32, } -#[derive(Clone, Copy, Debug, PartialEq, Pixel)] -pub struct SRGB { - pub r: f32, - pub g: f32, - pub b: f32, -} - const CUTOFF: f32 = 4.05e-2; const LINEAR_DIVISOR: f32 = 12.92; const SHIFT: f32 = 5.5e-2; @@ -46,12 +46,6 @@ impl SRGBA { } } -impl Into for SRGBA { - fn into(self) -> SRGB { - SRGB::new(self.r, self.g, self.b) - } -} - impl SRGB { pub fn new(r: f32, g: f32, b: f32) -> Self { Self { r, g, b } @@ -64,6 +58,12 @@ impl Into for SRGB { } } +impl From for SRGB { + fn from(rgba: SRGBA) -> Self { + Self::new(rgba.r, rgba.g, rgba.b) + } +} + impl Into for SRGB { fn into(self) -> LinearRGB { LinearRGB::new( @@ -84,6 +84,18 @@ impl From for SRGB { } } +impl Into for SRGBA { + fn into(self) -> LinearRGB { + SRGB::from(self).into() + } +} + +impl From for SRGBA { + fn from(linear: LinearRGB) -> Self { + SRGB::from(linear).into() + } +} + #[cfg(test)] mod tests { use super::*;