diff --git a/src/image/srgb.rs b/src/image/srgb.rs index a57db41..1551ed4 100644 --- a/src/image/srgb.rs +++ b/src/image/srgb.rs @@ -20,8 +20,45 @@ impl SRGBA { Self { r, g, b, a } } } + +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 } } } + +impl Into for SRGB { + fn into(self) -> SRGBA { + SRGBA::new(self.r, self.g, self.b, 1.0) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn srgb_from_srgba_drops_alpha() + { + let srgb: SRGB = SRGBA::new(0.1, 0.2, 0.3, 0.4).into(); + assert_eq!(srgb.r, 0.1); + assert_eq!(srgb.g, 0.2); + assert_eq!(srgb.b, 0.3); + } + + #[test] + fn srgba_from_srgb_adds_alpha_1() + { + let srgba: SRGBA = SRGB::new(0.1, 0.2, 0.3).into(); + assert_eq!(srgba.r, 0.1); + assert_eq!(srgba.g, 0.2); + assert_eq!(srgba.b, 0.3); + assert_eq!(srgba.a, 1.0); + } +}