Dimming works
This commit is contained in:
parent
e51d35f6d6
commit
bfd8db0098
4 changed files with 158 additions and 27 deletions
40
color.c
Normal file
40
color.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
#include "color.h"
|
||||
|
||||
|
||||
void hsv_to_rgb(struct hsvf *hsv, struct rgbf *rgb) {
|
||||
float h = hsv->h, s = hsv->s, v = hsv->v;
|
||||
float c = v * s; // Chroma
|
||||
float hmod = fmodf(h * 6.0f, 6.0f);
|
||||
float x = c * (1.0f - fabsf(fmodf(hmod, 2.0f) - 1.0f));
|
||||
float m = v - c;
|
||||
|
||||
switch ((int)hmod) {
|
||||
case 0:
|
||||
rgb->r = c; rgb->g = x; rgb->b = 0;
|
||||
break;
|
||||
case 1:
|
||||
rgb->r = x; rgb->g = c; rgb->b = 0;
|
||||
break;
|
||||
case 2:
|
||||
rgb->r = 0; rgb->g = c; rgb->b = x;
|
||||
break;
|
||||
case 3:
|
||||
rgb->r = 0; rgb->g = x; rgb->b = c;
|
||||
break;
|
||||
case 4:
|
||||
rgb->r = x; rgb->g = 0; rgb->b = c;
|
||||
break;
|
||||
case 5:
|
||||
rgb->r = c; rgb->g = 0; rgb->b = x;
|
||||
break;
|
||||
default:
|
||||
rgb->r = 0; rgb->g = 0; rgb->b = 0;
|
||||
}
|
||||
|
||||
rgb->r += m;
|
||||
rgb->g += m;
|
||||
rgb->b += m;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue