From 4233b69ecf6811181d0dd5d746cfeca8bdd57432 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Tue, 20 Apr 2021 12:39:48 -0700 Subject: [PATCH] Color: Add interpolate method --- Userland/Libraries/LibGfx/Color.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index f4045fff99..f3f2f98a09 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace Gfx { @@ -139,6 +140,15 @@ public: #endif } + constexpr Color interpolate(const Color& other, float weight) const + { + u8 r = red() + roundf(static_cast(other.red() - red()) * weight); + u8 g = green() + roundf(static_cast(other.green() - green()) * weight); + u8 b = blue() + roundf(static_cast(other.blue() - blue()) * weight); + u8 a = alpha() + roundf(static_cast(other.alpha() - alpha()) * weight); + return Color(r, g, b, a); + } + constexpr Color multiply(const Color& other) const { return Color(