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.7 2002/05/21 03:37:17 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 <errno.h> /* ENOMEM */
28 #include <string.h> /* strerror() */
29 #include <stdlib.h> /* malloc(), free() */
31 #include <videolan/vlc.h>
34 #include "video_output.h"
36 #include "i420_yuy2.h"
38 #define SRC_FOURCC "I420,IYUV,YV12"
40 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
41 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
43 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
46 /*****************************************************************************
47 * Local and extern prototypes.
48 *****************************************************************************/
49 static void chroma_getfunctions ( function_list_t * p_function_list );
51 static int chroma_Init ( vout_thread_t *p_vout );
52 static void chroma_End ( vout_thread_t *p_vout );
54 static void I420_YUY2 ( vout_thread_t *, picture_t *, picture_t * );
55 static void I420_YVYU ( vout_thread_t *, picture_t *, picture_t * );
56 static void I420_UYVY ( vout_thread_t *, picture_t *, picture_t * );
57 static void I420_IUYV ( vout_thread_t *, picture_t *, picture_t * );
58 static void I420_cyuv ( vout_thread_t *, picture_t *, picture_t * );
59 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
60 static void I420_Y211 ( vout_thread_t *, picture_t *, picture_t * );
63 /*****************************************************************************
64 * Build configuration tree.
65 *****************************************************************************/
70 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
71 SET_DESCRIPTION( _("conversions from " SRC_FOURCC " to " DEST_FOURCC) )
72 ADD_CAPABILITY( CHROMA, 80 )
73 #elif defined (MODULE_NAME_IS_chroma_i420_yuy2_mmx)
74 SET_DESCRIPTION( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) )
75 ADD_CAPABILITY( CHROMA, 100 )
76 ADD_REQUIREMENT( MMX )
81 chroma_getfunctions( &p_module->p_functions->chroma );
84 MODULE_DEACTIVATE_START
85 MODULE_DEACTIVATE_STOP
87 /*****************************************************************************
88 * Functions exported as capabilities. They are declared as static so that
89 * we don't pollute the namespace too much.
90 *****************************************************************************/
91 static void chroma_getfunctions( function_list_t * p_function_list )
93 p_function_list->functions.chroma.pf_init = chroma_Init;
94 p_function_list->functions.chroma.pf_end = chroma_End;
97 /*****************************************************************************
98 * chroma_Init: allocate a chroma function
99 *****************************************************************************
100 * This function allocates and initializes a chroma function
101 *****************************************************************************/
102 static int chroma_Init( vout_thread_t *p_vout )
104 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
109 switch( p_vout->render.i_chroma )
114 switch( p_vout->output.i_chroma )
118 p_vout->chroma.pf_convert = I420_YUY2;
122 p_vout->chroma.pf_convert = I420_YVYU;
128 p_vout->chroma.pf_convert = I420_UYVY;
132 p_vout->chroma.pf_convert = I420_IUYV;
136 p_vout->chroma.pf_convert = I420_cyuv;
139 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
141 p_vout->chroma.pf_convert = I420_Y211;
157 /*****************************************************************************
158 * chroma_End: free the chroma function
159 *****************************************************************************
160 * This function frees the previously allocated chroma function
161 *****************************************************************************/
162 static void chroma_End( vout_thread_t *p_vout )
167 /* Following functions are local */
169 /*****************************************************************************
170 * I420_YUY2: planar YUV 4:2:0 to packed YUYV 4:2:2
171 *****************************************************************************/
172 static void I420_YUY2( vout_thread_t *p_vout, picture_t *p_source,
175 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
176 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
177 u8 *p_u = p_source->U_PIXELS;
178 u8 *p_v = p_source->V_PIXELS;
182 const int i_source_margin = p_source->p->b_margin ?
183 p_source->p->i_pitch - p_source->p->i_visible_bytes : 0;
184 const int i_dest_margin = p_dest->p->b_margin ?
185 p_dest->p->i_pitch - p_dest->p->i_visible_bytes : 0;
187 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
190 p_line2 += p_dest->p->i_pitch;
193 p_y2 += p_source->p[Y_PLANE].i_pitch;
195 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
197 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
203 MMX_CALL( MMX_YUV420_YUYV );
207 p_y1 += i_source_margin;
208 p_y2 += i_source_margin;
209 p_line1 += i_dest_margin;
210 p_line2 += i_dest_margin;
214 /*****************************************************************************
215 * I420_YVYU: planar YUV 4:2:0 to packed YVYU 4:2:2
216 *****************************************************************************/
217 static void I420_YVYU( vout_thread_t *p_vout, picture_t *p_source,
220 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
221 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
222 u8 *p_u = p_source->U_PIXELS;
223 u8 *p_v = p_source->V_PIXELS;
227 const int i_source_margin = p_source->p->b_margin ?
228 p_source->p->i_pitch - p_source->p->i_visible_bytes : 0;
229 const int i_dest_margin = p_dest->p->b_margin ?
230 p_dest->p->i_pitch - p_dest->p->i_visible_bytes : 0;
232 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
235 p_line2 += p_dest->p->i_pitch;
238 p_y2 += p_source->p[Y_PLANE].i_pitch;
240 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
242 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
248 MMX_CALL( MMX_YUV420_YVYU );
252 p_y1 += i_source_margin;
253 p_y2 += i_source_margin;
254 p_line1 += i_dest_margin;
255 p_line2 += i_dest_margin;
259 /*****************************************************************************
260 * I420_UYVY: planar YUV 4:2:0 to packed UYVY 4:2:2
261 *****************************************************************************/
262 static void I420_UYVY( vout_thread_t *p_vout, picture_t *p_source,
265 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
266 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
267 u8 *p_u = p_source->U_PIXELS;
268 u8 *p_v = p_source->V_PIXELS;
272 const int i_source_margin = p_source->p->b_margin ?
273 p_source->p->i_pitch - p_source->p->i_visible_bytes : 0;
274 const int i_dest_margin = p_dest->p->b_margin ?
275 p_dest->p->i_pitch - p_dest->p->i_visible_bytes : 0;
277 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
280 p_line2 += p_dest->p->i_pitch;
283 p_y2 += p_source->p[Y_PLANE].i_pitch;
285 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
287 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
293 MMX_CALL( MMX_YUV420_UYVY );
297 p_y1 += i_source_margin;
298 p_y2 += i_source_margin;
299 p_line1 += i_dest_margin;
300 p_line2 += i_dest_margin;
304 /*****************************************************************************
305 * I420_IUYV: planar YUV 4:2:0 to interleaved packed UYVY 4:2:2
306 *****************************************************************************/
307 static void I420_IUYV( vout_thread_t *p_vout, picture_t *p_source,
311 intf_ErrMsg( "chroma error: I420_IUYV unimplemented, "
312 "please harass <sam@zoy.org>" );
315 /*****************************************************************************
316 * I420_cyuv: planar YUV 4:2:0 to upside-down packed UYVY 4:2:2
317 *****************************************************************************/
318 static void I420_cyuv( vout_thread_t *p_vout, picture_t *p_source,
321 u8 *p_line1 = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch
322 + p_dest->p->i_pitch;
323 u8 *p_line2 = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch;
324 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
325 u8 *p_u = p_source->U_PIXELS;
326 u8 *p_v = p_source->V_PIXELS;
330 const int i_source_margin = p_source->p->b_margin ?
331 p_source->p->i_pitch - p_source->p->i_visible_bytes : 0;
332 const int i_dest_margin = p_dest->p->b_margin ?
333 p_dest->p->i_pitch - p_dest->p->i_visible_bytes : 0;
335 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
337 p_line1 -= 3 * p_dest->p->i_pitch;
338 p_line2 -= 3 * p_dest->p->i_pitch;
341 p_y2 += p_source->p[Y_PLANE].i_pitch;
343 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
345 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
351 MMX_CALL( MMX_YUV420_UYVY );
355 p_y1 += i_source_margin;
356 p_y2 += i_source_margin;
357 p_line1 += i_dest_margin;
358 p_line2 += i_dest_margin;
362 /*****************************************************************************
363 * I420_Y211: planar YUV 4:2:0 to packed YUYV 2:1:1
364 *****************************************************************************/
365 #if defined (MODULE_NAME_IS_chroma_i420_yuy2)
366 static void I420_Y211( vout_thread_t *p_vout, picture_t *p_source,
369 u8 *p_line1, *p_line2 = p_dest->p->p_pixels;
370 u8 *p_y1, *p_y2 = p_source->Y_PIXELS;
371 u8 *p_u = p_source->U_PIXELS;
372 u8 *p_v = p_source->V_PIXELS;
376 const int i_source_margin = p_source->p->b_margin ?
377 p_source->p->i_pitch - p_source->p->i_visible_bytes : 0;
378 const int i_dest_margin = p_dest->p->b_margin ?
379 p_dest->p->i_pitch - p_dest->p->i_visible_bytes : 0;
381 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
384 p_line2 += p_dest->p->i_pitch;
387 p_y2 += p_source->p[Y_PLANE].i_pitch;
389 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
395 p_y1 += i_source_margin;
396 p_y2 += i_source_margin;
397 p_line1 += i_dest_margin;
398 p_line2 += i_dest_margin;