diff options
| author | Syndamia <kamen@syndamia.com> | 2026-03-15 12:23:21 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2026-03-15 12:23:21 +0200 |
| commit | 2202e87c466803eeaddd974006aa9950d8e0d067 (patch) | |
| tree | 55cac9843e5789ac6ff29345ecd4fc44775c6b31 /AnimationInterpolate.c | |
| parent | 47e28b44615b9b068776f61b8741ea8692461c1d (diff) | |
| download | ppm_graphics-2202e87c466803eeaddd974006aa9950d8e0d067.tar ppm_graphics-2202e87c466803eeaddd974006aa9950d8e0d067.tar.gz ppm_graphics-2202e87c466803eeaddd974006aa9950d8e0d067.zip | |
Diffstat (limited to 'AnimationInterpolate.c')
| -rw-r--r-- | AnimationInterpolate.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/AnimationInterpolate.c b/AnimationInterpolate.c new file mode 100644 index 0000000..2ff4a8b --- /dev/null +++ b/AnimationInterpolate.c @@ -0,0 +1,42 @@ +#include "AnimationInterpolate.h" +#include "AnimationObject.h" + +#define NUM_INTERPOLATE(a, b, perc) (a * (1.0 - (perc)) + b * (perc)) + +byte4 +colorInterpolate(byte4 ina, byte4 inb, double percentage) { + ARGB a, b; + ARGB_set(&a, ina); + ARGB_set(&b, inb); + + a.a = NUM_INTERPOLATE(a.a, b.a, percentage); + a.r = NUM_INTERPOLATE(a.r, b.r, percentage); + a.g = NUM_INTERPOLATE(a.g, b.g, percentage); + a.b = NUM_INTERPOLATE(a.b, b.b, percentage); + + return a.a << 24 | a.r << 16 | a.g << 8 | a.b; +} + +ARGB +A_Interpolate(const Animation* anim, u32 frameIndex, ARGB pixel, i32 r, i32 c, void* priv) { + struct A_Interpolate in = *(struct A_Interpolate*)priv; + + double perc = (double)(frameIndex - in.startFrame) / (in.endFrame - in.startFrame); + if (perc < 0.0) perc = 0.0; + if (perc > 1.0) perc = 1.0; + + in.interpolate(in.value, in.initialState, in.finalState, perc); + + return in.callback(anim, frameIndex, pixel, r, c, in.priv); +} + +void +AO_LineInterpolate(void* valueLine, const void* initialLine, const void* finalLine, double percentage) { + struct AO_Line* value = valueLine; + const struct AO_Line* initial = initialLine, *final = finalLine; + value->a = NUM_INTERPOLATE(initial->a, final->a, percentage); + value->b = NUM_INTERPOLATE(initial->b, final->b, percentage); + value->c = NUM_INTERPOLATE(initial->c, final->c, percentage); + value->width = NUM_INTERPOLATE(initial->width, final->width, percentage); + value->color = colorInterpolate(initial->color, final->color, percentage); +} |
