summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_convert_rgb_8.c
blob: 7ae0e86fd796b7dde2cd92571e4336494b1f1670 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "evas_common.h"
#include "evas_convert_rgb_8.h"

#ifdef USE_DITHER_44
extern const DATA8 _evas_dither_44[4][4];
#endif
#ifdef USE_DITHER_128128
extern const DATA8 _evas_dither_128128[128][128];
#endif

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith, dith2;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 3);
   dith2 = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 2);
/*   r = (R_VAL(src_ptr)) >> (8 - 3);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 3);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 3))) >= dith ) && (r < 0x07)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 3))) >= dith ) && (g < 0x07)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith2) && (b < 0x03)) b++;*/
   r = (R_VAL(src_ptr)) * 7 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 7)) >= dith ) && (r < 0x07)) r++;
   g = (G_VAL(src_ptr)) * 7 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 7)) >= dith ) && (g < 0x07)) g++;
   b = (B_VAL(src_ptr)) * 3 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith2) && (b < 0x03)) b++;

   *dst_ptr = pal[(r << 5) | (g << 2) | (b)];

   CONVERT_LOOP_END_ROT_0();
}

static DATA8 p_to_6[256];
static DATA8 p_to_6_err[256];

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith;
   static int tables_calcualted = 0;

   if (!tables_calcualted)
     {
	int i;

	tables_calcualted = 1;
	for (i = 0; i < 256; i++)
	  p_to_6[i] = (i * 5) / 255;
	for (i = 0; i < 256; i++)
	  p_to_6_err[i] = ((i * 5) - (p_to_6[i] * 255)) * DM_DIV / 255;
     }
   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   r = p_to_6[(R_VAL(src_ptr))];
   g = p_to_6[(G_VAL(src_ptr))];
   b = p_to_6[(B_VAL(src_ptr))];
   dith = DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK];
   if ((p_to_6_err[(R_VAL(src_ptr))] >= dith ) && (r < 5)) r++;
   if ((p_to_6_err[(G_VAL(src_ptr))] >= dith ) && (g < 5)) g++;
   if ((p_to_6_err[(B_VAL(src_ptr))] >= dith ) && (b < 5)) b++;

   *dst_ptr = pal[(r * 36) + (g * 6) + (b)];

   CONVERT_LOOP_END_ROT_0();
}

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith, dith2;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 3);
   dith2 = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 2);
/*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 3);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith2) && (r < 0x03)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 3))) >= dith ) && (g < 0x07)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith2) && (b < 0x03)) b++;*/
   r = (R_VAL(src_ptr)) * 3 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith2) && (r < 0x03)) r++;
   g = (G_VAL(src_ptr)) * 7 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 7)) >= dith ) && (g < 0x07)) g++;
   b = (B_VAL(src_ptr)) * 3 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith2) && (b < 0x03)) b++;

   *dst_ptr = pal[(r << 5) | (g << 2) | (b)];

   CONVERT_LOOP_END_ROT_0();
}

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 2);
/*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 2);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 2);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith ) && (r < 0x03)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 2))) >= dith ) && (g < 0x03)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 2))) >= dith ) && (b < 0x03)) b++;*/
   r = (R_VAL(src_ptr)) * 3 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith ) && (r < 0x03)) r++;
   g = (G_VAL(src_ptr)) * 3 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 3)) >= dith ) && (g < 0x03)) g++;
   b = (B_VAL(src_ptr)) * 3 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 3)) >= dith ) && (b < 0x03)) b++;

   *dst_ptr = pal[(r << 4) | (g << 2) | (b)];

   CONVERT_LOOP_END_ROT_0();
}

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith, dith2;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 2);
   dith2 = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 1);
/*   r = (R_VAL(src_ptr)) >> (8 - 2);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 2);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 1);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 2))) >= dith ) && (r < 0x03)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 2))) >= dith ) && (g < 0x03)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 1))) >= dith2) && (b < 0x01)) b++;*/
   r = (R_VAL(src_ptr)) * 3 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 3)) >= dith ) && (r < 0x03)) r++;
   g = (G_VAL(src_ptr)) * 3 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 3)) >= dith ) && (g < 0x03)) g++;
   b = (B_VAL(src_ptr)) * 1 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 1)) >= dith2) && (b < 0x01)) b++;

   *dst_ptr = pal[(r << 3) | (g << 1) | (b)];

   CONVERT_LOOP_END_ROT_0();
}

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith, dith2;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 2);
   dith2 = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 1);
/*   r = (R_VAL(src_ptr)) >> (8 - 1);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 2);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 1);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 1))) >= dith2) && (r < 0x01)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 2))) >= dith ) && (g < 0x03)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 1))) >= dith2) && (b < 0x01)) b++;*/

   r = (R_VAL(src_ptr)) * 1 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 1)) >= dith2) && (r < 0x01)) r++;
   g = (G_VAL(src_ptr)) * 3 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 3)) >= dith ) && (g < 0x03)) g++;
   b = (B_VAL(src_ptr)) * 1 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 1)) >= dith2) && (b < 0x01)) b++;

   *dst_ptr = pal[(r << 3) | (g << 1) | (b)];

   CONVERT_LOOP_END_ROT_0();
}

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)
{
   DATA32 *src_ptr;
   DATA8 *dst_ptr;
   int x, y;
   DATA8 r, g, b;
   DATA8 dith;

   dst_ptr = (DATA8 *)dst;

   CONVERT_LOOP_START_ROT_0();

   dith = DM_SHR(DM_TABLE[(x + dith_x) & DM_MSK][(y + dith_y) & DM_MSK], 1);
/*   r = (R_VAL(src_ptr)) >> (8 - 1);*/
/*   g = (G_VAL(src_ptr)) >> (8 - 1);*/
/*   b = (B_VAL(src_ptr)) >> (8 - 1);*/
/*   if (((R_VAL(src_ptr) - (r << (8 - 1))) >= dith ) && (r < 0x01)) r++;*/
/*   if (((G_VAL(src_ptr) - (g << (8 - 1))) >= dith ) && (g < 0x01)) g++;*/
/*   if (((B_VAL(src_ptr) - (b << (8 - 1))) >= dith ) && (b < 0x01)) b++;*/

   r = (R_VAL(src_ptr)) * 1 / 255;
   if (((R_VAL(src_ptr) - (r * 255 / 1)) >= dith ) && (r < 0x01)) r++;
   g = (G_VAL(src_ptr)) * 1 / 255;
   if (((G_VAL(src_ptr) - (g * 255 / 1)) >= dith ) && (g < 0x01)) g++;
   b = (B_VAL(src_ptr)) * 1 / 255;
   if (((B_VAL(src_ptr) - (b * 255 / 1)) >= dith ) && (b < 0x01)) b++;

   *dst_ptr = pal[(r << 2) | (g << 1) | (b)];

   CONVERT_LOOP_END_ROT_0();
}