1 /*****************************************************************************
2 * transforms_yuvmmx.c: MMX YUV transformation functions
3 * Provides functions to perform the YUV conversion.
4 *****************************************************************************
5 * Copyright (C) 1999, 2000 VideoLAN
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
30 #include <math.h> /* exp(), pow() */
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
33 #include <string.h> /* strerror() */
41 #include "video_output.h"
43 #include "video_common.h"
44 #include "transforms_common.h"
45 #include "transforms_yuvmmx.h"
49 /*****************************************************************************
50 * ConvertY4Gray8: grayscale YUV 4:x:x to RGB 8 bpp
51 *****************************************************************************/
52 void ConvertY4Gray8( YUV_ARGS_8BPP )
54 intf_ErrMsg( "yuvmmx error: unhandled function, grayscale, bpp = 8" );
57 /*****************************************************************************
58 * ConvertYUV420RGB8: color YUV 4:2:0 to RGB 8 bpp
59 *****************************************************************************/
60 void ConvertYUV420RGB8( YUV_ARGS_8BPP )
62 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, bpp = 8" );
65 /*****************************************************************************
66 * ConvertYUV422RGB8: color YUV 4:2:2 to RGB 8 bpp
67 *****************************************************************************/
68 void ConvertYUV422RGB8( YUV_ARGS_8BPP )
70 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, bpp = 8" );
73 /*****************************************************************************
74 * ConvertYUV444RGB8: color YUV 4:4:4 to RGB 8 bpp
75 *****************************************************************************/
76 void ConvertYUV444RGB8( YUV_ARGS_8BPP )
78 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, bpp = 8" );
81 /*****************************************************************************
82 * ConvertY4Gray16: color YUV 4:4:4 to RGB 2 Bpp
83 *****************************************************************************/
84 void ConvertY4Gray16( YUV_ARGS_16BPP )
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 */
98 * Initialize some values - i_pic_line_width will store the line skip
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 );
110 i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
111 for( i_y = 0; i_y < i_height; i_y++ )
113 /* Mark beginnning of line for possible later line copy, and initialize
116 p_buffer = b_horizontal_scaling ? p_buffer_start : p_pic;
118 for ( i_x = i_width / 8; i_x--; )
120 __asm__( MMX_INIT_16_GRAY
121 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
126 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
135 SCALE_HEIGHT( 420, 2 );
139 /*****************************************************************************
140 * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 2 Bpp
141 *****************************************************************************/
142 void ConvertYUV420RGB16( YUV_ARGS_16BPP )
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 */
156 * Initialize some values - i_pic_line_width will store the line skip
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 );
168 i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
169 for( i_y = 0; i_y < i_height; i_y++ )
172 p_buffer = b_horizontal_scaling ? p_buffer_start : p_pic;
174 for ( i_x = i_width / 8; i_x--; )
177 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
183 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
191 SCALE_HEIGHT( 420, 2 );
196 /*****************************************************************************
197 * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 2 Bpp
198 *****************************************************************************/
199 void ConvertYUV422RGB16( YUV_ARGS_16BPP )
201 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, bpp = 16" );
204 /*****************************************************************************
205 * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 2 Bpp
206 *****************************************************************************/
207 void ConvertYUV444RGB16( YUV_ARGS_16BPP )
209 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, bpp = 16" );
212 /*****************************************************************************
213 * ConvertY4Gray24: grayscale YUV 4:x:x to RGB 2 Bpp
214 *****************************************************************************/
215 void ConvertY4Gray24( YUV_ARGS_24BPP )
217 intf_ErrMsg( "yuvmmx error: unhandled function, grayscale, bpp = 24" );
220 /*****************************************************************************
221 * ConvertYUV420RGB24: color YUV 4:2:0 to RGB 2 Bpp
222 *****************************************************************************/
223 void ConvertYUV420RGB24( YUV_ARGS_24BPP )
225 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, bpp = 24" );
228 /*****************************************************************************
229 * ConvertYUV422RGB24: color YUV 4:2:2 to RGB 2 Bpp
230 *****************************************************************************/
231 void ConvertYUV422RGB24( YUV_ARGS_24BPP )
233 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, bpp = 24" );
236 /*****************************************************************************
237 * ConvertYUV444RGB24: color YUV 4:4:4 to RGB 2 Bpp
238 *****************************************************************************/
239 void ConvertYUV444RGB24( YUV_ARGS_24BPP )
241 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, bpp = 24" );
244 /*****************************************************************************
245 * ConvertY4Gray32: grayscale YUV 4:x:x to RGB 4 Bpp
246 *****************************************************************************/
247 void ConvertY4Gray32( YUV_ARGS_32BPP )
249 intf_ErrMsg( "yuvmmx error: unhandled function, grayscale, bpp = 32" );
253 /*****************************************************************************
254 * ConvertYUV420RGB32: color YUV 4:2:0 to RGB 4 Bpp
255 *****************************************************************************/
256 void ConvertYUV420RGB32( YUV_ARGS_32BPP )
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 */
270 * Initialize some values - i_pic_line_width will store the line skip
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 );
279 i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
280 for( i_y = 0; i_y < i_height; i_y++ )
283 p_buffer = b_horizontal_scaling ? p_buffer_start : p_pic;
285 for ( i_x = i_width / 8; i_x--; )
289 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
295 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
304 SCALE_HEIGHT( 420, 4 );
309 /*****************************************************************************
310 * ConvertYUV422RGB32: color YUV 4:2:2 to RGB 4 Bpp
311 *****************************************************************************/
312 void ConvertYUV422RGB32( YUV_ARGS_32BPP )
314 intf_ErrMsg( "yuv error: unhandled function, chroma = 422, bpp = 32" );
317 /*****************************************************************************
318 * ConvertYUV444RGB32: color YUV 4:4:4 to RGB 4 Bpp
319 *****************************************************************************/
320 void ConvertYUV444RGB32( YUV_ARGS_32BPP )
322 intf_ErrMsg( "yuv error: unhandled function, chroma = 444, bpp = 32" );
325 /*****************************************************************************
326 * ConvertYUV420YCbr8: color YUV 4:2:0 to YCbr 8 Bpp
327 *****************************************************************************/
329 void ConvertYUV420YCbr8 ( YUV_ARGS_8BPP )
331 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, YCbr = 8" );
333 /*****************************************************************************
334 * ConvertYUV422YCbr8: color YUV 4:2:2 to YCbr 8 Bpp
335 *****************************************************************************/
337 void ConvertYUV422YCbr8 ( YUV_ARGS_8BPP )
339 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 8" );
342 /*****************************************************************************
343 * ConvertYUV444YCbr8: color YUV 4:4:4 to YCbr 8 Bpp
344 *****************************************************************************/
345 void ConvertYUV444YCbr8 ( YUV_ARGS_8BPP )
347 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 8" );
350 /*****************************************************************************
351 * ConvertYUV420YCbr16: color YUV 4:2:0 to YCbr 16 Bpp
352 *****************************************************************************/
353 void ConvertYUV420YCbr16 ( YUV_ARGS_16BPP )
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 */
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 );
373 i_scale_count = ( i_vertical_scaling == 1 ) ? i_pic_height : i_height;
374 for( i_y = 0; i_y < i_height; i_y++ )
377 p_buffer = b_horizontal_scaling ? p_buffer_start : p_pic;
379 for ( i_x = i_width / 8; i_x--; )
382 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
386 : : "r" (p_y), "r" (p_u), "r" (p_v), "r" (p_buffer) );
394 SCALE_HEIGHT( 420, 2 );
399 /*****************************************************************************
400 * ConvertYUV422YCbr8: color YUV 4:2:2 to YCbr 16 Bpp
401 *****************************************************************************/
403 void ConvertYUV422YCbr16 ( YUV_ARGS_16BPP )
405 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 16" );
408 /*****************************************************************************
409 * ConvertYUV424YCbr8: color YUV 4:4:4 to YCbr 16 Bpp
410 *****************************************************************************/
412 void ConvertYUV444YCbr16 ( YUV_ARGS_16BPP )
414 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 16" );
417 /*****************************************************************************
418 * ConvertYUV420YCbr24: color YUV 4:2:0 to YCbr 24 Bpp
419 *****************************************************************************/
421 void ConvertYUV420YCbr24 ( YUV_ARGS_24BPP )
423 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, YCbr = 24" );
426 /*****************************************************************************
427 * ConvertYUV422YCbr24: color YUV 4:2:2 to YCbr 24 Bpp
428 *****************************************************************************/
430 void ConvertYUV422YCbr24 ( YUV_ARGS_24BPP )
432 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 24" );
435 /*****************************************************************************
436 * ConvertYUV444YCbr24: color YUV 4:4:4 to YCbr 24 Bpp
437 *****************************************************************************/
439 void ConvertYUV444YCbr24 ( YUV_ARGS_24BPP )
441 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 24" );
444 /*****************************************************************************
445 * ConvertYUV420YCbr32: color YUV 4:2:0 to YCbr 32 Bpp
446 *****************************************************************************/
448 void ConvertYUV420YCbr32 ( YUV_ARGS_32BPP )
450 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 420, YCbr = 32" );
453 /*****************************************************************************
454 * ConvertYUV422YCbr32: color YUV 4:2:2 to YCbr 32 Bpp
455 *****************************************************************************/
457 void ConvertYUV422YCbr32 ( YUV_ARGS_32BPP )
459 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 422, YCbr = 32" );
462 /*****************************************************************************
463 * ConvertYUV444YCbr32: color YUV 4:4:4 to YCbr 32 Bpp
464 *****************************************************************************/
465 void ConvertYUV444YCbr32 ( YUV_ARGS_32BPP )
467 intf_ErrMsg( "yuvmmx error: unhandled function, chroma = 444, YCbr = 32" );