new implementations for Gtkmm2ext::HSV::{darker,lighter} that follow "common sense" rather than Google.
HSV::shade() still follows the google model
This commit is contained in:
parent
ff6fe51d76
commit
783e33dc0c
@ -240,6 +240,10 @@ HSV::HSV (double hh, double ss, double vv, double aa)
|
||||
/* normalize negative hue values into positive range */
|
||||
h = 360.0 + h;
|
||||
}
|
||||
|
||||
s = max (0.0, min (1.0, s));
|
||||
v = max (0.0, min (1.0, v));
|
||||
a = max (0.0, min (1.0, a));
|
||||
}
|
||||
|
||||
HSV::HSV (Color c)
|
||||
@ -328,6 +332,25 @@ HSV::operator== (const HSV& other)
|
||||
a == other.a;
|
||||
}
|
||||
|
||||
HSV
|
||||
HSV::darker (double factor) const
|
||||
{
|
||||
HSV hsv (*this);
|
||||
/* factor == 1.0: reduce all the way to zero */
|
||||
hsv.v -= max (0.0, min (1.0, factor)) * hsv.v;
|
||||
return hsv;
|
||||
}
|
||||
|
||||
HSV
|
||||
HSV::lighter (double factor) const
|
||||
{
|
||||
HSV hsv (*this);
|
||||
/* factor == 1.0: increase all the way to 1.0 */
|
||||
hsv.v += max (0.0, min (1.0, factor)) * (1.0 - hsv.v);
|
||||
return hsv;
|
||||
}
|
||||
|
||||
|
||||
HSV
|
||||
HSV::shade (double factor) const
|
||||
{
|
||||
@ -344,15 +367,21 @@ HSV::shade (double factor) const
|
||||
*/
|
||||
|
||||
if (factor > 1.0) {
|
||||
if (s < 88) {
|
||||
hsv.v += (hsv.v * (factor * 10.0));
|
||||
}
|
||||
/* darker */
|
||||
/* increase saturation (factor is > 1.0, so s grows) */
|
||||
hsv.s *= factor;
|
||||
if (hsv.s >= 0.88) {
|
||||
/* above saturation threshold, so decrease v a bit */
|
||||
hsv.v -= (hsv.v * 0.05);
|
||||
}
|
||||
} else {
|
||||
if (s < 88) {
|
||||
hsv.v -= (hsv.v * (factor * 10.0));
|
||||
}
|
||||
/* lighter */
|
||||
/* reduce saturation, (factor is < 1.0, so s shrinks) */
|
||||
hsv.s *= factor;
|
||||
if (hsv.s > 0.88) {
|
||||
/* still above 88% saturation, so increase v a bit */
|
||||
hsv.v += (hsv.v * 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
hsv.clamp();
|
||||
|
@ -115,8 +115,8 @@ struct LIBGTKMM2EXT_API HSV
|
||||
double distance (const HSV& other) const;
|
||||
HSV delta (const HSV& other) const;
|
||||
|
||||
HSV darker (double factor = 1.3) const { return shade (factor); }
|
||||
HSV lighter (double factor = 0.7) const { return shade (factor); }
|
||||
HSV darker (double factor = 1.3) const;
|
||||
HSV lighter (double factor = 0.7) const;
|
||||
|
||||
HSV shade (double factor) const;
|
||||
HSV mix (const HSV& other, double amt) const;
|
||||
|
Loading…
Reference in New Issue
Block a user