]> git.sesse.net Git - vlc/blob - modules/video_chroma/yuy2_i422.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / video_chroma / yuy2_i422.c
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$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan dot org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
35
36 #define SRC_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,cyuv"
37 #define DEST_FOURCC  "I422"
38
39 /*****************************************************************************
40  * Local and extern prototypes.
41  *****************************************************************************/
42 static int  Activate ( vlc_object_t * );
43
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 * );
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", 80 )
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_out.video.i_chroma )
82     {
83         case VLC_CODEC_I422:
84             switch( p_filter->fmt_in.video.i_chroma )
85             {
86                 case VLC_CODEC_YUYV:
87                     p_filter->pf_video_filter = YUY2_I422_Filter;
88                     break;
89
90                 case VLC_CODEC_YVYU:
91                     p_filter->pf_video_filter = YVYU_I422_Filter;
92                     break;
93
94                 case VLC_CODEC_UYVY:
95                     p_filter->pf_video_filter = UYVY_I422_Filter;
96                     break;
97
98                 case VLC_CODEC_CYUV:
99                     p_filter->pf_video_filter = cyuv_I422_Filter;
100                     break;
101
102                 default:
103                     return -1;
104             }
105             break;
106
107         default:
108             return -1;
109     }
110     return 0;
111 }
112
113 /* Following functions are local */
114
115 VIDEO_FILTER_WRAPPER( YUY2_I422 )
116 VIDEO_FILTER_WRAPPER( YVYU_I422 )
117 VIDEO_FILTER_WRAPPER( UYVY_I422 )
118 VIDEO_FILTER_WRAPPER( cyuv_I422 )
119
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 )
125 {
126     uint8_t *p_line = p_source->p->p_pixels;
127
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;
131
132     int i_x, i_y;
133
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;
140
141     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
142     {
143         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
144         {
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 );
152         }
153         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
154         {
155             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
156         }
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;
161     }
162 }
163
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 )
169 {
170     uint8_t *p_line = p_source->p->p_pixels;
171
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;
175
176     int i_x, i_y;
177
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;
184
185     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
186     {
187         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
188         {
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 );
196         }
197         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
198         {
199             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
200         }
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;
205     }
206 }
207
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 )
213 {
214     uint8_t *p_line = p_source->p->p_pixels;
215
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;
219
220     int i_x, i_y;
221
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;
228
229     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
230     {
231         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
232         {
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 );
240         }
241         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
242         {
243             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
244         }
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;
249     }
250 }
251
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 )
258 {
259     uint8_t *p_line = p_source->p->p_pixels;
260
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;
264
265     int i_x, i_y;
266
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;
273
274     for( i_y = p_filter->fmt_out.video.i_height ; i_y-- ; )
275     {
276         for( i_x = p_filter->fmt_out.video.i_width / 8 ; i_x-- ; )
277         {
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 );
285         }
286         for( i_x = ( p_filter->fmt_out.video.i_width % 8 ) / 2; i_x-- ; )
287         {
288             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
289         }
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;
294     }
295 }