-
Notifications
You must be signed in to change notification settings - Fork 1
/
sad.c
68 lines (56 loc) · 1.1 KB
/
sad.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//#include <glib-object.h>
#define gint int
#define gdouble double
#define MAX(a, b) (a > b ? a : b)
#define ROUND(h) (int)h
void
gimp_rgb_to_hsl_int (gint *red,
gint *green,
gint *blue)
{
gint r, g, b;
gdouble h, s, l;
gint min, max;
gint delta;
r = *red;
g = *green;
b = *blue;
if (r > g)
{
max = MAX (r, b);
min = MIN (g, b);
}
else
{
max = MAX (g, b);
min = MIN (r, b);
}
l = (max + min) / 2.0;
if (max == min)
{
s = 0.0;
h = 0.0;
}
else
{
delta = (max - min);
if (l < 128)
s = 255 * (gdouble) delta / (gdouble) (max + min);
else
s = 255 * (gdouble) delta / (gdouble) (511 - max - min);
if (r == max)
h = (g - b) / (gdouble) delta;
else if (g == max)
h = 2 + (b - r) / (gdouble) delta;
else
h = 4 + (r - g) / (gdouble) delta;
h = h * 42.5;
if (h < 0)
h += 255;
else if (h > 255)
h -= 255;
}
*red = ROUND (h);
*green = ROUND (s);
*blue = ROUND (l);
}