Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions color/src/colorspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.),
Expand Down