1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:17:44 +00:00

LibGfx: Add saturation modification functions to Color

This operates via the HSV color space; I'm not 100% sure whether the
conversions are lossless.
This commit is contained in:
kleines Filmröllchen 2022-08-17 18:04:08 +02:00 committed by Linus Groh
parent 5bb277d9ec
commit 049c1a536c

View file

@ -313,6 +313,15 @@ public:
Vector<Color> shades(u32 steps, float max = 1.f) const;
Vector<Color> tints(u32 steps, float max = 1.f) const;
constexpr Color saturated_to(float saturation) const
{
auto hsv = to_hsv();
auto alpha = this->alpha();
auto color = Color::from_hsv(hsv.hue, static_cast<double>(saturation), hsv.value);
color.set_alpha(alpha);
return color;
}
constexpr Color inverted() const
{
return Color(~red(), ~green(), ~blue(), alpha());