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 *****************************************************************************/
33 #include <vlc_plugin.h>
36 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
37 #define DEST_FOURCC "I420"
39 /*****************************************************************************
40 * Local and extern prototypes.
41 *****************************************************************************/
42 static int Activate ( vlc_object_t * );
44 static void YUY2_I420 ( vout_thread_t *, picture_t *, picture_t * );
45 static void YVYU_I420 ( vout_thread_t *, picture_t *, picture_t * );
46 static void UYVY_I420 ( vout_thread_t *, picture_t *, picture_t * );
47 static void cyuv_I420 ( vout_thread_t *, picture_t *, picture_t * );
49 /*****************************************************************************
51 *****************************************************************************/
53 set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
54 set_capability( "chroma", 80 );
55 set_callbacks( Activate, NULL );
58 /*****************************************************************************
59 * Activate: allocate a chroma function
60 *****************************************************************************
61 * This function allocates and initializes a chroma function
62 *****************************************************************************/
63 static int Activate( vlc_object_t *p_this )
65 vout_thread_t *p_vout = (vout_thread_t *)p_this;
67 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
72 switch( p_vout->output.i_chroma )
74 case VLC_FOURCC('I','4','2','0'):
75 switch( p_vout->render.i_chroma )
77 case VLC_FOURCC('Y','U','Y','2'):
78 case VLC_FOURCC('Y','U','N','V'):
79 p_vout->chroma.pf_convert = YUY2_I420;
82 case VLC_FOURCC('Y','V','Y','U'):
83 p_vout->chroma.pf_convert = YVYU_I420;
86 case VLC_FOURCC('U','Y','V','Y'):
87 case VLC_FOURCC('U','Y','N','V'):
88 case VLC_FOURCC('Y','4','2','2'):
89 p_vout->chroma.pf_convert = UYVY_I420;
92 case VLC_FOURCC('c','y','u','v'):
93 p_vout->chroma.pf_convert = cyuv_I420;
107 /* Following functions are local */
109 /*****************************************************************************
110 * YUY2_I420: packed YUY2 4:2:2 to planar YUV 4:2:0
111 *****************************************************************************/
112 static void YUY2_I420( vout_thread_t *p_vout, picture_t *p_source,
115 uint8_t *p_line = p_source->p->p_pixels;
117 uint8_t *p_y = p_dest->Y_PIXELS;
118 uint8_t *p_u = p_dest->U_PIXELS;
119 uint8_t *p_v = p_dest->V_PIXELS;
123 const int i_dest_margin = p_dest->p[0].i_pitch
124 - p_dest->p[0].i_visible_pitch;
125 const int i_dest_margin_c = p_dest->p[1].i_pitch
126 - p_dest->p[1].i_visible_pitch;
127 const int i_source_margin = p_source->p->i_pitch
128 - p_source->p->i_visible_pitch;
132 for( i_y = p_vout->output.i_height ; i_y-- ; )
136 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
138 #define C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v ) \
139 *p_y++ = *p_line++; p_line++; \
140 *p_y++ = *p_line++; p_line++
141 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
142 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
143 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
144 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
146 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
148 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
153 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
155 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
156 *p_y++ = *p_line++; *p_u++ = *p_line++; \
157 *p_y++ = *p_line++; *p_v++ = *p_line++
158 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
159 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
160 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
161 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
163 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
165 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
168 p_line += i_source_margin;
169 p_y += i_dest_margin;
170 p_u += i_dest_margin_c;
171 p_v += i_dest_margin_c;
177 /*****************************************************************************
178 * YVYU_I420: packed YVYU 4:2:2 to planar YUV 4:2:0
179 *****************************************************************************/
180 static void YVYU_I420( vout_thread_t *p_vout, picture_t *p_source,
183 uint8_t *p_line = p_source->p->p_pixels;
185 uint8_t *p_y = p_dest->Y_PIXELS;
186 uint8_t *p_u = p_dest->U_PIXELS;
187 uint8_t *p_v = p_dest->V_PIXELS;
191 const int i_dest_margin = p_dest->p[0].i_pitch
192 - p_dest->p[0].i_visible_pitch;
193 const int i_dest_margin_c = p_dest->p[1].i_pitch
194 - p_dest->p[1].i_visible_pitch;
195 const int i_source_margin = p_source->p->i_pitch
196 - p_source->p->i_visible_pitch;
200 for( i_y = p_vout->output.i_height ; i_y-- ; )
204 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
206 #define C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v ) \
207 *p_y++ = *p_line++; p_line++; \
208 *p_y++ = *p_line++; p_line++
209 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
210 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
211 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
212 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
214 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
216 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
221 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
223 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
224 *p_y++ = *p_line++; *p_v++ = *p_line++; \
225 *p_y++ = *p_line++; *p_u++ = *p_line++
226 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
227 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
228 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
229 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
231 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
233 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
236 p_line += i_source_margin;
237 p_y += i_dest_margin;
238 p_u += i_dest_margin_c;
239 p_v += i_dest_margin_c;
245 /*****************************************************************************
246 * UYVY_I420: packed UYVY 4:2:2 to planar YUV 4:2:0
247 *****************************************************************************/
248 static void UYVY_I420( vout_thread_t *p_vout, picture_t *p_source,
251 uint8_t *p_line = p_source->p->p_pixels;
253 uint8_t *p_y = p_dest->Y_PIXELS;
254 uint8_t *p_u = p_dest->U_PIXELS;
255 uint8_t *p_v = p_dest->V_PIXELS;
259 const int i_dest_margin = p_dest->p[0].i_pitch
260 - p_dest->p[0].i_visible_pitch;
261 const int i_dest_margin_c = p_dest->p[1].i_pitch
262 - p_dest->p[1].i_visible_pitch;
263 const int i_source_margin = p_source->p->i_pitch
264 - p_source->p->i_visible_pitch;
268 for( i_y = p_vout->output.i_height ; i_y-- ; )
272 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
274 #define C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v ) \
275 *p_u++ = *p_line++; p_line++; \
276 *p_v++ = *p_line++; p_line++
277 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
278 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
279 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
280 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
282 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
284 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
289 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
291 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
292 *p_u++ = *p_line++; *p_y++ = *p_line++; \
293 *p_v++ = *p_line++; *p_y++ = *p_line++
294 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
295 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
296 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
297 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
299 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
301 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
304 p_line += i_source_margin;
305 p_y += i_dest_margin;
306 p_u += i_dest_margin_c;
307 p_v += i_dest_margin_c;
313 /*****************************************************************************
314 * cyuv_I420: upside-down packed UYVY 4:2:2 to planar YUV 4:2:0
316 *****************************************************************************/
317 static void cyuv_I420( vout_thread_t *p_vout, picture_t *p_source,
320 uint8_t *p_line = p_source->p->p_pixels;
322 uint8_t *p_y = p_dest->Y_PIXELS;
323 uint8_t *p_u = p_dest->U_PIXELS;
324 uint8_t *p_v = p_dest->V_PIXELS;
328 const int i_dest_margin = p_dest->p[0].i_pitch
329 - p_dest->p[0].i_visible_pitch;
330 const int i_dest_margin_c = p_dest->p[1].i_pitch
331 - p_dest->p[1].i_visible_pitch;
332 const int i_source_margin = p_source->p->i_pitch
333 - p_source->p->i_visible_pitch;
337 for( i_y = p_vout->output.i_height ; i_y-- ; )
341 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
343 #define C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v ) \
344 *p_y++ = *p_line++; p_line++; \
345 *p_y++ = *p_line++; p_line++
346 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
347 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
348 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
349 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
351 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
353 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
358 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
360 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
361 *p_y++ = *p_line++; *p_v++ = *p_line++; \
362 *p_y++ = *p_line++; *p_u++ = *p_line++
363 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
364 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
365 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
366 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
368 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
370 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
373 p_line += i_source_margin;
374 p_y += i_dest_margin;
375 p_u += i_dest_margin_c;
376 p_v += i_dest_margin_c;