diff --git a/include/color.hpp b/include/color.hpp index b0f251ac..a32868f4 100644 --- a/include/color.hpp +++ b/include/color.hpp @@ -34,6 +34,8 @@ NVGcolor plus(NVGcolor a, NVGcolor b); /** Multiplies color components elementwise. */ NVGcolor mult(NVGcolor a, NVGcolor b); NVGcolor mult(NVGcolor a, float x); +/** Interpolates RGBA color values. */ +NVGcolor lerp(NVGcolor a, NVGcolor b, float t); /** Screen blending with alpha compositing */ NVGcolor screen(NVGcolor a, NVGcolor b); /** Multiplies alpha value. */ diff --git a/src/color.cpp b/src/color.cpp index e1e04122..3c90a756 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -44,6 +44,13 @@ NVGcolor mult(NVGcolor a, float x) { return a; } +NVGcolor lerp(NVGcolor a, NVGcolor b, float t) { + NVGcolor c; + for (int i = 0; i < 4; i++) + c.rgba[i] = a.rgba[i] * (1 - t) + b.rgba[i] * t; + return c; +} + /** Screen blending with alpha compositing */ NVGcolor screen(NVGcolor a, NVGcolor b) { if (a.a == 0.f)