Skip to content

Commit 9b41605

Browse files
committed
[css-color] DCI P3 support in conversion code
1 parent 01046b5 commit 9b41605

3 files changed

Lines changed: 62 additions & 8 deletions

File tree

css-color/Overview.bs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,18 +1769,15 @@ Implementations may choose to implement these steps in some other way (for examp
17691769
using an ICC profile with relative colorimetric rendering intent) provided the results
17701770
are the same for colors inside the source and destination gamuts.
17711771

1772-
<h3 id="at-profile">Specifying a color profile: the ''profile'' at-rule</h3>
1773-
<!-- we agreed to call it profile rather than color-profile or icc-profile, for brevity -->
1772+
<h3 id="at-profile">Specifying a color profile: the ''color-profile'' at-rule</h3>
17741773

17751774
The <dfn data-dfn-type='at-rule' id="at-ruledef-profile">@color-profile</dfn>
17761775
rule is a group rule. It consists of the at-keyword
1777-
'@color-profile' followed by an identifier, followed by a group rule body.
1776+
'@color-profile' followed by a name, followed by a group rule body.
17781777

17791778
In a very similar way to the ''<@font-face.'' at-rule, the ''<@color-profile>''
1780-
at-rule has a descriptor
1781-
to give the profile a name which will be used inside the stylesheet,
1782-
<!-- is this actualy a descriptor, or a parameter to the at-rule?-->
1783-
and another descriptor to point to the actual
1779+
at-rule has a name (which will be used inside the stylesheet),
1780+
and a descriptor to point to the actual
17841781
data (<dfn for="@color-profile/src">src</dfn>, just like
17851782
<dfn for="@font-face/src">src</dfn> in font-face.)
17861783
<!-- not clear how I link to the two different descriptors therte, in bikeshed syntax -->

css-color/conversions.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,53 @@ function XYZ_to_lin_sRGB(XYZ) {
5050
return math.multiply(M, XYZ).valueOf();
5151
}
5252

53+
// DCI P3-related functions
54+
55+
56+
function lin_P3(RGB) {
57+
// convert an array of DCI P3 RGB values in the range 0.0 - 1.0
58+
// to linear light (un-companded) form.
59+
60+
return RGB.map(function (val) {
61+
return Math.pow(val, 2.6);
62+
});
63+
}
64+
65+
function gam_P3(RGB) {
66+
// convert an array of linear-light P3 RGB in the range 0.0-1.0
67+
// to gamma corrected form
68+
69+
return RGB.map(function (val) {
70+
return Math.pow(val, 1/2.6);
71+
}
72+
});
73+
}
74+
75+
function lin_P3_to_XYZ(rgb) {
76+
// convert an array of linear-light P3 values to CIE XYZ
77+
// using D65 (no chromatic adaptation)
78+
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
79+
var M = math.matrix([
80+
[0.4865709486482162, 0.26566769316909306, 0.1982172852343625],
81+
[0.2289745640697488, 0.6917385218365064, 0.079286914093745],
82+
[0.0000000000000000, 0.04511338185890264, 1.043944368900976]
83+
]);
84+
// 0 was computed as -3.972075516933488e-17
85+
86+
return math.multiply(M, rgb).valueOf();
87+
}
88+
89+
function XYZ_to_lin_P3(XYZ) {
90+
// convert XYZ to linear-light P3
91+
var M = math.matrix([
92+
[ 2.493496911941425, -0.9313836179191239, -0.40271078445071684],
93+
[-0.8294889695615747, 1.7626640603183463, 0.023624685841943577],
94+
[ 0.03584583024378447, -0.07617238926804182, 0.9568845240076872]
95+
]);
96+
97+
return math.multiply(M, XYZ).valueOf();
98+
}
99+
53100
//Rec.2020-related functions
54101

55102
function lin_2020(RGB) {

css-color/matrixmaker.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
// these are for ITU Rec BT.2020
16-
16+
/*
1717
const xred=0.708 ;
1818
const yred=0.292 ;
1919
@@ -22,7 +22,17 @@
2222
2323
const xblue=0.131 ;
2424
const yblue=0.046 ;
25+
*/
26+
27+
// these are for DCI P3
28+
const xred=0.680 ;
29+
const yred=0.320 ;
2530

31+
const xgreen=0.265 ;
32+
const ygreen=0.690 ;
33+
34+
const xblue=0.150 ;
35+
const yblue=0.060 ;
2636

2737
// AdobeRGB, for testing
2838
/*

0 commit comments

Comments
 (0)