]> git.sesse.net Git - movit/blob - util.cpp
Move the Effect class out into its own file.
[movit] / util.cpp
1 #include <math.h>
2
3 #include "util.h"
4
5 void hsv2rgb(float h, float s, float v, float *r, float *g, float *b)
6 {
7         if (h < 0.0f) {
8                 h += 2.0f * M_PI;
9         }
10         float c = v * s;
11         float hp = (h * 180.0 / M_PI) / 60.0;
12         float x = c * (1 - fabs(fmod(hp, 2.0f) - 1.0f));
13
14         if (hp >= 0 && hp < 1) {
15                 *r = c;
16                 *g = x;
17                 *b = 0.0f;
18         } else if (hp >= 1 && hp < 2) {
19                 *r = x;
20                 *g = c;
21                 *b = 0.0f;
22         } else if (hp >= 2 && hp < 3) {
23                 *r = 0.0f;
24                 *g = c;
25                 *b = x;
26         } else if (hp >= 3 && hp < 4) {
27                 *r = 0.0f;
28                 *g = x;
29                 *b = c;
30         } else if (hp >= 4 && hp < 5) {
31                 *r = x;
32                 *g = 0.0f;
33                 *b = c;
34         } else {
35                 *r = c;
36                 *g = 0.0f;
37                 *b = x;
38         }
39
40         float m = v - c;
41         *r += m;
42         *g += m;
43         *b += m;
44 }