-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.c
51 lines (46 loc) · 1.67 KB
/
color.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmoureu- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/11 22:52:12 by dmoureu- #+# #+# */
/* Updated: 2016/01/16 17:08:10 by dmoureu- ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int rgb_to_int(int r, int g, int b)
{
int color;
color = 0;
color = (r << 16) | (g << 8) | b;
return (color);
}
int hsv_to_rgb(unsigned int h, unsigned int s, unsigned int v)
{
unsigned char region;
unsigned char fpart;
unsigned char p;
unsigned char q;
unsigned char t;
if (h == 0)
return (rgb_to_int(v, v, v));
region = h / 43;
fpart = (h - (region * 43)) * 6;
p = (v * (255 - s)) >> 8;
q = (v * (255 - ((s * fpart) >> 8))) >> 8;
t = (v * (255 - ((s * (255 - fpart)) >> 8))) >> 8;
if (region == 0)
return (rgb_to_int(v, t, p));
if (region == 1)
return (rgb_to_int(q, v, p));
if (region == 2)
return (rgb_to_int(p, v, t));
if (region == 3)
return (rgb_to_int(p, q, v));
if (region == 4)
return (rgb_to_int(t, p, v));
else
return (rgb_to_int(v, p, q));
}