@@ -1788,11 +1788,16 @@ Converting HWB colors to sRGB colors</h3>
17881788 Converting an HWB color to sRGB is straightforward,
17891789 and related to how one converts HSL to RGB.
17901790 The following Javascript implementation of the algorithm
1791- assumes that the white and black components have already been normalized,
1792- so their sum is no larger than 100%,
1793- and have been converted into numbers in the range [0,1] .
1791+ first normalizes the white and black components,
1792+ so their sum is no larger than 100%.
17941793
17951794 <pre class="lang-javascript">
1795+ white /= 100;
1796+ black /= 100;
1797+ if (white + black >= 1) {
1798+ var gray = white / (white + black);
1799+ return [gray, gray, gray] ;
1800+ }
17961801 function hwbToRgb(hue, white, black) {
17971802 var rgb = hslToRgb(hue, 1, .5);
17981803 for(var i = 0; i < 3; i++) {
@@ -1806,17 +1811,13 @@ Converting HWB colors to sRGB colors</h3>
18061811<h3 id="rgb-to-hwb">Converting sRGB colors to HWB colors</h3>
18071812
18081813 Conversion in the reverse direction proceeds similarly.
1809- The following Javascript implementation
1810- leaves white and black
1811- in the range [0,1]
1812- rather than converting them to [0.0%,100.0%] .
18131814
18141815<pre class="lang-javascript">
18151816 function rgbToHwb(red, green, blue) {
18161817 var hsl = rgbToHsl(rgb);
18171818 var white = Math.min(...rgb);
18181819 var black = 1 - Math.max(...rgb);
1819- return([hsl[0] , white, black]);
1820+ return([hsl[0] , white*100 , black*100 ]);
18201821 }
18211822</pre>
18221823
0 commit comments