Skip to content

Commit 11e3936

Browse files
committed
[css-color-hdr] Clarify pseudo-code for color-hdr() to show each component is calculated separately #11694
Co-authored-by: @LeaVerou
1 parent 30200ed commit 11e3936

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

css-color-hdr-1/Overview.bs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ Mixing Dynamic Range Limits: the ''dynamic-range-limit-mix()'' function {#dynami
558558

559559
It does this by specifying two <<color>> values,
560560
each with an associated level of HDR headroom.
561+
(The two headroom values must not be the same).
561562
The actual value is computed by interpolating between these two colors,
562563
based on the current amount of HDR headroom,
563564
as described in [[#headroom-interpolation]].
@@ -567,7 +568,7 @@ Mixing Dynamic Range Limits: the ''dynamic-range-limit-mix()'' function {#dynami
567568
in raster images conforming to [[ISO_21496-1]].
568569
</div>
569570

570-
The actual calculated color is not exposed,
571+
For privacy reasons, the actual calculated color is not exposed,
571572
nor is the actual HDR headroom,
572573
as this is a fingerprinting vector.
573574

@@ -598,9 +599,10 @@ Mixing Dynamic Range Limits: the ''dynamic-range-limit-mix()'' function {#dynami
598599
<pre class="lang-css">color(rec2100-linear 1.8 2.0 1.5) 2);</pre>
599600

600601
For displays whose headroom lies between 0 and 2, the color is
601-
interpolated. For example, on a display with HDR headroom 1:
602+
interpolated. For <a href="#ex-hdr-interpolate">example</a>,
603+
on a display with HDR headroom 1:
602604

603-
@@ Add to the example with the calculated result at headroom 1 @@
605+
X = 243.664, Y = 275.713, Z = 244.000
604606

605607
</div>
606608

@@ -613,24 +615,27 @@ Mixing Dynamic Range Limits: the ''dynamic-range-limit-mix()'' function {#dynami
613615
giving result color <var>cxyz</var>,
614616
when the target headroom is <var>H</var>:
615617

616-
1. Let <var>c1xyz</var> be <var>c1</var> converted to D65 CIE XYZ
617-
2. Let <var>c2xyz</var> be <var>c2</var> converted to D65 CIE XYZ
618+
1. Let <var>c1xyz</var> be <var>c1</var> converted to Absolute D65 CIE XYZ
619+
2. Let <var>c2xyz</var> be <var>c2</var> converted to Absolute D65 CIE XYZ
618620
3. Let <var> w1</var> = clamp((<var>H</var> - <var>H2</var>) / (<var>H1</var> - <var>H2</var>), 0, 1)
619621
4. Let <var> w2</var> = clamp((<var>H</var> - <var>H1</var>) / (<var>H2</var> - <var>H1</var>), 0, 1)
620622
Note that <var> w2</var> = 1 - <var> w1</var>
621623
5. Let <var>eps</var> = 0.001 (one JND in linear-light space)
622-
6. Let <var>cxyz</var> = pow(<var>c1xyz</var> + <var>eps</var>, <var>w1</var>) * pow(<var>c2xyz</var> + <var>eps</var>, <var>w2</var>) - <var>eps</var>
624+
6. Let <var>cxyz</var> = Array(3)
625+
7. For i from 0 to 2:
626+
Let <var>cxyz</var>[i] = pow(<var>c1xyz</var>[i] + <var>eps</var>, <var>w1</var> ) * pow(<var>c2xyz</var>[i] + <var>eps</var>, <var>w2</var> ) - <var>eps</var>
623627

624628
<div class="example" id="ex-hdr-interpolate">
625629
For example, given c1 = color(rec2100-linear 0.9 1.0 0.8)
626630
c2 = color(rec2100-linear 1.8 2.0 1.5),
627631
H1 = 0, H2 = 2, and H = 1:
628632

629633
<pre class="lang-css">
630-
c1xyz = color(xyz-d65 0.853 0.9619 0.8769)
631-
c2xyz = color(xyz-d65 1.689 1.918 1.648)
632-
w1 =
633-
w2 =
634+
c1xyz = [ 173.156, 195.260, 178.003 ]
635+
c2xyz = [ 342.883, 389.315, 334.467 ]
636+
w1 = 0.5
637+
w2 = 0.5
638+
cxyz = [ 243.664, 275.713, 244.000 ]
634639
</pre>
635640
</div>
636641

css-color-hdr-1/workings/hdr-color.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ function colorHdr(col1, H1, col2, H2, H) {
1515

1616
let c1xyz = col1.to("xyz-abs-d65").coords;
1717
let c2xyz = col2.to("xyz-abs-d65").coords;
18+
console.log(c1xyz);
19+
console.log(c2xyz);
1820
let w1 = clamp((H - H2) / (H1 - H2), 0, 1);
1921
let w2 = clamp((H - H1) / (H2 - H1), 0, 1);
22+
console.log(w1, w2);
2023
let eps = 0.001;
2124
let cxyz = Array(3);
2225
for (let i=0; i<3; i++) {

0 commit comments

Comments
 (0)