* ./debian/rules: moved the gtk_main and gnome_main plugins to the gvlc
[vlc.git] / modules / video_chroma / i422_yuy2.c
1 /*****************************************************************************
2  * i422_yuy2.c : YUV to YUV conversion module for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: i422_yuy2.c,v 1.1 2002/08/04 17:23:43 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <string.h>                                            /* strerror() */
29 #include <stdlib.h>                                      /* malloc(), free() */
30
31 #include <vlc/vlc.h>
32 #include <vlc/vout.h>
33
34 #include "i422_yuy2.h"
35
36 #define SRC_FOURCC  "I422"
37 #if defined (MODULE_NAME_IS_i422_yuy2)
38 #    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv,Y211"
39 #else
40 #    define DEST_FOURCC "YUY2,YUNV,YVYU,UYVY,UYNV,Y422,IUYV,cyuv"
41 #endif
42
43 /*****************************************************************************
44  * Local and extern prototypes.
45  *****************************************************************************/
46 static int  Activate ( vlc_object_t * );
47
48 static void I422_YUY2           ( vout_thread_t *, picture_t *, picture_t * );
49 static void I422_YVYU           ( vout_thread_t *, picture_t *, picture_t * );
50 static void I422_UYVY           ( vout_thread_t *, picture_t *, picture_t * );
51 static void I422_IUYV           ( vout_thread_t *, picture_t *, picture_t * );
52 static void I422_cyuv           ( vout_thread_t *, picture_t *, picture_t * );
53 #if defined (MODULE_NAME_IS_i422_yuy2)
54 static void I422_Y211           ( vout_thread_t *, picture_t *, picture_t * );
55 #endif
56
57 /*****************************************************************************
58  * Module descriptor
59  *****************************************************************************/
60 vlc_module_begin();
61 #if defined (MODULE_NAME_IS_i422_yuy2)
62     set_description( _("conversions from " SRC_FOURCC " to " DEST_FOURCC) );
63     set_capability( "chroma", 80 );
64 #elif defined (MODULE_NAME_IS_i422_yuy2_mmx)
65     set_description( _("MMX conversions from " SRC_FOURCC " to " DEST_FOURCC) );
66     set_capability( "chroma", 100 );
67     add_requirement( MMX );
68 #endif
69     set_callbacks( Activate, NULL );
70 vlc_module_end();
71
72 /*****************************************************************************
73  * Activate: allocate a chroma function
74  *****************************************************************************
75  * This function allocates and initializes a chroma function
76  *****************************************************************************/
77 static int Activate( vlc_object_t *p_this )
78 {
79     vout_thread_t *p_vout = (vout_thread_t *)p_this;
80
81     if( p_vout->render.i_width & 1 || p_vout->render.i_height & 1 )
82     {
83         return -1;
84     }
85
86     switch( p_vout->render.i_chroma )
87     {
88         case VLC_FOURCC('I','4','2','2'):
89             switch( p_vout->output.i_chroma )
90             {
91                 case VLC_FOURCC('Y','U','Y','2'):
92                 case VLC_FOURCC('Y','U','N','V'):
93                     p_vout->chroma.pf_convert = I422_YUY2;
94                     break;
95
96                 case VLC_FOURCC('Y','V','Y','U'):
97                     p_vout->chroma.pf_convert = I422_YVYU;
98                     break;
99
100                 case VLC_FOURCC('U','Y','V','Y'):
101                 case VLC_FOURCC('U','Y','N','V'):
102                 case VLC_FOURCC('Y','4','2','2'):
103                     p_vout->chroma.pf_convert = I422_UYVY;
104                     break;
105
106                 case VLC_FOURCC('I','U','Y','V'):
107                     p_vout->chroma.pf_convert = I422_IUYV;
108                     break;
109
110                 case VLC_FOURCC('c','y','u','v'):
111                     p_vout->chroma.pf_convert = I422_cyuv;
112                     break;
113
114 #if defined (MODULE_NAME_IS_i422_yuy2)
115                 case VLC_FOURCC('Y','2','1','1'):
116                     p_vout->chroma.pf_convert = I422_Y211;
117                     break;
118 #endif
119
120                 default:
121                     return -1;
122             }
123             break;
124
125         default:
126             return -1;
127     }
128     
129     return 0; 
130 }
131
132 /* Following functions are local */
133
134 /*****************************************************************************
135  * I422_YUY2: planar YUV 4:2:2 to packed YUY2 4:2:2
136  *****************************************************************************/
137 static void I422_YUY2( vout_thread_t *p_vout, picture_t *p_source,
138                                               picture_t *p_dest )
139 {
140     u8 *p_line = p_dest->p->p_pixels;
141     u8 *p_y = p_source->Y_PIXELS;
142     u8 *p_u = p_source->U_PIXELS;
143     u8 *p_v = p_source->V_PIXELS;
144
145     int i_x, i_y;
146
147     for( i_y = p_vout->render.i_height ; i_y-- ; )
148     {
149         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
150         {
151 #if defined (MODULE_NAME_IS_i422_yuy2)
152             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
153             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
154             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
155             C_YUV422_YUYV( p_line, p_y, p_u, p_v );
156 #else
157             __asm__( ".align 8" MMX_YUV422_YUYV
158                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
159
160             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
161
162             __asm__( ".align 8" MMX_YUV422_YUYV
163                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
164
165             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
166 #endif
167         }
168     }
169 }
170
171 /*****************************************************************************
172  * I422_YVYU: planar YUV 4:2:2 to packed YVYU 4:2:2
173  *****************************************************************************/
174 static void I422_YVYU( vout_thread_t *p_vout, picture_t *p_source,
175                                               picture_t *p_dest )
176 {
177     u8 *p_line = p_dest->p->p_pixels;
178     u8 *p_y = p_source->Y_PIXELS;
179     u8 *p_u = p_source->U_PIXELS;
180     u8 *p_v = p_source->V_PIXELS;
181
182     int i_x, i_y;
183
184     for( i_y = p_vout->render.i_height ; i_y-- ; )
185     {
186         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
187         {
188 #if defined (MODULE_NAME_IS_i422_yuy2)
189             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
190             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
191             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
192             C_YUV422_YVYU( p_line, p_y, p_u, p_v );
193 #else
194             __asm__( ".align 8" MMX_YUV422_YVYU
195                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
196
197             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
198
199             __asm__( ".align 8" MMX_YUV422_YVYU
200                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
201
202             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
203 #endif
204         }
205     }
206 }
207
208 /*****************************************************************************
209  * I422_UYVY: planar YUV 4:2:2 to packed UYVY 4:2:2
210  *****************************************************************************/
211 static void I422_UYVY( vout_thread_t *p_vout, picture_t *p_source,
212                                               picture_t *p_dest )
213 {
214     u8 *p_line = p_dest->p->p_pixels;
215     u8 *p_y = p_source->Y_PIXELS;
216     u8 *p_u = p_source->U_PIXELS;
217     u8 *p_v = p_source->V_PIXELS;
218
219     int i_x, i_y;
220
221     for( i_y = p_vout->render.i_height ; i_y-- ; )
222     {
223         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
224         {
225 #if defined (MODULE_NAME_IS_i422_yuy2)
226             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
227             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
228             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
229             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
230 #else
231             __asm__( ".align 8" MMX_YUV422_UYVY
232                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
233
234             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
235
236             __asm__( ".align 8" MMX_YUV422_UYVY
237                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
238
239             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
240 #endif
241         }
242     }
243 }
244
245 /*****************************************************************************
246  * I422_IUYV: planar YUV 4:2:2 to interleaved packed IUYV 4:2:2
247  *****************************************************************************/
248 static void I422_IUYV( vout_thread_t *p_vout, picture_t *p_source,
249                                               picture_t *p_dest )
250 {
251     /* FIXME: TODO ! */
252     msg_Err( p_vout, "I422_IUYV unimplemented, please harass <sam@zoy.org>" );
253 }
254
255 /*****************************************************************************
256  * I422_cyuv: planar YUV 4:2:2 to upside-down packed UYVY 4:2:2
257  *****************************************************************************/
258 static void I422_cyuv( vout_thread_t *p_vout, picture_t *p_source,
259                                               picture_t *p_dest )
260 {
261     u8 *p_line = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch;
262     u8 *p_y = p_source->Y_PIXELS;
263     u8 *p_u = p_source->U_PIXELS;
264     u8 *p_v = p_source->V_PIXELS;
265
266     int i_x, i_y;
267
268     for( i_y = p_vout->render.i_height ; i_y-- ; )
269     {
270         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
271         {
272             p_line -= 2 * p_dest->p->i_pitch;
273
274 #if defined (MODULE_NAME_IS_i422_yuy2)
275             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
276             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
277             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
278             C_YUV422_UYVY( p_line, p_y, p_u, p_v );
279 #else
280             __asm__( ".align 8" MMX_YUV422_UYVY
281                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
282
283             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
284
285             __asm__( ".align 8" MMX_YUV422_UYVY
286                      : : "r" (p_line), "r" (p_y), "r" (p_u), "r" (p_v) ); 
287
288             p_line += 8; p_y += 4; p_u += 2; p_v += 2;
289 #endif
290         }
291     }
292 }
293
294 /*****************************************************************************
295  * I422_Y211: planar YUV 4:2:2 to packed YUYV 2:1:1
296  *****************************************************************************/
297 #if defined (MODULE_NAME_IS_i422_yuy2)
298 static void I422_Y211( vout_thread_t *p_vout, picture_t *p_source,
299                                               picture_t *p_dest )
300 {
301     u8 *p_line = p_dest->p->p_pixels + p_dest->p->i_lines * p_dest->p->i_pitch;
302     u8 *p_y = p_source->Y_PIXELS;
303     u8 *p_u = p_source->U_PIXELS;
304     u8 *p_v = p_source->V_PIXELS;
305
306     int i_x, i_y;
307
308     for( i_y = p_vout->render.i_height ; i_y-- ; )
309     {
310         for( i_x = p_vout->render.i_width / 8 ; i_x-- ; )
311         {
312             C_YUV422_Y211( p_line, p_y, p_u, p_v );
313             C_YUV422_Y211( p_line, p_y, p_u, p_v );
314         }
315     }
316 }
317 #endif
318