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
Notes: sideshowbarker 2024-07-18 18:46:19 +09:00

View file

@ -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(