1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:57:35 +00:00

Color: Add interpolate method

This commit is contained in:
Matthew Olsson 2021-04-20 12:39:48 -07:00 committed by Andreas Kling
parent ff76a5b8d2
commit 4233b69ecf

View file

@ -12,6 +12,7 @@
#include <AK/SIMD.h> #include <AK/SIMD.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <LibIPC/Forward.h> #include <LibIPC/Forward.h>
#include <math.h>
namespace Gfx { namespace Gfx {
@ -139,6 +140,15 @@ public:
#endif #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 constexpr Color multiply(const Color& other) const
{ {
return Color( return Color(