Skip to content

Commit 609a806

Browse files
facelessusersvgeesus
authored andcommitted
Match the flow CSS
- Return unbounded colors - Return black/white if SDR lightness is exceeded. - Then if color is out of gamut continue chroma reduction
1 parent c40412f commit 609a806

1 file changed

Lines changed: 39 additions & 35 deletions

File tree

css-color-4/Overview.bs

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6072,9 +6072,7 @@ Sample Pseudocode for the Ray Trace Gamut Mapping</h4>
60726072

60736073
<ol>
60746074
<!-- check if we need gamut mapping at all -->
6075-
<li>if |origin| is in gamut for |destination|,
6076-
convert |origin| to |destination| and return it as the gamut mapped color
6077-
</li>
6075+
<li>if |destination| has no gamut limits (XYZ-D65, XYZ-D50, Lab, LCH, Oklab, OkLCh) convert |origin| to |destination| and return it as the gamut mapped color
60786076
<!-- we do, so convert to OkLCh -->
60796077
<li>let |origin_OkLCh| be |origin| converted from |origin color space|
60806078
to the OkLCh color space</li>
@@ -6091,45 +6089,51 @@ Sample Pseudocode for the Ray Trace Gamut Mapping</h4>
60916089
</li>
60926090
<li>let |origin_rgb| be |origin_OkLCh|
60936091
converted to the <em>linear-light</em> form of |destination|</li>
6094-
<li>let |low| be 1E-6 <a href="#raytrace-footnote-1"><sup>1</sup></a></li>
6095-
<li>let |high| be 1.0 - |low| <a href="#raytrace-footnote-2"><sup>2</sup></a></li>
6096-
<li>let |last| be |origin_rgb|</li>
6097-
<li>for (i=0; i&lt;4; i++)
6092+
<!-- check if we need gamut mapping at all -->
6093+
<li>if |origin_rgb| is not in gamut
60986094
<ul>
6099-
<li>if (i > 0)
6095+
<!-- we do, so perform chroma reduction -->
6096+
<li>let |low| be 0.0 + 1E-6 <a href="#raytrace-footnote-1"><sup>1</sup></a></li>
6097+
<li>let |high| be 1.0 - 1E-6 <a href="#raytrace-footnote-2"><sup>2</sup></a></li>
6098+
<li>let |last| be |origin_rgb|</li>
6099+
<li>for (i=0; i&lt;4; i++)
61006100
<ul>
6101-
<li>let |current_OkLCh| be |origin_rgb| converted to OkLCh</li>
6102-
<li>let the lightness of |current_OkLCh| be |l_origin|</li>
6103-
<li>let the hue of |current_OkLCh| be |h_origin|
6104-
<a href="#raytrace-footnote-3"><sup>3</sup></a></li>
6105-
<li>let |origin_rgb| be |current_OkLCh|
6106-
converted to the <em>linear-light</em> form of |destination|
6101+
<li>if (i > 0)
6102+
<ul>
6103+
<li>let |current_OkLCh| be |origin_rgb| converted to OkLCh</li>
6104+
<li>let the lightness of |current_OkLCh| be |l_origin|</li>
6105+
<li>let the hue of |current_OkLCh| be |h_origin|
6106+
<a href="#raytrace-footnote-3"><sup>3</sup></a></li>
6107+
<li>let |origin_rgb| be |current_OkLCh|
6108+
converted to the <em>linear-light</em> form of |destination|
6109+
</li>
6110+
</ul>
6111+
</li>
6112+
<li><b>Cast a ray</b> from |anchor| to |origin_rgb|
6113+
and let |intersection| be
6114+
the intersection of this ray
6115+
with the gamut boundary
61076116
</li>
6117+
<li>if an intersection was not found,
6118+
let |origin_rgb| be |last| and exit the loop
6119+
<a href="#raytrace-footnote-5"><sup>5</sup></a>
6120+
</li>
6121+
<li>if (i >0) AND (each component of |origin_rgb| is between |low| and |high|) then
6122+
let |anchor| be |origin_rgb|
6123+
<a href="#raytrace-footnote-4"><sup>4</sup></a>
6124+
</li>
6125+
<li>let |origin_rgb| be |intersection|</li>
6126+
<li>let |last| be |intersection|</li>
61086127
</ul>
61096128
</li>
6110-
<li><b>Cast a ray</b> from |anchor| to |origin_rgb|
6111-
and let |intersection| be
6112-
the intersection of this ray
6113-
with the gamut boundary
6114-
</li>
6115-
<li>if an intersection was not found,
6116-
let |origin_rgb| be |last| and exit the loop
6117-
<a href="#raytrace-footnote-5"><sup>5</sup></a>
6118-
</li>
6119-
<li>if (i >0) AND (each component of |origin_rgb| is between |low| and |high|) then
6120-
let |anchor| be |origin_rgb|
6121-
<a href="#raytrace-footnote-4"><sup>4</sup></a>
6122-
</li>
6123-
<li>let |origin_rgb| be |intersection|</li>
6124-
<li>let |last| be |intersection|</li>
61256129
</ul>
61266130
</li>
6127-
<!-- final tidying up -->
6128-
<li>let |clipped| be |origin_rgb| clipped to gamut (components in range 0 to 1),
6129-
thus trimming off any noise due to floating point inaccuracy
6130-
</li>
6131-
<li>return |clipped|, converted to |destination| as the gamut mapped color</li>
6132-
<!-- should those two be in the reverse order, convert to destination then clip? -->
6131+
<!-- we already excluded spaces with no gamut limits in the first step, so this is fine -->
6132+
<li>let clip(|color|) be a function which converts |color| to |destination|,
6133+
clamps each component to the bounds of the reference range for that component
6134+
and returns the result</li>
6135+
<li>set |clipped| to clip(|current|)</li>
6136+
<li>return |clipped| as the gamut mapped color</li>
61336137
</ol>
61346138

61356139

0 commit comments

Comments
 (0)