1 /*****************************************************************************
2 * yuy2_i420.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>
36 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
37 #define DEST_FOURCC "I420"
39 /*****************************************************************************
40 * Local and extern prototypes.
41 *****************************************************************************/
42 static int Activate ( vlc_object_t
* );
44 static void YUY2_I420 ( filter_t
*, picture_t
*, picture_t
* );
45 static void YVYU_I420 ( filter_t
*, picture_t
*, picture_t
* );
46 static void UYVY_I420 ( filter_t
*, picture_t
*, picture_t
* );
47 static void cyuv_I420 ( filter_t
*, picture_t
*, picture_t
* );
49 static picture_t
*YUY2_I420_Filter ( filter_t
*, picture_t
* );
50 static picture_t
*YVYU_I420_Filter ( filter_t
*, picture_t
* );
51 static picture_t
*UYVY_I420_Filter ( filter_t
*, picture_t
* );
52 static picture_t
*cyuv_I420_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
)
85 switch( p_filter
->fmt_in
.video
.i_chroma
)
88 p_filter
->pf_video_filter
= YUY2_I420_Filter
;
92 p_filter
->pf_video_filter
= YVYU_I420_Filter
;
96 p_filter
->pf_video_filter
= UYVY_I420_Filter
;
100 p_filter
->pf_video_filter
= cyuv_I420_Filter
;
114 /* Following functions are local */
115 VIDEO_FILTER_WRAPPER( YUY2_I420
)
116 VIDEO_FILTER_WRAPPER( YVYU_I420
)
117 VIDEO_FILTER_WRAPPER( UYVY_I420
)
118 VIDEO_FILTER_WRAPPER( cyuv_I420
)
120 /*****************************************************************************
121 * YUY2_I420: packed YUY2 4:2:2 to planar YUV 4:2:0
122 *****************************************************************************/
123 static void YUY2_I420( filter_t
*p_filter
, picture_t
*p_source
,
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
;
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
;
143 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_skip( p_line, p_y, p_u, p_v ) \
150 *p_y++ = *p_line++; p_line++; \
151 *p_y++ = *p_line++; p_line++
152 C_YUYV_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
153 C_YUYV_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
154 C_YUYV_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
155 C_YUYV_YUV422_skip( 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_skip( p_line
, p_y
, p_u
, p_v
);
164 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
166 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v ) \
167 *p_y++ = *p_line++; *p_u++ = *p_line++; \
168 *p_y++ = *p_line++; *p_v++ = *p_line++
169 C_YUYV_YUV422( p_line
, p_y
, p_u
, p_v
);
170 C_YUYV_YUV422( p_line
, p_y
, p_u
, p_v
);
171 C_YUYV_YUV422( p_line
, p_y
, p_u
, p_v
);
172 C_YUYV_YUV422( p_line
, p_y
, p_u
, p_v
);
174 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
176 C_YUYV_YUV422( p_line
, p_y
, p_u
, p_v
);
179 p_line
+= i_source_margin
;
180 p_y
+= i_dest_margin
;
181 p_u
+= i_dest_margin_c
;
182 p_v
+= i_dest_margin_c
;
188 /*****************************************************************************
189 * YVYU_I420: packed YVYU 4:2:2 to planar YUV 4:2:0
190 *****************************************************************************/
191 static void YVYU_I420( filter_t
*p_filter
, picture_t
*p_source
,
194 uint8_t *p_line
= p_source
->p
->p_pixels
;
196 uint8_t *p_y
= p_dest
->Y_PIXELS
;
197 uint8_t *p_u
= p_dest
->U_PIXELS
;
198 uint8_t *p_v
= p_dest
->V_PIXELS
;
202 const int i_dest_margin
= p_dest
->p
[0].i_pitch
203 - p_dest
->p
[0].i_visible_pitch
;
204 const int i_dest_margin_c
= p_dest
->p
[1].i_pitch
205 - p_dest
->p
[1].i_visible_pitch
;
206 const int i_source_margin
= p_source
->p
->i_pitch
207 - p_source
->p
->i_visible_pitch
;
211 for( i_y
= p_filter
->fmt_out
.video
.i_height
; i_y
-- ; )
215 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
217 #define C_YVYU_YUV422_skip( p_line, p_y, p_u, p_v ) \
218 *p_y++ = *p_line++; p_line++; \
219 *p_y++ = *p_line++; p_line++
220 C_YVYU_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
221 C_YVYU_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
222 C_YVYU_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
223 C_YVYU_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
225 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
227 C_YVYU_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
232 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
234 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v ) \
235 *p_y++ = *p_line++; *p_v++ = *p_line++; \
236 *p_y++ = *p_line++; *p_u++ = *p_line++
237 C_YVYU_YUV422( p_line
, p_y
, p_u
, p_v
);
238 C_YVYU_YUV422( p_line
, p_y
, p_u
, p_v
);
239 C_YVYU_YUV422( p_line
, p_y
, p_u
, p_v
);
240 C_YVYU_YUV422( p_line
, p_y
, p_u
, p_v
);
242 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
244 C_YVYU_YUV422( p_line
, p_y
, p_u
, p_v
);
247 p_line
+= i_source_margin
;
248 p_y
+= i_dest_margin
;
249 p_u
+= i_dest_margin_c
;
250 p_v
+= i_dest_margin_c
;
256 /*****************************************************************************
257 * UYVY_I420: packed UYVY 4:2:2 to planar YUV 4:2:0
258 *****************************************************************************/
259 static void UYVY_I420( filter_t
*p_filter
, picture_t
*p_source
,
262 uint8_t *p_line
= p_source
->p
->p_pixels
;
264 uint8_t *p_y
= p_dest
->Y_PIXELS
;
265 uint8_t *p_u
= p_dest
->U_PIXELS
;
266 uint8_t *p_v
= p_dest
->V_PIXELS
;
270 const int i_dest_margin
= p_dest
->p
[0].i_pitch
271 - p_dest
->p
[0].i_visible_pitch
;
272 const int i_dest_margin_c
= p_dest
->p
[1].i_pitch
273 - p_dest
->p
[1].i_visible_pitch
;
274 const int i_source_margin
= p_source
->p
->i_pitch
275 - p_source
->p
->i_visible_pitch
;
279 for( i_y
= p_filter
->fmt_out
.video
.i_height
; i_y
-- ; )
283 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
285 #define C_UYVY_YUV422_skip( p_line, p_y, p_u, p_v ) \
286 *p_u++ = *p_line++; p_line++; \
287 *p_v++ = *p_line++; p_line++
288 C_UYVY_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
289 C_UYVY_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
290 C_UYVY_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
291 C_UYVY_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
293 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
295 C_UYVY_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
300 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
302 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v ) \
303 *p_u++ = *p_line++; *p_y++ = *p_line++; \
304 *p_v++ = *p_line++; *p_y++ = *p_line++
305 C_UYVY_YUV422( p_line
, p_y
, p_u
, p_v
);
306 C_UYVY_YUV422( p_line
, p_y
, p_u
, p_v
);
307 C_UYVY_YUV422( p_line
, p_y
, p_u
, p_v
);
308 C_UYVY_YUV422( p_line
, p_y
, p_u
, p_v
);
310 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
312 C_UYVY_YUV422( p_line
, p_y
, p_u
, p_v
);
315 p_line
+= i_source_margin
;
316 p_y
+= i_dest_margin
;
317 p_u
+= i_dest_margin_c
;
318 p_v
+= i_dest_margin_c
;
324 /*****************************************************************************
325 * cyuv_I420: upside-down packed UYVY 4:2:2 to planar YUV 4:2:0
327 *****************************************************************************/
328 static void cyuv_I420( filter_t
*p_filter
, picture_t
*p_source
,
331 uint8_t *p_line
= p_source
->p
->p_pixels
;
333 uint8_t *p_y
= p_dest
->Y_PIXELS
;
334 uint8_t *p_u
= p_dest
->U_PIXELS
;
335 uint8_t *p_v
= p_dest
->V_PIXELS
;
339 const int i_dest_margin
= p_dest
->p
[0].i_pitch
340 - p_dest
->p
[0].i_visible_pitch
;
341 const int i_dest_margin_c
= p_dest
->p
[1].i_pitch
342 - p_dest
->p
[1].i_visible_pitch
;
343 const int i_source_margin
= p_source
->p
->i_pitch
344 - p_source
->p
->i_visible_pitch
;
348 for( i_y
= p_filter
->fmt_out
.video
.i_height
; i_y
-- ; )
352 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
354 #define C_cyuv_YUV422_skip( p_line, p_y, p_u, p_v ) \
355 *p_y++ = *p_line++; p_line++; \
356 *p_y++ = *p_line++; p_line++
357 C_cyuv_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
358 C_cyuv_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
359 C_cyuv_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
360 C_cyuv_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
362 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
364 C_cyuv_YUV422_skip( p_line
, p_y
, p_u
, p_v
);
369 for( i_x
= p_filter
->fmt_out
.video
.i_width
/ 8 ; i_x
-- ; )
371 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v ) \
372 *p_y++ = *p_line++; *p_v++ = *p_line++; \
373 *p_y++ = *p_line++; *p_u++ = *p_line++
374 C_cyuv_YUV422( p_line
, p_y
, p_u
, p_v
);
375 C_cyuv_YUV422( p_line
, p_y
, p_u
, p_v
);
376 C_cyuv_YUV422( p_line
, p_y
, p_u
, p_v
);
377 C_cyuv_YUV422( p_line
, p_y
, p_u
, p_v
);
379 for( i_x
= ( p_filter
->fmt_out
.video
.i_width
% 8 ) / 2; i_x
-- ; )
381 C_cyuv_YUV422( p_line
, p_y
, p_u
, p_v
);
384 p_line
+= i_source_margin
;
385 p_y
+= i_dest_margin
;
386 p_u
+= i_dest_margin_c
;
387 p_v
+= i_dest_margin_c
;