]> git.sesse.net Git - vlc/blob - plugins/yuv/transforms_yuvmmx.c
Rewritten vout for BeOS. Now does not support overlay however code is simpler
[vlc] / plugins / yuv / transforms_yuvmmx.c
1 /*****************************************************************************
2  * transforms_yuvmmx.c: MMX YUV transformation functions
3  * Provides functions to perform the YUV conversion.
4  *****************************************************************************
5  * Copyright (C) 1999, 2000 VideoLAN
6  * $Id: transforms_yuvmmx.c,v 1.6 2001/06/03 12:47:21 sam Exp $
7  *
8  * Authors: Samuel Hocevar <sam@zoy.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 GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public
21  * License along with this program; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *****************************************************************************/
25
26 #define MODULE_NAME yuvmmx
27 #include "modules_inner.h"
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include "defs.h"
33
34 #include <math.h>                                            /* exp(), pow() */
35 #include <errno.h>                                                 /* ENOMEM */
36 #include <stdlib.h>                                                /* free() */
37 #include <string.h>                                            /* strerror() */
38
39 #include "config.h"
40 #include "common.h"
41 #include "threads.h"
42 #include "mtime.h"
43
44 #include "video.h"
45 #include "video_output.h"
46
47 #include "video_common.h"
48 #include "transforms_common.h"
49 #include "transforms_yuvmmx.h"
50
51 #include "intf_msg.h"
52
53 #include "modules.h"
54 #include "modules_export.h"
55
56 /*****************************************************************************
57  * ConvertY4Gray8: grayscale YUV 4:x:x to RGB 8 bpp
58  *****************************************************************************/
59 void _M( ConvertY4Gray8 )( YUV_ARGS_8BPP )
60 {
61     intf_ErrMsg( "yuvmmx error: unhandled function, grayscale, bpp = 8" );
62 }
63
64 /*****************************************************************************
65  * ConvertYUV420RGB8: color YUV 4:2:0 to RGB 8 bpp
66  *****************************************************************************/
67 void _M( ConvertYUV420RGB8 )( YUV_ARGS_8BPP )
68 {
69     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, bpp = 8" );
70 }
71
72 /*****************************************************************************
73  * ConvertYUV422RGB8: color YUV 4:2:2 to RGB 8 bpp
74  *****************************************************************************/
75 void _M( ConvertYUV422RGB8 )( YUV_ARGS_8BPP )
76 {
77     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, bpp = 8" );
78 }
79
80 /*****************************************************************************
81  * ConvertYUV444RGB8: color YUV 4:4:4 to RGB 8 bpp
82  *****************************************************************************/
83 void _M( ConvertYUV444RGB8 )( YUV_ARGS_8BPP )
84 {
85     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, bpp = 8" );
86 }
87
88 /*****************************************************************************
89  * ConvertY4Gray16: color YUV 4:4:4 to RGB 2 Bpp
90  *****************************************************************************/
91 void _M( ConvertY4Gray16 )( YUV_ARGS_16BPP )
92 {
93     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
94     int         i_vertical_scaling;                 /* vertical scaling type */
95     int         i_x, i_y;                 /* horizontal and vertical indexes */
96     int         i_scale_count;                       /* scale modulo counter */
97     int         i_chroma_width;                              /* chroma width */
98     u16 *       p_pic_start;       /* beginning of the current line for copy */
99     u16 *       p_buffer_start;                   /* conversion buffer start */
100     u16 *       p_buffer;                       /* conversion buffer pointer */
101     int *       p_offset_start;                        /* offset array start */
102     int *       p_offset;                            /* offset array pointer */
103
104     /*
105      * Initialize some values  - i_pic_line_width will store the line skip
106      */
107     i_pic_line_width -= i_pic_width;
108     i_chroma_width =    i_width / 2;
109     p_buffer_start =    p_vout->yuv.p_buffer;
110     p_offset_start =    p_vout->yuv.p_offset;
111     _M( SetOffset )( i_width, i_height, i_pic_width, i_pic_height,
112                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start, 0 );
113
114     /*
115      * Perform conversion
116      */
117     i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
118     for( i_y = 0; i_y < i_height; i_y++ )
119     {
120         /* Mark beginnning of line for possible later line copy, and initialize
121          * buffer */
122         p_pic_start =   p_pic;
123         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
124
125         for ( i_x = i_width / 8; i_x--; )
126         {
127             __asm__( MMX_INIT_16_GRAY
128                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
129
130             __asm__( ".align 8"
131                      MMX_YUV_GRAY
132                      MMX_UNPACK_16_GRAY
133                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
134
135             p_y += 8;
136             p_u += 4;
137             p_v += 4;
138             p_buffer += 8;
139         }
140
141         SCALE_WIDTH;
142         SCALE_HEIGHT( 420, 2 );
143     }
144 }
145
146 /*****************************************************************************
147  * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 2 Bpp
148  *****************************************************************************/
149 void _M( ConvertYUV420RGB16 )( YUV_ARGS_16BPP )
150 {
151     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
152     int         i_vertical_scaling;                 /* vertical scaling type */
153     int         i_x, i_y;                 /* horizontal and vertical indexes */
154     int         i_scale_count;                       /* scale modulo counter */
155     int         i_chroma_width;                              /* chroma width */
156     u16 *       p_pic_start;       /* beginning of the current line for copy */
157     u16 *       p_buffer_start;                   /* conversion buffer start */
158     u16 *       p_buffer;                       /* conversion buffer pointer */
159     int *       p_offset_start;                        /* offset array start */
160     int *       p_offset;                            /* offset array pointer */
161
162     /*
163      * Initialize some values  - i_pic_line_width will store the line skip
164      */
165     i_pic_line_width -= i_pic_width;
166     i_chroma_width =    i_width / 2;
167     p_buffer_start =    p_vout->yuv.p_buffer;
168     p_offset_start =    p_vout->yuv.p_offset;
169     _M( SetOffset )( i_width, i_height, i_pic_width, i_pic_height,
170                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start, 0 );
171
172     /*
173      * Perform conversion
174      */
175     i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
176     for( i_y = 0; i_y < i_height; i_y++ )
177     {
178         p_pic_start =   p_pic;
179         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
180
181         for ( i_x = i_width / 8; i_x--; )
182         {
183             __asm__( MMX_INIT_16
184                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
185
186             __asm__( ".align 8"
187                      MMX_YUV_MUL
188                      MMX_YUV_ADD
189                      MMX_UNPACK_16
190                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
191
192             p_y += 8;
193             p_u += 4;
194             p_v += 4;
195             p_buffer += 8;
196         }
197         SCALE_WIDTH;
198         SCALE_HEIGHT( 420, 2 );
199       }
200 }
201
202 /*****************************************************************************
203  * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 2 Bpp
204  *****************************************************************************/
205 void _M( ConvertYUV422RGB16 )( YUV_ARGS_16BPP )
206 {
207     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, bpp = 16" );
208 }
209
210 /*****************************************************************************
211  * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 2 Bpp
212  *****************************************************************************/
213 void _M( ConvertYUV444RGB16 )( YUV_ARGS_16BPP )
214 {
215     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, bpp = 16" );
216 }
217
218 /*****************************************************************************
219  * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 2 Bpp
220  *****************************************************************************/
221 void _M( ConvertY4Gray24 )( YUV_ARGS_24BPP )
222 {
223     intf_ErrMsg( "yuvmmx error: unhandled function, grayscale, bpp = 24" );
224 }
225
226 /*****************************************************************************
227  * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 2 Bpp
228  *****************************************************************************/
229 void _M( ConvertYUV420RGB24 )( YUV_ARGS_24BPP )
230 {
231     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, bpp = 24" );
232 }
233
234 /*****************************************************************************
235  * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 2 Bpp
236  *****************************************************************************/
237 void _M( ConvertYUV422RGB24 )( YUV_ARGS_24BPP )
238 {
239     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, bpp = 24" );
240 }
241
242 /*****************************************************************************
243  * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 2 Bpp
244  *****************************************************************************/
245 void _M( ConvertYUV444RGB24 )( YUV_ARGS_24BPP )
246 {
247     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, bpp = 24" );
248 }
249
250 /*****************************************************************************
251  * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 4 Bpp
252  *****************************************************************************/
253 void _M( ConvertY4Gray32 )( YUV_ARGS_32BPP )
254 {
255     intf_ErrMsg( "yuvmmx error: unhandled function, grayscale, bpp = 32" );
256 }
257
258 /*****************************************************************************
259  * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 4 Bpp
260  *****************************************************************************/
261 void _M( ConvertYUV420RGB32 )( YUV_ARGS_32BPP )
262 {
263     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
264     int         i_vertical_scaling;                 /* vertical scaling type */
265     int         i_x, i_y;                 /* horizontal and vertical indexes */
266     int         i_scale_count;                       /* scale modulo counter */
267     int         i_chroma_width;                              /* chroma width */
268     u32 *       p_pic_start;       /* beginning of the current line for copy */
269     u32 *       p_buffer_start;                   /* conversion buffer start */
270     u32 *       p_buffer;                       /* conversion buffer pointer */
271     int *       p_offset_start;                        /* offset array start */
272     int *       p_offset;                            /* offset array pointer */
273
274     /*
275      * Initialize some values  - i_pic_line_width will store the line skip
276      */
277     i_pic_line_width -= i_pic_width;
278     i_chroma_width =    i_width / 2;
279     p_buffer_start =    p_vout->yuv.p_buffer;
280     p_offset_start =    p_vout->yuv.p_offset;
281     _M( SetOffset )( i_width, i_height, i_pic_width, i_pic_height,
282                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start, 0 );
283
284     i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
285     for( i_y = 0; i_y < i_height; i_y++ )
286     {
287         p_pic_start =   p_pic;
288         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
289
290         for ( i_x = i_width / 8; i_x--; )
291         {
292             __asm__( ".align 8"
293                      MMX_INIT_32
294                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
295
296             __asm__( ".align 8"
297                      MMX_YUV_MUL
298                      MMX_YUV_ADD
299                      MMX_UNPACK_32
300                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
301
302             p_y += 8;
303             p_u += 4;
304             p_v += 4;
305             p_buffer += 8;
306         }
307
308         SCALE_WIDTH;
309         SCALE_HEIGHT( 420, 4 );
310     }
311
312 }
313
314 /*****************************************************************************
315  * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 4 Bpp
316  *****************************************************************************/
317 void _M( ConvertYUV422RGB32 )( YUV_ARGS_32BPP )
318 {
319     intf_ErrMsg( "yuv error: unhandled function, chroma = 422, bpp = 32" );
320 }
321
322 /*****************************************************************************
323  * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 4 Bpp
324  *****************************************************************************/
325 void _M( ConvertYUV444RGB32 )( YUV_ARGS_32BPP )
326 {
327     intf_ErrMsg( "yuv error: unhandled function, chroma = 444, bpp = 32" );
328 }
329
330 /*****************************************************************************
331  * ConvertYUV420YCbr8: color YUV 4:2:0 to YCbr 8 Bpp
332  *****************************************************************************/
333 void _M( ConvertYUV420YCbr8 )( YUV_ARGS_8BPP )
334 {
335     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, YCbr = 8" );
336 }
337
338 /*****************************************************************************
339  * ConvertYUV422YCbr8: color YUV 4:2:2 to YCbr 8 Bpp
340  *****************************************************************************/
341 void _M( ConvertYUV422YCbr8 )( YUV_ARGS_8BPP )
342 {
343     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 8" );
344
345 }
346
347 /*****************************************************************************
348  * ConvertYUV444YCbr8: color YUV 4:4:4 to YCbr 8 Bpp
349  *****************************************************************************/
350 void _M( ConvertYUV444YCbr8 )( YUV_ARGS_8BPP )
351 {
352     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 8" );
353
354 }
355
356 /*****************************************************************************
357  * ConvertYUV420YCbr16: color YUV 4:2:0 to YCbr 16 Bpp
358  *****************************************************************************/
359 void _M( ConvertYUV420YCbr16 )( YUV_ARGS_16BPP )
360 {
361     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
362     int         i_vertical_scaling;                 /* vertical scaling type */
363     int         i_x, i_y;                 /* horizontal and vertical indexes */
364     int         i_scale_count;                       /* scale modulo counter */
365     int         i_chroma_width;                              /* chroma width */
366     u16 *       p_pic_start;       /* beginning of the current line for copy */
367     u16 *       p_buffer_start;                   /* conversion buffer start */
368     u16 *       p_buffer;                       /* conversion buffer pointer */
369     int *       p_offset_start;                        /* offset array start */
370     int *       p_offset;                            /* offset array pointer */
371
372     i_pic_line_width -= i_pic_width;
373     i_chroma_width =    i_width / 2;
374     p_buffer_start =    p_vout->yuv.p_buffer;
375     p_offset_start =    p_vout->yuv.p_offset;
376     _M( SetOffset )( i_width, i_height, i_pic_width, i_pic_height,
377                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start, 0 );
378
379     i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
380     for( i_y = 0; i_y < i_height; i_y++ )
381     {
382         p_pic_start =   p_pic;
383         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
384
385         for ( i_x = i_width / 8; i_x--; )
386         {
387             __asm__( MMX_INIT_16
388                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
389
390             __asm__( ".align 8"
391                      MMX_YUV_YCBR_422
392                      : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
393
394             p_y += 8;
395             p_u += 4;
396             p_v += 4;
397             p_buffer += 8;
398         }
399         SCALE_WIDTH;
400         SCALE_HEIGHT( 420, 2 );
401   
402       }
403
404 }
405
406 /*****************************************************************************
407  * ConvertYUV422YCbr8: color YUV 4:2:2 to YCbr 16 Bpp
408  *****************************************************************************/
409 void _M( ConvertYUV422YCbr16 )( YUV_ARGS_16BPP )
410 {
411     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 16" );
412
413 }
414
415 /*****************************************************************************
416  * ConvertYUV424YCbr8: color YUV 4:4:4 to YCbr 16 Bpp
417  *****************************************************************************/
418 void _M( ConvertYUV444YCbr16 )( YUV_ARGS_16BPP )
419 {
420     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 16" );
421
422 }
423
424 /*****************************************************************************
425  * ConvertYUV420YCbr24: color YUV 4:2:0 to YCbr 24 Bpp
426  *****************************************************************************/
427 void _M( ConvertYUV420YCbr24 )( YUV_ARGS_24BPP )
428 {
429     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, YCbr = 24" );
430
431 }
432
433 /*****************************************************************************
434  * ConvertYUV422YCbr24: color YUV 4:2:2 to YCbr 24 Bpp
435  *****************************************************************************/
436 void _M( ConvertYUV422YCbr24 )( YUV_ARGS_24BPP )
437 {
438     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 24" );
439
440 }
441
442 /*****************************************************************************
443  * ConvertYUV444YCbr24: color YUV 4:4:4 to YCbr 24 Bpp
444  *****************************************************************************/
445 void _M( ConvertYUV444YCbr24 )( YUV_ARGS_24BPP )
446 {
447     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 24" );
448
449 }
450
451 /*****************************************************************************
452  * ConvertYUV420YCbr32: color YUV 4:2:0 to YCbr 32 Bpp
453  *****************************************************************************/
454 void _M( ConvertYUV420YCbr32 )( YUV_ARGS_32BPP )
455 {
456     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, YCbr = 32" );
457
458 }
459
460 /*****************************************************************************
461  * ConvertYUV422YCbr32: color YUV 4:2:2 to YCbr 32 Bpp
462  *****************************************************************************/
463 void _M( ConvertYUV422YCbr32 )( YUV_ARGS_32BPP )
464 {
465     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 32" );
466
467 }
468
469 /*****************************************************************************
470  * ConvertYUV444YCbr32: color YUV 4:4:4 to YCbr 32 Bpp
471  *****************************************************************************/
472 void _M( ConvertYUV444YCbr32 )( YUV_ARGS_32BPP )
473 {
474     intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 32" );
475
476 }
477