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