summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Olsson <matthewcolsson@gmail.com>2021-04-20 12:39:48 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-02 22:48:06 +0200
commit4233b69ecf6811181d0dd5d746cfeca8bdd57432 (patch)
tree3903b61792267fc35a227a9a72c5f3a8470887c1
parentff76a5b8d2e4dfe007c20a1376cb6862a2c2dbe0 (diff)
downloadserenity-4233b69ecf6811181d0dd5d746cfeca8bdd57432.zip
Color: Add interpolate method
-rw-r--r--Userland/Libraries/LibGfx/Color.h10
1 files changed, 10 insertions, 0 deletions
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 <AK/SIMD.h>
#include <AK/StdLibExtras.h>
#include <LibIPC/Forward.h>
+#include <math.h>
namespace Gfx {
@@ -139,6 +140,15 @@ public:
#endif
}
+ constexpr Color interpolate(const Color& other, float weight) const
+ {
+ u8 r = red() + roundf(static_cast<float>(other.red() - red()) * weight);
+ u8 g = green() + roundf(static_cast<float>(other.green() - green()) * weight);
+ u8 b = blue() + roundf(static_cast<float>(other.blue() - blue()) * weight);
+ u8 a = alpha() + roundf(static_cast<float>(other.alpha() - alpha()) * weight);
+ return Color(r, g, b, a);
+ }
+
constexpr Color multiply(const Color& other) const
{
return Color(