Skip to content

Commit

Permalink
Add range striping to saturation/lightness modification function to w…
Browse files Browse the repository at this point in the history
…ork like ruby sass implementation
  • Loading branch information
Nabellaleen committed Oct 18, 2013
1 parent d04d552 commit fea744c
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,15 @@ namespace Sass {
HSL hsl_color = rgb_to_hsl(rgb_color->r(),
rgb_color->g(),
rgb_color->b());
//Check lightness is not negative before lighten it
double hslcolorL = hsl_color.l;
if (hslcolorL < 0) {
hslcolorL = 0;
}

return hsla_impl(hsl_color.h,
hsl_color.s,
hsl_color.l + amount->value(),
hslcolorL + amount->value(),
rgb_color->a(),
ctx,
path,
Expand All @@ -317,9 +323,16 @@ namespace Sass {
HSL hsl_color = rgb_to_hsl(rgb_color->r(),
rgb_color->g(),
rgb_color->b());

//Check lightness if not over 100, before darken it
double hslcolorL = hsl_color.l;
if (hslcolorL > 100) {
hslcolorL = 100;
}

return hsla_impl(hsl_color.h,
hsl_color.s,
hsl_color.l - amount->value(),
hslcolorL - amount->value(),
rgb_color->a(),
ctx,
path,
Expand All @@ -334,8 +347,15 @@ 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;
if (hslcolorS < 0) {
hslcolorS = 0;
}


return hsla_impl(hsl_color.h,
hsl_color.s + amount->value(),
hslcolorS + amount->value(),
hsl_color.l,
rgb_color->a(),
ctx,
Expand All @@ -351,8 +371,14 @@ 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;
if (hslcolorS > 100) {
hslcolorS = 100;
}

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

0 comments on commit fea744c

Please sign in to comment.