diff options
-rw-r--r-- | include/blender/blender.h | 16 | ||||
-rw-r--r-- | src/blender/blender.c | 12 | ||||
-rw-r--r-- | test/blender/blender.c | 9 |
3 files changed, 4 insertions, 33 deletions
diff --git a/include/blender/blender.h b/include/blender/blender.h index 356c68e..8e89208 100644 --- a/include/blender/blender.h +++ b/include/blender/blender.h | |||
@@ -8,7 +8,6 @@ | |||
8 | 8 | ||
9 | #include "common/time.h" | 9 | #include "common/time.h" |
10 | #include "blender/canvas.h" | 10 | #include "blender/canvas.h" |
11 | #include "blender/color.h" | ||
12 | #include "morpher/morpher.h" | 11 | #include "morpher/morpher.h" |
13 | 12 | ||
14 | /** | 13 | /** |
@@ -24,19 +23,4 @@ | |||
24 | */ | 23 | */ |
25 | void blender_blend_canvas(Canvas *canvas, Canvas *source, Canvas *target, Morphing *morphing, TimeVector frame); | 24 | void blender_blend_canvas(Canvas *canvas, Canvas *source, Canvas *target, Morphing *morphing, TimeVector frame); |
26 | 25 | ||
27 | /** | ||
28 | * Function: blender_blend_colors | ||
29 | * Properly blends two coloured pixels, interpolated at the given time frame. | ||
30 | * (https://www.youtube.com/watch?v=LKnqECcg6Gw) | ||
31 | * | ||
32 | * Parameters: | ||
33 | * origin - the origin colour | ||
34 | * target - the target colour | ||
35 | * frame - the interpolation distance from the origin colour [0;1] | ||
36 | * | ||
37 | * Returns: | ||
38 | * The blended coloured pixel | ||
39 | */ | ||
40 | Color blender_blend_colors(Color origin, Color target, TimeVector frame); | ||
41 | |||
42 | #endif | 26 | #endif |
diff --git a/src/blender/blender.c b/src/blender/blender.c index 738811d..99abedd 100644 --- a/src/blender/blender.c +++ b/src/blender/blender.c | |||
@@ -3,12 +3,12 @@ | |||
3 | #include <math.h> | 3 | #include <math.h> |
4 | #include "morpher/morpher.h" | 4 | #include "morpher/morpher.h" |
5 | 5 | ||
6 | static ColorComponent blend_components(ColorComponent origin, ColorComponent target, TimeVector frame) { | 6 | static inline ColorComponent blend_components(ColorComponent origin, ColorComponent target, TimeVector frame) { |
7 | // https://www.youtube.com/watch?v=LKnqECcg6Gw | ||
7 | return (ColorComponent) sqrt((TIME_UNIT - frame) * pow(origin, 2) + frame * pow(target, 2)); | 8 | return (ColorComponent) sqrt((TIME_UNIT - frame) * pow(origin, 2) + frame * pow(target, 2)); |
8 | } | 9 | } |
9 | 10 | ||
10 | Color blender_blend_colors(Color origin, Color target, TimeVector frame) { | 11 | static inline Color blend_colors(Color origin, Color target, TimeVector frame) { |
11 | assert(frame >= TIME_ORIGIN && frame <= TIME_UNIT); | ||
12 | return (Color) {{blend_components(origin.rgba.r, target.rgba.r, frame), | 12 | return (Color) {{blend_components(origin.rgba.r, target.rgba.r, frame), |
13 | blend_components(origin.rgba.g, target.rgba.g, frame), | 13 | blend_components(origin.rgba.g, target.rgba.g, frame), |
14 | blend_components(origin.rgba.b, target.rgba.b, frame), | 14 | blend_components(origin.rgba.b, target.rgba.b, frame), |
@@ -34,11 +34,7 @@ void blender_blend_canvas(Canvas *canvas, Canvas *source, Canvas *target, Morphi | |||
34 | point.y = flat_dim / dim.y; | 34 | point.y = flat_dim / dim.y; |
35 | 35 | ||
36 | mapping = morpher_get_point_mapping(morphing, point, frame); | 36 | mapping = morpher_get_point_mapping(morphing, point, frame); |
37 | 37 | pixel = blend_colors(canvas_get_pixel(source, mapping.origin), canvas_get_pixel(target, mapping.target), frame); | |
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); | 38 | canvas_set_pixel(canvas, point, pixel); |
43 | } | 39 | } |
44 | } | 40 | } |
diff --git a/test/blender/blender.c b/test/blender/blender.c index 9a43db0..bf16dc6 100644 --- a/test/blender/blender.c +++ b/test/blender/blender.c | |||
@@ -1,14 +1,6 @@ | |||
1 | #include "blender/blender.h" | 1 | #include "blender/blender.h" |
2 | #include <assert.h> | 2 | #include <assert.h> |
3 | 3 | ||
4 | static void test_color_blending() { | ||
5 | Color origin = {{0xFF, 0xED, 0x00, 0x00}}; | ||
6 | Color target = {{0x00, 0x47, 0xAB, 0x00}}; | ||
7 | Color result = blender_blend_colors(origin, target, 0.125); | ||
8 | |||
9 | assert(color_equals(result, (Color) {{0xEE, 0xDF, 0x3C, 0x00}})); | ||
10 | } | ||
11 | |||
12 | static void test_canvas_blending() { | 4 | static void test_canvas_blending() { |
13 | Morphing morphing; | 5 | Morphing morphing; |
14 | Canvas origin, target, result; | 6 | Canvas origin, target, result; |
@@ -32,7 +24,6 @@ static void test_canvas_blending() { | |||
32 | } | 24 | } |
33 | 25 | ||
34 | int main(int argc, char **argv) { | 26 | int main(int argc, char **argv) { |
35 | test_color_blending(); | ||
36 | test_canvas_blending(); | 27 | test_canvas_blending(); |
37 | return 0; | 28 | return 0; |
38 | } | 29 | } |