Skip to content

Commit 216f037

Browse files
authored
Merge pull request w3c#557 from cabanier/master
[css-color] Changes to CSS color spec from Adobe (see discussion thread)
2 parents 6e41562 + 619c1fd commit 216f037

3 files changed

Lines changed: 80 additions & 64 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ cssom-view/Overview.src.html
1313
*.orig
1414
Thumbs.db
1515

16-
*/Overview.html
1716

1817
node_modules

css-color/Overview.bs

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ Notes On Using Colors</h3>
152152

153153
An <dfn export>untagged image</dfn> is an image that is not explicitly assigned a color profile, as defined by the image format.
154154

155-
Note that this rule does not apply to videos, since untagged video should be presumed to be in CCIR 601.
155+
Note that this rule does not apply to videos, since untagged video should be presumed to be in ITU.
156+
* At below 720p, it is Recommendation ITU-R BT.601 [[!ITU-R-BT.601]]
157+
* At 720p, it is SMPTE ST 296 (same colorimetry as 709) [[!SMPTE-ST-296]]
158+
* At 1080p, it is Recommendation ITU-R BT.709 [[!ITU-R-BT.709]]
156159

157160
Issue:
158161
Really? Isn't HD video in Rec.709? Shouldn't video be consistent with images?
@@ -1613,7 +1616,7 @@ Converting sRGB colors to Lab colors</h3>
16131616

16141617
<!-- make these steps links to the appropriate section in a calculations appendix -->
16151618
<ol>
1616-
<li>Convert from sRGB to linear-light sRGB (undo gamma correction)
1619+
<li>Convert from sRGB to linear-light sRGB (undo gamma encoding)
16171620
<li>Convert from linear sRGB to CIE XYZ
16181621
<li>Convert from a D65 whitepoint (used by sRGB) to the D50 whitepoint used
16191622
in Lab, with the Bradford transform
@@ -1633,7 +1636,7 @@ Converting Lab colors to sRGB colors</h3>
16331636
<li>Convert from a D50 whitepoint (used by Lab) to the D65 whitepoint used
16341637
in sRGB, with the Bradford transform
16351638
<li>Convert from (D65-adapted) CIE XYZ to linear sRGB
1636-
<li>Convert from linear-light sRGB to sRGB (do gamma correction)
1639+
<li>Convert from linear-light sRGB to sRGB (do gamma encoding)
16371640
</ol>
16381641

16391642
<h3 id='lab-to-lch'>
@@ -1691,7 +1694,7 @@ Converting gray colors to sRGB colors</h3>
16911694
<li>Convert Lab to XYZ
16921695
<li>Adapt from D50 to D65 (Bradford transform)
16931696
<li>Convert from (D65-adapted) CIE XYZ to linear sRGB
1694-
<li>Convert from linear-light sRGB to sRGB (do gamma correction)
1697+
<li>Convert from linear-light sRGB to sRGB (do gamma encoding)
16951698
</ol>
16961699

16971700
<h2 id='icc-colors'>
@@ -1714,7 +1717,7 @@ Profiled, Device-dependent Colors</h2>
17141717
or an RGB colorspace (such as ProPhoto <!-- ref -->, <!-- would be good to mention AdobeRGB 1998 here too, need to check trademark and copyright issues first --> widely used by photographers), or any other color or monochrome output device which has been characterized.
17151718
In addition, for convenience,
17161719
CSS provides two predefined RGB color spaces:
1717-
DCI P3 [[!DCI-P3]],
1720+
image-p3 [[!DCI-P3]],
17181721
which is a wide gamut space typical of current wide-gamut monitors,
17191722
and Rec. 2020 [[[!Rec.2020]],
17201723
which is a ultra-wide gamut space capable of representing almost all visible real-world colors.
@@ -1770,7 +1773,7 @@ Profiled, Device-dependent Colors</h2>
17701773

17711774
* An optional <<ident>> denoting the colorspace.
17721775
This can be one of the predefined colorspaces
1773-
(such as ''dci-p3''),
1776+
(such as ''image-p3''),
17741777
or one defined by a ''@color-profile'' rule.
17751778
If omitted, it defaults to the predefined ''srgb'' color profile.
17761779

@@ -1819,7 +1822,7 @@ Profiled, Device-dependent Colors</h2>
18191822
identical to ''rgb(0 0 0)''.
18201823

18211824
<h3 id="predefined">
1822-
Predefined colorspaces: ''srgb'', ''dci-p3'', and ''rec2020''.</h3>
1825+
Predefined colorspaces: ''srgb'', ''image-p3'', and ''rec2020''.</h3>
18231826

18241827
The following colorspaces are predefined for use in the ''color()'' function.
18251828
They can be used without any ''@color-profile'' rule.
@@ -1830,35 +1833,50 @@ Predefined colorspaces: ''srgb'', ''dci-p3'', and ''rec2020''.</h3>
18301833
<dl dfn-type=value dfn-for="color()">
18311834
<dt><dfn>srgb</dfn>
18321835
<dd>
1833-
The ''srgb'' [[!DCI-P3]] colorspace accepts three numeric parameters,
1836+
The ''srgb'' [[!SRGB]] colorspace accepts three numeric parameters,
18341837
representing the red, green, and blue channels of the color,
18351838
with each having a valid range of [0, 1].
18361839

18371840
It is the default colorspace for CSS,
18381841
identical to specifying a color with the ''rgb()'' function.
18391842

1840-
<dt><dfn>dci-p3</dfn>
1843+
It has the following characteristics:
1844+
1845+
<table>
1846+
<thead><td></td><td>x</td><td>y</td></thead>
1847+
<tr><th>Red chromaticity</th><td>0.640</td><td>0.330</td></tr>
1848+
<tr><th>Green chromaticity</th><td>0.300</td><td>0.600</td></tr>
1849+
<tr><th>Blue chromaticity</th><td>0.150</td><td>0.060</td></tr>
1850+
<tr><th>White chromaticity</th><td>0.3127</td><td>3290</td></tr>
1851+
<tr><th>Transfer function</th><td>see below</td></tr>
1852+
</table>
1853+
1854+
<pre class="lang-javascript">
1855+
var Cl;
1856+
if (C <= 0.04045)
1857+
Cl = C / 12.92;
1858+
else
1859+
Cl = Math.pow((C + 0.055) / 1.055, 2.4);
1860+
</pre>
1861+
C is the red, green or blue component.
1862+
1863+
<dt><dfn>image-p3</dfn>
18411864
<dd>
1842-
The ''dci-p3'' [[!DCI-P3]] colorspace accepts three numeric parameters,
1865+
The ''image-p3'' [[!DCI-P3]] colorspace accepts three numeric parameters,
18431866
representing the red, green, and blue channels of the color,
18441867
with each having a valid range of [0, 1].
18451868

18461869
It has the following characteristics:
18471870

18481871
<table>
1849-
<tr><th>Red chromaticity</th><td>x=0.680 y=0.320</td></tr>
1850-
<tr><th>Green chromaticity</th><td>x=0.265 y=0.690</td></tr>
1851-
<tr><th>Blue chromaticity</th><td>x=0.150 y=0.060</td></tr>
1852-
<tr><th>White chromaticity</th><td>x=0.3127 y=0.3290 (D65)</td></tr>
1853-
<tr><th>Transfer function</th><td>1/2.6</td></tr>
1872+
<thead><td></td><td>x</td><td>y</td></thead>
1873+
<tr><th>Red chromaticity</th><td>0.680</td><td>0.320</td></tr>
1874+
<tr><th>Green chromaticity</th><td>0.265</td><td>0.690</td></tr>
1875+
<tr><th>Blue chromaticity</th><td>0.150</td><td>0.060</td></tr>
1876+
<tr><th>White chromaticity</th><td>0.3127</td><td>3290</td></tr>
1877+
<tr><th>Transfer function</th><td>same as srgb</td></tr>
18541878
</table>
18551879

1856-
Issue: The defining spec for dci-p3 is not freely available. It costs USD 240.
1857-
There is a Wikipedia article, which is non-authoritative and of unknown accuracy
1858-
(particularly for the transfer function and viewing conditions).
1859-
1860-
Issue: DCI transfer function for P3 is gamma 1/2.6 while Apple P3 displays use gamma 1/2.2.
1861-
18621880
<dt><dfn>rec2020</dfn>
18631881
<dd>
18641882
The ''rec2020'' [[!Rec.2020]] colorspace accepts three numeric parameters,
@@ -1872,18 +1890,14 @@ Predefined colorspaces: ''srgb'', ''dci-p3'', and ''rec2020''.</h3>
18721890
<tr><th>Green chromaticity</th><td>x=0.170 y=0.797</td></tr>
18731891
<tr><th>Blue chromaticity</th><td>x=0.131 y=0.046</td></tr>
18741892
<tr><th>White chromaticity</th><td>x=0.3127 y=0.3290 (D65)</td></tr>
1875-
<tr><th>Transfer function</th><td>see below</td></tr>
1893+
<tr><th>Transfer function</th><td>1/2.4 (see note)</td></tr>
18761894
</table>
18771895

1878-
''rec2020'' transfer function has the same form as the one for sRGB, but with
1879-
the constants at higher precision to cope with 10 or 12-bit components:
1896+
Note: Rec2020 references a different transfer curve for cameras. However
1897+
this curve is never used in production cameras or 2020 displays.<br/>
1898+
"In typical production practice the encoding function of image sources is adjusted so that the final picture has the desired look, as viewed on a reference monitor having the reference decoding function of Recommendation ITU-R BT.1886, in the reference viewing environment defined in Recommendation ITU-R BT.2035."<br/>
1899+
The transfer function (1886) for reference Rec.2020 displays is gamma 2.4 [[!Rec.2020]]
18801900

1881-
<pre class="lang-javascript">
1882-
E < β ? 4.5 * E : α * Math.pow(E, 0.45) - (α - 1);
1883-
</pre>
1884-
1885-
Where α=1.09929682680944 and β=0.018053968510807
1886-
<!-- full-precision constants here, not the rounded ones for 10 or 12bit components -->.
18871901
</dl>
18881902

18891903
<h4 id="predefined-to-lab">
@@ -1895,9 +1909,9 @@ Converting predefined colorspaces to Lab</h4>
18951909

18961910
<!-- make these steps links to the appropriate section in a calculations appendix -->
18971911
<ol>
1898-
<li>Convert from gamma-corrected RGB to linear-light RGB (undo gamma correction)
1912+
<li>Convert from gamma-corrected RGB to linear-light RGB (undo gamma encoding)
18991913
<li>Convert from linear RGB to CIE XYZ
1900-
<li>Convert from a D65 whitepoint (used by both dci-p3 and rec2020) to the D50 whitepoint used in Lab,
1914+
<li>Convert from a D65 whitepoint (used by both image-p3 and rec2020) to the D50 whitepoint used in Lab,
19011915
with the Bradford transform
19021916
<li>Convert D50-adapted XYZ to Lab
19031917
</ol>
@@ -1907,15 +1921,15 @@ Converting predefined colorspaces to Lab</h4>
19071921
<h4 id="lab-to-predefined">
19081922
Converting Lab to predefined colorspaces</h4>
19091923

1910-
Conversion from Lab to dci-p3 or rec2020 also requires multiple steps,
1924+
Conversion from Lab to image-p3 or rec2020 also requires multiple steps,
19111925
and again in practice all but the last step are linear calculations and can be combined.
19121926

19131927
<ol>
19141928
<li>Convert Lab to (D50-adapted) XYZ
19151929
<li>Convert from a D50 whitepoint (used by Lab) to the D65 whitepoint used in sRGB,
19161930
with the Bradford transform
19171931
<li>Convert from (D65-adapted) CIE XYZ to linear RGB
1918-
<li>Convert from linear-light RGB to RGB (do gamma correction)
1932+
<li>Convert from linear-light RGB to RGB (do gamma encoding)
19191933
</ol>
19201934

19211935
Implementations may choose to implement these steps in some other way
@@ -1936,7 +1950,7 @@ Specifying a color profile: the ''color-profile'' at-rule</h3>
19361950

19371951
The <<custom-ident>> gives the <a>color profile's</a> name.
19381952
All of the predefined colorspace keywords
1939-
(''srgb'', ''dci-p3'', ''rec2020'')
1953+
(''srgb'', ''image-p3'', ''rec2020'')
19401954
are excluded from this <<custom-ident>>,
19411955
as they're predefined by this specification and always available.
19421956

@@ -2653,9 +2667,6 @@ Issue: The code below is only for sRGB, and duplicates the
26532667
Otherwise, set the channel's value to
26542668
<code>((channel + 0.055) / 1.055) ^ 2.4</code>.
26552669

2656-
Note: This reverses the logarithmic power scaling of the sRGB gamut,
2657-
so the value of the channel is linear with respect to the amount of light produced.
2658-
26592670
<li>
26602671
The luminance is:
26612672

@@ -2741,11 +2752,7 @@ Transparency: the 'opacity' property</h2>
27412752
Simple alpha compositing</h3>
27422753

27432754
When drawing, implementations must handle alpha
2744-
according to the rules in <a href="https://www.w3.org/TR/2003/REC-SVG11-20030114/masking.html#SimpleAlphaBlending">Section 14.2 Simple alpha compositing</a> of [[!SVG11]].
2745-
(If the <a property spec=svg2>color-interpolation</a>
2746-
or 'color-rendering' properties mentioned in that section
2747-
are not implemented or do not apply, implementations must act as though they have their initial values.)
2748-
2755+
according to the rules in <a href="https://www.w3.org/TR/compositing-1/#simplealphacompositing">Section 5.1 Simple alpha compositing</a> of [[!Compositing]].
27492756

27502757
<h2 id='color-adjust'>
27512758
Preserving Colors in Different-Capability Devices: the 'color-adjust' property</h2>
@@ -2846,6 +2853,8 @@ Default Style Rules</h2>
28462853

28472854
<h2 id="color-conversion-code">Sample code for color conversions</h2>
28482855

2856+
<em>This section is not normative.</em>
2857+
28492858
<pre class="lang-javascript">
28502859
<!-- imported 11 May 2016-->
28512860
// sRGB-related functions
@@ -2900,15 +2909,19 @@ function XYZ_to_lin_sRGB(XYZ) {
29002909
return math.multiply(M, XYZ).valueOf();
29012910
}
29022911

2903-
// DCI P3-related functions
2912+
// image-p3-related functions
29042913

29052914

29062915
function lin_P3(RGB) {
2907-
// convert an array of DCI P3 RGB values in the range 0.0 - 1.0
2916+
// convert an array of image-p3 RGB values in the range 0.0 - 1.0
29082917
// to linear light (un-companded) form.
29092918

29102919
return RGB.map(function (val) {
2911-
return Math.pow(val, 2.6);
2920+
if (val < 0.04045) {
2921+
return val / 12.92;
2922+
}
2923+
2924+
return Math.pow((val + 0.055) / 1.055, 2.4);
29122925
});
29132926
}
29142927

@@ -2917,7 +2930,11 @@ function gam_P3(RGB) {
29172930
// to gamma corrected form
29182931

29192932
return RGB.map(function (val) {
2920-
return Math.pow(val, 1/2.6);
2933+
if (val > 0.0031308) {
2934+
return 1.055 * Math.pow(val, 1/2.4) - 0.055;
2935+
}
2936+
2937+
return 12.92 * val;
29212938
});
29222939
}
29232940

@@ -2951,31 +2968,17 @@ function XYZ_to_lin_P3(XYZ) {
29512968
function lin_2020(RGB) {
29522969
// convert an array of Rec. 2020 RGB values in the range 0.0 - 1.0
29532970
// to linear light (un-companded) form.
2954-
const α = 1.09929682680944 ;
2955-
const β = 0.018053968510807;
2956-
29572971
return RGB.map(function (val) {
2958-
if (val < β * 4.5 ) {
2959-
return val / 4.5;
2960-
}
2961-
2962-
return Math.pow((val + α -1 ) / α, 2.4);
2972+
return Math.pow(val, 2.4);
29632973
});
29642974
}
29652975
//check with standard this really is 2.4 and 1/2.4, not 0.45 was wikipedia claims
29662976

29672977
function gam_2020(RGB) {
29682978
// convert an array of linear-light Rec. 2020 RGB in the range 0.0-1.0
29692979
// to gamma corrected form
2970-
const α = 1.09929682680944 ;
2971-
const β = 0.018053968510807;
2972-
29732980
return RGB.map(function (val) {
2974-
if (val > β ) {
2975-
return α * Math.pow(val, 1/2.4) - (α - 1);
2976-
}
2977-
2978-
return 4.5 * val;
2981+
return Math.pow(val, 1/2.4);
29792982
});
29802983
}
29812984

css-color/biblio.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"ITU-R-BT.601": {
3+
"href": "https://www.itu.int/rec/R-REC-BT.601/en",
4+
"title": "Recommendation ITU-R BT.601"
5+
},
6+
"ITU-R-BT.709": {
7+
"title": "Recommendation ITU-R BT.709",
8+
"href": "https://www.itu.int/rec/R-REC-BT.709/en"
9+
},
10+
"SMPTE-ST-296": {
11+
"title": "SMPTE ST 296",
12+
"href": "http://ieeexplore.ieee.org/document/7291722/"
13+
}
14+
}

0 commit comments

Comments
 (0)