diff --git a/palette/src/encoding/adobe.rs b/palette/src/encoding/adobe.rs index 280f7fe3..93bea80c 100644 --- a/palette/src/encoding/adobe.rs +++ b/palette/src/encoding/adobe.rs @@ -155,5 +155,23 @@ mod test { let half_to_linear = AdobeRgb::into_linear(0.5); assert_relative_eq!(half_to_linear, 0.21775552, epsilon = 0.0000001); } + + #[test] + fn u8_to_f32_to_u8() { + for expected in 0u8..=255u8 { + let linear: f32 = AdobeRgb::into_linear(expected); + let result: u8 = AdobeRgb::from_linear(linear); + assert_eq!(result, expected); + } + } + + #[test] + fn u8_to_f64_to_u8() { + for expected in 0u8..=255u8 { + let linear: f64 = AdobeRgb::into_linear(expected); + let result: u8 = AdobeRgb::from_linear(linear); + assert_eq!(result, expected); + } + } } } diff --git a/palette/src/encoding/p3.rs b/palette/src/encoding/p3.rs index 0bfc4feb..333c3fc0 100644 --- a/palette/src/encoding/p3.rs +++ b/palette/src/encoding/p3.rs @@ -99,10 +99,18 @@ pub struct DciP3Plus(PhantomData); impl Primaries for DciP3Plus { fn red() -> Yxy { - Yxy::new(T::from_f64(0.740), T::from_f64(0.270), T::from_f64(0.203986)) + Yxy::new( + T::from_f64(0.740), + T::from_f64(0.270), + T::from_f64(0.203986), + ) } fn green() -> Yxy { - Yxy::new(T::from_f64(0.220), T::from_f64(0.780), T::from_f64(0.882591)) + Yxy::new( + T::from_f64(0.220), + T::from_f64(0.780), + T::from_f64(0.882591), + ) } fn blue() -> Yxy { Yxy::new( @@ -311,4 +319,26 @@ mod test { assert_relative_eq!(red + green + blue, DciP3::get_xyz(), epsilon = 0.00001) } } + + mod transfer { + use crate::encoding::{FromLinear, IntoLinear, P3Gamma}; + + #[test] + fn u8_to_f32_to_u8() { + for expected in 0u8..=255u8 { + let linear: f32 = P3Gamma::into_linear(expected); + let result: u8 = P3Gamma::from_linear(linear); + assert_eq!(result, expected); + } + } + + #[test] + fn u8_to_f64_to_u8() { + for expected in 0u8..=255u8 { + let linear: f64 = P3Gamma::into_linear(expected); + let result: u8 = P3Gamma::from_linear(linear); + assert_eq!(result, expected); + } + } + } } diff --git a/palette/src/encoding/prophoto.rs b/palette/src/encoding/prophoto.rs index b05159b0..a68882e8 100644 --- a/palette/src/encoding/prophoto.rs +++ b/palette/src/encoding/prophoto.rs @@ -147,4 +147,26 @@ mod test { assert_relative_eq!(red + green + blue, D50::get_xyz(), epsilon = 0.0001); } } + + mod transfer { + use crate::encoding::{FromLinear, IntoLinear, ProPhotoRgb}; + + #[test] + fn u16_to_f32_to_u16() { + for expected in 0u16..=65535u16 { + let linear: f32 = ProPhotoRgb::into_linear(expected as f32 / 65535.0); + let result: u16 = ProPhotoRgb::from_linear(linear); + assert_eq!(result, expected); + } + } + + #[test] + fn u16_to_f64_to_u16() { + for expected in 0u16..=65535u16 { + let linear: f64 = ProPhotoRgb::into_linear(expected as f64 / 65535.0); + let result: u16 = ProPhotoRgb::from_linear(linear); + assert_eq!(result, expected); + } + } + } }