Skip to content

Commit

Permalink
Merge pull request #865 from alprs/fix_desaturate-grey
Browse files Browse the repository at this point in the history
Fix desaturation of greyscale colours
  • Loading branch information
xzyfer committed Feb 2, 2015
2 parents 4d5ea59 + 657486b commit 175c167
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,19 @@ namespace Sass {
HSL hsl_color = rgb_to_hsl(rgb_color->r(),
rgb_color->g(),
rgb_color->b());
//Check saturation is not negative before saturate it
double hslcolorS = hsl_color.s;

double hslcolorS = hsl_color.s + amount->value();

// Saturation cannot be below 0 or above 100
if (hslcolorS < 0) {
hslcolorS = 0;
}

if (hslcolorS > 100) {
hslcolorS = 100;
}

return hsla_impl(hsl_color.h,
hslcolorS + amount->value(),
hslcolorS,
hsl_color.l,
rgb_color->a(),
ctx,
Expand All @@ -431,14 +435,19 @@ namespace Sass {
HSL hsl_color = rgb_to_hsl(rgb_color->r(),
rgb_color->g(),
rgb_color->b());
//Check saturation is not over 100 before desaturate it
double hslcolorS = hsl_color.s;

double hslcolorS = hsl_color.s - amount->value();

// Saturation cannot be below 0 or above 100
if (hslcolorS <= 0) {
hslcolorS = 0;
}
if (hslcolorS > 100) {
hslcolorS = 100;
}

return hsla_impl(hsl_color.h,
hslcolorS - amount->value(),
hslcolorS,
hsl_color.l,
rgb_color->a(),
ctx,
Expand Down

0 comments on commit 175c167

Please sign in to comment.