demux: mp4: avoid audio cuts on seek
[vlc.git] / modules / video_chroma / yuy2_i422.c
blob169e4316852ffb5c3c28c77130b1a2ed07552d48
1 /*****************************************************************************
2 * yuy2_i422.c : Packed YUV 4:2:2 to Planar YUV conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
35 #include <vlc_picture.h>
37 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422"
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 picture_t *YUY2_I422_Filter ( filter_t *, picture_t * );
49 static picture_t *YVYU_I422_Filter ( filter_t *, picture_t * );
50 static picture_t *UYVY_I422_Filter ( filter_t *, picture_t * );
52 /*****************************************************************************
53 * Module descriptor
54 *****************************************************************************/
55 vlc_module_begin ()
56 set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
57 set_capability( "video converter", 80 )
58 set_callbacks( Activate, NULL )
59 vlc_module_end ()
61 /*****************************************************************************
62 * Activate: allocate a chroma function
63 *****************************************************************************
64 * This function allocates and initializes a chroma function
65 *****************************************************************************/
66 static int Activate( vlc_object_t *p_this )
68 filter_t *p_filter = (filter_t *)p_this;
70 if( p_filter->fmt_in.video.i_width & 1
71 || p_filter->fmt_in.video.i_height & 1 )
73 return -1;
76 if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
77 || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height
78 || p_filter->fmt_in.video.orientation != p_filter->fmt_out.video.orientation)
79 return -1;
81 switch( p_filter->fmt_out.video.i_chroma )
83 case VLC_CODEC_I422:
84 switch( p_filter->fmt_in.video.i_chroma )
86 case VLC_CODEC_YUYV:
87 p_filter->pf_video_filter = YUY2_I422_Filter;
88 break;
90 case VLC_CODEC_YVYU:
91 p_filter->pf_video_filter = YVYU_I422_Filter;
92 break;
94 case VLC_CODEC_UYVY:
95 p_filter->pf_video_filter = UYVY_I422_Filter;
96 break;
98 default:
99 return -1;
101 break;
103 default:
104 return -1;
106 return 0;
109 /* Following functions are local */
111 VIDEO_FILTER_WRAPPER( YUY2_I422 )
112 VIDEO_FILTER_WRAPPER( YVYU_I422 )
113 VIDEO_FILTER_WRAPPER( UYVY_I422 )
115 /*****************************************************************************
116 * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
117 *****************************************************************************/
118 static void YUY2_I422( filter_t *p_filter, picture_t *p_source,
119 picture_t *p_dest )
121 uint8_t *p_line = p_source->p->p_pixels;
123 uint8_t *p_y = p_dest->Y_PIXELS;
124 uint8_t *p_u = p_dest->U_PIXELS;
125 uint8_t *p_v = p_dest->V_PIXELS;
127 int i_x, i_y;
129 const int i_dest_margin = p_dest->p[0].i_pitch
130 - p_dest->p[0].i_visible_pitch;
131 const int i_dest_margin_c = p_dest->p[1].i_pitch
132 - p_dest->p[1].i_visible_pitch;
133 const int i_source_margin = p_source->p->i_pitch
134 - p_source->p->i_visible_pitch;
136 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
138 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
140 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
141 *p_y++ = *p_line++; *p_u++ = *p_line++; \
142 *p_y++ = *p_line++; *p_v++ = *p_line++
143 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
144 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
145 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
146 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
148 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
150 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
152 p_line += i_source_margin;
153 p_y += i_dest_margin;
154 p_u += i_dest_margin_c;
155 p_v += i_dest_margin_c;
159 /*****************************************************************************
160 * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
161 *****************************************************************************/
162 static void YVYU_I422( filter_t *p_filter, picture_t *p_source,
163 picture_t *p_dest )
165 uint8_t *p_line = p_source->p->p_pixels;
167 uint8_t *p_y = p_dest->Y_PIXELS;
168 uint8_t *p_u = p_dest->U_PIXELS;
169 uint8_t *p_v = p_dest->V_PIXELS;
171 int i_x, i_y;
173 const int i_dest_margin = p_dest->p[0].i_pitch
174 - p_dest->p[0].i_visible_pitch;
175 const int i_dest_margin_c = p_dest->p[1].i_pitch
176 - p_dest->p[1].i_visible_pitch;
177 const int i_source_margin = p_source->p->i_pitch
178 - p_source->p->i_visible_pitch;
180 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
182 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
184 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
185 *p_y++ = *p_line++; *p_v++ = *p_line++; \
186 *p_y++ = *p_line++; *p_u++ = *p_line++
187 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
188 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
189 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
190 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
192 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
194 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
196 p_line += i_source_margin;
197 p_y += i_dest_margin;
198 p_u += i_dest_margin_c;
199 p_v += i_dest_margin_c;
203 /*****************************************************************************
204 * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
205 *****************************************************************************/
206 static void UYVY_I422( filter_t *p_filter, picture_t *p_source,
207 picture_t *p_dest )
209 uint8_t *p_line = p_source->p->p_pixels;
211 uint8_t *p_y = p_dest->Y_PIXELS;
212 uint8_t *p_u = p_dest->U_PIXELS;
213 uint8_t *p_v = p_dest->V_PIXELS;
215 int i_x, i_y;
217 const int i_dest_margin = p_dest->p[0].i_pitch
218 - p_dest->p[0].i_visible_pitch;
219 const int i_dest_margin_c = p_dest->p[1].i_pitch
220 - p_dest->p[1].i_visible_pitch;
221 const int i_source_margin = p_source->p->i_pitch
222 - p_source->p->i_visible_pitch;
224 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
226 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
228 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
229 *p_u++ = *p_line++; *p_y++ = *p_line++; \
230 *p_v++ = *p_line++; *p_y++ = *p_line++
231 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
232 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
233 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
234 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
236 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
238 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
240 p_line += i_source_margin;
241 p_y += i_dest_margin;
242 p_u += i_dest_margin_c;
243 p_v += i_dest_margin_c;