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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
37 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
38 #define DEST_FOURCC "I422"
40 /*****************************************************************************
41 * Local and extern prototypes.
42 *****************************************************************************/
43 static int Activate ( vlc_object_t * );
45 static void YUY2_I422 ( filter_t *, picture_t *, picture_t * );
46 static void YVYU_I422 ( filter_t *, picture_t *, picture_t * );
47 static void UYVY_I422 ( filter_t *, picture_t *, picture_t * );
48 static void cyuv_I422 ( filter_t *, picture_t *, picture_t * );
50 /*****************************************************************************
52 *****************************************************************************/
54 set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
55 set_capability( "chroma", 80 );
56 set_callbacks( Activate, NULL );
59 /*****************************************************************************
60 * Activate: allocate a chroma function
61 *****************************************************************************
62 * This function allocates and initializes a chroma function
63 *****************************************************************************/
64 static int Activate( vlc_object_t *p_this )
66 filter_t *p_filter = (filter_t *)p_this;
68 if( p_filter->fmt_in.video.i_width & 1
69 || p_filter->fmt_in.video.i_height & 1 )
74 switch( p_filter->fmt_out.video.i_chroma )
76 case VLC_FOURCC('I','4','2','2'):
77 switch( p_filter->fmt_in.video.i_chroma )
79 case VLC_FOURCC('Y','U','Y','2'):
80 case VLC_FOURCC('Y','U','N','V'):
81 p_filter->pf_video_filter_io = YUY2_I422;
84 case VLC_FOURCC('Y','V','Y','U'):
85 p_filter->pf_video_filter_io = YVYU_I422;
88 case VLC_FOURCC('U','Y','V','Y'):
89 case VLC_FOURCC('U','Y','N','V'):
90 case VLC_FOURCC('Y','4','2','2'):
91 p_filter->pf_video_filter_io = UYVY_I422;
94 case VLC_FOURCC('c','y','u','v'):
95 p_filter->pf_video_filter_io = cyuv_I422;
109 /* Following functions are local */
111 /*****************************************************************************
112 * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
113 *****************************************************************************/
114 static void YUY2_I422( filter_t *p_filter, picture_t *p_source,
117 uint8_t *p_line = p_source->p->p_pixels;
119 uint8_t *p_y = p_dest->Y_PIXELS;
120 uint8_t *p_u = p_dest->U_PIXELS;
121 uint8_t *p_v = p_dest->V_PIXELS;
125 const int i_dest_margin = p_dest->p[0].i_pitch
126 - p_dest->p[0].i_visible_pitch;
127 const int i_dest_margin_c = p_dest->p[1].i_pitch
128 - p_dest->p[1].i_visible_pitch;
129 const int i_source_margin = p_source->p->i_pitch
130 - p_source->p->i_visible_pitch;
132 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
134 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
136 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
137 *p_y++ = *p_line++; *p_u++ = *p_line++; \
138 *p_y++ = *p_line++; *p_v++ = *p_line++
139 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
140 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
141 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
142 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
144 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
146 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
148 p_line += i_source_margin;
149 p_y += i_dest_margin;
150 p_u += i_dest_margin_c;
151 p_v += i_dest_margin_c;
155 /*****************************************************************************
156 * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
157 *****************************************************************************/
158 static void YVYU_I422( filter_t *p_filter, picture_t *p_source,
161 uint8_t *p_line = p_source->p->p_pixels;
163 uint8_t *p_y = p_dest->Y_PIXELS;
164 uint8_t *p_u = p_dest->U_PIXELS;
165 uint8_t *p_v = p_dest->V_PIXELS;
169 const int i_dest_margin = p_dest->p[0].i_pitch
170 - p_dest->p[0].i_visible_pitch;
171 const int i_dest_margin_c = p_dest->p[1].i_pitch
172 - p_dest->p[1].i_visible_pitch;
173 const int i_source_margin = p_source->p->i_pitch
174 - p_source->p->i_visible_pitch;
176 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
178 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
180 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
181 *p_y++ = *p_line++; *p_v++ = *p_line++; \
182 *p_y++ = *p_line++; *p_u++ = *p_line++
183 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
184 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
185 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
186 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
188 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
190 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
192 p_line += i_source_margin;
193 p_y += i_dest_margin;
194 p_u += i_dest_margin_c;
195 p_v += i_dest_margin_c;
199 /*****************************************************************************
200 * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
201 *****************************************************************************/
202 static void UYVY_I422( filter_t *p_filter, picture_t *p_source,
205 uint8_t *p_line = p_source->p->p_pixels;
207 uint8_t *p_y = p_dest->Y_PIXELS;
208 uint8_t *p_u = p_dest->U_PIXELS;
209 uint8_t *p_v = p_dest->V_PIXELS;
213 const int i_dest_margin = p_dest->p[0].i_pitch
214 - p_dest->p[0].i_visible_pitch;
215 const int i_dest_margin_c = p_dest->p[1].i_pitch
216 - p_dest->p[1].i_visible_pitch;
217 const int i_source_margin = p_source->p->i_pitch
218 - p_source->p->i_visible_pitch;
220 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
222 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
224 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
225 *p_u++ = *p_line++; *p_y++ = *p_line++; \
226 *p_v++ = *p_line++; *p_y++ = *p_line++
227 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
228 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
229 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
230 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
232 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
234 C_UYVY_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;
243 /*****************************************************************************
244 * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
246 *****************************************************************************/
247 static void cyuv_I422( filter_t *p_filter, 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;
265 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
267 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
269 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
270 *p_y++ = *p_line++; *p_v++ = *p_line++; \
271 *p_y++ = *p_line++; *p_u++ = *p_line++
272 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
273 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
274 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
275 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
277 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
279 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
281 p_line += i_source_margin;
282 p_y += i_dest_margin;
283 p_u += i_dest_margin_c;
284 p_v += i_dest_margin_c;