1 /*****************************************************************************
2 * yuy2_i422.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 "I422"
34 /*****************************************************************************
35 * Local and extern prototypes.
36 *****************************************************************************/
37 static int Activate ( vlc_object_t * );
39 static void YUY2_I422 ( vout_thread_t *, picture_t *, picture_t * );
40 static void YVYU_I422 ( vout_thread_t *, picture_t *, picture_t * );
41 static void UYVY_I422 ( vout_thread_t *, picture_t *, picture_t * );
42 static void cyuv_I422 ( 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','2'):
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_I422;
77 case VLC_FOURCC('Y','V','Y','U'):
78 p_vout->chroma.pf_convert = YVYU_I422;
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_I422;
87 case VLC_FOURCC('c','y','u','v'):
88 p_vout->chroma.pf_convert = cyuv_I422;
102 /* Following functions are local */
104 /*****************************************************************************
105 * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
106 *****************************************************************************/
107 static void YUY2_I422( 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 for( i_y = p_vout->output.i_height ; i_y-- ; )
127 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
129 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
130 *p_y++ = *p_line++; *p_u++ = *p_line++; \
131 *p_y++ = *p_line++; *p_v++ = *p_line++
132 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
133 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
134 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
135 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
137 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
139 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
141 p_line += i_source_margin;
142 p_y += i_dest_margin;
143 p_u += i_dest_margin_c;
144 p_v += i_dest_margin_c;
148 /*****************************************************************************
149 * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
150 *****************************************************************************/
151 static void YVYU_I422( vout_thread_t *p_vout, picture_t *p_source,
154 uint8_t *p_line = p_source->p->p_pixels;
156 uint8_t *p_y = p_dest->Y_PIXELS;
157 uint8_t *p_u = p_dest->U_PIXELS;
158 uint8_t *p_v = p_dest->V_PIXELS;
162 const int i_dest_margin = p_dest->p[0].i_pitch
163 - p_dest->p[0].i_visible_pitch;
164 const int i_dest_margin_c = p_dest->p[1].i_pitch
165 - p_dest->p[1].i_visible_pitch;
166 const int i_source_margin = p_source->p->i_pitch
167 - p_source->p->i_visible_pitch;
169 for( i_y = p_vout->output.i_height ; i_y-- ; )
171 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
173 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
174 *p_y++ = *p_line++; *p_v++ = *p_line++; \
175 *p_y++ = *p_line++; *p_u++ = *p_line++
176 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
177 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
178 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
179 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
181 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
183 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
185 p_line += i_source_margin;
186 p_y += i_dest_margin;
187 p_u += i_dest_margin_c;
188 p_v += i_dest_margin_c;
192 /*****************************************************************************
193 * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
194 *****************************************************************************/
195 static void UYVY_I422( vout_thread_t *p_vout, picture_t *p_source,
198 uint8_t *p_line = p_source->p->p_pixels;
200 uint8_t *p_y = p_dest->Y_PIXELS;
201 uint8_t *p_u = p_dest->U_PIXELS;
202 uint8_t *p_v = p_dest->V_PIXELS;
206 const int i_dest_margin = p_dest->p[0].i_pitch
207 - p_dest->p[0].i_visible_pitch;
208 const int i_dest_margin_c = p_dest->p[1].i_pitch
209 - p_dest->p[1].i_visible_pitch;
210 const int i_source_margin = p_source->p->i_pitch
211 - p_source->p->i_visible_pitch;
213 for( i_y = p_vout->output.i_height ; i_y-- ; )
215 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
217 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
218 *p_u++ = *p_line++; *p_y++ = *p_line++; \
219 *p_v++ = *p_line++; *p_y++ = *p_line++
220 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
221 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
222 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
223 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
225 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
227 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
229 p_line += i_source_margin;
230 p_y += i_dest_margin;
231 p_u += i_dest_margin_c;
232 p_v += i_dest_margin_c;
236 /*****************************************************************************
237 * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
239 *****************************************************************************/
240 static void cyuv_I422( vout_thread_t *p_vout, picture_t *p_source,
243 uint8_t *p_line = p_source->p->p_pixels;
245 uint8_t *p_y = p_dest->Y_PIXELS;
246 uint8_t *p_u = p_dest->U_PIXELS;
247 uint8_t *p_v = p_dest->V_PIXELS;
251 const int i_dest_margin = p_dest->p[0].i_pitch
252 - p_dest->p[0].i_visible_pitch;
253 const int i_dest_margin_c = p_dest->p[1].i_pitch
254 - p_dest->p[1].i_visible_pitch;
255 const int i_source_margin = p_source->p->i_pitch
256 - p_source->p->i_visible_pitch;
258 for( i_y = p_vout->output.i_height ; i_y-- ; )
260 for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
262 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
263 *p_y++ = *p_line++; *p_v++ = *p_line++; \
264 *p_y++ = *p_line++; *p_u++ = *p_line++
265 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
266 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
267 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
268 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
270 for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
272 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
274 p_line += i_source_margin;
275 p_y += i_dest_margin;
276 p_u += i_dest_margin_c;
277 p_v += i_dest_margin_c;