Remove most stray semi-colons in module descriptions
[vlc.git] / modules / video_chroma / i422_i420.c
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 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Damien Fouilleul <damienf@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_filter.h>
36 #include <vlc_vout.h>
37
38 #define SRC_FOURCC  "I422,J422"
39 #define DEST_FOURCC "I420,IYUV,J420,YV12,YUVA"
40
41 /*****************************************************************************
42  * Local and extern prototypes.
43  *****************************************************************************/
44 static int  Activate ( vlc_object_t * );
45
46 static void I422_I420( filter_t *, picture_t *, picture_t * );
47 static void I422_YV12( filter_t *, picture_t *, picture_t * );
48 static void I422_YUVA( filter_t *, picture_t *, picture_t * );
49 static picture_t *I422_I420_Filter( filter_t *, picture_t * );
50 static picture_t *I422_YV12_Filter( filter_t *, picture_t * );
51 static picture_t *I422_YUVA_Filter( filter_t *, picture_t * );
52
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", 60 )
59     set_callbacks( Activate, NULL )
60 vlc_module_end ()
61
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 )
68 {
69     filter_t *p_filter = (filter_t *)p_this;
70
71     if( p_filter->fmt_in.video.i_width & 1
72      || p_filter->fmt_in.video.i_height & 1 )
73     {
74         return -1;
75     }
76
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;
80
81     switch( p_filter->fmt_in.video.i_chroma )
82     {
83         case VLC_FOURCC('I','4','2','2'):
84         case VLC_FOURCC('J','4','2','2'):
85             switch( p_filter->fmt_out.video.i_chroma )
86             {
87                 case VLC_FOURCC('I','4','2','0'):
88                 case VLC_FOURCC('I','Y','U','V'):
89                 case VLC_FOURCC('J','4','2','0'):
90                     p_filter->pf_video_filter = I422_I420_Filter;
91                     break;
92
93                 case VLC_FOURCC('Y','V','1','2'):
94                     p_filter->pf_video_filter = I422_YV12_Filter;
95                     break;
96
97                 case VLC_FOURCC('Y','U','V','A'):
98                     p_filter->pf_video_filter = I422_YUVA_Filter;
99                     break;
100
101                 default:
102                     return -1;
103             }
104             break;
105
106         default:
107             return -1;
108     }
109     return 0;
110 }
111
112 /* Following functions are local */
113 VIDEO_FILTER_WRAPPER( I422_I420 )
114 VIDEO_FILTER_WRAPPER( I422_YV12 )
115 VIDEO_FILTER_WRAPPER( I422_YUVA )
116
117 /*****************************************************************************
118  * I422_I420: planar YUV 4:2:2 to planar I420 4:2:0 Y:U:V
119  *****************************************************************************/
120 static void I422_I420( filter_t *p_filter, picture_t *p_source,
121                                            picture_t *p_dest )
122 {
123     uint16_t i_dpy = p_dest->p[Y_PLANE].i_pitch;
124     uint16_t i_spy = p_source->p[Y_PLANE].i_pitch;
125     uint16_t i_dpuv = p_dest->p[U_PLANE].i_pitch;
126     uint16_t i_spuv = p_source->p[U_PLANE].i_pitch;
127     uint16_t i_width = p_filter->fmt_in.video.i_width;
128     uint16_t i_y = p_filter->fmt_in.video.i_height;
129     uint8_t *p_dy = p_dest->Y_PIXELS + (i_y-1)*i_dpy;
130     uint8_t *p_y = p_source->Y_PIXELS + (i_y-1)*i_spy;
131     uint8_t *p_du = p_dest->U_PIXELS + (i_y/2-1)*i_dpuv;
132     uint8_t *p_u = p_source->U_PIXELS + (i_y-1)*i_spuv;
133     uint8_t *p_dv = p_dest->V_PIXELS + (i_y/2-1)*i_dpuv;
134     uint8_t *p_v = p_source->V_PIXELS + (i_y-1)*i_spuv;
135     i_y /= 2;
136
137     for ( ; i_y--; )
138     {
139         vlc_memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
140         vlc_memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
141         vlc_memcpy(p_du, p_u, i_width/2); p_du -= i_dpuv; p_u -= 2*i_spuv;
142         vlc_memcpy(p_dv, p_v, i_width/2); p_dv -= i_dpuv; p_v -= 2*i_spuv;
143     }
144 }
145
146 /*****************************************************************************
147  * I422_YV12: planar YUV 4:2:2 to planar YV12 4:2:0 Y:V:U
148  *****************************************************************************/
149 static void I422_YV12( filter_t *p_filter, picture_t *p_source,
150                                            picture_t *p_dest )
151 {
152     uint16_t i_dpy = p_dest->p[Y_PLANE].i_pitch;
153     uint16_t i_spy = p_source->p[Y_PLANE].i_pitch;
154     uint16_t i_dpuv = p_dest->p[U_PLANE].i_pitch;
155     uint16_t i_spuv = p_source->p[U_PLANE].i_pitch;
156     uint16_t i_width = p_filter->fmt_in.video.i_width;
157     uint16_t i_y = p_filter->fmt_in.video.i_height;
158     uint8_t *p_dy = p_dest->Y_PIXELS + (i_y-1)*i_dpy;
159     uint8_t *p_y = p_source->Y_PIXELS + (i_y-1)*i_spy;
160     uint8_t *p_du = p_dest->V_PIXELS + (i_y/2-1)*i_dpuv; /* U and V are swapped */
161     uint8_t *p_u = p_source->U_PIXELS + (i_y-1)*i_spuv;
162     uint8_t *p_dv = p_dest->U_PIXELS + (i_y/2-1)*i_dpuv; /* U and V are swapped */
163     uint8_t *p_v = p_source->V_PIXELS + (i_y-1)*i_spuv;
164     i_y /= 2;
165
166     for ( ; i_y--; )
167     {
168         vlc_memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
169         vlc_memcpy(p_dy, p_y, i_width); p_dy -= i_dpy; p_y -= i_spy;
170         vlc_memcpy(p_du, p_u, i_width/2); p_du -= i_dpuv; p_u -= 2*i_spuv;
171         vlc_memcpy(p_dv, p_v, i_width/2); p_dv -= i_dpuv; p_v -= 2*i_spuv;
172     }
173 }
174
175 /*****************************************************************************
176  * I422_YUVA: planar YUV 4:2:2 to planar YUVA 4:2:0:4 Y:U:V:A
177  *****************************************************************************/
178 static void I422_YUVA( filter_t *p_filter, picture_t *p_source,
179                                            picture_t *p_dest )
180 {
181     I422_I420( p_filter, p_source, p_dest );
182     vlc_memset( p_dest->p[A_PLANE].p_pixels, 0xff,
183                 p_dest->p[A_PLANE].i_lines * p_dest->p[A_PLANE].i_pitch );
184 }