add_savefile: remove callback parameter
[vlc/asuraparaju-public.git] / modules / video_chroma / yuy2_i422.c
blobbcd6b1c89bdd61a312ec06817f3304fc8ac40214
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
5 * $Id$
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 /*****************************************************************************
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>
36 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
37 #define DEST_FOURCC "I422"
39 /*****************************************************************************
40 * Local and extern prototypes.
41 *****************************************************************************/
42 static int Activate ( vlc_object_t * );
44 static void YUY2_I422 ( filter_t *, picture_t *, picture_t * );
45 static void YVYU_I422 ( filter_t *, picture_t *, picture_t * );
46 static void UYVY_I422 ( filter_t *, picture_t *, picture_t * );
47 static void cyuv_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 * );
51 static picture_t *cyuv_I422_Filter ( filter_t *, picture_t * );
53 /*****************************************************************************
54 * Module descriptor
55 *****************************************************************************/
56 vlc_module_begin ()
57 set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) )
58 set_capability( "video filter2", 80 )
59 set_callbacks( Activate, NULL )
60 vlc_module_end ()
62 /*****************************************************************************
63 * Activate: allocate a chroma function
64 *****************************************************************************
65 * This function allocates and initializes a chroma function
66 *****************************************************************************/
67 static int Activate( vlc_object_t *p_this )
69 filter_t *p_filter = (filter_t *)p_this;
71 if( p_filter->fmt_in.video.i_width & 1
72 || p_filter->fmt_in.video.i_height & 1 )
74 return -1;
77 if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width
78 || p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height )
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 case VLC_CODEC_CYUV:
99 p_filter->pf_video_filter = cyuv_I422_Filter;
100 break;
102 default:
103 return -1;
105 break;
107 default:
108 return -1;
110 return 0;
113 /* Following functions are local */
115 VIDEO_FILTER_WRAPPER( YUY2_I422 )
116 VIDEO_FILTER_WRAPPER( YVYU_I422 )
117 VIDEO_FILTER_WRAPPER( UYVY_I422 )
118 VIDEO_FILTER_WRAPPER( cyuv_I422 )
120 /*****************************************************************************
121 * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
122 *****************************************************************************/
123 static void YUY2_I422( filter_t *p_filter, picture_t *p_source,
124 picture_t *p_dest )
126 uint8_t *p_line = p_source->p->p_pixels;
128 uint8_t *p_y = p_dest->Y_PIXELS;
129 uint8_t *p_u = p_dest->U_PIXELS;
130 uint8_t *p_v = p_dest->V_PIXELS;
132 int i_x, i_y;
134 const int i_dest_margin = p_dest->p[0].i_pitch
135 - p_dest->p[0].i_visible_pitch;
136 const int i_dest_margin_c = p_dest->p[1].i_pitch
137 - p_dest->p[1].i_visible_pitch;
138 const int i_source_margin = p_source->p->i_pitch
139 - p_source->p->i_visible_pitch;
141 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
143 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
145 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
146 *p_y++ = *p_line++; *p_u++ = *p_line++; \
147 *p_y++ = *p_line++; *p_v++ = *p_line++
148 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
149 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
150 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
151 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
153 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
155 C_YUYV_YUV422( p_line, p_y, p_u, p_v );
157 p_line += i_source_margin;
158 p_y += i_dest_margin;
159 p_u += i_dest_margin_c;
160 p_v += i_dest_margin_c;
164 /*****************************************************************************
165 * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
166 *****************************************************************************/
167 static void YVYU_I422( filter_t *p_filter, picture_t *p_source,
168 picture_t *p_dest )
170 uint8_t *p_line = p_source->p->p_pixels;
172 uint8_t *p_y = p_dest->Y_PIXELS;
173 uint8_t *p_u = p_dest->U_PIXELS;
174 uint8_t *p_v = p_dest->V_PIXELS;
176 int i_x, i_y;
178 const int i_dest_margin = p_dest->p[0].i_pitch
179 - p_dest->p[0].i_visible_pitch;
180 const int i_dest_margin_c = p_dest->p[1].i_pitch
181 - p_dest->p[1].i_visible_pitch;
182 const int i_source_margin = p_source->p->i_pitch
183 - p_source->p->i_visible_pitch;
185 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
187 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
189 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
190 *p_y++ = *p_line++; *p_v++ = *p_line++; \
191 *p_y++ = *p_line++; *p_u++ = *p_line++
192 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
193 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
194 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
195 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
197 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
199 C_YVYU_YUV422( p_line, p_y, p_u, p_v );
201 p_line += i_source_margin;
202 p_y += i_dest_margin;
203 p_u += i_dest_margin_c;
204 p_v += i_dest_margin_c;
208 /*****************************************************************************
209 * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
210 *****************************************************************************/
211 static void UYVY_I422( filter_t *p_filter, picture_t *p_source,
212 picture_t *p_dest )
214 uint8_t *p_line = p_source->p->p_pixels;
216 uint8_t *p_y = p_dest->Y_PIXELS;
217 uint8_t *p_u = p_dest->U_PIXELS;
218 uint8_t *p_v = p_dest->V_PIXELS;
220 int i_x, i_y;
222 const int i_dest_margin = p_dest->p[0].i_pitch
223 - p_dest->p[0].i_visible_pitch;
224 const int i_dest_margin_c = p_dest->p[1].i_pitch
225 - p_dest->p[1].i_visible_pitch;
226 const int i_source_margin = p_source->p->i_pitch
227 - p_source->p->i_visible_pitch;
229 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
231 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
233 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
234 *p_u++ = *p_line++; *p_y++ = *p_line++; \
235 *p_v++ = *p_line++; *p_y++ = *p_line++
236 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
237 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
238 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
239 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
241 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
243 C_UYVY_YUV422( p_line, p_y, p_u, p_v );
245 p_line += i_source_margin;
246 p_y += i_dest_margin;
247 p_u += i_dest_margin_c;
248 p_v += i_dest_margin_c;
252 /*****************************************************************************
253 * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
254 * FIXME
255 *****************************************************************************/
256 static void cyuv_I422( filter_t *p_filter, picture_t *p_source,
257 picture_t *p_dest )
259 uint8_t *p_line = p_source->p->p_pixels;
261 uint8_t *p_y = p_dest->Y_PIXELS;
262 uint8_t *p_u = p_dest->U_PIXELS;
263 uint8_t *p_v = p_dest->V_PIXELS;
265 int i_x, i_y;
267 const int i_dest_margin = p_dest->p[0].i_pitch
268 - p_dest->p[0].i_visible_pitch;
269 const int i_dest_margin_c = p_dest->p[1].i_pitch
270 - p_dest->p[1].i_visible_pitch;
271 const int i_source_margin = p_source->p->i_pitch
272 - p_source->p->i_visible_pitch;
274 for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
276 for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
278 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
279 *p_y++ = *p_line++; *p_v++ = *p_line++; \
280 *p_y++ = *p_line++; *p_u++ = *p_line++
281 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
282 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
283 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
284 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
286 for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
288 C_cyuv_YUV422( p_line, p_y, p_u, p_v );
290 p_line += i_source_margin;
291 p_y += i_dest_margin;
292 p_u += i_dest_margin_c;
293 p_v += i_dest_margin_c;