1 /*****************************************************************************
2 * i422_i420.c : Planar YUV 4:2:2 to Planar YUV 4:2:0 conversion module for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 - 2007 VLC authors and VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Damien Fouilleul <damienf@videolan.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 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
35 #include <vlc_picture.h>
37 #define SRC_FOURCC "I422,J422"
38 #define DEST_FOURCC "I420,IYUV,J420,YV12,YUVA"
40 /*****************************************************************************
41 * Local and extern prototypes.
42 *****************************************************************************/
43 static int Activate ( vlc_object_t
* );
45 static void I422_I420( filter_t
*, picture_t
*, picture_t
* );
46 static void I422_YV12( filter_t
*, picture_t
*, picture_t
* );
47 static void I422_YUVA( filter_t
*, picture_t
*, picture_t
* );
48 static picture_t
*I422_I420_Filter( filter_t
*, picture_t
* );
49 static picture_t
*I422_YV12_Filter( filter_t
*, picture_t
* );
50 static picture_t
*I422_YUVA_Filter( filter_t
*, picture_t
* );
52 /*****************************************************************************
54 *****************************************************************************/
56 set_description( N_("Conversions from " SRC_FOURCC
" to " DEST_FOURCC
) )
57 set_capability( "video converter", 60 )
58 set_callbacks( Activate
, NULL
)
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 )
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
)
81 switch( p_filter
->fmt_in
.video
.i_chroma
)
85 switch( p_filter
->fmt_out
.video
.i_chroma
)
89 p_filter
->pf_video_filter
= I422_I420_Filter
;
93 p_filter
->pf_video_filter
= I422_YV12_Filter
;
96 case VLC_CODEC_YUV420A
:
97 p_filter
->pf_video_filter
= I422_YUVA_Filter
;
111 /* Following functions are local */
112 VIDEO_FILTER_WRAPPER( I422_I420
)
113 VIDEO_FILTER_WRAPPER( I422_YV12
)
114 VIDEO_FILTER_WRAPPER( I422_YUVA
)
116 /*****************************************************************************
117 * I422_I420: planar YUV 4:2:2 to planar I420 4:2:0 Y:U:V
118 *****************************************************************************/
119 static void I422_I420( filter_t
*p_filter
, picture_t
*p_source
,
122 uint16_t i_dpy
= p_dest
->p
[Y_PLANE
].i_pitch
;
123 uint16_t i_spy
= p_source
->p
[Y_PLANE
].i_pitch
;
124 uint16_t i_dpuv
= p_dest
->p
[U_PLANE
].i_pitch
;
125 uint16_t i_spuv
= p_source
->p
[U_PLANE
].i_pitch
;
126 uint16_t i_width
= p_filter
->fmt_in
.video
.i_width
;
127 uint16_t i_y
= p_filter
->fmt_in
.video
.i_height
;
128 uint8_t *p_dy
= p_dest
->Y_PIXELS
+ (i_y
-1)*i_dpy
;
129 uint8_t *p_y
= p_source
->Y_PIXELS
+ (i_y
-1)*i_spy
;
130 uint8_t *p_du
= p_dest
->U_PIXELS
+ (i_y
/2-1)*i_dpuv
;
131 uint8_t *p_u
= p_source
->U_PIXELS
+ (i_y
-1)*i_spuv
;
132 uint8_t *p_dv
= p_dest
->V_PIXELS
+ (i_y
/2-1)*i_dpuv
;
133 uint8_t *p_v
= p_source
->V_PIXELS
+ (i_y
-1)*i_spuv
;
138 memcpy(p_dy
, p_y
, i_width
); p_dy
-= i_dpy
; p_y
-= i_spy
;
139 memcpy(p_dy
, p_y
, i_width
); p_dy
-= i_dpy
; p_y
-= i_spy
;
140 memcpy(p_du
, p_u
, i_width
/2); p_du
-= i_dpuv
; p_u
-= 2*i_spuv
;
141 memcpy(p_dv
, p_v
, i_width
/2); p_dv
-= i_dpuv
; p_v
-= 2*i_spuv
;
145 /*****************************************************************************
146 * I422_YV12: planar YUV 4:2:2 to planar YV12 4:2:0 Y:V:U
147 *****************************************************************************/
148 static void I422_YV12( filter_t
*p_filter
, picture_t
*p_source
,
151 uint16_t i_dpy
= p_dest
->p
[Y_PLANE
].i_pitch
;
152 uint16_t i_spy
= p_source
->p
[Y_PLANE
].i_pitch
;
153 uint16_t i_dpuv
= p_dest
->p
[U_PLANE
].i_pitch
;
154 uint16_t i_spuv
= p_source
->p
[U_PLANE
].i_pitch
;
155 uint16_t i_width
= p_filter
->fmt_in
.video
.i_width
;
156 uint16_t i_y
= p_filter
->fmt_in
.video
.i_height
;
157 uint8_t *p_dy
= p_dest
->Y_PIXELS
+ (i_y
-1)*i_dpy
;
158 uint8_t *p_y
= p_source
->Y_PIXELS
+ (i_y
-1)*i_spy
;
159 uint8_t *p_du
= p_dest
->V_PIXELS
+ (i_y
/2-1)*i_dpuv
; /* U and V are swapped */
160 uint8_t *p_u
= p_source
->U_PIXELS
+ (i_y
-1)*i_spuv
;
161 uint8_t *p_dv
= p_dest
->U_PIXELS
+ (i_y
/2-1)*i_dpuv
; /* U and V are swapped */
162 uint8_t *p_v
= p_source
->V_PIXELS
+ (i_y
-1)*i_spuv
;
167 memcpy(p_dy
, p_y
, i_width
); p_dy
-= i_dpy
; p_y
-= i_spy
;
168 memcpy(p_dy
, p_y
, i_width
); p_dy
-= i_dpy
; p_y
-= i_spy
;
169 memcpy(p_du
, p_u
, i_width
/2); p_du
-= i_dpuv
; p_u
-= 2*i_spuv
;
170 memcpy(p_dv
, p_v
, i_width
/2); p_dv
-= i_dpuv
; p_v
-= 2*i_spuv
;
174 /*****************************************************************************
175 * I422_YUVA: planar YUV 4:2:2 to planar YUVA 4:2:0:4 Y:U:V:A
176 *****************************************************************************/
177 static void I422_YUVA( filter_t
*p_filter
, picture_t
*p_source
,
180 I422_I420( p_filter
, p_source
, p_dest
);
181 memset( p_dest
->p
[A_PLANE
].p_pixels
, 0xff,
182 p_dest
->p
[A_PLANE
].i_lines
* p_dest
->p
[A_PLANE
].i_pitch
);