From 049c1a536c295cc85c0e3e42721cd3e4c382fe00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 17 Aug 2022 18:04:08 +0200 Subject: [PATCH] LibGfx: Add saturation modification functions to Color This operates via the HSV color space; I'm not 100% sure whether the conversions are lossless. --- Userland/Libraries/LibGfx/Color.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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 shades(u32 steps, float max = 1.f) const; Vector 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(saturation), hsv.value); + color.set_alpha(alpha); + return color; + } + constexpr Color inverted() const { return Color(~red(), ~green(), ~blue(), alpha());