Skip to content

Commit 0503cf1

Browse files
committed
[css-color-4] update inline transfer functions for extended
1 parent 29a198d commit 0503cf1

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

css-color-4/Overview.bs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,14 +3313,18 @@ and ''xyz''.</h3>
33133313
</table>
33143314

33153315
<pre class="lang-javascript">
3316-
var Cl;
3317-
if (C <= 0.04045)
3318-
Cl = C / 12.92;
3319-
else
3320-
Cl = Math.pow((C + 0.055) / 1.055, 2.4);
3316+
let sign = c < 0? -1 : 1;
3317+
let abs = Math.abs(c);
3318+
3319+
if (abs < 0.04045) {
3320+
cl = c / 12.92;
3321+
}
3322+
else {
3323+
cl = sign * (Math.pow((abs + 0.055) / 1.055, 2.4));
3324+
}
33213325
</pre>
3322-
C is the gamma-encoded red, green or blue component.
3323-
Cl is the corresponding linear-light component.
3326+
c is the gamma-encoded red, green or blue component.
3327+
cl is the corresponding linear-light component.
33243328

33253329
<figure>
33263330
<img src="images/sRGB-prim-sec.svg" width=540 height=520
@@ -3472,13 +3476,19 @@ and ''xyz''.</h3>
34723476
</table>
34733477

34743478
<pre class="lang-javascript">
3475-
var Cl;
3476-
if (C <= (16/512))
3477-
Cl = C / 16;
3478-
else
3479-
Cl = Math.pow(C, 1.8);
3480-
</pre>
3481-
C is the red, green or blue component.
3479+
const E = 16/512;
3480+
let sign = c < 0? -1 : 1;
3481+
let abs = Math.abs(c);
3482+
3483+
if (abs <= E) {
3484+
cl = c / 16;
3485+
}
3486+
else {
3487+
cl = sign * Math.pow(c, 1.8);
3488+
}
3489+
</pre>
3490+
c is the gamma-encoded red, green or blue component.
3491+
cl is the corresponding linear-light component.
34823492

34833493
<figure>
34843494
<img src="images/prophoto-prim-sec.svg" width=780 height=760
@@ -3523,7 +3533,7 @@ and ''xyz''.</h3>
35233533
<tr><th>Green chromaticity</th><td>0.170</td><td>0.797</td></tr>
35243534
<tr><th>Blue chromaticity</th><td>0.131</td><td>0.046</td></tr>
35253535
<tr><th>White chromaticity</th><td>0.31272</td><td>0.32903</td><td>(D65)</td></tr>
3526-
<tr><th>Transfer function</th><td colspan="2">1/2.4 (see note)</td></tr>
3536+
<tr><th>Transfer function</th><td colspan="2">see below</td></tr>
35273537
<tr><th>Image state</th><td colspan="2">display-referred</td></tr>
35283538
<tr>
35293539
<th>Percentages</th>
@@ -3532,16 +3542,21 @@ and ''xyz''.</h3>
35323542
</table>
35333543

35343544
<pre class="lang-javascript">
3535-
const α = 1.09929682680944;
3536-
const β = 0.018053968510807,
3537-
var Cl;
3538-
if (C < β * 4.5)
3539-
Cl = C / 4.5;
3540-
else
3541-
Cl = Math.pow((val + α -1 ) / α, 1/4.5);
3542-
</pre>
3543-
C is the gamma-encoded red, green or blue component.
3544-
Cl is the corresponding linear-light component.
3545+
const α = 1.09929682680944 ;
3546+
const β = 0.018053968510807;
3547+
3548+
let sign = c < 0? -1 : 1;
3549+
let abs = Math.abs(c);
3550+
3551+
if (abs < β * 4.5 ) {
3552+
cl = c / 4.5;
3553+
}
3554+
else {
3555+
cl = sign * (Math.pow((abs + α -1 ) / α, 1/0.45));
3556+
}
3557+
</pre>
3558+
c is the gamma-encoded red, green or blue component.
3559+
cl is the corresponding linear-light component.
35453560

35463561
<figure>
35473562
<img src="images/2020-prim-sec.svg" width=670 height=580

0 commit comments

Comments
 (0)