diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-08-17 18:04:08 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-03 16:57:37 +0100 |
commit | 049c1a536c295cc85c0e3e42721cd3e4c382fe00 (patch) | |
tree | 81d20b6623528d9cfd9a0801fcc5c80bfe1dec20 /Userland | |
parent | 5bb277d9ecb845211646db3b08a3d6e32c6800d9 (diff) | |
download | serenity-049c1a536c295cc85c0e3e42721cd3e4c382fe00.zip |
LibGfx: Add saturation modification functions to Color
This operates via the HSV color space; I'm not 100% sure whether the
conversions are lossless.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGfx/Color.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index 4277089712..941bc2dd7c 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -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()); |