diff options
author | pacien | 2017-12-28 01:22:41 +0100 |
---|---|---|
committer | pacien | 2017-12-28 01:22:41 +0100 |
commit | 190449ee18bec69b2e385dccd9bd42ddc83dd418 (patch) | |
tree | 6038429dcdd01def5410183148e582256d461fcc /src/painter/color.c | |
parent | c970da3f5830fae5b4d98dcdcc8d34d678ec0434 (diff) | |
download | morpher-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.c | 20 |
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 | |||
4 | static 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 | |||
8 | bool 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 | |||
15 | Color 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 | } | ||