Skip to content

Commit cf862fb

Browse files
committed
[css-color-4] Define rec2020 color space to use 2.4 gamma w3c#12574
1 parent 9b4203e commit cf862fb

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
lines changed

css-color-4/Overview.bs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ spec: css-backgrounds-3; type: property; text: border-right-color
106106
"title": "What is CCT? A Guide to Choosing Correlated Color Temperature for Your Lighting",
107107
"date": "2024-08-14",
108108
"href": "https://litomatic.com/blog/what-is-cct-in-lighting/"
109+
},
110+
"Rec_BT.1886": {
111+
"href": "https://www.itu.int/rec/R-REC-BT.1886/en",
112+
"title": "ITU-R BT.1886 Reference electro-optical transfer function for flat panel displays used in HDTV studio production",
113+
"publisher": "ITU",
114+
"date": "2011-03"
109115
}
110116
}
111117
</pre>
@@ -276,7 +282,7 @@ Value Definitions</h3>
276282
<span class="swatch" style="--color: rgb(41.587%, 50.3670%, 36.664%)"></span> color(display-p3 0.43313 0.50108 0.37950);
277283
<span class="swatch" style="--color: rgb(41.587%, 50.3670%, 36.664%)"></span> color(a98-rgb 0.44091 0.49971 0.37408);
278284
<span class="swatch" style="--color: rgb(41.587%, 50.3670%, 36.664%)"></span> color(prophoto-rgb 0.36589 0.41717 0.31333);
279-
<span class="swatch" style="--color: rgb(41.587%, 50.3670%, 36.664%)"></span> color(rec2020 0.42210 0.47580 0.35605);
285+
<span class="swatch" style="--color: rgb(41.587%, 50.3670%, 36.664%)"></span> color(rec2020 0.6295 0.9657 0.3633);
280286
</pre>
281287

282288
</div>
@@ -3871,9 +3877,9 @@ Specifying Predefined Colors: the ''color()'' function</h3>
38713877
This very intense lime color is in-gamut for rec.2020:
38723878
<pre class="lang-css">color(rec2020 0.42053 0.979780 0.00579);</pre>
38733879
in LCH, that color is
3874-
<pre class="lang-css">lch(86.6146% 160.0000 136.0088);</pre>
3880+
<pre class="lang-css">lch(85.9017% 166.116 138.207);</pre>
38753881
in display-p3, that color is
3876-
<pre class="lang-css">color(display-p3 -0.6112 1.0079 -0.2192);</pre>
3882+
<pre class="lang-css">color(display-p3 -0.350289 1.00707 -0.144209);</pre>
38773883
and is out of gamut for display-p3
38783884
(red and blue are negative, green is greater than 1).
38793885
If you have a display-p3 screen, that color is:
@@ -4363,7 +4369,7 @@ The Predefined ITU-R BT.2020-2 Color Space: the ''rec2020'' keyword</h3>
43634369
<tr><th>Green chromaticity</th><td>0.170</td><td>0.797</td></tr>
43644370
<tr><th>Blue chromaticity</th><td>0.131</td><td>0.046</td></tr>
43654371
<tr><th>White chromaticity</th> <td colspan="2">[=D65=]</td></tr>
4366-
<tr><th>Transfer function</th><td colspan="2">see below, from [[!Rec.2020]] table 4</td></tr>
4372+
<tr><th>Transfer function</th><td colspan="2">gamma 2.40, from [[REC_BT.1886]]</td></tr>
43674373
<tr><th>Image state</th><td colspan="2">display-referred</td></tr>
43684374
<tr>
43694375
<th>Percentages</th>
@@ -4375,23 +4381,6 @@ The Predefined ITU-R BT.2020-2 Color Space: the ''rec2020'' keyword</h3>
43754381
</tr>
43764382
</table>
43774383

4378-
<pre class="lang-javascript">
4379-
const α = 1.09929682680944 ;
4380-
const β = 0.018053968510807;
4381-
4382-
let sign = c < 0? -1 : 1;
4383-
let abs = Math.abs(c);
4384-
4385-
if (abs < β * 4.5 ) {
4386-
cl = c / 4.5;
4387-
}
4388-
else {
4389-
cl = sign * (Math.pow((abs + α -1 ) / α, 1/0.45));
4390-
}
4391-
</pre>
4392-
c is the gamma-encoded red, green or blue component.
4393-
cl is the corresponding linear-light component.
4394-
43954384
<figure id="fig-rec2020-lch">
43964385
<img src="images/2020-prim-sec.svg" width=670 height=580
43974386
alt="diagram of rec2020 primaries and secondaries in LCH">

css-color-4/conversions.js

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,48 +234,34 @@ function XYZ_to_lin_a98rgb(XYZ) {
234234
function lin_2020(RGB) {
235235
// convert an array of rec2020 RGB values in the range 0.0 - 1.0
236236
// to linear light (un-companded) form.
237-
// ITU-R BT.2020-2 p.4
238-
239-
const α = 1.09929682680944 ;
240-
const β = 0.018053968510807;
237+
// Reference electro-optical transfer function from Rec. ITU-R BT.1886 Annex 1
238+
// with b (black lift) = 0 and a (user gain) = 1
239+
// defined over the extended range, not clamped
241240

242241
return RGB.map(function (val) {
243242
let sign = val < 0? -1 : 1;
244243
let abs = Math.abs(val);
245-
246-
if (abs < β * 4.5 ) {
247-
return val / 4.5;
248-
}
249-
250-
return sign * (Math.pow((abs + α -1 ) / α, 1/0.45));
244+
return sign * Math.pow(abs, 2.4);
251245
});
252246
}
253247

254248
function gam_2020(RGB) {
255249
// convert an array of linear-light rec2020 RGB in the range 0.0-1.0
256250
// to gamma corrected form
257-
// ITU-R BT.2020-2 p.4
258-
259-
const α = 1.09929682680944 ;
260-
const β = 0.018053968510807;
261-
251+
// Reference electro-optical transfer function from Rec. ITU-R BT.1886 Annex 1
252+
// with b (black lift) = 0 and a (user gain) = 1
253+
// defined over the extended range, not clamped
262254

263255
return RGB.map(function (val) {
264256
let sign = val < 0? -1 : 1;
265257
let abs = Math.abs(val);
266-
267-
if (abs > β ) {
268-
return sign * (α * Math.pow(abs, 0.45) - (α - 1));
269-
}
270-
271-
return 4.5 * val;
258+
return sign * Math.pow(abs, 1 / 2.4);
272259
});
273260
}
274261

275262
function lin_2020_to_XYZ(rgb) {
276263
// convert an array of linear-light rec2020 values to CIE XYZ
277264
// using D65 (no chromatic adaptation)
278-
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
279265
var M = [
280266
[ 63426534 / 99577255, 20160776 / 139408157, 47086771 / 278816314 ],
281267
[ 26158966 / 99577255, 472592308 / 697040785, 8267143 / 139408157 ],

0 commit comments

Comments
 (0)