Skip to content

Commit

Permalink
[css-color-4] Update pseudocode for GMA per #7135
Browse files Browse the repository at this point in the history
  • Loading branch information
svgeesus committed Jul 4, 2022
1 parent d452a10 commit e30aec4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions css-color-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5553,23 +5553,36 @@ Sample Pseudocode for the Binary Search Gamut Mapping Algorithm with Local MINDE
<li>if inGamut(|origin_OKLCH|) is true, convert |origin_OKLCH| to |destination| and return it as the gamut mapped color</li>
<li>otherwise, let delta(|one|, |two|) be a function which returns the deltaEOK of color |one| compared to color |two|</li>
<li>let |JND| be 0.02</li>
<li>let |epsilon| be 0.0001</li>
<!-- we already excluded spaces with no gamut limits in the first step, so this is fine -->
<li>let clip(|color|)| be a function which converts |color| to |destination|,
converts all negative components to zero,
converts all components greater that one to one,
and returns the result
</li>
<li>set |min| to zero</li>
<li>set |max| to the OKLCH chroma of |origin_OKLCH|</li>
<li>repeat the following steps
<li> let |min_inGamut| be a boolean that represents when |min| is still in gamut, and set it to true
<li>while (|max| - |min| is greater than |epsilon|) repeat the following steps
<ol>
<li>set |chroma| to (|min| + |max|) /2</li>
<li>set |current| to |origin_OKLCH| and then set the chroma component to |chroma|</li>
<li>if inGamut(|current|) is true, set |min| to |chroma| and continue to repeat these steps</li>
<li>if |min_inGamut| is true and also if inGamut(|current|) is true, set |min| to |chroma| and continue to repeat these steps</li>
<li>otherwise, if inGamut(|current|) is false carry out these steps:
<ol>
<li>set |clipped| to clip(|current|)</li>
<li>set |E| to delta(|clipped|, |current|)</li>
<li>if |E| < |JND| return |clipped| as the gamut mapped color</li>
<li>if |E| < |JND|
<ol>
<li>if (|E| - |JND| < |epsilon|) return |clipped| as the gamut mapped color</li>
<li>otherwise,
<ol>
<li>set |min_inGamut| to false</li>
<li>set |min| to |chroma|</li>
</ol>
</li>
</ol>
</li>
<li>otherwise, set |max| to |chroma| and continue to repeat these steps</li>
</ol>
</li>
Expand Down

0 comments on commit e30aec4

Please sign in to comment.