[svn] / branches / dev-api-3 / xvidcore / src / image / colorspace.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-3/xvidcore/src/image/colorspace.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 631 - (view) (download)

1 : edgomez 195 /**************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * colorspace conversions
5 :     *
6 :     * This program is free software; you can redistribute it and/or modify
7 :     * it under the terms of the GNU General Public License as published by
8 :     * the Free Software Foundation; either version 2 of the License, or
9 :     * (at your option) any later version.
10 :     *
11 :     * This program is distributed in the hope that it will be useful,
12 :     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 :     * GNU General Public License for more details.
15 :     *
16 :     * You should have received a copy of the GNU General Public License
17 :     * along with this program; if not, write to the Free Software
18 :     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 :     *
20 :     *************************************************************************/
21 :    
22 :     /**************************************************************************
23 :     *
24 :     * History:
25 :     *
26 :     * 14.04.2002 added user_to_yuv_c()
27 :     * 30.02.2002 out_yuv dst_stride2 fix
28 :     * 26.02.2002 rgb555, rgb565
29 :     * 24.11.2001 accuracy improvement to yuyv/vyuy conversion
30 :     * 28.10.2001 total rewrite <pross@cs.rmit.edu.au>
31 :     *
32 :     **************************************************************************/
33 :    
34 :     #include <string.h> // memcpy
35 :    
36 :     #include "colorspace.h"
37 :     #include "../divx4.h"
38 :    
39 :     // function pointers
40 :    
41 :     /* input */
42 : suxen_drol 631 packedFuncPtr rgb555_to_yv12;
43 :     packedFuncPtr rgb565_to_yv12;
44 :     packedFuncPtr bgr_to_yv12;
45 :     packedFuncPtr bgra_to_yv12;
46 :     packedFuncPtr abgr_to_yv12;
47 :     packedFuncPtr rgba_to_yv12;
48 :     packedFuncPtr yuv_to_yv12;
49 :     packedFuncPtr yuyv_to_yv12;
50 :     packedFuncPtr uyvy_to_yv12;
51 : edgomez 195
52 : suxen_drol 631 packedFuncPtr rgb555i_to_yv12;
53 :     packedFuncPtr rgb565i_to_yv12;
54 :     packedFuncPtr bgri_to_yv12;
55 :     packedFuncPtr bgrai_to_yv12;
56 :     packedFuncPtr abgri_to_yv12;
57 :     packedFuncPtr rgbai_to_yv12;
58 :     packedFuncPtr yuyvi_to_yv12;
59 :     packedFuncPtr uyvyi_to_yv12;
60 :    
61 : edgomez 195 /* output */
62 : suxen_drol 631 packedFuncPtr yv12_to_rgb555;
63 :     packedFuncPtr yv12_to_rgb565;
64 :     packedFuncPtr yv12_to_bgr;
65 :     packedFuncPtr yv12_to_bgra;
66 :     packedFuncPtr yv12_to_abgr;
67 :     packedFuncPtr yv12_to_rgba;
68 :     packedFuncPtr yv12_to_yuv;
69 :     packedFuncPtr yv12_to_yuyv;
70 :     packedFuncPtr yv12_to_uyvy;
71 : edgomez 195
72 : suxen_drol 631 packedFuncPtr yv12_to_rgb555i;
73 :     packedFuncPtr yv12_to_rgb565i;
74 :     packedFuncPtr yv12_to_bgri;
75 :     packedFuncPtr yv12_to_bgrai;
76 :     packedFuncPtr yv12_to_abgri;
77 :     packedFuncPtr yv12_to_rgbai;
78 :     packedFuncPtr yv12_to_yuyvi;
79 :     packedFuncPtr yv12_to_uyvyi;
80 :    
81 :     planarFuncPtr yv12_to_yv12;
82 :    
83 :    
84 :     int32_t RGB_Y_tab[256];
85 :     int32_t B_U_tab[256];
86 :     int32_t G_U_tab[256];
87 :     int32_t G_V_tab[256];
88 :     int32_t R_V_tab[256];
89 :    
90 :    
91 : edgomez 195 #define MIN(A,B) ((A)<(B)?(A):(B))
92 :     #define MAX(A,B) ((A)>(B)?(A):(B))
93 :    
94 : suxen_drol 631
95 :     /********** generic colorspace macro **********/
96 :    
97 :    
98 :     #define MAKE_COLORSPACE(NAME,SIZE,PIXELS,VPIXELS,FUNC,C1,C2,C3,C4) \
99 :     void \
100 :     NAME(uint8_t * x_ptr, int x_stride, \
101 :     uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr, \
102 :     int y_stride, int uv_stride, \
103 :     int width, int height, int vflip) \
104 :     { \
105 :     int fixed_width = (width + 1) & ~1; \
106 :     int x_dif = x_stride - (SIZE)*fixed_width; \
107 :     int y_dif = y_stride - fixed_width; \
108 :     int uv_dif = uv_stride - (fixed_width / 2); \
109 :     int x, y; \
110 :     if (vflip) { \
111 :     x_ptr += (height - 1) * x_stride; \
112 :     x_dif = -(SIZE)*fixed_width - x_stride; \
113 :     x_stride = -x_stride; \
114 :     } \
115 :     for (y = 0; y < height; y+=(VPIXELS)) { \
116 :     FUNC##_ROW(SIZE,C1,C2,C3,C4); \
117 :     for (x = 0; x < fixed_width; x+=(PIXELS)) { \
118 :     FUNC(SIZE,C1,C2,C3,C4); \
119 :     x_ptr += (PIXELS)*(SIZE); \
120 :     y_ptr += (PIXELS); \
121 :     u_ptr += (PIXELS)/2; \
122 :     v_ptr += (PIXELS)/2; \
123 :     } \
124 :     x_ptr += x_dif + (VPIXELS-1)*x_stride; \
125 :     y_ptr += y_dif + (VPIXELS-1)*y_stride; \
126 :     u_ptr += uv_dif + ((VPIXELS/2)-1)*uv_stride; \
127 :     v_ptr += uv_dif + ((VPIXELS/2)-1)*uv_stride; \
128 :     } \
129 :     }
130 :    
131 :    
132 :    
133 :     /********** colorspace input (xxx_to_yv12) functions **********/
134 :    
135 : edgomez 195 /* rgb -> yuv def's
136 :    
137 :     this following constants are "official spec"
138 :     Video Demystified" (ISBN 1-878707-09-4)
139 :    
140 :     rgb<->yuv _is_ lossy, since most programs do the conversion differently
141 :    
142 :     SCALEBITS/FIX taken from ffmpeg
143 :     */
144 :    
145 :     #define Y_R_IN 0.257
146 :     #define Y_G_IN 0.504
147 :     #define Y_B_IN 0.098
148 :     #define Y_ADD_IN 16
149 :    
150 :     #define U_R_IN 0.148
151 :     #define U_G_IN 0.291
152 :     #define U_B_IN 0.439
153 :     #define U_ADD_IN 128
154 :    
155 :     #define V_R_IN 0.439
156 :     #define V_G_IN 0.368
157 :     #define V_B_IN 0.071
158 :     #define V_ADD_IN 128
159 :    
160 :     #define SCALEBITS_IN 8
161 :     #define FIX_IN(x) ((uint16_t) ((x) * (1L<<SCALEBITS_IN) + 0.5))
162 :    
163 :    
164 : suxen_drol 631 /* rgb16/rgb16i input */
165 : edgomez 195
166 : suxen_drol 631 #define MK_RGB555_B(RGB) ((RGB) << 3) & 0xf8
167 :     #define MK_RGB555_G(RGB) ((RGB) >> 2) & 0xf8
168 :     #define MK_RGB555_R(RGB) ((RGB) >> 7) & 0xf8
169 : edgomez 195
170 : suxen_drol 631 #define MK_RGB565_B(RGB) ((RGB) << 3) & 0xf8
171 :     #define MK_RGB565_G(RGB) ((RGB) >> 3) & 0xfc
172 :     #define MK_RGB565_R(RGB) ((RGB) >> 8) & 0xf8
173 : edgomez 195
174 :    
175 : suxen_drol 631 #define READ_RGB16_Y(ROW, UVID, C1,C2,C3,C4) \
176 :     rgb = *(uint16_t *) (x_ptr + ((ROW)*x_stride) + 0); \
177 :     b##UVID += b = C1##_B(rgb); \
178 :     g##UVID += g = C1##_G(rgb); \
179 :     r##UVID += r = C1##_R(rgb); \
180 :     y_ptr[(ROW)*y_stride+0] = \
181 :     (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + \
182 :     FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; \
183 :     rgb = *(uint16_t *) (x_ptr + ((ROW)*x_stride) + 2); \
184 :     b##UVID += b = C1##_B(rgb); \
185 :     g##UVID += g = C1##_G(rgb); \
186 :     r##UVID += r = C1##_R(rgb); \
187 :     y_ptr[(ROW)*y_stride+1] = \
188 :     (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + \
189 :     FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
190 : edgomez 195
191 : suxen_drol 631 #define READ_RGB16_UV(UV_ROW,UVID) \
192 :     u_ptr[(UV_ROW)*uv_stride] = \
193 :     (uint8_t) ((-FIX_IN(U_R_IN) * r##UVID - FIX_IN(U_G_IN) * g##UVID + \
194 :     FIX_IN(U_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + U_ADD_IN; \
195 :     v_ptr[(UV_ROW)*uv_stride] = \
196 :     (uint8_t) ((FIX_IN(V_R_IN) * r##UVID - FIX_IN(V_G_IN) * g##UVID - \
197 :     FIX_IN(V_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + V_ADD_IN;
198 : edgomez 195
199 : suxen_drol 631 #define RGB16_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \
200 :     /* nothing */
201 :     #define RGB16_TO_YV12(SIZE,C1,C2,C3,C4) \
202 :     uint32_t rgb, r, g, b, r0, g0, b0; \
203 :     r0 = g0 = b0 = 0; \
204 :     READ_RGB16_Y (0, 0, C1,C2,C3,C4) \
205 :     READ_RGB16_Y (1, 0, C1,C2,C3,C4) \
206 :     READ_RGB16_UV(0, 0)
207 : edgomez 195
208 :    
209 : suxen_drol 631 #define RGB16I_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \
210 :     /* nothing */
211 :     #define RGB16I_TO_YV12(SIZE,C1,C2,C3,C4) \
212 :     uint32_t rgb, r, g, b, r0, g0, b0, r1, g1, b1; \
213 :     r0 = g0 = b0 = r1 = g1 = b1 = 0; \
214 :     READ_RGB16_Y (0, 0, C1,C2,C3,C4) \
215 :     READ_RGB16_Y (1, 1, C1,C2,C3,C4) \
216 :     READ_RGB16_Y (2, 0, C1,C2,C3,C4) \
217 :     READ_RGB16_Y (3, 1, C1,C2,C3,C4) \
218 :     READ_RGB16_UV(0, 0) \
219 :     READ_RGB16_UV(1, 1)
220 : edgomez 195
221 :    
222 : suxen_drol 631 /* rgb/rgbi input */
223 : edgomez 195
224 : suxen_drol 631 #define READ_RGB_Y(SIZE, ROW, UVID, C1,C2,C3,C4) \
225 :     r##UVID += r = x_ptr[(ROW)*x_stride+(C1)]; \
226 :     g##UVID += g = x_ptr[(ROW)*x_stride+(C2)]; \
227 :     b##UVID += b = x_ptr[(ROW)*x_stride+(C3)]; \
228 :     y_ptr[(ROW)*y_stride+0] = \
229 :     (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + \
230 :     FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; \
231 :     r##UVID += r = x_ptr[(ROW)*x_stride+(SIZE)+(C1)]; \
232 :     g##UVID += g = x_ptr[(ROW)*x_stride+(SIZE)+(C2)]; \
233 :     b##UVID += b = x_ptr[(ROW)*x_stride+(SIZE)+(C3)]; \
234 :     y_ptr[(ROW)*y_stride+1] = \
235 :     (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + \
236 :     FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
237 : edgomez 195
238 : suxen_drol 631 #define READ_RGB_UV(UV_ROW,UVID) \
239 :     u_ptr[(UV_ROW)*uv_stride] = \
240 :     (uint8_t) ((-FIX_IN(U_R_IN) * r##UVID - FIX_IN(U_G_IN) * g##UVID + \
241 :     FIX_IN(U_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + U_ADD_IN; \
242 :     v_ptr[(UV_ROW)*uv_stride] = \
243 :     (uint8_t) ((FIX_IN(V_R_IN) * r##UVID - FIX_IN(V_G_IN) * g##UVID - \
244 :     FIX_IN(V_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + V_ADD_IN;
245 : edgomez 195
246 :    
247 : suxen_drol 631 #define RGB_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \
248 :     /* nothing */
249 :     #define RGB_TO_YV12(SIZE,C1,C2,C3,C4) \
250 :     uint32_t r, g, b, r0, g0, b0; \
251 :     r0 = g0 = b0 = 0; \
252 :     READ_RGB_Y(SIZE, 0, 0, C1,C2,C3,C4) \
253 :     READ_RGB_Y(SIZE, 1, 0, C1,C2,C3,C4) \
254 :     READ_RGB_UV( 0, 0)
255 : edgomez 195
256 : suxen_drol 631 #define RGBI_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \
257 :     /* nothing */
258 :     #define RGBI_TO_YV12(SIZE,C1,C2,C3,C4) \
259 :     uint32_t r, g, b, r0, g0, b0, r1, g1, b1; \
260 :     r0 = g0 = b0 = r1 = g1 = b1 = 0; \
261 :     READ_RGB_Y(SIZE, 0, 0, C1,C2,C3,C4) \
262 :     READ_RGB_Y(SIZE, 1, 1, C1,C2,C3,C4) \
263 :     READ_RGB_Y(SIZE, 2, 0, C1,C2,C3,C4) \
264 :     READ_RGB_Y(SIZE, 3, 1, C1,C2,C3,C4) \
265 :     READ_RGB_UV( 0, 0) \
266 :     READ_RGB_UV( 1, 1)
267 : edgomez 195
268 :    
269 : suxen_drol 631 /* yuyv/yuyvi input */
270 : edgomez 195
271 : suxen_drol 631 #define READ_YUYV_Y(ROW,C1,C2,C3,C4) \
272 :     y_ptr[(ROW)*y_stride+0] = x_ptr[(ROW)*x_stride+(C1)]; \
273 :     y_ptr[(ROW)*y_stride+1] = x_ptr[(ROW)*x_stride+(C3)];
274 :     #define READ_YUYV_UV(UV_ROW,ROW1,ROW2,C1,C2,C3,C4) \
275 :     u_ptr[(UV_ROW)*uv_stride] = (x_ptr[(ROW1)*x_stride+(C2)] + x_ptr[(ROW2)*x_stride+(C2)] + 1) / 2; \
276 :     v_ptr[(UV_ROW)*uv_stride] = (x_ptr[(ROW1)*x_stride+(C4)] + x_ptr[(ROW2)*x_stride+(C4)] + 1) / 2;
277 : edgomez 195
278 : suxen_drol 631 #define YUYV_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \
279 :     /* nothing */
280 :     #define YUYV_TO_YV12(SIZE,C1,C2,C3,C4) \
281 :     READ_YUYV_Y (0, C1,C2,C3,C4) \
282 :     READ_YUYV_Y (1, C1,C2,C3,C4) \
283 :     READ_YUYV_UV(0, 0,1, C1,C2,C3,C4)
284 : edgomez 195
285 : suxen_drol 631 #define YUYVI_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \
286 :     /* nothing */
287 :     #define YUYVI_TO_YV12(SIZE,C1,C2,C3,C4) \
288 :     READ_YUYV_Y (0, C1,C2,C3,C4) \
289 :     READ_YUYV_Y (1, C1,C2,C3,C4) \
290 :     READ_YUYV_Y (2, C1,C2,C3,C4) \
291 :     READ_YUYV_Y (3, C1,C2,C3,C4) \
292 :     READ_YUYV_UV(0, 0,2, C1,C2,C3,C4) \
293 :     READ_YUYV_UV(1, 1,3, C1,C2,C3,C4)
294 : edgomez 195
295 :    
296 : suxen_drol 631 MAKE_COLORSPACE(rgb555_to_yv12_c, 2,2,2, RGB16_TO_YV12, MK_RGB555, 0,0,0)
297 :     MAKE_COLORSPACE(rgb565_to_yv12_c, 2,2,2, RGB16_TO_YV12, MK_RGB565, 0,0,0)
298 :     MAKE_COLORSPACE(bgr_to_yv12_c, 3,2,2, RGB_TO_YV12, 2,1,0, 0)
299 :     MAKE_COLORSPACE(bgra_to_yv12_c, 4,2,2, RGB_TO_YV12, 2,1,0, 0)
300 :     MAKE_COLORSPACE(abgr_to_yv12_c, 4,2,2, RGB_TO_YV12, 3,2,1, 0)
301 :     MAKE_COLORSPACE(rgba_to_yv12_c, 4,2,2, RGB_TO_YV12, 0,1,2, 0)
302 :     MAKE_COLORSPACE(yuyv_to_yv12_c, 2,2,2, YUYV_TO_YV12, 0,1,2,3)
303 :     MAKE_COLORSPACE(uyvy_to_yv12_c, 2,2,2, YUYV_TO_YV12, 1,0,3,2)
304 : edgomez 195
305 : suxen_drol 631 MAKE_COLORSPACE(rgb555i_to_yv12_c, 2,2,4, RGB16I_TO_YV12, MK_RGB555, 0,0,0)
306 :     MAKE_COLORSPACE(rgb565i_to_yv12_c, 2,2,4, RGB16I_TO_YV12, MK_RGB565, 0,0,0)
307 :     MAKE_COLORSPACE(bgri_to_yv12_c, 3,2,4, RGBI_TO_YV12, 2,1,0, 0)
308 :     MAKE_COLORSPACE(bgrai_to_yv12_c, 4,2,4, RGBI_TO_YV12, 2,1,0, 0)
309 :     MAKE_COLORSPACE(abgri_to_yv12_c, 4,2,4, RGBI_TO_YV12, 3,2,1, 0)
310 :     MAKE_COLORSPACE(rgbai_to_yv12_c, 4,2,4, RGBI_TO_YV12, 0,1,2, 0)
311 :     MAKE_COLORSPACE(yuyvi_to_yv12_c, 2,2,4, YUYVI_TO_YV12, 0,1,2,3)
312 :     MAKE_COLORSPACE(uyvyi_to_yv12_c, 2,2,4, YUYVI_TO_YV12, 1,0,3,2)
313 : edgomez 195
314 :    
315 : suxen_drol 631 /********** colorspace output (yv12_to_xxx) functions **********/
316 : edgomez 195
317 : suxen_drol 631 /* yuv -> rgb def's */
318 : edgomez 195
319 :     #define RGB_Y_OUT 1.164
320 :     #define B_U_OUT 2.018
321 :     #define Y_ADD_OUT 16
322 :    
323 :     #define G_U_OUT 0.391
324 :     #define G_V_OUT 0.813
325 :     #define U_ADD_OUT 128
326 :    
327 :     #define R_V_OUT 1.596
328 :     #define V_ADD_OUT 128
329 :    
330 :     #define SCALEBITS_OUT 13
331 :     #define FIX_OUT(x) ((uint16_t) ((x) * (1L<<SCALEBITS_OUT) + 0.5))
332 :    
333 :    
334 : suxen_drol 631 /* rgb16/rgb16i output */
335 : edgomez 195
336 : suxen_drol 631 #define MK_RGB555(R,G,B) \
337 :     ((MAX(0,MIN(255, R)) << 7) & 0x7c00) | \
338 :     ((MAX(0,MIN(255, G)) << 2) & 0x03e0) | \
339 :     ((MAX(0,MIN(255, B)) >> 3) & 0x001f)
340 : edgomez 195
341 : suxen_drol 631 #define MK_RGB565(R,G,B) \
342 :     ((MAX(0,MIN(255, R)) << 8) & 0xf800) | \
343 :     ((MAX(0,MIN(255, G)) << 3) & 0x07e0) | \
344 :     ((MAX(0,MIN(255, B)) >> 3) & 0x001f)
345 : edgomez 195
346 : suxen_drol 631 #define WRITE_RGB16(ROW,UV_ROW,C1) \
347 :     rgb_y = RGB_Y_tab[ y_ptr[y_stride + 0] ]; \
348 :     b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT); \
349 :     g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT); \
350 :     r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT); \
351 :     *(uint16_t *) (x_ptr+((ROW)*x_stride)+0) = C1(r[ROW], g[ROW], b[ROW]); \
352 :     rgb_y = RGB_Y_tab[ y_ptr[y_stride + 1] ]; \
353 :     b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT); \
354 :     g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT); \
355 :     r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT); \
356 :     *(uint16_t *) (x_ptr+((ROW)*x_stride)+2) = C1(r[ROW], g[ROW], b[ROW]);
357 : edgomez 195
358 : suxen_drol 631 #define YV12_TO_RGB16_ROW(SIZE,C1,C2,C3,C4) \
359 :     int r[2], g[2], b[2]; \
360 :     r[0] = r[1] = g[0] = g[1] = b[0] = b[1] = 0;
361 :     #define YV12_TO_RGB16(SIZE,C1,C2,C3,C4) \
362 :     int rgb_y; \
363 :     int b_u0 = B_U_tab[ u_ptr[0] ]; \
364 :     int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ]; \
365 :     int r_v0 = R_V_tab[ v_ptr[0] ]; \
366 :     WRITE_RGB16(0, 0, C1) \
367 :     WRITE_RGB16(1, 0, C1)
368 : edgomez 195
369 : suxen_drol 631 #define YV12_TO_RGB16I_ROW(SIZE,C1,C2,C3,C4) \
370 :     int r[4], g[4], b[4]; \
371 :     r[0] = r[1] = r[2] = r[3] = 0; \
372 :     g[0] = g[1] = g[2] = g[3] = 0; \
373 :     b[0] = b[1] = b[2] = b[3] = 0;
374 :     #define YV12_TO_RGB16I(SIZE,C1,C2,C3,C4) \
375 :     int rgb_y; \
376 :     int b_u0 = B_U_tab[ u_ptr[0] ]; \
377 :     int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ]; \
378 :     int r_v0 = R_V_tab[ v_ptr[0] ]; \
379 :     int b_u1 = B_U_tab[ u_ptr[uv_stride] ]; \
380 :     int g_uv1 = G_U_tab[ u_ptr[uv_stride] ] + G_V_tab[ v_ptr[uv_stride] ]; \
381 :     int r_v1 = R_V_tab[ v_ptr[uv_stride] ]; \
382 :     WRITE_RGB16(0, 0, C1) \
383 :     WRITE_RGB16(1, 1, C1) \
384 :     WRITE_RGB16(2, 0, C1) \
385 :     WRITE_RGB16(3, 1, C1) \
386 :    
387 : edgomez 195
388 : suxen_drol 631 /* rgb/rgbi output */
389 : edgomez 195
390 : suxen_drol 631 #define WRITE_RGB(SIZE,ROW,UV_ROW,C1,C2,C3,C4) \
391 :     rgb_y = RGB_Y_tab[ y_ptr[(ROW)*y_stride + 0] ]; \
392 :     x_ptr[(ROW)*x_stride+(C3)] = MAX(0, MIN(255, (rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT)); \
393 :     x_ptr[(ROW)*x_stride+(C2)] = MAX(0, MIN(255, (rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT)); \
394 :     x_ptr[(ROW)*x_stride+(C1)] = MAX(0, MIN(255, (rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT)); \
395 :     if ((SIZE)>3) x_ptr[(ROW)*x_stride+(C4)] = 0; \
396 :     rgb_y = RGB_Y_tab[ y_ptr[(ROW)*y_stride + 1] ]; \
397 :     x_ptr[(ROW)*x_stride+(SIZE)+(C3)] = MAX(0, MIN(255, (rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT)); \
398 :     x_ptr[(ROW)*x_stride+(SIZE)+(C2)] = MAX(0, MIN(255, (rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT)); \
399 :     x_ptr[(ROW)*x_stride+(SIZE)+(C1)] = MAX(0, MIN(255, (rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT)); \
400 :     if ((SIZE)>3) x_ptr[(ROW)*x_stride+(SIZE)+(C4)] = 0;
401 : edgomez 195
402 :    
403 : suxen_drol 631 #define YV12_TO_RGB_ROW(SIZE,C1,C2,C3,C4) /* nothing */
404 :     #define YV12_TO_RGB(SIZE,C1,C2,C3,C4) \
405 :     int rgb_y; \
406 :     int b_u0 = B_U_tab[ u_ptr[0] ]; \
407 :     int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ]; \
408 :     int r_v0 = R_V_tab[ v_ptr[0] ]; \
409 :     WRITE_RGB(SIZE, 0, 0, C1,C2,C3,C4) \
410 :     WRITE_RGB(SIZE, 1, 0, C1,C2,C3,C4)
411 : edgomez 195
412 : suxen_drol 631 #define YV12_TO_RGBI_ROW(SIZE,C1,C2,C3,C4) /* nothing */
413 :     #define YV12_TO_RGBI(SIZE,C1,C2,C3,C4) \
414 :     int rgb_y; \
415 :     int b_u0 = B_U_tab[ u_ptr[0] ]; \
416 :     int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ]; \
417 :     int r_v0 = R_V_tab[ v_ptr[0] ]; \
418 :     int b_u1 = B_U_tab[ u_ptr[uv_stride] ]; \
419 :     int g_uv1 = G_U_tab[ u_ptr[uv_stride] ] + G_V_tab[ v_ptr[uv_stride] ]; \
420 :     int r_v1 = R_V_tab[ v_ptr[uv_stride] ]; \
421 :     WRITE_RGB(SIZE, 0, 0, C1,C2,C3,C4) \
422 :     WRITE_RGB(SIZE, 1, 1, C1,C2,C3,C4) \
423 :     WRITE_RGB(SIZE, 2, 0, C1,C2,C3,C4) \
424 :     WRITE_RGB(SIZE, 3, 1, C1,C2,C3,C4)
425 : edgomez 195
426 :    
427 : suxen_drol 631 /* yuyv/yuyvi output */
428 : edgomez 195
429 : suxen_drol 631 #define WRITE_YUYV(ROW,UV_ROW,C1,C2,C3,C4) \
430 :     x_ptr[(ROW)*x_stride+(C1)] = y_ptr[ (ROW)*y_stride +0]; \
431 :     x_ptr[(ROW)*x_stride+(C2)] = u_ptr[(UV_ROW)*uv_stride+0]; \
432 :     x_ptr[(ROW)*x_stride+(C3)] = y_ptr[ (ROW)*y_stride +1]; \
433 :     x_ptr[(ROW)*x_stride+(C4)] = v_ptr[(UV_ROW)*uv_stride+0]; \
434 : edgomez 195
435 : suxen_drol 631 #define YV12_TO_YUYV_ROW(SIZE,C1,C2,C3,C4) /* nothing */
436 :     #define YV12_TO_YUYV(SIZE,C1,C2,C3,C4) \
437 :     WRITE_YUYV(0, 0, C1,C2,C3,C4) \
438 :     WRITE_YUYV(1, 0, C1,C2,C3,C4)
439 : edgomez 195
440 : suxen_drol 631 #define YV12_TO_YUYVI_ROW(SIZE,C1,C2,C3,C4) /* nothing */
441 :     #define YV12_TO_YUYVI(SIZE,C1,C2,C3,C4) \
442 :     WRITE_YUYV(0, 0, C1,C2,C3,C4) \
443 :     WRITE_YUYV(1, 1, C1,C2,C3,C4) \
444 :     WRITE_YUYV(2, 0, C1,C2,C3,C4) \
445 :     WRITE_YUYV(3, 1, C1,C2,C3,C4)
446 : edgomez 195
447 :    
448 : suxen_drol 631 MAKE_COLORSPACE(yv12_to_rgb555_c, 2,2,2, YV12_TO_RGB16, MK_RGB555, 0,0,0)
449 :     MAKE_COLORSPACE(yv12_to_rgb565_c, 2,2,2, YV12_TO_RGB16, MK_RGB565, 0,0,0)
450 :     MAKE_COLORSPACE(yv12_to_bgr_c, 3,2,2, YV12_TO_RGB, 2,1,0, 0)
451 :     MAKE_COLORSPACE(yv12_to_bgra_c, 4,2,2, YV12_TO_RGB, 2,1,0,3)
452 :     MAKE_COLORSPACE(yv12_to_abgr_c, 4,2,2, YV12_TO_RGB, 3,2,1,0)
453 :     MAKE_COLORSPACE(yv12_to_rgba_c, 4,2,2, YV12_TO_RGB, 0,1,2,3)
454 :     MAKE_COLORSPACE(yv12_to_yuyv_c, 2,2,2, YV12_TO_YUYV, 0,1,2,3)
455 :     MAKE_COLORSPACE(yv12_to_uyvy_c, 2,2,2, YV12_TO_YUYV, 1,0,3,2)
456 : edgomez 195
457 : suxen_drol 631 MAKE_COLORSPACE(yv12_to_rgb555i_c, 2,2,4, YV12_TO_RGB16I, MK_RGB555, 0,0,0)
458 :     MAKE_COLORSPACE(yv12_to_rgb565i_c, 2,2,4, YV12_TO_RGB16I, MK_RGB565, 0,0,0)
459 :     MAKE_COLORSPACE(yv12_to_bgri_c, 3,2,4, YV12_TO_RGBI, 2,1,0, 0)
460 :     MAKE_COLORSPACE(yv12_to_bgrai_c, 4,2,4, YV12_TO_RGBI, 2,1,0,3)
461 :     MAKE_COLORSPACE(yv12_to_abgri_c, 4,2,4, YV12_TO_RGBI, 3,2,1,0)
462 :     MAKE_COLORSPACE(yv12_to_rgbai_c, 4,2,4, YV12_TO_RGBI, 0,1,2,3)
463 :     MAKE_COLORSPACE(yv12_to_yuyvi_c, 2,2,4, YV12_TO_YUYVI, 0,1,2,3)
464 :     MAKE_COLORSPACE(yv12_to_uyvyi_c, 2,2,4, YV12_TO_YUYVI, 1,0,3,2)
465 : edgomez 195
466 :    
467 :    
468 : suxen_drol 631 /* yv12 to yv12 copy function */
469 : edgomez 195
470 :     void
471 : suxen_drol 631 yv12_to_yv12_c(uint8_t * y_dst, uint8_t * u_dst, uint8_t * v_dst,
472 :     int y_dst_stride, int uv_dst_stride,
473 :     uint8_t * y_src, uint8_t * u_src, uint8_t * v_src,
474 :     int y_src_stride, int uv_src_stride,
475 :     int width, int height, int vflip)
476 : edgomez 195 {
477 : suxen_drol 631 int width2 = width / 2;
478 :     int height2 = height / 2;
479 :     int y;
480 : edgomez 195
481 : suxen_drol 631 if (vflip) {
482 :     y_src += (height - 1) * y_src_stride;
483 :     u_src += (height2 - 1) * uv_src_stride;
484 :     v_src += (height2 - 1) * uv_src_stride;
485 :     y_src_stride = -y_src_stride;
486 :     uv_src_stride = -uv_src_stride;
487 : edgomez 195 }
488 :    
489 :     for (y = height; y; y--) {
490 : suxen_drol 631 memcpy(y_dst, y_src, width);
491 :     y_src += y_src_stride;
492 :     y_dst += y_dst_stride;
493 : edgomez 195 }
494 :    
495 : suxen_drol 631 for (y = height2; y; y--) {
496 :     memcpy(u_dst, u_src, width2);
497 :     u_src += uv_src_stride;
498 :     u_dst += uv_dst_stride;
499 : edgomez 195 }
500 :    
501 : suxen_drol 631 for (y = height2; y; y--) {
502 :     memcpy(v_dst, v_src, width2);
503 :     v_src += uv_src_stride;
504 :     v_dst += uv_dst_stride;
505 : edgomez 195 }
506 :     }
507 :    
508 :    
509 :    
510 : suxen_drol 631 /* initialize rgb lookup tables */
511 : edgomez 195
512 :     void
513 : suxen_drol 631 colorspace_init(void)
514 : edgomez 195 {
515 : suxen_drol 631 int32_t i;
516 : edgomez 195
517 : suxen_drol 631 for (i = 0; i < 256; i++) {
518 :     RGB_Y_tab[i] = FIX_OUT(RGB_Y_OUT) * (i - Y_ADD_OUT);
519 :     B_U_tab[i] = FIX_OUT(B_U_OUT) * (i - U_ADD_OUT);
520 :     G_U_tab[i] = FIX_OUT(G_U_OUT) * (i - U_ADD_OUT);
521 :     G_V_tab[i] = FIX_OUT(G_V_OUT) * (i - V_ADD_OUT);
522 :     R_V_tab[i] = FIX_OUT(R_V_OUT) * (i - V_ADD_OUT);
523 : edgomez 195 }
524 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4