2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "evas_common.h"
6 #include "evas_convert_rgb_8.h"
9 extern const DATA8 _evas_dither_44[4][4];
11 #ifdef USE_DITHER_128128
12 extern const DATA8 _evas_dither_128128[128][128];
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)
24 dst_ptr = (DATA8 *)dst;
26 CONVERT_LOOP_START_ROT_0();
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++;
43 *dst_ptr = pal[(r << 5) | (g << 2) | (b)];
45 CONVERT_LOOP_END_ROT_0();
48 #ifdef BUILD_CONVERT_8_RGB_666
49 static DATA8 p_to_6[256];
50 static DATA8 p_to_6_err[256];
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)
59 static int tables_calcualted = 0;
61 if (!tables_calcualted)
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;
71 dst_ptr = (DATA8 *)dst;
73 CONVERT_LOOP_START_ROT_0();
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++;
83 *dst_ptr = pal[(r * 36) + (g * 6) + (b)];
85 CONVERT_LOOP_END_ROT_0();
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)
97 dst_ptr = (DATA8 *)dst;
99 CONVERT_LOOP_START_ROT_0();
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++;
116 *dst_ptr = pal[(r << 5) | (g << 2) | (b)];
118 CONVERT_LOOP_END_ROT_0();
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)
130 dst_ptr = (DATA8 *)dst;
132 CONVERT_LOOP_START_ROT_0();
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++;
148 *dst_ptr = pal[(r << 4) | (g << 2) | (b)];
150 CONVERT_LOOP_END_ROT_0();
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)
162 dst_ptr = (DATA8 *)dst;
164 CONVERT_LOOP_START_ROT_0();
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++;
181 *dst_ptr = pal[(r << 3) | (g << 1) | (b)];
183 CONVERT_LOOP_END_ROT_0();
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)
195 dst_ptr = (DATA8 *)dst;
197 CONVERT_LOOP_START_ROT_0();
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++;*/
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++;
215 *dst_ptr = pal[(r << 3) | (g << 1) | (b)];
217 CONVERT_LOOP_END_ROT_0();
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)
229 dst_ptr = (DATA8 *)dst;
231 CONVERT_LOOP_START_ROT_0();
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++;*/
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++;
248 *dst_ptr = pal[(r << 2) | (g << 1) | (b)];
250 CONVERT_LOOP_END_ROT_0();