Plugins: include vlc_common.h directly instead of vlc/vlc.h
[vlc.git] / 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_vout.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           ( vout_thread_t *, picture_t *, picture_t * );
45 static void YVYU_I422           ( vout_thread_t *, picture_t *, picture_t * );
46 static void UYVY_I422           ( vout_thread_t *, picture_t *, picture_t * );
47 static void cyuv_I422           ( vout_thread_t *, picture_t *, picture_t * );
48
49 /*****************************************************************************
50  * Module descriptor
51  *****************************************************************************/
52 vlc_module_begin();
53     set_description( N_("Conversions from " SRC_FOURCC " to " DEST_FOURCC) );
54     set_capability( "chroma", 80 );
55     set_callbacks( Activate, NULL );
56 vlc_module_end();
57
58 /*****************************************************************************
59  * Activate: allocate a chroma function
60  *****************************************************************************
61  * This function allocates and initializes a chroma function
62  *****************************************************************************/
63 static int Activate( vlc_object_t *p_this )
64 {
65     vout_thread_t *p_vout = (vout_thread_t *)p_this;
66
67     if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
68     {
69         return -1;
70     }
71
72     switch( p_vout->output.i_chroma )
73     {
74         case VLC_FOURCC('I','4','2','2'):
75             switch( p_vout->render.i_chroma )
76             {
77                 case VLC_FOURCC('Y','U','Y','2'):
78                 case VLC_FOURCC('Y','U','N','V'):
79                     p_vout->chroma.pf_convert = YUY2_I422;
80                     break;
81
82                 case VLC_FOURCC('Y','V','Y','U'):
83                     p_vout->chroma.pf_convert = YVYU_I422;
84                     break;
85
86                 case VLC_FOURCC('U','Y','V','Y'):
87                 case VLC_FOURCC('U','Y','N','V'):
88                 case VLC_FOURCC('Y','4','2','2'):
89                     p_vout->chroma.pf_convert = UYVY_I422;
90                     break;
91
92                 case VLC_FOURCC('c','y','u','v'):
93                     p_vout->chroma.pf_convert = cyuv_I422;
94                     break;
95
96                 default:
97                     return -1;
98             }
99             break;
100
101         default:
102             return -1;
103     }
104     return 0;
105 }
106
107 /* Following functions are local */
108
109 /*****************************************************************************
110  * YUY2_I422: packed YUY2 4:2:2 to planar YUV 4:2:2
111  *****************************************************************************/
112 static void YUY2_I422( vout_thread_t *p_vout, picture_t *p_source,
113                                               picture_t *p_dest )
114 {
115     uint8_t *p_line = p_source->p->p_pixels;
116
117     uint8_t *p_y = p_dest->Y_PIXELS;
118     uint8_t *p_u = p_dest->U_PIXELS;
119     uint8_t *p_v = p_dest->V_PIXELS;
120
121     int i_x, i_y;
122
123     const int i_dest_margin = p_dest->p[0].i_pitch
124                                  - p_dest->p[0].i_visible_pitch;
125     const int i_dest_margin_c = p_dest->p[1].i_pitch
126                                  - p_dest->p[1].i_visible_pitch;
127     const int i_source_margin = p_source->p->i_pitch
128                                - p_source->p->i_visible_pitch;
129
130     for( i_y = p_vout->output.i_height ; i_y-- ; )
131     {
132         for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
133         {
134 #define C_YUYV_YUV422( p_line, p_y, p_u, p_v )      \
135             *p_y++ = *p_line++; *p_u++ = *p_line++; \
136             *p_y++ = *p_line++; *p_v++ = *p_line++
137             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
138             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
139             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
140             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
141         }
142         for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
143         {
144             C_YUYV_YUV422( p_line, p_y, p_u, p_v );
145         }
146         p_line += i_source_margin;
147         p_y += i_dest_margin;
148         p_u += i_dest_margin_c;
149         p_v += i_dest_margin_c;
150     }
151 }
152
153 /*****************************************************************************
154  * YVYU_I422: packed YVYU 4:2:2 to planar YUV 4:2:2
155  *****************************************************************************/
156 static void YVYU_I422( vout_thread_t *p_vout, picture_t *p_source,
157                                               picture_t *p_dest )
158 {
159     uint8_t *p_line = p_source->p->p_pixels;
160
161     uint8_t *p_y = p_dest->Y_PIXELS;
162     uint8_t *p_u = p_dest->U_PIXELS;
163     uint8_t *p_v = p_dest->V_PIXELS;
164
165     int i_x, i_y;
166
167     const int i_dest_margin = p_dest->p[0].i_pitch
168                                  - p_dest->p[0].i_visible_pitch;
169     const int i_dest_margin_c = p_dest->p[1].i_pitch
170                                  - p_dest->p[1].i_visible_pitch;
171     const int i_source_margin = p_source->p->i_pitch
172                                - p_source->p->i_visible_pitch;
173
174     for( i_y = p_vout->output.i_height ; i_y-- ; )
175     {
176         for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
177         {
178 #define C_YVYU_YUV422( p_line, p_y, p_u, p_v )      \
179             *p_y++ = *p_line++; *p_v++ = *p_line++; \
180             *p_y++ = *p_line++; *p_u++ = *p_line++
181             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
182             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
183             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
184             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
185         }
186         for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
187         {
188             C_YVYU_YUV422( p_line, p_y, p_u, p_v );
189         }
190         p_line += i_source_margin;
191         p_y += i_dest_margin;
192         p_u += i_dest_margin_c;
193         p_v += i_dest_margin_c;
194     }
195 }
196
197 /*****************************************************************************
198  * UYVY_I422: packed UYVY 4:2:2 to planar YUV 4:2:2
199  *****************************************************************************/
200 static void UYVY_I422( vout_thread_t *p_vout, picture_t *p_source,
201                                               picture_t *p_dest )
202 {
203     uint8_t *p_line = p_source->p->p_pixels;
204
205     uint8_t *p_y = p_dest->Y_PIXELS;
206     uint8_t *p_u = p_dest->U_PIXELS;
207     uint8_t *p_v = p_dest->V_PIXELS;
208
209     int i_x, i_y;
210
211     const int i_dest_margin = p_dest->p[0].i_pitch
212                                  - p_dest->p[0].i_visible_pitch;
213     const int i_dest_margin_c = p_dest->p[1].i_pitch
214                                  - p_dest->p[1].i_visible_pitch;
215     const int i_source_margin = p_source->p->i_pitch
216                                - p_source->p->i_visible_pitch;
217
218     for( i_y = p_vout->output.i_height ; i_y-- ; )
219     {
220         for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
221         {
222 #define C_UYVY_YUV422( p_line, p_y, p_u, p_v )      \
223             *p_u++ = *p_line++; *p_y++ = *p_line++; \
224             *p_v++ = *p_line++; *p_y++ = *p_line++
225             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
226             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
227             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
228             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
229         }
230         for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
231         {
232             C_UYVY_YUV422( p_line, p_y, p_u, p_v );
233         }
234         p_line += i_source_margin;
235         p_y += i_dest_margin;
236         p_u += i_dest_margin_c;
237         p_v += i_dest_margin_c;
238     }
239 }
240
241 /*****************************************************************************
242  * cyuv_I422: upside-down packed UYVY 4:2:2 to planar YUV 4:2:2
243  * FIXME
244  *****************************************************************************/
245 static void cyuv_I422( vout_thread_t *p_vout, picture_t *p_source,
246                                               picture_t *p_dest )
247 {
248     uint8_t *p_line = p_source->p->p_pixels;
249
250     uint8_t *p_y = p_dest->Y_PIXELS;
251     uint8_t *p_u = p_dest->U_PIXELS;
252     uint8_t *p_v = p_dest->V_PIXELS;
253
254     int i_x, i_y;
255
256     const int i_dest_margin = p_dest->p[0].i_pitch
257                                  - p_dest->p[0].i_visible_pitch;
258     const int i_dest_margin_c = p_dest->p[1].i_pitch
259                                  - p_dest->p[1].i_visible_pitch;
260     const int i_source_margin = p_source->p->i_pitch
261                                - p_source->p->i_visible_pitch;
262
263     for( i_y = p_vout->output.i_height ; i_y-- ; )
264     {
265         for( i_x = p_vout->output.i_width / 8 ; i_x-- ; )
266         {
267 #define C_cyuv_YUV422( p_line, p_y, p_u, p_v )      \
268             *p_y++ = *p_line++; *p_v++ = *p_line++; \
269             *p_y++ = *p_line++; *p_u++ = *p_line++
270             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
271             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
272             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
273             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
274         }
275         for( i_x = ( p_vout->output.i_width % 8 ) / 2; i_x-- ; )
276         {
277             C_cyuv_YUV422( p_line, p_y, p_u, p_v );
278         }
279         p_line += i_source_margin;
280         p_y += i_dest_margin;
281         p_u += i_dest_margin_c;
282         p_v += i_dest_margin_c;
283     }
284 }