From 8e60a5afe55bf5b7814cdb47b63ee9e8d3d830cb Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Wed, 17 Feb 2021 23:19:11 +0000 Subject: [PATCH] Bug 1693404 - Add Profile::new_XYZD50(). r=aosmond This will be useful implementing Profile::approx_eq() Differential Revision: https://phabricator.services.mozilla.com/D105518 --- gfx/qcms/src/gtest.rs | 15 +++++++++++++++ gfx/qcms/src/iccread.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gfx/qcms/src/gtest.rs b/gfx/qcms/src/gtest.rs index d47a4829e61b..3917de36331d 100644 --- a/gfx/qcms/src/gtest.rs +++ b/gfx/qcms/src/gtest.rs @@ -884,4 +884,19 @@ mod test { xfm.apply(&mut data); assert_eq!(data, [4, 30, 80]); } + #[test] + fn D50() { + let p1 = crate::Profile::new_sRGB(); + let p2 = crate::Profile::new_XYZD50(); + let xfm = crate::Transform::new( + &p1, + &p2, + crate::DataType::RGB8, + crate::Intent::default(), + ) + .unwrap(); + let mut data = [4, 30, 80]; + xfm.apply(&mut data); + assert_eq!(data, [4, 4, 15]); + } } diff --git a/gfx/qcms/src/iccread.rs b/gfx/qcms/src/iccread.rs index 0113e17aff3e..740bac60a064 100644 --- a/gfx/qcms/src/iccread.rs +++ b/gfx/qcms/src/iccread.rs @@ -26,7 +26,7 @@ use std::{ sync::Arc, }; -use crate::transform::{set_rgb_colorants, PrecacheOuput}; +use crate::{double_to_s15Fixed16Number, transform::{set_rgb_colorants, PrecacheOuput}}; use crate::{matrix::Matrix, s15Fixed16Number, s15Fixed16Number_to_float, Intent, Intent::*}; pub static SUPPORTS_ICCV4: AtomicBool = AtomicBool::new(cfg!(feature = "iccv4-enabled")); @@ -932,6 +932,10 @@ fn curve_from_gamma(gamma: f32) -> Box { Box::new(curveType::Curve(vec![float_to_u8Fixed8Number(gamma)])) } +fn identity_curve() -> Box { + Box::new(curveType::Curve(Vec::new())) +} + /* from lcms: cmsWhitePointFromTemp */ /* tempK must be >= 4000. and <= 25000. * Invalid values of tempK will return @@ -1031,6 +1035,29 @@ impl Profile { Profile::new_rgb_with_table(D65, Rec709Primaries, &table).unwrap() } + /// Create a new profile with D50 adopted white and identity transform functions + pub fn new_XYZD50() -> Box { + let mut profile = profile_create(); + profile.redColorant.X = double_to_s15Fixed16Number(1.); + profile.redColorant.Y = double_to_s15Fixed16Number(0.); + profile.redColorant.Z = double_to_s15Fixed16Number(0.); + profile.greenColorant.X = double_to_s15Fixed16Number(0.); + profile.greenColorant.Y = double_to_s15Fixed16Number(1.); + profile.greenColorant.Z = double_to_s15Fixed16Number(0.); + profile.blueColorant.X = double_to_s15Fixed16Number(0.); + profile.blueColorant.Y = double_to_s15Fixed16Number(0.); + profile.blueColorant.Z = double_to_s15Fixed16Number(1.); + profile.redTRC = Some(identity_curve()); + profile.blueTRC = Some(identity_curve()); + profile.greenTRC = Some(identity_curve()); + + profile.class_type = DISPLAY_DEVICE_PROFILE; + profile.rendering_intent = Perceptual; + profile.color_space = RGB_SIGNATURE; + profile.pcs = XYZ_TYPE; + profile + } + pub fn new_gray_with_gamma(gamma: f32) -> Box { let mut profile = profile_create();