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 * );
49 static picture_t *YUY2_I422_Filter ( filter_t *, picture_t * );
50 static picture_t *YVYU_I422_Filter ( filter_t *, picture_t * );
51 static picture_t *UYVY_I422_Filter ( filter_t *, picture_t * );
52 static picture_t *cyuv_I422_Filter ( filter_t *, picture_t * );
54 /*****************************************************************************
56 *****************************************************************************/
58 set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
59 set_capability( "video filter2", 80 );
60 set_callbacks( Activate, NULL );
63 /*****************************************************************************
64 * Activate: allocate a chroma function
65 *****************************************************************************
66 * This function allocates and initializes a chroma function
67 *****************************************************************************/
68 static int Activate( vlc_object_t *p_this )
70 filter_t *p_filter = (filter_t *)p_this;
72 if( p_filter->fmt_in.video.i_width & 1
73 || p_filter->fmt_in.video.i_height & 1 )
78 if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
79 || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
82 switch( p_filter->fmt_out.video.i_chroma )
84 case VLC_FOURCC('I','4','2','2'):
85 switch( p_filter->fmt_in.video.i_chroma )
87 case VLC_FOURCC('Y','U','Y','2'):
88 case VLC_FOURCC('Y','U','N','V'):
89 p_filter->pf_video_filter = YUY2_I422_Filter;
92 case VLC_FOURCC('Y','V','Y','U'):
93 p_filter->pf_video_filter = YVYU_I422_Filter;
96 case VLC_FOURCC('U','Y','V','Y'):
97 case VLC_FOURCC('U','Y','N','V'):
98 case VLC_FOURCC('Y','4','2','2'):
99 p_filter->pf_video_filter = UYVY_I422_Filter;
102 case VLC_FOURCC('c','y','u','v'):
103 p_filter->pf_video_filter = cyuv_I422_Filter;
117 /* Following functions are local */
119 VIDEO_FILTER_WRAPPER( YUY2_I422 )
120 VIDEO_FILTER_WRAPPER( YVYU_I422 )
121 VIDEO_FILTER_WRAPPER( UYVY_I422 )
122 VIDEO_FILTER_WRAPPER( cyuv_I422 )
124 /*****************************************************************************
125 * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
126 *****************************************************************************/
127 static void YUY2_I422( filter_t *p_filter, picture_t *p_source,
130 uint8_t *p_line = p_source->p->p_pixels;
132 uint8_t *p_y = p_dest->Y_PIXELS;
133 uint8_t *p_u = p_dest->U_PIXELS;
134 uint8_t *p_v = p_dest->V_PIXELS;
138 const int i_dest_margin = p_dest->p[0].i_pitch
139 - p_dest->p[0].i_visible_pitch;
140 const int i_dest_margin_c = p_dest->p[1].i_pitch
141 - p_dest->p[1].i_visible_pitch;
142 const int i_source_margin = p_source->p->i_pitch
143 - p_source->p->i_visible_pitch;
145 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
147 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
149 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
150 *p_y++ = *p_line++; *p_u++ = *p_line++; \
151 *p_y++ = *p_line++; *p_v++ = *p_line++
152 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
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 );
157 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
159 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
161 p_line += i_source_margin;
162 p_y += i_dest_margin;
163 p_u += i_dest_margin_c;
164 p_v += i_dest_margin_c;
168 /*****************************************************************************
169 * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
170 *****************************************************************************/
171 static void YVYU_I422( filter_t *p_filter, picture_t *p_source,
174 uint8_t *p_line = p_source->p->p_pixels;
176 uint8_t *p_y = p_dest->Y_PIXELS;
177 uint8_t *p_u = p_dest->U_PIXELS;
178 uint8_t *p_v = p_dest->V_PIXELS;
182 const int i_dest_margin = p_dest->p[0].i_pitch
183 - p_dest->p[0].i_visible_pitch;
184 const int i_dest_margin_c = p_dest->p[1].i_pitch
185 - p_dest->p[1].i_visible_pitch;
186 const int i_source_margin = p_source->p->i_pitch
187 - p_source->p->i_visible_pitch;
189 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
191 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
193 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
194 *p_y++ = *p_line++; *p_v++ = *p_line++; \
195 *p_y++ = *p_line++; *p_u++ = *p_line++
196 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
197 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
198 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
199 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
201 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
203 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
205 p_line += i_source_margin;
206 p_y += i_dest_margin;
207 p_u += i_dest_margin_c;
208 p_v += i_dest_margin_c;
212 /*****************************************************************************
213 * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
214 *****************************************************************************/
215 static void UYVY_I422( filter_t *p_filter, picture_t *p_source,
218 uint8_t *p_line = p_source->p->p_pixels;
220 uint8_t *p_y = p_dest->Y_PIXELS;
221 uint8_t *p_u = p_dest->U_PIXELS;
222 uint8_t *p_v = p_dest->V_PIXELS;
226 const int i_dest_margin = p_dest->p[0].i_pitch
227 - p_dest->p[0].i_visible_pitch;
228 const int i_dest_margin_c = p_dest->p[1].i_pitch
229 - p_dest->p[1].i_visible_pitch;
230 const int i_source_margin = p_source->p->i_pitch
231 - p_source->p->i_visible_pitch;
233 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
235 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
237 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
238 *p_u++ = *p_line++; *p_y++ = *p_line++; \
239 *p_v++ = *p_line++; *p_y++ = *p_line++
240 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
241 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
242 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
243 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
245 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
247 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
249 p_line += i_source_margin;
250 p_y += i_dest_margin;
251 p_u += i_dest_margin_c;
252 p_v += i_dest_margin_c;
256 /*****************************************************************************
257 * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
259 *****************************************************************************/
260 static void cyuv_I422( filter_t *p_filter, picture_t *p_source,
263 uint8_t *p_line = p_source->p->p_pixels;
265 uint8_t *p_y = p_dest->Y_PIXELS;
266 uint8_t *p_u = p_dest->U_PIXELS;
267 uint8_t *p_v = p_dest->V_PIXELS;
271 const int i_dest_margin = p_dest->p[0].i_pitch
272 - p_dest->p[0].i_visible_pitch;
273 const int i_dest_margin_c = p_dest->p[1].i_pitch
274 - p_dest->p[1].i_visible_pitch;
275 const int i_source_margin = p_source->p->i_pitch
276 - p_source->p->i_visible_pitch;
278 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
280 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
282 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
283 *p_y++ = *p_line++; *p_v++ = *p_line++; \
284 *p_y++ = *p_line++; *p_u++ = *p_line++
285 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
286 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
287 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
288 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
290 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
292 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
294 p_line += i_source_margin;
295 p_y += i_dest_margin;
296 p_u += i_dest_margin_c;
297 p_v += i_dest_margin_c;