qt: playlist: use item title if available
[vlc.git] / modules / video_chroma / yuy2_i420.c
blob2ed4d660611dc933149d8ce9c988b7a59dc848f3
1 /*****************************************************************************
2 * yuy2_i420.c : Packed YUV 4:2:2 to Planar YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 VLC authors and VideoLAN
6 * Authors: Antoine Cellerier <dionoea at videolan dot org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
24 * Preamble
25 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_filter.h>
34 #include <vlc_picture.h>
36 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422"
37 #define DEST_FOURCC "I420"
39 /*****************************************************************************
40 * Local and extern prototypes.
41 *****************************************************************************/
42 static int Activate ( filter_t * );
44 /*****************************************************************************
45 * Module descriptor
46 *****************************************************************************/
47 vlc_module_begin ()
48 set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
49 set_callback_video_converter( Activate, 80 )
50 vlc_module_end ()
52 VIDEO_FILTER_WRAPPER( YUY2_I420 )
53 VIDEO_FILTER_WRAPPER( YVYU_I420 )
54 VIDEO_FILTER_WRAPPER( UYVY_I420 )
56 /*****************************************************************************
57 * Activate: allocate a chroma function
58 *****************************************************************************
59 * This function allocates and initializes a chroma function
60 *****************************************************************************/
61 static int Activate( filter_t *p_filter )
63 if( p_filter->fmt_in.video.i_width & 1
64 || p_filter->fmt_in.video.i_height & 1 )
66 return -1;
69 if( p_filter->fmt_in.video.i_width != (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width)
70 || p_filter->fmt_in.video.i_height != (p_filter->fmt_out.video.i_y_offset + p_filter->fmt_out.video.i_visible_height)
71 || p_filter->fmt_in.video.orientation != p_filter->fmt_out.video.orientation)
72 return -1;
74 switch( p_filter->fmt_out.video.i_chroma )
76 case VLC_CODEC_I420:
77 switch( p_filter->fmt_in.video.i_chroma )
79 case VLC_CODEC_YUYV:
80 p_filter->ops = &YUY2_I420_ops;
81 break;
83 case VLC_CODEC_YVYU:
84 p_filter->ops = &YVYU_I420_ops;
85 break;
87 case VLC_CODEC_UYVY:
88 p_filter->ops = &UYVY_I420_ops;
89 break;
91 default:
92 return -1;
94 break;
96 default:
97 return -1;
99 return 0;
102 /* Following functions are local */
104 /*****************************************************************************
105 * YUY2_I420: packed YUY2 4:2:2 to planar YUV 4:2:0
106 *****************************************************************************/
107 static void YUY2_I420( filter_t *p_filter, picture_t *p_source,
108 picture_t *p_dest )
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;
116 int i_x, i_y;
118 const int i_dest_margin = p_dest->p[0].i_pitch
119 - p_dest->p[0].i_visible_pitch
120 - p_filter->fmt_out.video.i_x_offset;
121 const int i_dest_margin_c = p_dest->p[1].i_pitch
122 - p_dest->p[1].i_visible_pitch
123 - ( p_filter->fmt_out.video.i_x_offset / 2 );
124 const int i_source_margin = p_source->p->i_pitch
125 - p_source->p->i_visible_pitch
126 - ( p_filter->fmt_in.video.i_x_offset * 2 );
128 bool b_skip = false;
130 for( i_y = (p_filter->fmt_out.video.i_y_offset + p_filter->fmt_out.video.i_visible_height) ; i_y-- ; )
132 if( b_skip )
134 for( i_x = (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) / 8 ; i_x-- ; )
136 #define C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v ) \
137 *p_y++ = *p_line++; p_line++; \
138 *p_y++ = *p_line++; p_line++
139 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
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 );
144 for( i_x = ( (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) % 8 ) / 2; i_x-- ; )
146 C_YUYV_YUV422_skip( p_line, p_y, p_u, p_v );
149 else
151 for( i_x = (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) / 8 ; i_x-- ; )
153 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
154 *p_y++ = *p_line++; *p_u++ = *p_line++; \
155 *p_y++ = *p_line++; *p_v++ = *p_line++
156 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
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 );
161 for( i_x = ( (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) % 8 ) / 2; i_x-- ; )
163 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
165 p_u += i_dest_margin_c;
166 p_v += i_dest_margin_c;
168 p_line += i_source_margin;
169 p_y += i_dest_margin;
171 b_skip = !b_skip;
175 /*****************************************************************************
176 * YVYU_I420: packed YVYU 4:2:2 to planar YUV 4:2:0
177 *****************************************************************************/
178 static void YVYU_I420( filter_t *p_filter, picture_t *p_source,
179 picture_t *p_dest )
181 uint8_t *p_line = p_source->p->p_pixels;
183 uint8_t *p_y = p_dest->Y_PIXELS;
184 uint8_t *p_u = p_dest->U_PIXELS;
185 uint8_t *p_v = p_dest->V_PIXELS;
187 int i_x, i_y;
189 const int i_dest_margin = p_dest->p[0].i_pitch
190 - p_dest->p[0].i_visible_pitch
191 - p_filter->fmt_out.video.i_x_offset;
192 const int i_dest_margin_c = p_dest->p[1].i_pitch
193 - p_dest->p[1].i_visible_pitch
194 - ( p_filter->fmt_out.video.i_x_offset / 2 );
195 const int i_source_margin = p_source->p->i_pitch
196 - p_source->p->i_visible_pitch
197 - ( p_filter->fmt_in.video.i_x_offset * 2 );
199 bool b_skip = false;
201 for( i_y = (p_filter->fmt_out.video.i_y_offset + p_filter->fmt_out.video.i_visible_height) ; i_y-- ; )
203 if( b_skip )
205 for( i_x = (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) / 8 ; i_x-- ; )
207 #define C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v ) \
208 *p_y++ = *p_line++; p_line++; \
209 *p_y++ = *p_line++; p_line++
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 );
213 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
215 for( i_x = ( (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) % 8 ) / 2; i_x-- ; )
217 C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v );
220 else
222 for( i_x = (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) / 8 ; i_x-- ; )
224 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
225 *p_y++ = *p_line++; *p_v++ = *p_line++; \
226 *p_y++ = *p_line++; *p_u++ = *p_line++
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 );
230 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
232 for( i_x = ( (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) % 8 ) / 2; i_x-- ; )
234 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
236 p_u += i_dest_margin_c;
237 p_v += i_dest_margin_c;
239 p_line += i_source_margin;
240 p_y += i_dest_margin;
242 b_skip = !b_skip;
246 /*****************************************************************************
247 * UYVY_I420: packed UYVY 4:2:2 to planar YUV 4:2:0
248 *****************************************************************************/
249 static void UYVY_I420( filter_t *p_filter, picture_t *p_source,
250 picture_t *p_dest )
252 uint8_t *p_line = p_source->p->p_pixels;
254 uint8_t *p_y = p_dest->Y_PIXELS;
255 uint8_t *p_u = p_dest->U_PIXELS;
256 uint8_t *p_v = p_dest->V_PIXELS;
258 int i_x, i_y;
260 const int i_dest_margin = p_dest->p[0].i_pitch
261 - p_dest->p[0].i_visible_pitch
262 - p_filter->fmt_out.video.i_x_offset;
263 const int i_dest_margin_c = p_dest->p[1].i_pitch
264 - p_dest->p[1].i_visible_pitch
265 - ( p_filter->fmt_out.video.i_x_offset / 2 );
266 const int i_source_margin = p_source->p->i_pitch
267 - p_source->p->i_visible_pitch
268 - ( p_filter->fmt_in.video.i_x_offset * 2 );
270 bool b_skip = false;
272 for( i_y = (p_filter->fmt_out.video.i_y_offset + p_filter->fmt_out.video.i_visible_height) ; i_y-- ; )
274 if( b_skip )
276 for( i_x = (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) / 8 ; i_x-- ; )
278 #define C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v ) \
279 *p_u++ = *p_line++; p_line++; \
280 *p_v++ = *p_line++; p_line++
281 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
282 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
283 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
284 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
286 for( i_x = ( (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) % 8 ) / 2; i_x-- ; )
288 C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v );
291 else
293 for( i_x = (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) / 8 ; i_x-- ; )
295 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
296 *p_u++ = *p_line++; *p_y++ = *p_line++; \
297 *p_v++ = *p_line++; *p_y++ = *p_line++
298 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
299 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
300 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
301 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
303 for( i_x = ( (p_filter->fmt_out.video.i_x_offset + p_filter->fmt_out.video.i_visible_width) % 8 ) / 2; i_x-- ; )
305 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
307 p_y += i_dest_margin;
309 p_line += i_source_margin;
310 p_u += i_dest_margin_c;
311 p_v += i_dest_margin_c;
313 b_skip = !b_skip;