1 /*****************************************************************************
2 * i420_yuy2.c : YUV to YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: i420_yuy2.c,v 1.1 2002/01/04 14:01:34 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <math.h> /* exp(), pow() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
30 #include <stdlib.h> /* malloc(), free() */
32 #include <videolan/vlc.h>
35 #include "video_output.h"
37 #include "i420_yuy2.h"
39 #define SRC_FOURCC "I420/IYUV/YV12"
41 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
42 # define DEST_FOURCC "YUY2/YUNV/YVYU/UYVY/UYNV/Y422/IUYV/cyuv/Y211"
44 # define DEST_FOURCC "YUY2/YUNV/YVYU/UYVY/UYNV/Y422/IUYV/cyuv"
47 /*****************************************************************************
48 * Local and extern prototypes.
49 *****************************************************************************/
50 static void chroma_getfunctions ( function_list_t * p_function_list );
52 static int chroma_Probe ( probedata_t *p_data );
53 static int chroma_Init ( vout_thread_t *p_vout );
54 static void chroma_End ( vout_thread_t *p_vout );
56 static void I420_YUY2 ( vout_thread_t *, picture_t *, picture_t * );
57 static void I420_YVYU ( vout_thread_t *, picture_t *, picture_t * );
58 static void I420_UYVY ( vout_thread_t *, picture_t *, picture_t * );
59 static void I420_IUYV ( vout_thread_t *, picture_t *, picture_t * );
60 static void I420_cyuv ( vout_thread_t *, picture_t *, picture_t * );
61 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
62 static void I420_Y211 ( vout_thread_t *, picture_t *, picture_t * );
65 /*****************************************************************************
66 * Build configuration tree.
67 *****************************************************************************/
72 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
73 SET_DESCRIPTION( "conversions from " SRC_FOURCC " to " DEST_FOURCC )
74 ADD_CAPABILITY( CHROMA, 80 )
75 #elif defined (MODULE_NAME_IS_chroma_i420_yuy2_mmx)
76 SET_DESCRIPTION( "MMX conversions from " SRC_FOURCC " to " DEST_FOURCC )
77 ADD_CAPABILITY( CHROMA, 100 )
78 ADD_REQUIREMENT( MMX )
83 chroma_getfunctions( &p_module->p_functions->chroma );
86 MODULE_DEACTIVATE_START
87 MODULE_DEACTIVATE_STOP
89 /*****************************************************************************
90 * Functions exported as capabilities. They are declared as static so that
91 * we don't pollute the namespace too much.
92 *****************************************************************************/
93 static void chroma_getfunctions( function_list_t * p_function_list )
95 p_function_list->pf_probe = chroma_Probe;
96 p_function_list->functions.chroma.pf_init = chroma_Init;
97 p_function_list->functions.chroma.pf_end = chroma_End;
100 /*****************************************************************************
101 * chroma_Probe: return a score
102 *****************************************************************************
103 * This function checks that we can handle the required data
104 *****************************************************************************/
105 static int chroma_Probe( probedata_t *p_data )
107 if( p_data->chroma.p_render->i_width & 1
108 || p_data->chroma.p_render->i_height & 1 )
113 switch( p_data->chroma.p_render->i_chroma )
118 switch( p_data->chroma.p_output->i_chroma )
138 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
155 /*****************************************************************************
156 * chroma_Init: allocate a chroma function
157 *****************************************************************************
158 * This function allocates and initializes a chroma function
159 *****************************************************************************/
160 static int chroma_Init( vout_thread_t *p_vout )
162 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
167 switch( p_vout->render.i_chroma )
172 switch( p_vout->output.i_chroma )
176 p_vout->chroma.pf_convert = I420_YUY2;
180 p_vout->chroma.pf_convert = I420_YVYU;
186 p_vout->chroma.pf_convert = I420_UYVY;
190 p_vout->chroma.pf_convert = I420_IUYV;
194 p_vout->chroma.pf_convert = I420_cyuv;
197 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
199 p_vout->chroma.pf_convert = I420_Y211;
215 /*****************************************************************************
216 * chroma_End: free the chroma function
217 *****************************************************************************
218 * This function frees the previously allocated chroma function
219 *****************************************************************************/
220 static void chroma_End( vout_thread_t *p_vout )
225 /* Following functions are local */
227 /*****************************************************************************
228 * I420_YUY2: planar YUV 4:2:0 to packed YUYV 4:2:2
229 *****************************************************************************/
230 static void I420_YUY2( vout_thread_t *p_vout, picture_t *p_source,
233 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
234 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
235 u8 *p_u = p_source->U_PIXELS;
236 u8 *p_v = p_source->V_PIXELS;
240 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
243 p_line2 += p_dest->p->i_pitch;
246 p_y2 += p_source->p[Y_PLANE].i_pitch;
248 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
250 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
251 C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
252 C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
253 C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
254 C_YUV420_YUYV( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
256 __asm__( ".align 8" MMX_YUV420_YUYV
257 : : "r" (p_line1), "r" (p_line2),
258 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
260 p_line1 += 8; p_line2 += 8;
261 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
263 __asm__( ".align 8" MMX_YUV420_YUYV
264 : : "r" (p_line1), "r" (p_line2),
265 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
267 p_line1 += 8; p_line2 += 8;
268 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
274 /*****************************************************************************
275 * I420_YVYU: planar YUV 4:2:0 to packed YVYU 4:2:2
276 *****************************************************************************/
277 static void I420_YVYU( vout_thread_t *p_vout, picture_t *p_source,
280 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
281 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
282 u8 *p_u = p_source->U_PIXELS;
283 u8 *p_v = p_source->V_PIXELS;
287 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
290 p_line2 += p_dest->p->i_pitch;
293 p_y2 += p_source->p[Y_PLANE].i_pitch;
295 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
297 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
298 C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
299 C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
300 C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
301 C_YUV420_YVYU( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
303 __asm__( ".align 8" MMX_YUV420_YVYU
304 : : "r" (p_line1), "r" (p_line2),
305 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
307 p_line1 += 8; p_line2 += 8;
308 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
310 __asm__( ".align 8" MMX_YUV420_YVYU
311 : : "r" (p_line1), "r" (p_line2),
312 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
314 p_line1 += 8; p_line2 += 8;
315 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
321 /*****************************************************************************
322 * I420_UYVY: planar YUV 4:2:0 to packed UYVY 4:2:2
323 *****************************************************************************/
324 static void I420_UYVY( vout_thread_t *p_vout, picture_t *p_source,
327 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
328 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
329 u8 *p_u = p_source->U_PIXELS;
330 u8 *p_v = p_source->V_PIXELS;
334 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
337 p_line2 += p_dest->p->i_pitch;
340 p_y2 += p_source->p[Y_PLANE].i_pitch;
342 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
344 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
345 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
346 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
347 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
348 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
350 __asm__( ".align 8" MMX_YUV420_UYVY
351 : : "r" (p_line1), "r" (p_line2),
352 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
354 p_line1 += 8; p_line2 += 8;
355 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
357 __asm__( ".align 8" MMX_YUV420_UYVY
358 : : "r" (p_line1), "r" (p_line2),
359 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
361 p_line1 += 8; p_line2 += 8;
362 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
368 /*****************************************************************************
369 * I420_IUYV: planar YUV 4:2:0 to interleaved packed UYVY 4:2:2
370 *****************************************************************************/
371 static void I420_IUYV( vout_thread_t *p_vout, picture_t *p_source,
375 intf_ErrMsg( "chroma error: I420_IUYV unimplemented, "
376 "please harass <sam@zoy.org>" );
379 /*****************************************************************************
380 * I420_cyuv: planar YUV 4:2:0 to upside-down packed UYVY 4:2:2
381 *****************************************************************************/
382 static void I420_cyuv( vout_thread_t *p_vout, picture_t *p_source,
385 u8 *p_line1 = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch
386 + p_dest->p->i_pitch;
387 u8 *p_line2 = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch;
388 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
389 u8 *p_u = p_source->U_PIXELS;
390 u8 *p_v = p_source->V_PIXELS;
394 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
396 p_line1 -= 3 * p_dest->p->i_pitch;
397 p_line2 -= 3 * p_dest->p->i_pitch;
400 p_y2 += p_source->p[Y_PLANE].i_pitch;
402 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
404 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
405 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
406 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
407 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
408 C_YUV420_UYVY( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
410 __asm__( ".align 8" MMX_YUV420_UYVY
411 : : "r" (p_line1), "r" (p_line2),
412 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
414 p_line1 += 8; p_line2 += 8;
415 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
417 __asm__( ".align 8" MMX_YUV420_UYVY
418 : : "r" (p_line1), "r" (p_line2),
419 "r" (p_y1), "r" (p_y2), "r" (p_u), "r" (p_v) );
421 p_line1 += 8; p_line2 += 8;
422 p_y1 += 4; p_y2 += 4; p_u += 2; p_v += 2;
428 /*****************************************************************************
429 * I420_Y211: planar YUV 4:2:0 to packed YUYV 2:1:1
430 *****************************************************************************/
431 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
432 static void I420_Y211( vout_thread_t *p_vout, picture_t *p_source,
435 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
436 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
437 u8 *p_u = p_source->U_PIXELS;
438 u8 *p_v = p_source->V_PIXELS;
442 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
445 p_line2 += p_dest->p->i_pitch;
448 p_y2 += p_source->p[Y_PLANE].i_pitch;
450 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
452 C_YUV420_Y211( p_line1, p_line2, p_y1, p_y2, p_u, p_v );
453 C_YUV420_Y211( p_line1, p_line2, p_y1, p_y2, p_u, p_v );