summaryrefslogtreecommitdiff
path: root/src/blender
diff options
context:
space:
mode:
Diffstat (limited to 'src/blender')
-rw-r--r--src/blender/blender.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/blender/blender.c b/src/blender/blender.c
index 0e0835d..738811d 100644
--- a/src/blender/blender.c
+++ b/src/blender/blender.c
@@ -1,6 +1,7 @@
1#include "blender/blender.h" 1#include "blender/blender.h"
2#include <assert.h> 2#include <assert.h>
3#include <math.h> 3#include <math.h>
4#include "morpher/morpher.h"
4 5
5static ColorComponent blend_components(ColorComponent origin, ColorComponent target, TimeVector frame) { 6static ColorComponent blend_components(ColorComponent origin, ColorComponent target, TimeVector frame) {
6 return (ColorComponent) sqrt((TIME_UNIT - frame) * pow(origin, 2) + frame * pow(target, 2)); 7 return (ColorComponent) sqrt((TIME_UNIT - frame) * pow(origin, 2) + frame * pow(target, 2));
@@ -13,3 +14,31 @@ Color blender_blend_colors(Color origin, Color target, TimeVector frame) {
13 blend_components(origin.rgba.b, target.rgba.b, frame), 14 blend_components(origin.rgba.b, target.rgba.b, frame),
14 blend_components(origin.rgba.a, target.rgba.a, frame)}}; 15 blend_components(origin.rgba.a, target.rgba.a, frame)}};
15} 16}
17
18void blender_blend_canvas(Canvas *canvas, Canvas *source, Canvas *target, Morphing *morphing, TimeVector frame) {
19 IntVector flat_dim;
20 CartesianVector dim, point;
21 CartesianMapping mapping;
22 Color pixel;
23
24 dim = morpher_get_dim(morphing);
25
26 assert(dim.x > 0 && dim.y > 0);
27 assert(vector_equals(dim, canvas_get_dim(canvas)));
28 assert(vector_equals(dim, canvas_get_dim(source)));
29 assert(vector_equals(dim, canvas_get_dim(target)));
30 assert(frame >= TIME_ORIGIN && frame <= TIME_UNIT);
31
32 for (flat_dim = (dim.x - 1) * (dim.y - 1); flat_dim >= 0; --flat_dim) {
33 point.x = flat_dim % dim.y;
34 point.y = flat_dim / dim.y;
35
36 mapping = morpher_get_point_mapping(morphing, point, frame);
37
38 pixel = blender_blend_colors(canvas_get_pixel(source, mapping.origin),
39 canvas_get_pixel(target, mapping.target),
40 frame);
41
42 canvas_set_pixel(canvas, point, pixel);
43 }
44}