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.5 2004/01/25 17:20:18 kuehne 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 <string.h> /* strerror() */
28 #include <stdlib.h> /* malloc(), free() */
33 #include "i420_yuy2.h"
35 #define SRC_FOURCC "I420,IYUV,YV12"
37 #if defined (MODULE_NAME_IS_i420_yuy2)
38 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
40 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
43 /*****************************************************************************
44 * Local and extern prototypes.
45 *****************************************************************************/
46 static int Activate ( vlc_object_t * );
48 static void I420_YUY2 ( vout_thread_t *, picture_t *, picture_t * );
49 static void I420_YVYU ( vout_thread_t *, picture_t *, picture_t * );
50 static void I420_UYVY ( vout_thread_t *, picture_t *, picture_t * );
51 static void I420_IUYV ( vout_thread_t *, picture_t *, picture_t * );
52 static void I420_cyuv ( vout_thread_t *, picture_t *, picture_t * );
53 #if defined (MODULE_NAME_IS_i420_yuy2)
54 static void I420_Y211 ( vout_thread_t *, picture_t *, picture_t * );
57 #ifdef MODULE_NAME_IS_i420_yuy2_mmx
58 static uint64_t i_00ffw;
59 static uint64_t i_80w;
62 /*****************************************************************************
64 *****************************************************************************/
66 #if defined (MODULE_NAME_IS_i420_yuy2)
67 set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
68 set_capability( "chroma", 80 );
69 #elif defined (MODULE_NAME_IS_i420_yuy2_mmx)
70 set_description( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) );
71 set_capability( "chroma", 100 );
72 add_requirement( MMX );
73 /* Initialize MMX-specific constants */
74 i_00ffw = 0x00ff00ff00ff00ffULL;
75 i_80w = 0x0000000080808080ULL;
77 set_callbacks( Activate, NULL );
80 /*****************************************************************************
81 * Activate: allocate a chroma function
82 *****************************************************************************
83 * This function allocates and initializes a chroma function
84 *****************************************************************************/
85 static int Activate( vlc_object_t *p_this )
87 vout_thread_t *p_vout = (vout_thread_t *)p_this;
89 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
94 switch( p_vout->render.i_chroma )
96 case VLC_FOURCC('Y','V','1','2'):
97 case VLC_FOURCC('I','4','2','0'):
98 case VLC_FOURCC('I','Y','U','V'):
99 switch( p_vout->output.i_chroma )
101 case VLC_FOURCC('Y','U','Y','2'):
102 case VLC_FOURCC('Y','U','N','V'):
103 p_vout->chroma.pf_convert = I420_YUY2;
106 case VLC_FOURCC('Y','V','Y','U'):
107 p_vout->chroma.pf_convert = I420_YVYU;
110 case VLC_FOURCC('U','Y','V','Y'):
111 case VLC_FOURCC('U','Y','N','V'):
112 case VLC_FOURCC('Y','4','2','2'):
113 p_vout->chroma.pf_convert = I420_UYVY;
116 case VLC_FOURCC('I','U','Y','V'):
117 p_vout->chroma.pf_convert = I420_IUYV;
120 case VLC_FOURCC('c','y','u','v'):
121 p_vout->chroma.pf_convert = I420_cyuv;
124 #if defined (MODULE_NAME_IS_i420_yuy2)
125 case VLC_FOURCC('Y','2','1','1'):
126 p_vout->chroma.pf_convert = I420_Y211;
142 /* Following functions are local */
144 /*****************************************************************************
145 * I420_YUY2: planar YUV 4:2:0 to packed YUYV 4:2:2
146 *****************************************************************************/
147 static void I420_YUY2( vout_thread_t *p_vout, picture_t *p_source,
150 uint8_t *p_line1, *p_line2 = p_dest->p->p_pixels;
151 uint8_t *p_y1, *p_y2 = p_source->Y_PIXELS;
152 uint8_t *p_u = p_source->U_PIXELS;
153 uint8_t *p_v = p_source->V_PIXELS;
157 const int i_source_margin = p_source->p->i_pitch
158 - p_source->p->i_visible_pitch;
159 const int i_dest_margin = p_dest->p->i_pitch
160 - p_dest->p->i_visible_pitch;
162 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
165 p_line2 += p_dest->p->i_pitch;
168 p_y2 += p_source->p[Y_PLANE].i_pitch;
170 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
172 #if defined (MODULE_NAME_IS_i420_yuy2)
178 MMX_CALL( MMX_YUV420_YUYV );
182 p_y1 += i_source_margin;
183 p_y2 += i_source_margin;
184 p_line1 += i_dest_margin;
185 p_line2 += i_dest_margin;
189 /*****************************************************************************
190 * I420_YVYU: planar YUV 4:2:0 to packed YVYU 4:2:2
191 *****************************************************************************/
192 static void I420_YVYU( vout_thread_t *p_vout, picture_t *p_source,
195 uint8_t *p_line1, *p_line2 = p_dest->p->p_pixels;
196 uint8_t *p_y1, *p_y2 = p_source->Y_PIXELS;
197 uint8_t *p_u = p_source->U_PIXELS;
198 uint8_t *p_v = p_source->V_PIXELS;
202 const int i_source_margin = p_source->p->i_pitch
203 - p_source->p->i_visible_pitch;
204 const int i_dest_margin = p_dest->p->i_pitch
205 - p_dest->p->i_visible_pitch;
207 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
210 p_line2 += p_dest->p->i_pitch;
213 p_y2 += p_source->p[Y_PLANE].i_pitch;
215 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
217 #if defined (MODULE_NAME_IS_i420_yuy2)
223 MMX_CALL( MMX_YUV420_YVYU );
227 p_y1 += i_source_margin;
228 p_y2 += i_source_margin;
229 p_line1 += i_dest_margin;
230 p_line2 += i_dest_margin;
234 /*****************************************************************************
235 * I420_UYVY: planar YUV 4:2:0 to packed UYVY 4:2:2
236 *****************************************************************************/
237 static void I420_UYVY( vout_thread_t *p_vout, picture_t *p_source,
240 uint8_t *p_line1, *p_line2 = p_dest->p->p_pixels;
241 uint8_t *p_y1, *p_y2 = p_source->Y_PIXELS;
242 uint8_t *p_u = p_source->U_PIXELS;
243 uint8_t *p_v = p_source->V_PIXELS;
247 const int i_source_margin = p_source->p->i_pitch
248 - p_source->p->i_visible_pitch;
249 const int i_dest_margin = p_dest->p->i_pitch
250 - p_dest->p->i_visible_pitch;
252 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
255 p_line2 += p_dest->p->i_pitch;
258 p_y2 += p_source->p[Y_PLANE].i_pitch;
260 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
262 #if defined (MODULE_NAME_IS_i420_yuy2)
268 MMX_CALL( MMX_YUV420_UYVY );
272 p_y1 += i_source_margin;
273 p_y2 += i_source_margin;
274 p_line1 += i_dest_margin;
275 p_line2 += i_dest_margin;
279 /*****************************************************************************
280 * I420_IUYV: planar YUV 4:2:0 to interleaved packed UYVY 4:2:2
281 *****************************************************************************/
282 static void I420_IUYV( vout_thread_t *p_vout, picture_t *p_source,
286 msg_Err( p_vout, "I420_IUYV unimplemented, please harass <sam@zoy.org>" );
289 /*****************************************************************************
290 * I420_cyuv: planar YUV 4:2:0 to upside-down packed UYVY 4:2:2
291 *****************************************************************************/
292 static void I420_cyuv( vout_thread_t *p_vout, picture_t *p_source,
295 uint8_t *p_line1 = p_dest->p->p_pixels +
296 p_dest->p->i_lines * p_dest->p->i_pitch
297 + p_dest->p->i_pitch;
298 uint8_t *p_line2 = p_dest->p->p_pixels +
299 p_dest->p->i_lines * p_dest->p->i_pitch;
300 uint8_t *p_y1, *p_y2 = p_source->Y_PIXELS;
301 uint8_t *p_u = p_source->U_PIXELS;
302 uint8_t *p_v = p_source->V_PIXELS;
306 const int i_source_margin = p_source->p->i_pitch
307 - p_source->p->i_visible_pitch;
308 const int i_dest_margin = p_dest->p->i_pitch
309 - p_dest->p->i_visible_pitch;
311 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
313 p_line1 -= 3 * p_dest->p->i_pitch;
314 p_line2 -= 3 * p_dest->p->i_pitch;
317 p_y2 += p_source->p[Y_PLANE].i_pitch;
319 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
321 #if defined (MODULE_NAME_IS_i420_yuy2)
327 MMX_CALL( MMX_YUV420_UYVY );
331 p_y1 += i_source_margin;
332 p_y2 += i_source_margin;
333 p_line1 += i_dest_margin;
334 p_line2 += i_dest_margin;
338 /*****************************************************************************
339 * I420_Y211: planar YUV 4:2:0 to packed YUYV 2:1:1
340 *****************************************************************************/
341 #if defined (MODULE_NAME_IS_i420_yuy2)
342 static void I420_Y211( vout_thread_t *p_vout, picture_t *p_source,
345 uint8_t *p_line1, *p_line2 = p_dest->p->p_pixels;
346 uint8_t *p_y1, *p_y2 = p_source->Y_PIXELS;
347 uint8_t *p_u = p_source->U_PIXELS;
348 uint8_t *p_v = p_source->V_PIXELS;
352 const int i_source_margin = p_source->p->i_pitch
353 - p_source->p->i_visible_pitch;
354 const int i_dest_margin = p_dest->p->i_pitch
355 - p_dest->p->i_visible_pitch;
357 for( i_y = p_vout->render.i_height / 2 ; i_y-- ; )
360 p_line2 += p_dest->p->i_pitch;
363 p_y2 += p_source->p[Y_PLANE].i_pitch;
365 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
371 p_y1 += i_source_margin;
372 p_y2 += i_source_margin;
373 p_line1 += i_dest_margin;
374 p_line2 += i_dest_margin;