summaryrefslogtreecommitdiff
path: root/AnimationInterpolate.c
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2026-03-15 12:23:21 +0200
committerSyndamia <kamen@syndamia.com>2026-03-15 12:23:21 +0200
commit2202e87c466803eeaddd974006aa9950d8e0d067 (patch)
tree55cac9843e5789ac6ff29345ecd4fc44775c6b31 /AnimationInterpolate.c
parent47e28b44615b9b068776f61b8741ea8692461c1d (diff)
downloadppm_graphics-master.tar
ppm_graphics-master.tar.gz
ppm_graphics-master.zip
feat!: Split into separate filesHEADmaster
Diffstat (limited to 'AnimationInterpolate.c')
-rw-r--r--AnimationInterpolate.c42
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);
+}