fixing memory overwrite bugs again ...
[libav.git] / postproc / rgb2rgb.c
CommitLineData
fcfbc150 1/*
a3aece93
NK
2 *
3 * rgb2rgb.c, Software RGB to RGB convertor
6611aa83
NK
4 * pluralize by Software PAL8 to RGB convertor
5 * Software YUV to YUV convertor
6 * Software YUV to RGB convertor
a3aece93 7 * Written by Nick Kurshev.
1de97d84 8 * palette & yuv & runtime cpu stuff by Michael (michaelni@gmx.at) (under GPL)
a3aece93 9 */
b234ae81
NK
10#include <inttypes.h>
11#include "../config.h"
12#include "rgb2rgb.h"
1de97d84 13#include "../cpudetect.h"
854288bb 14#include "../mangle.h"
a3aece93 15
1de97d84
MN
16#ifdef ARCH_X86
17#define CAN_COMPILE_X86_ASM
18#endif
19
21316f3c
MN
20#define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
21
1de97d84 22#ifdef CAN_COMPILE_X86_ASM
0d9f3d85
A
23static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL;
24static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
99969243
MN
25static const uint64_t mask32b __attribute__((aligned(8))) = 0x000000FF000000FFULL;
26static const uint64_t mask32g __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
27static const uint64_t mask32r __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
a3aece93 28static const uint64_t mask32 __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL;
74d35835
MN
29static const uint64_t mask24b __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL;
30static const uint64_t mask24g __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL;
31static const uint64_t mask24r __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL;
a3aece93
NK
32static const uint64_t mask24l __attribute__((aligned(8))) = 0x0000000000FFFFFFULL;
33static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL;
2b3eef22
NK
34static const uint64_t mask24hh __attribute__((aligned(8))) = 0xffff000000000000ULL;
35static const uint64_t mask24hhh __attribute__((aligned(8))) = 0xffffffff00000000ULL;
36static const uint64_t mask24hhhh __attribute__((aligned(8))) = 0xffffffffffff0000ULL;
a3aece93
NK
37static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */
38static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */
9b2c28e6 39static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
0d9f3d85
A
40static const uint64_t mask15g __attribute__((aligned(8))) = 0x03E003E003E003E0ULL;
41static const uint64_t mask15r __attribute__((aligned(8))) = 0x7C007C007C007C00ULL;
42#define mask16b mask15b
43static const uint64_t mask16g __attribute__((aligned(8))) = 0x07E007E007E007E0ULL;
44static const uint64_t mask16r __attribute__((aligned(8))) = 0xF800F800F800F800ULL;
53445e83
NK
45static const uint64_t red_16mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
46static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL;
47static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
48static const uint64_t red_15mask __attribute__((aligned(8))) = 0x00007c000000f800ULL;
49static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000007e0ULL;
50static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
21316f3c
MN
51
52#ifdef FAST_BGR2YV12
53static const uint64_t bgr2YCoeff __attribute__((aligned(8))) = 0x000000210041000DULL;
54static const uint64_t bgr2UCoeff __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
55static const uint64_t bgr2VCoeff __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
56#else
57static const uint64_t bgr2YCoeff __attribute__((aligned(8))) = 0x000020E540830C8BULL;
58static const uint64_t bgr2UCoeff __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
59static const uint64_t bgr2VCoeff __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
60#endif
61static const uint64_t bgr2YOffset __attribute__((aligned(8))) = 0x1010101010101010ULL;
62static const uint64_t bgr2UVOffset __attribute__((aligned(8)))= 0x8080808080808080ULL;
63static const uint64_t w1111 __attribute__((aligned(8))) = 0x0001000100010001ULL;
64
99969243
MN
65#if 0
66static volatile uint64_t __attribute__((aligned(8))) b5Dither;
67static volatile uint64_t __attribute__((aligned(8))) g5Dither;
68static volatile uint64_t __attribute__((aligned(8))) g6Dither;
69static volatile uint64_t __attribute__((aligned(8))) r5Dither;
70
71static uint64_t __attribute__((aligned(8))) dither4[2]={
72 0x0103010301030103LL,
73 0x0200020002000200LL,};
74
75static uint64_t __attribute__((aligned(8))) dither8[2]={
76 0x0602060206020602LL,
77 0x0004000400040004LL,};
78#endif
e697a141 79#endif
79811694 80
1de97d84
MN
81#define RGB2YUV_SHIFT 8
82#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
83#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
84#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
85#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
86#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
87#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
88#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
89#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
90#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
91
92//Note: we have C, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
93//Plain C versions
94#undef HAVE_MMX
95#undef HAVE_MMX2
96#undef HAVE_3DNOW
97#undef ARCH_X86
52075cde 98#undef HAVE_SSE2
1de97d84
MN
99#define RENAME(a) a ## _C
100#include "rgb2rgb_template.c"
101
102#ifdef CAN_COMPILE_X86_ASM
103
104//MMX versions
105#undef RENAME
106#define HAVE_MMX
107#undef HAVE_MMX2
108#undef HAVE_3DNOW
52075cde 109#undef HAVE_SSE2
1de97d84
MN
110#define ARCH_X86
111#define RENAME(a) a ## _MMX
112#include "rgb2rgb_template.c"
113
114//MMX2 versions
115#undef RENAME
116#define HAVE_MMX
117#define HAVE_MMX2
118#undef HAVE_3DNOW
52075cde 119#undef HAVE_SSE2
1de97d84
MN
120#define ARCH_X86
121#define RENAME(a) a ## _MMX2
122#include "rgb2rgb_template.c"
123
124//3DNOW versions
125#undef RENAME
126#define HAVE_MMX
127#undef HAVE_MMX2
128#define HAVE_3DNOW
52075cde 129#undef HAVE_SSE2
1de97d84
MN
130#define ARCH_X86
131#define RENAME(a) a ## _3DNow
132#include "rgb2rgb_template.c"
133
134#endif //CAN_COMPILE_X86_ASM
135
996e1a7c 136void rgb24to32(const uint8_t *src,uint8_t *dst,unsigned src_size)
b234ae81 137{
1de97d84
MN
138#ifdef CAN_COMPILE_X86_ASM
139 // ordered per speed fasterst first
140 if(gCpuCaps.hasMMX2)
141 rgb24to32_MMX2(src, dst, src_size);
142 else if(gCpuCaps.has3DNow)
143 rgb24to32_3DNow(src, dst, src_size);
144 else if(gCpuCaps.hasMMX)
145 rgb24to32_MMX(src, dst, src_size);
146 else
0d9f3d85 147#endif
1de97d84 148 rgb24to32_C(src, dst, src_size);
0d9f3d85
A
149}
150
151void rgb15to24(const uint8_t *src,uint8_t *dst,unsigned src_size)
152{
153#ifdef CAN_COMPILE_X86_ASM
154 // ordered per speed fasterst first
155 if(gCpuCaps.hasMMX2)
156 rgb15to24_MMX2(src, dst, src_size);
157 else if(gCpuCaps.has3DNow)
158 rgb15to24_3DNow(src, dst, src_size);
159 else if(gCpuCaps.hasMMX)
160 rgb15to24_MMX(src, dst, src_size);
161 else
49a0c6ee 162#endif
0d9f3d85
A
163 rgb15to24_C(src, dst, src_size);
164}
165
166void rgb16to24(const uint8_t *src,uint8_t *dst,unsigned src_size)
167{
168#ifdef CAN_COMPILE_X86_ASM
169 // ordered per speed fasterst first
170 if(gCpuCaps.hasMMX2)
171 rgb16to24_MMX2(src, dst, src_size);
172 else if(gCpuCaps.has3DNow)
173 rgb16to24_3DNow(src, dst, src_size);
174 else if(gCpuCaps.hasMMX)
175 rgb16to24_MMX(src, dst, src_size);
176 else
177#endif
178 rgb16to24_C(src, dst, src_size);
179}
180
181void rgb15to32(const uint8_t *src,uint8_t *dst,unsigned src_size)
182{
183#ifdef CAN_COMPILE_X86_ASM
184 // ordered per speed fasterst first
185 if(gCpuCaps.hasMMX2)
186 rgb15to32_MMX2(src, dst, src_size);
187 else if(gCpuCaps.has3DNow)
188 rgb15to32_3DNow(src, dst, src_size);
189 else if(gCpuCaps.hasMMX)
190 rgb15to32_MMX(src, dst, src_size);
191 else
192#endif
193 rgb15to32_C(src, dst, src_size);
194}
195
196void rgb16to32(const uint8_t *src,uint8_t *dst,unsigned src_size)
197{
198#ifdef CAN_COMPILE_X86_ASM
199 // ordered per speed fasterst first
200 if(gCpuCaps.hasMMX2)
201 rgb16to32_MMX2(src, dst, src_size);
202 else if(gCpuCaps.has3DNow)
203 rgb16to32_3DNow(src, dst, src_size);
204 else if(gCpuCaps.hasMMX)
205 rgb16to32_MMX(src, dst, src_size);
206 else
207#endif
208 rgb16to32_C(src, dst, src_size);
b234ae81 209}
59ac5a93 210
996e1a7c 211void rgb32to24(const uint8_t *src,uint8_t *dst,unsigned src_size)
59ac5a93 212{
1de97d84
MN
213#ifdef CAN_COMPILE_X86_ASM
214 // ordered per speed fasterst first
215 if(gCpuCaps.hasMMX2)
216 rgb32to24_MMX2(src, dst, src_size);
217 else if(gCpuCaps.has3DNow)
218 rgb32to24_3DNow(src, dst, src_size);
219 else if(gCpuCaps.hasMMX)
220 rgb32to24_MMX(src, dst, src_size);
221 else
494a6294 222#endif
0d9f3d85 223 rgb32to24_C(src, dst, src_size);
59ac5a93 224}
b238eb2e 225
a3aece93
NK
226/*
227 Original by Strepto/Astral
228 ported to gcc & bugfixed : A'rpi
51da31f1 229 MMX2, 3DNOW optimization by Nick Kurshev
9b2c28e6 230 32bit c version, and and&add trick by Michael Niedermayer
a3aece93 231*/
996e1a7c 232void rgb15to16(const uint8_t *src,uint8_t *dst,unsigned src_size)
b238eb2e 233{
1de97d84
MN
234#ifdef CAN_COMPILE_X86_ASM
235 // ordered per speed fasterst first
236 if(gCpuCaps.hasMMX2)
237 rgb15to16_MMX2(src, dst, src_size);
238 else if(gCpuCaps.has3DNow)
239 rgb15to16_3DNow(src, dst, src_size);
240 else if(gCpuCaps.hasMMX)
241 rgb15to16_MMX(src, dst, src_size);
242 else
b238eb2e 243#endif
0d9f3d85 244 rgb15to16_C(src, dst, src_size);
b238eb2e 245}
fcfbc150
MN
246
247/**
248 * Pallete is assumed to contain bgr32
249 */
996e1a7c 250void palette8torgb32(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
fcfbc150 251{
996e1a7c 252 unsigned i;
4060205b 253 for(i=0; i<num_pixels; i++)
996e1a7c 254 ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ];
fcfbc150
MN
255}
256
9ce6584e
MN
257/**
258 * Pallete is assumed to contain bgr32
259 */
996e1a7c 260void palette8torgb24(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
9ce6584e 261{
996e1a7c 262 unsigned i;
9ce6584e
MN
263/*
264 writes 1 byte o much and might cause alignment issues on some architectures?
4060205b 265 for(i=0; i<num_pixels; i++)
996e1a7c 266 ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
9ce6584e 267*/
4060205b 268 for(i=0; i<num_pixels; i++)
9ce6584e
MN
269 {
270 //FIXME slow?
271 dst[0]= palette[ src[i]*4+0 ];
272 dst[1]= palette[ src[i]*4+1 ];
273 dst[2]= palette[ src[i]*4+2 ];
274 dst+= 3;
275 }
276}
277
d661d18d
AB
278void bgr24torgb24(const uint8_t *src, uint8_t *dst, unsigned src_size)
279{
280#ifdef CAN_COMPILE_X86_ASM
281 // ordered per speed fasterst first
282 if(gCpuCaps.hasMMX2)
283 bgr24torgb24_MMX2(src, dst, src_size);
284 else if(gCpuCaps.has3DNow)
285 bgr24torgb24_3DNow(src, dst, src_size);
286 else if(gCpuCaps.hasMMX)
287 bgr24torgb24_MMX(src, dst, src_size);
288 else
289 bgr24torgb24_C(src, dst, src_size);
290#else
291 bgr24torgb24_C(src, dst, src_size);
292#endif
293}
294
996e1a7c 295void rgb32to16(const uint8_t *src, uint8_t *dst, unsigned src_size)
fcfbc150 296{
1de97d84
MN
297#ifdef CAN_COMPILE_X86_ASM
298 // ordered per speed fasterst first
299 if(gCpuCaps.hasMMX2)
300 rgb32to16_MMX2(src, dst, src_size);
301 else if(gCpuCaps.has3DNow)
302 rgb32to16_3DNow(src, dst, src_size);
303 else if(gCpuCaps.hasMMX)
304 rgb32to16_MMX(src, dst, src_size);
305 else
53445e83 306#endif
0d9f3d85 307 rgb32to16_C(src, dst, src_size);
fcfbc150
MN
308}
309
996e1a7c 310void rgb32to15(const uint8_t *src, uint8_t *dst, unsigned src_size)
fcfbc150 311{
1de97d84
MN
312#ifdef CAN_COMPILE_X86_ASM
313 // ordered per speed fasterst first
314 if(gCpuCaps.hasMMX2)
315 rgb32to15_MMX2(src, dst, src_size);
316 else if(gCpuCaps.has3DNow)
317 rgb32to15_3DNow(src, dst, src_size);
318 else if(gCpuCaps.hasMMX)
319 rgb32to15_MMX(src, dst, src_size);
320 else
53445e83 321#endif
0d9f3d85 322 rgb32to15_C(src, dst, src_size);
fcfbc150
MN
323}
324
996e1a7c
NK
325void rgb24to16(const uint8_t *src, uint8_t *dst, unsigned src_size)
326{
1de97d84
MN
327#ifdef CAN_COMPILE_X86_ASM
328 // ordered per speed fasterst first
329 if(gCpuCaps.hasMMX2)
330 rgb24to16_MMX2(src, dst, src_size);
331 else if(gCpuCaps.has3DNow)
332 rgb24to16_3DNow(src, dst, src_size);
333 else if(gCpuCaps.hasMMX)
334 rgb24to16_MMX(src, dst, src_size);
335 else
3eb2151c 336#endif
0d9f3d85 337 rgb24to16_C(src, dst, src_size);
996e1a7c
NK
338}
339
340void rgb24to15(const uint8_t *src, uint8_t *dst, unsigned src_size)
341{
1de97d84
MN
342#ifdef CAN_COMPILE_X86_ASM
343 // ordered per speed fasterst first
344 if(gCpuCaps.hasMMX2)
345 rgb24to15_MMX2(src, dst, src_size);
346 else if(gCpuCaps.has3DNow)
347 rgb24to15_3DNow(src, dst, src_size);
348 else if(gCpuCaps.hasMMX)
349 rgb24to15_MMX(src, dst, src_size);
350 else
53445e83 351#endif
0d9f3d85 352 rgb24to15_C(src, dst, src_size);
996e1a7c 353}
fcfbc150
MN
354
355/**
356 * Palette is assumed to contain bgr16, see rgb32to16 to convert the palette
357 */
996e1a7c 358void palette8torgb16(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
fcfbc150 359{
996e1a7c 360 unsigned i;
4060205b 361 for(i=0; i<num_pixels; i++)
fcfbc150
MN
362 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
363}
364
365/**
366 * Pallete is assumed to contain bgr15, see rgb32to15 to convert the palette
367 */
996e1a7c 368void palette8torgb15(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
fcfbc150 369{
996e1a7c 370 unsigned i;
4060205b 371 for(i=0; i<num_pixels; i++)
fcfbc150 372 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
9ce6584e 373}
99969243
MN
374
375void rgb32tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
376{
1de97d84
MN
377#ifdef CAN_COMPILE_X86_ASM
378 // ordered per speed fasterst first
379 if(gCpuCaps.hasMMX2)
380 rgb32tobgr32_MMX2(src, dst, src_size);
381 else if(gCpuCaps.has3DNow)
382 rgb32tobgr32_3DNow(src, dst, src_size);
383 else if(gCpuCaps.hasMMX)
384 rgb32tobgr32_MMX(src, dst, src_size);
385 else
99969243 386#endif
0d9f3d85 387 rgb32tobgr32_C(src, dst, src_size);
99969243
MN
388}
389
74d35835
MN
390void rgb24tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
391{
392#ifdef CAN_COMPILE_X86_ASM
393 // ordered per speed fasterst first
394 if(gCpuCaps.hasMMX2)
395 rgb24tobgr24_MMX2(src, dst, src_size);
396 else if(gCpuCaps.has3DNow)
397 rgb24tobgr24_3DNow(src, dst, src_size);
398 else if(gCpuCaps.hasMMX)
399 rgb24tobgr24_MMX(src, dst, src_size);
400 else
74d35835 401#endif
0d9f3d85 402 rgb24tobgr24_C(src, dst, src_size);
74d35835
MN
403}
404
4060205b
MN
405/**
406 *
dabcdbc4
MN
407 * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
408 * problem for anyone then tell me, and ill fix it)
4060205b 409 */
42b5fcb8 410void yv12toyuy2(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
cfc15dc6
MN
411 unsigned int width, unsigned int height,
412 unsigned int lumStride, unsigned int chromStride, unsigned int dstStride)
d9d58d17 413{
1de97d84
MN
414#ifdef CAN_COMPILE_X86_ASM
415 // ordered per speed fasterst first
416 if(gCpuCaps.hasMMX2)
417 yv12toyuy2_MMX2(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
418 else if(gCpuCaps.has3DNow)
419 yv12toyuy2_3DNow(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
420 else if(gCpuCaps.hasMMX)
421 yv12toyuy2_MMX(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
422 else
4060205b 423#endif
0d9f3d85 424 yv12toyuy2_C(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
d9d58d17
MN
425}
426
dabcdbc4
MN
427/**
428 *
b1ec5875
MN
429 * width should be a multiple of 16
430 */
431void yuv422ptoyuy2(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
432 unsigned int width, unsigned int height,
433 unsigned int lumStride, unsigned int chromStride, unsigned int dstStride)
434{
435#ifdef CAN_COMPILE_X86_ASM
436 // ordered per speed fasterst first
437 if(gCpuCaps.hasMMX2)
438 yuv422ptoyuy2_MMX2(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
439 else if(gCpuCaps.has3DNow)
440 yuv422ptoyuy2_3DNow(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
441 else if(gCpuCaps.hasMMX)
442 yuv422ptoyuy2_MMX(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
443 else
b1ec5875 444#endif
0d9f3d85 445 yuv422ptoyuy2_C(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride);
b1ec5875
MN
446}
447
448/**
449 *
dabcdbc4
MN
450 * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
451 * problem for anyone then tell me, and ill fix it)
452 */
453void yuy2toyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
cfc15dc6
MN
454 unsigned int width, unsigned int height,
455 unsigned int lumStride, unsigned int chromStride, unsigned int srcStride)
d9d58d17 456{
1de97d84
MN
457#ifdef CAN_COMPILE_X86_ASM
458 // ordered per speed fasterst first
459 if(gCpuCaps.hasMMX2)
460 yuy2toyv12_MMX2(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
461 else if(gCpuCaps.has3DNow)
462 yuy2toyv12_3DNow(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
463 else if(gCpuCaps.hasMMX)
464 yuy2toyv12_MMX(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
465 else
bd09433f 466#endif
0d9f3d85 467 yuy2toyv12_C(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
42b5fcb8 468}
81c0590e
A
469
470/**
471 *
472 * height should be a multiple of 2 and width should be a multiple of 16 (if this is a
473 * problem for anyone then tell me, and ill fix it)
1de97d84 474 * chrominance data is only taken from every secound line others are ignored FIXME write HQ version
81c0590e
A
475 */
476void uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
477 unsigned int width, unsigned int height,
478 unsigned int lumStride, unsigned int chromStride, unsigned int srcStride)
479{
1de97d84
MN
480#ifdef CAN_COMPILE_X86_ASM
481 // ordered per speed fasterst first
482 if(gCpuCaps.hasMMX2)
483 uyvytoyv12_MMX2(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
484 else if(gCpuCaps.has3DNow)
485 uyvytoyv12_3DNow(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
486 else if(gCpuCaps.hasMMX)
487 uyvytoyv12_MMX(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
488 else
489 uyvytoyv12_C(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
ed8c0670 490#else
1de97d84 491 uyvytoyv12_C(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
ed8c0670 492#endif
81c0590e
A
493}
494
d661d18d
AB
495void yvu9toyv12(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc,
496 uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
497 unsigned int width, unsigned int height,
498 unsigned int lumStride, unsigned int chromStride)
499{
500#ifdef CAN_COMPILE_X86_ASM
501 // ordered per speed fasterst first
502 if(gCpuCaps.hasMMX2)
503 yvu9toyv12_MMX2(ysrc, usrc, vsrc, ydst, udst, vdst, width, height, lumStride, chromStride);
504 else if(gCpuCaps.has3DNow)
505 yvu9toyv12_3DNow(ysrc, usrc, vsrc, ydst, udst, vdst, width, height, lumStride, chromStride);
506 else if(gCpuCaps.hasMMX)
507 yvu9toyv12_MMX(ysrc, usrc, vsrc, ydst, udst, vdst, width, height, lumStride, chromStride);
508 else
509 yvu9toyv12_C(ysrc, usrc, vsrc, ydst, udst, vdst, width, height, lumStride, chromStride);
510#else
511 yvu9toyv12_C(ysrc, usrc, vsrc, ydst, udst, vdst, width, height, lumStride, chromStride);
512#endif
513}
514
b241cbf2
MN
515void planar2x(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride)
516{
517#ifdef CAN_COMPILE_X86_ASM
518 // ordered per speed fasterst first
519 if(gCpuCaps.hasMMX2)
520 planar2x_MMX2(src, dst, width, height, srcStride, dstStride);
521 else if(gCpuCaps.has3DNow)
522 planar2x_3DNow(src, dst, width, height, srcStride, dstStride);
523 else
524#endif
525 planar2x_C(src, dst, width, height, srcStride, dstStride);
526}
527
1de97d84
MN
528/**
529 *
530 * height should be a multiple of 2 and width should be a multiple of 2 (if this is a
531 * problem for anyone then tell me, and ill fix it)
532 * chrominance data is only taken from every secound line others are ignored FIXME write HQ version
533 */
534void rgb24toyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
535 unsigned int width, unsigned int height,
536 unsigned int lumStride, unsigned int chromStride, unsigned int srcStride)
537{
538#ifdef CAN_COMPILE_X86_ASM
539 // ordered per speed fasterst first
540 if(gCpuCaps.hasMMX2)
541 rgb24toyv12_MMX2(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
542 else if(gCpuCaps.has3DNow)
543 rgb24toyv12_3DNow(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
544 else if(gCpuCaps.hasMMX)
545 rgb24toyv12_MMX(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
546 else
1de97d84 547#endif
0d9f3d85 548 rgb24toyv12_C(src, ydst, udst, vdst, width, height, lumStride, chromStride, srcStride);
1de97d84 549}
5d55fdb4
MN
550
551void interleaveBytes(uint8_t *src1, uint8_t *src2, uint8_t *dst,
0d9f3d85
A
552 unsigned width, unsigned height, unsigned src1Stride,
553 unsigned src2Stride, unsigned dstStride)
5d55fdb4
MN
554{
555#ifdef CAN_COMPILE_X86_ASM
556 // ordered per speed fasterst first
557 if(gCpuCaps.hasMMX2)
558 interleaveBytes_MMX2(src1, src2, dst, width, height, src1Stride, src2Stride, dstStride);
559 else if(gCpuCaps.has3DNow)
560 interleaveBytes_3DNow(src1, src2, dst, width, height, src1Stride, src2Stride, dstStride);
561 else if(gCpuCaps.hasMMX)
562 interleaveBytes_MMX(src1, src2, dst, width, height, src1Stride, src2Stride, dstStride);
563 else
5d55fdb4 564#endif
0d9f3d85 565 interleaveBytes_C(src1, src2, dst, width, height, src1Stride, src2Stride, dstStride);
5d55fdb4 566}