summaryrefslogtreecommitdiff
path: root/src/painter/color.c
diff options
context:
space:
mode:
authorpacien2017-12-28 01:22:41 +0100
committerpacien2017-12-28 01:22:41 +0100
commit190449ee18bec69b2e385dccd9bd42ddc83dd418 (patch)
tree6038429dcdd01def5410183148e582256d461fcc /src/painter/color.c
parentc970da3f5830fae5b4d98dcdcc8d34d678ec0434 (diff)
downloadmorpher-190449ee18bec69b2e385dccd9bd42ddc83dd418.tar.gz
Refactor and test color
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/painter/color.c')
-rw-r--r--src/painter/color.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/painter/color.c b/src/painter/color.c
new file mode 100644
index 0000000..65c4f20
--- /dev/null
+++ b/src/painter/color.c
@@ -0,0 +1,20 @@
1#include "painter/color.h"
2#include <math.h>
3
4static inline ColorComponent blend_component(ColorComponent origin, ColorComponent target, TimeVector frame) {
5 return (ColorComponent) round(sqrt((TIME_UNIT - frame) * pow(origin, 2) + frame * pow(target, 2)));
6}
7
8bool color_equals(Color c1, Color c2) {
9 return c1.rgba.r == c2.rgba.r &&
10 c1.rgba.g == c2.rgba.g &&
11 c1.rgba.b == c2.rgba.b &&
12 c1.rgba.a == c2.rgba.a;
13}
14
15Color color_blend(Color origin, Color target, TimeVector distance) {
16 return (Color) {{blend_component(origin.rgba.a, target.rgba.a, distance),
17 blend_component(origin.rgba.b, target.rgba.b, distance),
18 blend_component(origin.rgba.g, target.rgba.g, distance),
19 blend_component(origin.rgba.r, target.rgba.r, distance)}};
20}