move around - flatter.
[profile/ivi/evas.git] / src / lib / engines / common / evas_convert_rgb_8.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #include "evas_common.h"
6 #include "evas_convert_rgb_8.h"
7
8 #ifdef USE_DITHER_44
9 extern const DATA8 _evas_dither_44[4][4];
10 #endif
11 #ifdef USE_DITHER_128128
12 extern const DATA8 _evas_dither_128128[128][128];
13 #endif
14
15 #ifdef BUILD_CONVERT_8_RGB_332
16 void evas_common_convert_rgba_to_8bpp_rgb_332_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
17 {
18    DATA32 *src_ptr;
19    DATA8 *dst_ptr;
20    int x, y;
21    DATA8 r, g, b;
22    DATA8 dith, dith2;
23
24    dst_ptr = (DATA8 *)dst;
25
26    CONVERT_LOOP_START_ROT_0();
27
28    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(3);
29    dith2 = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(2);
30 /*   r = (R_VAL(src_ptr)) >> (8 - 3);*/
31 /*   g = (G_VAL(src_ptr)) >> (8 - 3);*/
32 /*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
33 /*   if (((R_VAL(src_ptr) - (r << (8 - 3))) >= dith ) && (r < 0x07)) r++;*/
34 /*   if (((G_VAL(src_ptr) - (g << (8 - 3))) >= dith ) && (g < 0x07)) g++;*/
35 /*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith2) && (b < 0x03)) b++;*/
36    r = (R_VAL(src_ptr)) * 7 / 255;
37    if (((R_VAL(src_ptr) - (r * 255 / 7)) >= dith ) && (r < 0x07)) r++;
38    g = (G_VAL(src_ptr)) * 7 / 255;
39    if (((G_VAL(src_ptr) - (g * 255 / 7)) >= dith ) && (g < 0x07)) g++;
40    b = (B_VAL(src_ptr)) * 3 / 255;
41    if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith2) && (b < 0x03)) b++;
42
43    *dst_ptr = pal[(r << 5) | (g << 2) | (b)];
44
45    CONVERT_LOOP_END_ROT_0();
46 }
47 #endif
48 #ifdef BUILD_CONVERT_8_RGB_666
49 static DATA8 p_to_6[256];
50 static DATA8 p_to_6_err[256];
51
52 void evas_common_convert_rgba_to_8bpp_rgb_666_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
53 {
54    DATA32 *src_ptr;
55    DATA8 *dst_ptr;
56    int x, y;
57    DATA8 r, g, b;
58    DATA8 dith;
59    static int tables_calcualted = 0;
60
61    if (!tables_calcualted)
62      {
63         int i;
64
65         tables_calcualted = 1;
66         for (i = 0; i < 256; i++)
67           p_to_6[i] = (i * 5) / 255;
68         for (i = 0; i < 256; i++)
69           p_to_6_err[i] = ((i * 5) - (p_to_6[i] * 255)) * DM_DIV / 255;
70      }
71    dst_ptr = (DATA8 *)dst;
72
73    CONVERT_LOOP_START_ROT_0();
74
75    r = p_to_6[(R_VAL(src_ptr))];
76    g = p_to_6[(G_VAL(src_ptr))];
77    b = p_to_6[(B_VAL(src_ptr))];
78    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK];
79    if ((p_to_6_err[(R_VAL(src_ptr))] >= dith ) && (r < 5)) r++;
80    if ((p_to_6_err[(G_VAL(src_ptr))] >= dith ) && (g < 5)) g++;
81    if ((p_to_6_err[(B_VAL(src_ptr))] >= dith ) && (b < 5)) b++;
82
83    *dst_ptr = pal[(r * 36) + (g * 6) + (b)];
84
85    CONVERT_LOOP_END_ROT_0();
86 }
87 #endif
88 #ifdef BUILD_CONVERT_8_RGB_232
89 void evas_common_convert_rgba_to_8bpp_rgb_232_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
90 {
91    DATA32 *src_ptr;
92    DATA8 *dst_ptr;
93    int x, y;
94    DATA8 r, g, b;
95    DATA8 dith, dith2;
96
97    dst_ptr = (DATA8 *)dst;
98
99    CONVERT_LOOP_START_ROT_0();
100
101    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(3);
102    dith2 = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(2);
103 /*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
104 /*   g = (G_VAL(src_ptr)) >> (8 - 3);*/
105 /*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
106 /*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith2) && (r < 0x03)) r++;*/
107 /*   if (((G_VAL(src_ptr) - (g << (8 - 3))) >= dith ) && (g < 0x07)) g++;*/
108 /*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith2) && (b < 0x03)) b++;*/
109    r = (R_VAL(src_ptr)) * 3 / 255;
110    if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith2) && (r < 0x03)) r++;
111    g = (G_VAL(src_ptr)) * 7 / 255;
112    if (((G_VAL(src_ptr) - (g * 255 / 7)) >= dith ) && (g < 0x07)) g++;
113    b = (B_VAL(src_ptr)) * 3 / 255;
114    if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith2) && (b < 0x03)) b++;
115
116    *dst_ptr = pal[(r << 5) | (g << 2) | (b)];
117
118    CONVERT_LOOP_END_ROT_0();
119 }
120 #endif
121 #ifdef BUILD_CONVERT_8_RGB_222
122 void evas_common_convert_rgba_to_8bpp_rgb_222_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
123 {
124    DATA32 *src_ptr;
125    DATA8 *dst_ptr;
126    int x, y;
127    DATA8 r, g, b;
128    DATA8 dith;
129
130    dst_ptr = (DATA8 *)dst;
131
132    CONVERT_LOOP_START_ROT_0();
133
134    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(2);
135 /*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
136 /*   g = (G_VAL(src_ptr)) >> (8 - 2);*/
137 /*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
138 /*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith ) && (r < 0x03)) r++;*/
139 /*   if (((G_VAL(src_ptr) - (g << (8 - 2))) >= dith ) && (g < 0x03)) g++;*/
140 /*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith ) && (b < 0x03)) b++;*/
141    r = (R_VAL(src_ptr)) * 3 / 255;
142    if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith ) && (r < 0x03)) r++;
143    g = (G_VAL(src_ptr)) * 3 / 255;
144    if (((G_VAL(src_ptr) - (g * 255 / 3)) >= dith ) && (g < 0x03)) g++;
145    b = (B_VAL(src_ptr)) * 3 / 255;
146    if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith ) && (b < 0x03)) b++;
147
148    *dst_ptr = pal[(r << 4) | (g << 2) | (b)];
149
150    CONVERT_LOOP_END_ROT_0();
151 }
152 #endif
153 #ifdef BUILD_CONVERT_8_RGB_221
154 void evas_common_convert_rgba_to_8bpp_rgb_221_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
155 {
156    DATA32 *src_ptr;
157    DATA8 *dst_ptr;
158    int x, y;
159    DATA8 r, g, b;
160    DATA8 dith, dith2;
161
162    dst_ptr = (DATA8 *)dst;
163
164    CONVERT_LOOP_START_ROT_0();
165
166    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(2);
167    dith2 = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(1);
168 /*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
169 /*   g = (G_VAL(src_ptr)) >> (8 - 2);*/
170 /*   b = (B_VAL(src_ptr)) >> (8 - 1);*/
171 /*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith ) && (r < 0x03)) r++;*/
172 /*   if (((G_VAL(src_ptr) - (g << (8 - 2))) >= dith ) && (g < 0x03)) g++;*/
173 /*   if (((B_VAL(src_ptr) - (b << (8 - 1))) >= dith2) && (b < 0x01)) b++;*/
174    r = (R_VAL(src_ptr)) * 3 / 255;
175    if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith ) && (r < 0x03)) r++;
176    g = (G_VAL(src_ptr)) * 3 / 255;
177    if (((G_VAL(src_ptr) - (g * 255 / 3)) >= dith ) && (g < 0x03)) g++;
178    b = (B_VAL(src_ptr)) * 1 / 255;
179    if (((B_VAL(src_ptr) - (b * 255 / 1)) >= dith2) && (b < 0x01)) b++;
180
181    *dst_ptr = pal[(r << 3) | (g << 1) | (b)];
182
183    CONVERT_LOOP_END_ROT_0();
184 }
185 #endif
186 #ifdef BUILD_CONVERT_8_RGB_121
187 void evas_common_convert_rgba_to_8bpp_rgb_121_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
188 {
189    DATA32 *src_ptr;
190    DATA8 *dst_ptr;
191    int x, y;
192    DATA8 r, g, b;
193    DATA8 dith, dith2;
194
195    dst_ptr = (DATA8 *)dst;
196
197    CONVERT_LOOP_START_ROT_0();
198
199    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(2);
200    dith2 = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(1);
201 /*   r = (R_VAL(src_ptr)) >> (8 - 1);*/
202 /*   g = (G_VAL(src_ptr)) >> (8 - 2);*/
203 /*   b = (B_VAL(src_ptr)) >> (8 - 1);*/
204 /*   if (((R_VAL(src_ptr) - (r << (8 - 1))) >= dith2) && (r < 0x01)) r++;*/
205 /*   if (((G_VAL(src_ptr) - (g << (8 - 2))) >= dith ) && (g < 0x03)) g++;*/
206 /*   if (((B_VAL(src_ptr) - (b << (8 - 1))) >= dith2) && (b < 0x01)) b++;*/
207
208    r = (R_VAL(src_ptr)) * 1 / 255;
209    if (((R_VAL(src_ptr) - (r * 255 / 1)) >= dith2) && (r < 0x01)) r++;
210    g = (G_VAL(src_ptr)) * 3 / 255;
211    if (((G_VAL(src_ptr) - (g * 255 / 3)) >= dith ) && (g < 0x03)) g++;
212    b = (B_VAL(src_ptr)) * 1 / 255;
213    if (((B_VAL(src_ptr) - (b * 255 / 1)) >= dith2) && (b < 0x01)) b++;
214
215    *dst_ptr = pal[(r << 3) | (g << 1) | (b)];
216
217    CONVERT_LOOP_END_ROT_0();
218 }
219 #endif
220 #ifdef BUILD_CONVERT_8_RGB_111
221 void evas_common_convert_rgba_to_8bpp_rgb_111_dith     (DATA32 *src, DATA8 *dst, int src_jump, int dst_jump, int w, int h, int dith_x, int dith_y, DATA8 *pal)
222 {
223    DATA32 *src_ptr;
224    DATA8 *dst_ptr;
225    int x, y;
226    DATA8 r, g, b;
227    DATA8 dith;
228
229    dst_ptr = (DATA8 *)dst;
230
231    CONVERT_LOOP_START_ROT_0();
232
233    dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK] >> DM_SHF(1);
234 /*   r = (R_VAL(src_ptr)) >> (8 - 1);*/
235 /*   g = (G_VAL(src_ptr)) >> (8 - 1);*/
236 /*   b = (B_VAL(src_ptr)) >> (8 - 1);*/
237 /*   if (((R_VAL(src_ptr) - (r << (8 - 1))) >= dith ) && (r < 0x01)) r++;*/
238 /*   if (((G_VAL(src_ptr) - (g << (8 - 1))) >= dith ) && (g < 0x01)) g++;*/
239 /*   if (((B_VAL(src_ptr) - (b << (8 - 1))) >= dith ) && (b < 0x01)) b++;*/
240
241    r = (R_VAL(src_ptr)) * 1 / 255;
242    if (((R_VAL(src_ptr) - (r * 255 / 1)) >= dith ) && (r < 0x01)) r++;
243    g = (G_VAL(src_ptr)) * 1 / 255;
244    if (((G_VAL(src_ptr) - (g * 255 / 1)) >= dith ) && (g < 0x01)) g++;
245    b = (B_VAL(src_ptr)) * 1 / 255;
246    if (((B_VAL(src_ptr) - (b * 255 / 1)) >= dith ) && (b < 0x01)) b++;
247
248    *dst_ptr = pal[(r << 2) | (g << 1) | (b)];
249
250    CONVERT_LOOP_END_ROT_0();
251 }
252 #endif