1 /*****************************************************************************
2 * i422_yuy2.c : YUV to YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: i422_yuy2.c,v 1.4 2003/11/06 17:08:12 nitrox 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 "i422_yuy2.h"
35 #define SRC_FOURCC "I422"
36 #if defined (MODULE_NAME_IS_i422_yuy2)
37 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
39 # define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
42 /*****************************************************************************
43 * Local and extern prototypes.
44 *****************************************************************************/
45 static int Activate ( vlc_object_t * );
47 static void I422_YUY2 ( vout_thread_t *, picture_t *, picture_t * );
48 static void I422_YVYU ( vout_thread_t *, picture_t *, picture_t * );
49 static void I422_UYVY ( vout_thread_t *, picture_t *, picture_t * );
50 static void I422_IUYV ( vout_thread_t *, picture_t *, picture_t * );
51 static void I422_cyuv ( vout_thread_t *, picture_t *, picture_t * );
52 #if defined (MODULE_NAME_IS_i422_yuy2)
53 static void I422_Y211 ( vout_thread_t *, picture_t *, picture_t * );
54 static void I422_Y211 ( vout_thread_t *, picture_t *, picture_t * );
55 static void I422_YV12 ( vout_thread_t *, picture_t *, picture_t * );
58 /*****************************************************************************
60 *****************************************************************************/
62 #if defined (MODULE_NAME_IS_i422_yuy2)
63 set_description( _("conversions from " SRC_FOURCC " to " DEST_FOURCC) );
64 set_capability( "chroma", 80 );
65 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
66 set_description( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) );
67 set_capability( "chroma", 100 );
68 add_requirement( MMX );
70 set_callbacks( Activate, NULL );
73 /*****************************************************************************
74 * Activate: allocate a chroma function
75 *****************************************************************************
76 * This function allocates and initializes a chroma function
77 *****************************************************************************/
78 static int Activate( vlc_object_t *p_this )
80 vout_thread_t *p_vout = (vout_thread_t *)p_this;
82 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
87 switch( p_vout->render.i_chroma )
89 case VLC_FOURCC('I','4','2','2'):
90 switch( p_vout->output.i_chroma )
92 case VLC_FOURCC('Y','U','Y','2'):
93 case VLC_FOURCC('Y','U','N','V'):
94 p_vout->chroma.pf_convert = I422_YUY2;
97 case VLC_FOURCC('Y','V','Y','U'):
98 p_vout->chroma.pf_convert = I422_YVYU;
101 case VLC_FOURCC('U','Y','V','Y'):
102 case VLC_FOURCC('U','Y','N','V'):
103 case VLC_FOURCC('Y','4','2','2'):
104 p_vout->chroma.pf_convert = I422_UYVY;
107 case VLC_FOURCC('I','U','Y','V'):
108 p_vout->chroma.pf_convert = I422_IUYV;
111 case VLC_FOURCC('c','y','u','v'):
112 p_vout->chroma.pf_convert = I422_cyuv;
115 #if defined (MODULE_NAME_IS_i422_yuy2)
116 case VLC_FOURCC('Y','2','1','1'):
117 p_vout->chroma.pf_convert = I422_Y211;
120 case VLC_FOURCC('Y','V','1','2'):
121 p_vout->chroma.pf_convert = I422_YV12;
137 /* Following functions are local */
139 /*****************************************************************************
140 * I422_YUY2: planar YUV 4:2:2 to packed YUY2 4:2:2
141 *****************************************************************************/
142 static void I422_YUY2( vout_thread_t *p_vout, picture_t *p_source,
145 uint8_t *p_line = p_dest->p->p_pixels;
146 uint8_t *p_y = p_source->Y_PIXELS;
147 uint8_t *p_u = p_source->U_PIXELS;
148 uint8_t *p_v = p_source->V_PIXELS;
152 for( i_y = p_vout->render.i_height ; i_y-- ; )
154 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
156 #if defined (MODULE_NAME_IS_i422_yuy2)
157 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
158 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
159 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
160 C_YUV422_YUYV( p_line, p_y, p_u, p_v );
162 __asm__( ".align 8" MMX_YUV422_YUYV
163 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
165 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
167 __asm__( ".align 8" MMX_YUV422_YUYV
168 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
170 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
176 /*****************************************************************************
177 * I422_YVYU: planar YUV 4:2:2 to packed YVYU 4:2:2
178 *****************************************************************************/
179 static void I422_YVYU( vout_thread_t *p_vout, picture_t *p_source,
182 uint8_t *p_line = p_dest->p->p_pixels;
183 uint8_t *p_y = p_source->Y_PIXELS;
184 uint8_t *p_u = p_source->U_PIXELS;
185 uint8_t *p_v = p_source->V_PIXELS;
189 for( i_y = p_vout->render.i_height ; i_y-- ; )
191 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
193 #if defined (MODULE_NAME_IS_i422_yuy2)
194 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
195 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
196 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
197 C_YUV422_YVYU( p_line, p_y, p_u, p_v );
199 __asm__( ".align 8" MMX_YUV422_YVYU
200 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
202 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
204 __asm__( ".align 8" MMX_YUV422_YVYU
205 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
207 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
213 /*****************************************************************************
214 * I422_UYVY: planar YUV 4:2:2 to packed UYVY 4:2:2
215 *****************************************************************************/
216 static void I422_UYVY( vout_thread_t *p_vout, picture_t *p_source,
219 uint8_t *p_line = p_dest->p->p_pixels;
220 uint8_t *p_y = p_source->Y_PIXELS;
221 uint8_t *p_u = p_source->U_PIXELS;
222 uint8_t *p_v = p_source->V_PIXELS;
226 for( i_y = p_vout->render.i_height ; i_y-- ; )
228 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
230 #if defined (MODULE_NAME_IS_i422_yuy2)
231 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
232 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
233 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
234 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
236 __asm__( ".align 8" MMX_YUV422_UYVY
237 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
239 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
241 __asm__( ".align 8" MMX_YUV422_UYVY
242 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
244 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
250 /*****************************************************************************
251 * I422_IUYV: planar YUV 4:2:2 to interleaved packed IUYV 4:2:2
252 *****************************************************************************/
253 static void I422_IUYV( vout_thread_t *p_vout, picture_t *p_source,
257 msg_Err( p_vout, "I422_IUYV unimplemented, please harass <sam@zoy.org>" );
260 /*****************************************************************************
261 * I422_cyuv: planar YUV 4:2:2 to upside-down packed UYVY 4:2:2
262 *****************************************************************************/
263 static void I422_cyuv( vout_thread_t *p_vout, picture_t *p_source,
266 uint8_t *p_line = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch;
267 uint8_t *p_y = p_source->Y_PIXELS;
268 uint8_t *p_u = p_source->U_PIXELS;
269 uint8_t *p_v = p_source->V_PIXELS;
273 for( i_y = p_vout->render.i_height ; i_y-- ; )
275 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
277 p_line -= 2 * p_dest->p->i_pitch;
279 #if defined (MODULE_NAME_IS_i422_yuy2)
280 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
281 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
282 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
283 C_YUV422_UYVY( p_line, p_y, p_u, p_v );
285 __asm__( ".align 8" MMX_YUV422_UYVY
286 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
288 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
290 __asm__( ".align 8" MMX_YUV422_UYVY
291 : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) );
293 p_line += 8; p_y += 4; p_u += 2; p_v += 2;
299 /*****************************************************************************
300 * I422_Y211: planar YUV 4:2:2 to packed YUYV 2:1:1
301 *****************************************************************************/
302 #if defined (MODULE_NAME_IS_i422_yuy2)
303 static void I422_Y211( vout_thread_t *p_vout, picture_t *p_source,
306 uint8_t *p_line = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch;
307 uint8_t *p_y = p_source->Y_PIXELS;
308 uint8_t *p_u = p_source->U_PIXELS;
309 uint8_t *p_v = p_source->V_PIXELS;
313 for( i_y = p_vout->render.i_height ; i_y-- ; )
315 for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
317 C_YUV422_Y211( p_line, p_y, p_u, p_v );
318 C_YUV422_Y211( p_line, p_y, p_u, p_v );
325 /*****************************************************************************
326 * I422_YV12: planar YUV 4:2:2 to planar YV12
327 *****************************************************************************/
328 #if defined (MODULE_NAME_IS_i422_yuy2)
329 static void I422_YV12( vout_thread_t *p_vout, picture_t *p_source,
332 uint16_t i_dpy = p_dest->p[Y_PLANE].i_pitch;
333 uint16_t i_spy = p_source->p[Y_PLANE].i_pitch;
334 uint16_t i_dpuv = p_dest->p[U_PLANE].i_pitch;
335 uint16_t i_spuv = p_source->p[U_PLANE].i_pitch;
336 uint16_t i_width = p_vout->render.i_width;
337 uint16_t i_y = p_vout->render.i_height;
338 uint8_t *p_dy = p_dest->Y_PIXELS + (i_y-1)*i_dpy;
339 uint8_t *p_y = p_source->Y_PIXELS + (i_y-1)*i_spy;
340 uint8_t *p_du = p_dest->U_PIXELS + (i_y/2-1)*i_dpuv;
341 uint8_t *p_u = p_source->U_PIXELS + (i_y-1)*i_spuv;
342 uint8_t *p_dv = p_dest->V_PIXELS + (i_y/2-1)*i_dpuv;
343 uint8_t *p_v = p_source->V_PIXELS + (i_y-1)*i_spuv;
348 memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
349 memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
350 memcpy(p_du, p_u, i_width/2); p_du -= i_dpuv; p_u -= 2*i_spuv;
351 memcpy(p_dv, p_v, i_width/2); p_dv -= i_dpuv; p_v -= 2*i_spuv;