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