Skip to content

Commit 91429dc

Browse files
committed
Fix the RGB to HSL algorithm
1 parent 25f2d10 commit 91429dc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

functions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,16 @@ namespace Sass {
249249
h = s = 0; // achromatic
250250
}
251251
else {
252-
if (l < 0.5) s = del / (2.0 * l);
253-
else s = del / (2.0 - 2.0 * l);
252+
if (l < 0.5) s = del / (max + min);
253+
else s = del / (2.0 - max - min);
254254

255-
if (r == max) h = 60 * (g - b) / del;
256-
else if (g == max) h = 60 * (b - r) / del + 120;
257-
else if (b == max) h = 60 * (r - g) / del + 240;
255+
if (r == max) h = (g - b) / del + (g < b ? 6 : 0);
256+
else if (g == max) h = (b - r) / del + 2;
257+
else if (b == max) h = (r - g) / del + 4;
258258
}
259259

260260
HSL hsl_struct;
261-
hsl_struct.h = h;
261+
hsl_struct.h = h / 6 * 360;
262262
hsl_struct.s = s * 100;
263263
hsl_struct.l = l * 100;
264264

0 commit comments

Comments
 (0)