mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
Color: Add interpolate method
This commit is contained in:
parent
ff76a5b8d2
commit
4233b69ecf
1 changed files with 10 additions and 0 deletions
|
@ -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(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue