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