diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/engines/common/evas_convert_color.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/lib/engines/common/evas_convert_color.c')
-rw-r--r-- | libraries/evas/src/lib/engines/common/evas_convert_color.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/engines/common/evas_convert_color.c b/libraries/evas/src/lib/engines/common/evas_convert_color.c new file mode 100644 index 0000000..70a9e90 --- /dev/null +++ b/libraries/evas/src/lib/engines/common/evas_convert_color.c | |||
@@ -0,0 +1,246 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_convert_color.h" | ||
3 | |||
4 | |||
5 | EAPI DATA32 | ||
6 | evas_common_convert_argb_premul(DATA32 *data, unsigned int len) | ||
7 | { | ||
8 | DATA32 *de = data + len; | ||
9 | DATA32 nas = 0; | ||
10 | |||
11 | while (data < de) | ||
12 | { | ||
13 | DATA32 a = 1 + (*data >> 24); | ||
14 | |||
15 | *data = (*data & 0xff000000) + | ||
16 | (((((*data) >> 8) & 0xff) * a) & 0xff00) + | ||
17 | (((((*data) & 0x00ff00ff) * a) >> 8) & 0x00ff00ff); | ||
18 | data++; | ||
19 | |||
20 | if ((a == 1) || (a == 256)) | ||
21 | nas++; | ||
22 | } | ||
23 | |||
24 | return nas; | ||
25 | } | ||
26 | |||
27 | EAPI void | ||
28 | evas_common_convert_argb_unpremul(DATA32 *data, unsigned int len) | ||
29 | { | ||
30 | DATA32 *de = data + len; | ||
31 | |||
32 | while (data < de) | ||
33 | { | ||
34 | DATA32 a = (*data >> 24); | ||
35 | |||
36 | if ((a > 0) && (a < 255)) | ||
37 | *data = ARGB_JOIN(a, | ||
38 | (R_VAL(data) * 255) / a, | ||
39 | (G_VAL(data) * 255) / a, | ||
40 | (B_VAL(data) * 255) / a); | ||
41 | data++; | ||
42 | } | ||
43 | |||
44 | } | ||
45 | |||
46 | EAPI void | ||
47 | evas_common_convert_color_argb_premul(int a, int *r, int *g, int *b) | ||
48 | { | ||
49 | a++; | ||
50 | if (r) { *r = (a * *r) >> 8; } | ||
51 | if (g) { *g = (a * *g) >> 8; } | ||
52 | if (b) { *b = (a * *b) >> 8; } | ||
53 | } | ||
54 | |||
55 | EAPI void | ||
56 | evas_common_convert_color_argb_unpremul(int a, int *r, int *g, int *b) | ||
57 | { | ||
58 | if (!a) return; | ||
59 | if (r) { *r = (255 * *r) / a; } | ||
60 | if (g) { *g = (255 * *g) / a; } | ||
61 | if (b) { *b = (255 * *b) / a; } | ||
62 | } | ||
63 | |||
64 | EAPI void | ||
65 | evas_common_convert_color_hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b) | ||
66 | { | ||
67 | int i; | ||
68 | float f; | ||
69 | |||
70 | v *= 255; | ||
71 | if (s == 0) | ||
72 | { | ||
73 | if (r) *r = v; | ||
74 | if (g) *g = v; | ||
75 | if (b) *b = v; | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | h /= 60; | ||
80 | i = h; | ||
81 | f = h - i; | ||
82 | |||
83 | s *= v; | ||
84 | f *= s; | ||
85 | s = v - s; | ||
86 | |||
87 | switch (i) | ||
88 | { | ||
89 | case 1: | ||
90 | if (r) *r = v - f; if (g) *g = v; if (b) *b = s; | ||
91 | return; | ||
92 | case 2: | ||
93 | if (r) *r = s; if (g) *g = v; if (b) *b = s + f; | ||
94 | return; | ||
95 | case 3: | ||
96 | if (r) *r = s; if (g) *g = v - f; if (b) *b = v; | ||
97 | return; | ||
98 | case 4: | ||
99 | if (r) *r = s + f; if (g) *g = s; if (b) *b = v; | ||
100 | return; | ||
101 | case 5: | ||
102 | if (r) *r = v; if (g) *g = s; if (b) *b = v - f; | ||
103 | return; | ||
104 | default: | ||
105 | if (r) *r = v; if (g) *g = s + f; if (b) *b = s; | ||
106 | break; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | EAPI void | ||
111 | evas_common_convert_color_rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v) | ||
112 | { | ||
113 | int max, min, d = r - g; | ||
114 | |||
115 | //set min to MIN(g,r) | ||
116 | d = (d & (~(d >> 8))); | ||
117 | min = r - d; | ||
118 | //set max to MAX(g,r) | ||
119 | max = g + d; | ||
120 | |||
121 | //set min to MIN(b,min) | ||
122 | d = min - b; | ||
123 | min -= (d & (~(d >> 8))); | ||
124 | |||
125 | //set max to MAX(max,b) | ||
126 | d = b - max; | ||
127 | max += (d & (~(d >> 8))); | ||
128 | |||
129 | d = max - min; | ||
130 | |||
131 | if (v) *v = (max / 255.0); | ||
132 | if (!max || !d) | ||
133 | { | ||
134 | if (s) *s = 0; | ||
135 | if (h) *h = 0; | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | if (s) *s = (d / (float)max); | ||
140 | if (r == max) | ||
141 | { | ||
142 | if (h) | ||
143 | { | ||
144 | *h = 60 * ((g - b) / (float)d); | ||
145 | if (*h < 0) *h += 360; | ||
146 | } | ||
147 | return; | ||
148 | } | ||
149 | if (g == max) | ||
150 | { | ||
151 | if (h) | ||
152 | { | ||
153 | *h = 120 + (60 * ((b - r) / (float)d)); | ||
154 | if (*h < 0) *h += 360; | ||
155 | } | ||
156 | return; | ||
157 | } | ||
158 | if (h) | ||
159 | { | ||
160 | *h = 240 + (60 * ((r - g) / (float)d)); | ||
161 | if (*h < 0) *h += 360; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | EAPI void | ||
166 | evas_common_convert_color_hsv_to_rgb_int(int h, int s, int v, int *r, int *g, int *b) | ||
167 | { | ||
168 | int i, f; | ||
169 | |||
170 | if (!s) | ||
171 | { | ||
172 | *r = *g = *b = v; | ||
173 | return; | ||
174 | } | ||
175 | |||
176 | i = h / 255; | ||
177 | f = h - (i * 255); | ||
178 | s = (v * s) / 255; | ||
179 | f = (s * f) / 255; | ||
180 | s = v - s; | ||
181 | |||
182 | switch (i) | ||
183 | { | ||
184 | case 1: | ||
185 | *r = v - f; *g = v; *b = s; | ||
186 | return; | ||
187 | case 2: | ||
188 | *r = s; *g = v; *b = s + f; | ||
189 | return; | ||
190 | case 3: | ||
191 | *r = s; *g = v - f; *b = v; | ||
192 | return; | ||
193 | case 4: | ||
194 | *r = s + f; *g = s; *b = v; | ||
195 | return; | ||
196 | case 5: | ||
197 | *r = v; *g = s; *b = v - f; | ||
198 | return; | ||
199 | default: | ||
200 | *r = v; *g = s + f; *b = s; | ||
201 | break; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | EAPI void | ||
206 | evas_common_convert_color_rgb_to_hsv_int(int r, int g, int b, int *h, int *s, int *v) | ||
207 | { | ||
208 | int min, max, d = r - g; | ||
209 | |||
210 | d = (d & (~(d >> 8))); | ||
211 | min = r - d; | ||
212 | max = g + d; | ||
213 | |||
214 | d = min - b; | ||
215 | min -= (d & (~(d >> 8))); | ||
216 | |||
217 | d = b - max; | ||
218 | max += (d & (~(d >> 8))); | ||
219 | |||
220 | d = max - min; | ||
221 | |||
222 | *v = max; | ||
223 | if (!max) | ||
224 | { | ||
225 | *s = *h = 0; | ||
226 | return; | ||
227 | } | ||
228 | |||
229 | *s = ((d * 255) / max); | ||
230 | |||
231 | if (r == max) | ||
232 | { | ||
233 | *h = (((g - b) * 255) / d); | ||
234 | if (*h < 0) *h += 1530; | ||
235 | return; | ||
236 | } | ||
237 | if (g == max) | ||
238 | { | ||
239 | *h = 510 + (((b - r) * 255) / d); | ||
240 | if (*h < 0) *h += 1530; | ||
241 | return; | ||
242 | } | ||
243 | *h = 1020 + (((r - g) * 255) / d); | ||
244 | if (*h < 0) *h += 1530; | ||
245 | |||
246 | } | ||