1 /*****************************************************************************
2 * yuy2_i420.c : Packed YUV 4:2:2 to Planar YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan dot 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
32 #define DEST_FOURCC "I420"
34 /*****************************************************************************
35 * Local and extern prototypes.
36 *****************************************************************************/
37 static int Activate ( vlc_object_t * );
39 static void YUY2_I420 ( vout_thread_t *, picture_t *, picture_t * );
40 static void YVYU_I420 ( vout_thread_t *, picture_t *, picture_t * );
41 static void UYVY_I420 ( vout_thread_t *, picture_t *, picture_t * );
42 static void cyuv_I420 ( vout_thread_t *, picture_t *, picture_t * );
44 /*****************************************************************************
46 *****************************************************************************/
48 set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
49 set_capability( "chroma", 80 );
50 set_callbacks( Activate, NULL );
53 /*****************************************************************************
54 * Activate: allocate a chroma function
55 *****************************************************************************
56 * This function allocates and initializes a chroma function
57 *****************************************************************************/
58 static int Activate( vlc_object_t *p_this )
60 vout_thread_t *p_vout = (vout_thread_t *)p_this;
62 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
67 switch( p_vout->output.i_chroma )
69 case VLC_FOURCC('I','4','2','0'):
70 switch( p_vout->render.i_chroma )
72 case VLC_FOURCC('Y','U','Y','2'):
73 case VLC_FOURCC('Y','U','N','V'):
74 p_vout->chroma.pf_convert = YUY2_I420;
77 case VLC_FOURCC('Y','V','Y','U'):
78 p_vout->chroma.pf_convert = YVYU_I420;
81 case VLC_FOURCC('U','Y','V','Y'):
82 case VLC_FOURCC('U','Y','N','V'):
83 case VLC_FOURCC('Y','4','2','2'):
84 p_vout->chroma.pf_convert = UYVY_I420;
87 case VLC_FOURCC('c','y','u','v'):
88 p_vout->chroma.pf_convert = cyuv_I420;
102 /* Following functions are local */
104 /*****************************************************************************
105 * YUY2_I420: packed YUY2 4:2:2 to planar YUV 4:2:0
106 *****************************************************************************/
107 static void YUY2_I420( vout_thread_t *p_vout, picture_t *p_source,
110 uint8_t *p_line = p_source->p->p_pixels;
112 uint8_t *p_y = p_dest->Y_PIXELS;
113 uint8_t *p_u = p_dest->U_PIXELS;
114 uint8_t *p_v = p_dest->V_PIXELS;
118 const int i_dest_margin = p_dest->p[0].i_pitch
119 - p_dest->p[0].i_visible_pitch;
120 const int i_dest_margin_c = p_dest->p[1].i_pitch
121 - p_dest->p[1].i_visible_pitch;
122 const int i_source_margin = p_source->p->i_pitch
123 - p_source->p->i_visible_pitch;
125 vlc_bool_t b_skip = VLC_FALSE;
127 for( i_y = p_vout->output.i_height ; i_y-- ; )
131 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
133 #define C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v ) \
134 *p_y++ = *p_line++; p_line++; \
135 *p_y++ = *p_line++; p_line++
136 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
137 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
138 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
139 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
141 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
143 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
148 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
150 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
151 *p_y++ = *p_line++; *p_u++ = *p_line++; \
152 *p_y++ = *p_line++; *p_v++ = *p_line++
153 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
154 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
155 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
156 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
158 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
160 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
163 p_line += i_source_margin;
164 p_y += i_dest_margin;
165 p_u += i_dest_margin_c;
166 p_v += i_dest_margin_c;
172 /*****************************************************************************
173 * YVYU_I420: packed YVYU 4:2:2 to planar YUV 4:2:0
174 *****************************************************************************/
175 static void YVYU_I420( vout_thread_t *p_vout, picture_t *p_source,
178 uint8_t *p_line = p_source->p->p_pixels;
180 uint8_t *p_y = p_dest->Y_PIXELS;
181 uint8_t *p_u = p_dest->U_PIXELS;
182 uint8_t *p_v = p_dest->V_PIXELS;
186 const int i_dest_margin = p_dest->p[0].i_pitch
187 - p_dest->p[0].i_visible_pitch;
188 const int i_dest_margin_c = p_dest->p[1].i_pitch
189 - p_dest->p[1].i_visible_pitch;
190 const int i_source_margin = p_source->p->i_pitch
191 - p_source->p->i_visible_pitch;
193 vlc_bool_t b_skip = VLC_FALSE;
195 for( i_y = p_vout->output.i_height ; i_y-- ; )
199 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
201 #define C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v ) \
202 *p_y++ = *p_line++; p_line++; \
203 *p_y++ = *p_line++; p_line++
204 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
205 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
206 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
207 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
209 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
211 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
216 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
218 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
219 *p_y++ = *p_line++; *p_v++ = *p_line++; \
220 *p_y++ = *p_line++; *p_u++ = *p_line++
221 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
222 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
223 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
224 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
226 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
228 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
231 p_line += i_source_margin;
232 p_y += i_dest_margin;
233 p_u += i_dest_margin_c;
234 p_v += i_dest_margin_c;
240 /*****************************************************************************
241 * UYVY_I420: packed UYVY 4:2:2 to planar YUV 4:2:0
242 *****************************************************************************/
243 static void UYVY_I420( vout_thread_t *p_vout, picture_t *p_source,
246 uint8_t *p_line = p_source->p->p_pixels;
248 uint8_t *p_y = p_dest->Y_PIXELS;
249 uint8_t *p_u = p_dest->U_PIXELS;
250 uint8_t *p_v = p_dest->V_PIXELS;
254 const int i_dest_margin = p_dest->p[0].i_pitch
255 - p_dest->p[0].i_visible_pitch;
256 const int i_dest_margin_c = p_dest->p[1].i_pitch
257 - p_dest->p[1].i_visible_pitch;
258 const int i_source_margin = p_source->p->i_pitch
259 - p_source->p->i_visible_pitch;
261 vlc_bool_t b_skip = VLC_FALSE;
263 for( i_y = p_vout->output.i_height ; i_y-- ; )
267 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
269 #define C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v ) \
270 *p_u++ = *p_line++; p_line++; \
271 *p_v++ = *p_line++; p_line++
272 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
273 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
274 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
275 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
277 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
279 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
284 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
286 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
287 *p_u++ = *p_line++; *p_y++ = *p_line++; \
288 *p_v++ = *p_line++; *p_y++ = *p_line++
289 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
290 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
291 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
292 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
294 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
296 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
299 p_line += i_source_margin;
300 p_y += i_dest_margin;
301 p_u += i_dest_margin_c;
302 p_v += i_dest_margin_c;
308 /*****************************************************************************
309 * cyuv_I420: upside-down packed UYVY 4:2:2 to planar YUV 4:2:0
311 *****************************************************************************/
312 static void cyuv_I420( vout_thread_t *p_vout, picture_t *p_source,
315 uint8_t *p_line = p_source->p->p_pixels;
317 uint8_t *p_y = p_dest->Y_PIXELS;
318 uint8_t *p_u = p_dest->U_PIXELS;
319 uint8_t *p_v = p_dest->V_PIXELS;
323 const int i_dest_margin = p_dest->p[0].i_pitch
324 - p_dest->p[0].i_visible_pitch;
325 const int i_dest_margin_c = p_dest->p[1].i_pitch
326 - p_dest->p[1].i_visible_pitch;
327 const int i_source_margin = p_source->p->i_pitch
328 - p_source->p->i_visible_pitch;
330 vlc_bool_t b_skip = VLC_FALSE;
332 for( i_y = p_vout->output.i_height ; i_y-- ; )
336 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
338 #define C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v ) \
339 *p_y++ = *p_line++; p_line++; \
340 *p_y++ = *p_line++; p_line++
341 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
342 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
343 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
344 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
346 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
348 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
353 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
355 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
356 *p_y++ = *p_line++; *p_v++ = *p_line++; \
357 *p_y++ = *p_line++; *p_u++ = *p_line++
358 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
359 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
360 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
361 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
363 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
365 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
368 p_line += i_source_margin;
369 p_y += i_dest_margin;
370 p_u += i_dest_margin_c;
371 p_v += i_dest_margin_c;