diff options
author | pacien | 2017-12-02 15:20:34 +0100 |
---|---|---|
committer | pacien | 2017-12-02 15:20:34 +0100 |
commit | 52d6a488137736630d35ebddb6cc5b8c118b2e07 (patch) | |
tree | 58a690263e06746df95b9e8b2004b16f4a75078d | |
parent | 59c1fece82944d4f904cf6a02f97df2818961bb3 (diff) | |
download | morpher-52d6a488137736630d35ebddb6cc5b8c118b2e07.tar.gz |
Impl. color blending and unit test, minor API change
Signed-off-by: pacien <pacien.trangirard@pacien.net>
-rw-r--r-- | include/blender/color.h | 5 | ||||
-rw-r--r-- | src/blender/blender.c | 15 | ||||
-rw-r--r-- | test/blender/blender.c | 18 |
3 files changed, 37 insertions, 1 deletions
diff --git a/include/blender/color.h b/include/blender/color.h index cdf488a..22ed563 100644 --- a/include/blender/color.h +++ b/include/blender/color.h | |||
@@ -20,7 +20,10 @@ typedef uint8_t ColorComponent; | |||
20 | * Compatible with the libMLV representation. | 20 | * Compatible with the libMLV representation. |
21 | */ | 21 | */ |
22 | typedef union { | 22 | typedef union { |
23 | ColorComponent r, g, b, a; | 23 | struct { |
24 | ColorComponent r, g, b, a; | ||
25 | } rgba; | ||
26 | |||
24 | MLV_Color mlv; | 27 | MLV_Color mlv; |
25 | } Color; | 28 | } Color; |
26 | 29 | ||
diff --git a/src/blender/blender.c b/src/blender/blender.c new file mode 100644 index 0000000..0e0835d --- /dev/null +++ b/src/blender/blender.c | |||
@@ -0,0 +1,15 @@ | |||
1 | #include "blender/blender.h" | ||
2 | #include <assert.h> | ||
3 | #include <math.h> | ||
4 | |||
5 | static ColorComponent blend_components(ColorComponent origin, ColorComponent target, TimeVector frame) { | ||
6 | return (ColorComponent) sqrt((TIME_UNIT - frame) * pow(origin, 2) + frame * pow(target, 2)); | ||
7 | } | ||
8 | |||
9 | Color blender_blend_colors(Color origin, Color target, TimeVector frame) { | ||
10 | assert(frame >= TIME_ORIGIN && frame <= TIME_UNIT); | ||
11 | return (Color) {{blend_components(origin.rgba.r, target.rgba.r, frame), | ||
12 | blend_components(origin.rgba.g, target.rgba.g, frame), | ||
13 | blend_components(origin.rgba.b, target.rgba.b, frame), | ||
14 | blend_components(origin.rgba.a, target.rgba.a, frame)}}; | ||
15 | } | ||
diff --git a/test/blender/blender.c b/test/blender/blender.c new file mode 100644 index 0000000..7c33198 --- /dev/null +++ b/test/blender/blender.c | |||
@@ -0,0 +1,18 @@ | |||
1 | #include "blender/blender.h" | ||
2 | #include <assert.h> | ||
3 | |||
4 | static void test_color_blending() { | ||
5 | Color a = {{0xFF, 0xED, 0x00, 0x00}}; | ||
6 | Color b = {{0x00, 0x47, 0xAB, 0x00}}; | ||
7 | Color result = blender_blend_colors(a, b, 0.125); | ||
8 | |||
9 | assert(result.rgba.r == 0xEE && | ||
10 | result.rgba.g == 0xDF && | ||
11 | result.rgba.b == 0x3C && | ||
12 | result.rgba.a == 0x00); | ||
13 | } | ||
14 | |||
15 | int main(int argc, char **argv) { | ||
16 | test_color_blending(); | ||
17 | return 0; | ||
18 | } | ||