@@ -5553,23 +5553,36 @@ Sample Pseudocode for the Binary Search Gamut Mapping Algorithm with Local MINDE
5553
5553
<li> if inGamut(|origin_OKLCH|) is true, convert |origin_OKLCH| to |destination| and return it as the gamut mapped color</li>
5554
5554
<li> otherwise, let delta(|one|, |two|) be a function which returns the deltaEOK of color |one| compared to color |two|</li>
5555
5555
<li> let |JND| be 0.02</li>
5556
+ <li> let |epsilon| be 0.0001</li>
5557
+ <!-- we already excluded spaces with no gamut limits in the first step, so this is fine -->
5556
5558
<li> let clip(|color|)| be a function which converts |color| to |destination|,
5557
5559
converts all negative components to zero,
5558
5560
converts all components greater that one to one,
5559
5561
and returns the result
5560
5562
</li>
5561
5563
<li> set |min| to zero</li>
5562
5564
<li> set |max| to the OKLCH chroma of |origin_OKLCH|</li>
5563
- <li> repeat the following steps
5565
+ <li> let |min_inGamut| be a boolean that represents when |min| is still in gamut, and set it to true
5566
+ <li> while (|max| - |min| is greater than |epsilon|) repeat the following steps
5564
5567
<ol>
5565
5568
<li> set |chroma| to (|min| + |max|) /2</li>
5566
5569
<li> set |current| to |origin_OKLCH| and then set the chroma component to |chroma|</li>
5567
- <li> if inGamut(|current|) is true, set |min| to |chroma| and continue to repeat these steps</li>
5570
+ <li> if |min_inGamut| is true and also if inGamut(|current|) is true, set |min| to |chroma| and continue to repeat these steps</li>
5568
5571
<li> otherwise, if inGamut(|current|) is false carry out these steps:
5569
5572
<ol>
5570
5573
<li> set |clipped| to clip(|current|)</li>
5571
5574
<li> set |E| to delta(|clipped|, |current|)</li>
5572
- <li> if |E| < |JND| return |clipped| as the gamut mapped color</li>
5575
+ <li> if |E| < |JND|
5576
+ <ol>
5577
+ <li> if (|E| - |JND| < |epsilon|) return |clipped| as the gamut mapped color</li>
5578
+ <li> otherwise,
5579
+ <ol>
5580
+ <li> set |min_inGamut| to false</li>
5581
+ <li> set |min| to |chroma|</li>
5582
+ </ol>
5583
+ </li>
5584
+ </ol>
5585
+ </li>
5573
5586
<li> otherwise, set |max| to |chroma| and continue to repeat these steps</li>
5574
5587
</ol>
5575
5588
</li>
0 commit comments