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 *****************************************************************************/
35 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
36 #define DEST_FOURCC "I420"
38 /*****************************************************************************
39 * Local and extern prototypes.
40 *****************************************************************************/
41 static int Activate ( vlc_object_t * );
43 static void YUY2_I420 ( vout_thread_t *, picture_t *, picture_t * );
44 static void YVYU_I420 ( vout_thread_t *, picture_t *, picture_t * );
45 static void UYVY_I420 ( vout_thread_t *, picture_t *, picture_t * );
46 static void cyuv_I420 ( vout_thread_t *, picture_t *, picture_t * );
48 /*****************************************************************************
50 *****************************************************************************/
52 set_description( _("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
53 set_capability( "chroma", 80 );
54 set_callbacks( Activate, NULL );
57 /*****************************************************************************
58 * Activate: allocate a chroma function
59 *****************************************************************************
60 * This function allocates and initializes a chroma function
61 *****************************************************************************/
62 static int Activate( vlc_object_t *p_this )
64 vout_thread_t *p_vout = (vout_thread_t *)p_this;
66 if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
71 switch( p_vout->output.i_chroma )
73 case VLC_FOURCC('I','4','2','0'):
74 switch( p_vout->render.i_chroma )
76 case VLC_FOURCC('Y','U','Y','2'):
77 case VLC_FOURCC('Y','U','N','V'):
78 p_vout->chroma.pf_convert = YUY2_I420;
81 case VLC_FOURCC('Y','V','Y','U'):
82 p_vout->chroma.pf_convert = YVYU_I420;
85 case VLC_FOURCC('U','Y','V','Y'):
86 case VLC_FOURCC('U','Y','N','V'):
87 case VLC_FOURCC('Y','4','2','2'):
88 p_vout->chroma.pf_convert = UYVY_I420;
91 case VLC_FOURCC('c','y','u','v'):
92 p_vout->chroma.pf_convert = cyuv_I420;
106 /* Following functions are local */
108 /*****************************************************************************
109 * YUY2_I420: packed YUY2 4:2:2 to planar YUV 4:2:0
110 *****************************************************************************/
111 static void YUY2_I420( vout_thread_t *p_vout, picture_t *p_source,
114 uint8_t *p_line = p_source->p->p_pixels;
116 uint8_t *p_y = p_dest->Y_PIXELS;
117 uint8_t *p_u = p_dest->U_PIXELS;
118 uint8_t *p_v = p_dest->V_PIXELS;
122 const int i_dest_margin = p_dest->p[0].i_pitch
123 - p_dest->p[0].i_visible_pitch;
124 const int i_dest_margin_c = p_dest->p[1].i_pitch
125 - p_dest->p[1].i_visible_pitch;
126 const int i_source_margin = p_source->p->i_pitch
127 - p_source->p->i_visible_pitch;
131 for( i_y = p_vout->output.i_height ; i_y-- ; )
135 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
137 #define C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v ) \
138 *p_y++ = *p_line++; p_line++; \
139 *p_y++ = *p_line++; p_line++
140 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
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 );
145 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
147 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
152 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
154 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
155 *p_y++ = *p_line++; *p_u++ = *p_line++; \
156 *p_y++ = *p_line++; *p_v++ = *p_line++
157 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
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 );
162 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
164 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
167 p_line += i_source_margin;
168 p_y += i_dest_margin;
169 p_u += i_dest_margin_c;
170 p_v += i_dest_margin_c;
176 /*****************************************************************************
177 * YVYU_I420: packed YVYU 4:2:2 to planar YUV 4:2:0
178 *****************************************************************************/
179 static void YVYU_I420( vout_thread_t *p_vout, picture_t *p_source,
182 uint8_t *p_line = p_source->p->p_pixels;
184 uint8_t *p_y = p_dest->Y_PIXELS;
185 uint8_t *p_u = p_dest->U_PIXELS;
186 uint8_t *p_v = p_dest->V_PIXELS;
190 const int i_dest_margin = p_dest->p[0].i_pitch
191 - p_dest->p[0].i_visible_pitch;
192 const int i_dest_margin_c = p_dest->p[1].i_pitch
193 - p_dest->p[1].i_visible_pitch;
194 const int i_source_margin = p_source->p->i_pitch
195 - p_source->p->i_visible_pitch;
199 for( i_y = p_vout->output.i_height ; i_y-- ; )
203 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
205 #define C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v ) \
206 *p_y++ = *p_line++; p_line++; \
207 *p_y++ = *p_line++; p_line++
208 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
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 );
213 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
215 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
220 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
222 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
223 *p_y++ = *p_line++; *p_v++ = *p_line++; \
224 *p_y++ = *p_line++; *p_u++ = *p_line++
225 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
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 );
230 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
232 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
235 p_line += i_source_margin;
236 p_y += i_dest_margin;
237 p_u += i_dest_margin_c;
238 p_v += i_dest_margin_c;
244 /*****************************************************************************
245 * UYVY_I420: packed UYVY 4:2:2 to planar YUV 4:2:0
246 *****************************************************************************/
247 static void UYVY_I420( vout_thread_t *p_vout, picture_t *p_source,
250 uint8_t *p_line = p_source->p->p_pixels;
252 uint8_t *p_y = p_dest->Y_PIXELS;
253 uint8_t *p_u = p_dest->U_PIXELS;
254 uint8_t *p_v = p_dest->V_PIXELS;
258 const int i_dest_margin = p_dest->p[0].i_pitch
259 - p_dest->p[0].i_visible_pitch;
260 const int i_dest_margin_c = p_dest->p[1].i_pitch
261 - p_dest->p[1].i_visible_pitch;
262 const int i_source_margin = p_source->p->i_pitch
263 - p_source->p->i_visible_pitch;
267 for( i_y = p_vout->output.i_height ; i_y-- ; )
271 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
273 #define C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v ) \
274 *p_u++ = *p_line++; p_line++; \
275 *p_v++ = *p_line++; p_line++
276 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
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 );
281 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
283 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
288 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
290 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
291 *p_u++ = *p_line++; *p_y++ = *p_line++; \
292 *p_v++ = *p_line++; *p_y++ = *p_line++
293 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
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 );
298 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
300 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
303 p_line += i_source_margin;
304 p_y += i_dest_margin;
305 p_u += i_dest_margin_c;
306 p_v += i_dest_margin_c;
312 /*****************************************************************************
313 * cyuv_I420: upside-down packed UYVY 4:2:2 to planar YUV 4:2:0
315 *****************************************************************************/
316 static void cyuv_I420( vout_thread_t *p_vout, picture_t *p_source,
319 uint8_t *p_line = p_source->p->p_pixels;
321 uint8_t *p_y = p_dest->Y_PIXELS;
322 uint8_t *p_u = p_dest->U_PIXELS;
323 uint8_t *p_v = p_dest->V_PIXELS;
327 const int i_dest_margin = p_dest->p[0].i_pitch
328 - p_dest->p[0].i_visible_pitch;
329 const int i_dest_margin_c = p_dest->p[1].i_pitch
330 - p_dest->p[1].i_visible_pitch;
331 const int i_source_margin = p_source->p->i_pitch
332 - p_source->p->i_visible_pitch;
336 for( i_y = p_vout->output.i_height ; i_y-- ; )
340 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
342 #define C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v ) \
343 *p_y++ = *p_line++; p_line++; \
344 *p_y++ = *p_line++; p_line++
345 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
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 );
350 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
352 C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v );
357 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
359 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
360 *p_y++ = *p_line++; *p_v++ = *p_line++; \
361 *p_y++ = *p_line++; *p_u++ = *p_line++
362 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
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 );
367 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
369 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
372 p_line += i_source_margin;
373 p_y += i_dest_margin;
374 p_u += i_dest_margin_c;
375 p_v += i_dest_margin_c;