summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-08-17 18:04:08 +0200
committerLinus Groh <mail@linusgroh.de>2022-09-03 16:57:37 +0100
commit049c1a536c295cc85c0e3e42721cd3e4c382fe00 (patch)
tree81d20b6623528d9cfd9a0801fcc5c80bfe1dec20 /Userland
parent5bb277d9ecb845211646db3b08a3d6e32c6800d9 (diff)
downloadserenity-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.h9
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());