From 68875e561a054ff818e901c5fe0b2d4705c3cb49 Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Tue, 29 Apr 2025 16:42:58 +0200 Subject: [PATCH 1/2] Add absolute conversion matrices for ACEScg --- color/src/colorspace.rs | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/color/src/colorspace.rs b/color/src/colorspace.rs index 916c1bd..ddb6a60 100644 --- a/color/src/colorspace.rs +++ b/color/src/colorspace.rs @@ -956,6 +956,50 @@ impl ColorSpace for AcesCg { matvecmul(&LINEAR_SRGB_TO_ACESCG, src) } + fn to_linear_srgb_absolute(src: [f32; 3]) -> [f32; 3] { + // XYZ_to_lin_sRGB * ACEScg_to_XYZ + const ACESCG_TO_LINEAR_SRGB: [[f32; 3]; 3] = [ + [ + 9_932_023_100_445. / 5_736_895_993_442., + -1_732_666_183_650. / 2_868_447_996_721., + -229_784_797_280. / 2_868_447_996_721., + ], + [ + -194_897_543_280. / 1_480_771_385_773., + 72_258_955_647_750. / 63_673_169_588_239., + -552_646_980_800. / 63_673_169_588_239., + ], + [ + -68_657_089_110. / 2_794_545_067_783., + -8082548957250. / 64_274_536_559_009., + 14_669_805_440. / 13_766_231_861., + ], + ]; + matvecmul(&ACESCG_TO_LINEAR_SRGB, src) + } + + fn from_linear_srgb_absolute(src: [f32; 3]) -> [f32; 3] { + // XYZ_to_ACEScg * lin_sRGB_to_XYZ + const LINEAR_SRGB_TO_ACESCG: [[f32; 3]; 3] = [ + [ + 2_095_356_009_722. / 3_474_270_183_447., + 17_006_614_853_437. / 52_114_052_751_705., + 71_464_174_897. / 1_488_972_935_763., + ], + [ + 1_774_515_482_522. / 25_307_573_950_575., + 69_842_555_782_672. / 75_922_721_851_725., + 276_870_186_577. / 21_692_206_243_350., + ], + [ + 101_198_449_621. / 4_562_827_993_584., + 31_778_718_978_443. / 273_769_679_615_040., + 1_600_138_878_851. / 1_700_432_792_640., + ], + ]; + matvecmul(&LINEAR_SRGB_TO_ACESCG, src) + } + fn clip([r, g, b]: [f32; 3]) -> [f32; 3] { [ r.clamp(-65504., 65504.), From fa3f96cdf697e6f3db845f751af0674480fb80b8 Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Tue, 29 Apr 2025 17:03:59 +0200 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b73d33..f93a9c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ This release has an [MSRV][] of 1.82. ### Added -* Support converting between color spaces without chromatic adaptation, thereby representing the same absolute color in the destination color space as in the source color space. ([#139][], [#153][], [#156][] by [@tomcur][]) +* Support converting between color spaces without chromatic adaptation, thereby representing the same absolute color in the destination color space as in the source color space. ([#139][], [#153][], [#156][], [#164][], [#165][] by [@tomcur][]) **Note to `ColorSpace` implementers:** the `WHITE_POINT` associated constant is added to `ColorSpace`, defaulting to D65. Implementations with a non-D65 white point should set this constant to get correct default absolute conversion behavior. @@ -161,6 +161,8 @@ This is the initial release. [#157]: https://github.com/linebender/color/pull/157 [#158]: https://github.com/linebender/color/pull/158 [#159]: https://github.com/linebender/color/pull/159 +[#164]: https://github.com/linebender/color/pull/164 +[#165]: https://github.com/linebender/color/pull/165 [Unreleased]: https://github.com/linebender/color/compare/v0.2.3...HEAD [0.2.3]: https://github.com/linebender/color/releases/tag/v0.2.3