FFmpeg  1.2.12
swscale.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <inttypes.h>
22 #include "config.h"
23 #include "libswscale/swscale.h"
25 #include "libavutil/attributes.h"
26 #include "libavutil/avassert.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/x86/asm.h"
29 #include "libavutil/x86/cpu.h"
30 #include "libavutil/cpu.h"
31 #include "libavutil/pixdesc.h"
32 
33 #if HAVE_INLINE_ASM
34 
35 #define DITHER1XBPP
36 
37 DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL;
38 DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL;
39 DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL;
40 DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL;
41 
42 const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = {
43  0x0103010301030103LL,
44  0x0200020002000200LL,};
45 
46 const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = {
47  0x0602060206020602LL,
48  0x0004000400040004LL,};
49 
50 DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL;
51 DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL;
52 DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL;
53 DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL;
54 DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL;
55 DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL;
56 
57 DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL;
58 DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL;
59 DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL;
60 
61 #ifdef FAST_BGR2YV12
62 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL;
63 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL;
64 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL;
65 #else
66 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL;
67 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL;
68 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL;
69 #endif /* FAST_BGR2YV12 */
70 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL;
71 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL;
72 DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL;
73 
74 
75 //MMX versions
76 #if HAVE_MMX_INLINE
77 #undef RENAME
78 #define COMPILE_TEMPLATE_MMXEXT 0
79 #define RENAME(a) a ## _MMX
80 #include "swscale_template.c"
81 #endif
82 
83 // MMXEXT versions
84 #if HAVE_MMXEXT_INLINE
85 #undef RENAME
86 #undef COMPILE_TEMPLATE_MMXEXT
87 #define COMPILE_TEMPLATE_MMXEXT 1
88 #define RENAME(a) a ## _MMXEXT
89 #include "swscale_template.c"
90 #endif
91 
93  int lastInLumBuf, int lastInChrBuf)
94 {
95  const int dstH= c->dstH;
96  const int flags= c->flags;
97  int16_t **lumPixBuf= c->lumPixBuf;
98  int16_t **chrUPixBuf= c->chrUPixBuf;
99  int16_t **alpPixBuf= c->alpPixBuf;
100  const int vLumBufSize= c->vLumBufSize;
101  const int vChrBufSize= c->vChrBufSize;
104  int16_t *vLumFilter= c->vLumFilter;
105  int16_t *vChrFilter= c->vChrFilter;
109  const int vLumFilterSize= c->vLumFilterSize;
110  const int vChrFilterSize= c->vChrFilterSize;
111  const int chrDstY= dstY>>c->chrDstVSubSample;
112  const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
113  const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
114 
115  c->blueDither= ff_dither8[dstY&1];
117  c->greenDither= ff_dither8[dstY&1];
118  else
119  c->greenDither= ff_dither4[dstY&1];
120  c->redDither= ff_dither8[(dstY+1)&1];
121  if (dstY < dstH - 2) {
122  const int16_t **lumSrcPtr= (const int16_t **)(void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
123  const int16_t **chrUSrcPtr= (const int16_t **)(void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
124  const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
125  int i;
126 
127  if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {
128  const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize;
129  int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);
130  for (i = 0; i < neg; i++)
131  tmpY[i] = lumSrcPtr[neg];
132  for ( ; i < end; i++)
133  tmpY[i] = lumSrcPtr[i];
134  for ( ; i < vLumFilterSize; i++)
135  tmpY[i] = tmpY[i-1];
136  lumSrcPtr = tmpY;
137 
138  if (alpSrcPtr) {
139  const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize;
140  for (i = 0; i < neg; i++)
141  tmpA[i] = alpSrcPtr[neg];
142  for ( ; i < end; i++)
143  tmpA[i] = alpSrcPtr[i];
144  for ( ; i < vLumFilterSize; i++)
145  tmpA[i] = tmpA[i - 1];
146  alpSrcPtr = tmpA;
147  }
148  }
149  if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {
150  const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize;
151  int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);
152  for (i = 0; i < neg; i++) {
153  tmpU[i] = chrUSrcPtr[neg];
154  }
155  for ( ; i < end; i++) {
156  tmpU[i] = chrUSrcPtr[i];
157  }
158  for ( ; i < vChrFilterSize; i++) {
159  tmpU[i] = tmpU[i - 1];
160  }
161  chrUSrcPtr = tmpU;
162  }
163 
164  if (flags & SWS_ACCURATE_RND) {
165  int s= APCK_SIZE / 8;
166  for (i=0; i<vLumFilterSize; i+=2) {
167  *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
168  *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
169  lumMmxFilter[s*i+APCK_COEF/4 ]=
170  lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ]
171  + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
172  if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
173  *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ];
174  *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)];
175  alpMmxFilter[s*i+APCK_COEF/4 ]=
176  alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ];
177  }
178  }
179  for (i=0; i<vChrFilterSize; i+=2) {
180  *(const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
181  *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
182  chrMmxFilter[s*i+APCK_COEF/4 ]=
183  chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
184  + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
185  }
186  } else {
187  for (i=0; i<vLumFilterSize; i++) {
188  *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
189  lumMmxFilter[4*i+2]=
190  lumMmxFilter[4*i+3]=
191  ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001U;
192  if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
193  *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
194  alpMmxFilter[4*i+2]=
195  alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
196  }
197  }
198  for (i=0; i<vChrFilterSize; i++) {
199  *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
200  chrMmxFilter[4*i+2]=
201  chrMmxFilter[4*i+3]=
202  ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001U;
203  }
204  }
205  }
206 }
207 
208 #if HAVE_MMXEXT
209 static void yuv2yuvX_sse3(const int16_t *filter, int filterSize,
210  const int16_t **src, uint8_t *dest, int dstW,
211  const uint8_t *dither, int offset)
212 {
213  if(((int)dest) & 15){
214  return yuv2yuvX_MMXEXT(filter, filterSize, src, dest, dstW, dither, offset);
215  }
216  if (offset) {
217  __asm__ volatile("movq (%0), %%xmm3\n\t"
218  "movdqa %%xmm3, %%xmm4\n\t"
219  "psrlq $24, %%xmm3\n\t"
220  "psllq $40, %%xmm4\n\t"
221  "por %%xmm4, %%xmm3\n\t"
222  :: "r"(dither)
223  );
224  } else {
225  __asm__ volatile("movq (%0), %%xmm3\n\t"
226  :: "r"(dither)
227  );
228  }
229  filterSize--;
230  __asm__ volatile(
231  "pxor %%xmm0, %%xmm0\n\t"
232  "punpcklbw %%xmm0, %%xmm3\n\t"
233  "movd %0, %%xmm1\n\t"
234  "punpcklwd %%xmm1, %%xmm1\n\t"
235  "punpckldq %%xmm1, %%xmm1\n\t"
236  "punpcklqdq %%xmm1, %%xmm1\n\t"
237  "psllw $3, %%xmm1\n\t"
238  "paddw %%xmm1, %%xmm3\n\t"
239  "psraw $4, %%xmm3\n\t"
240  ::"m"(filterSize)
241  );
242  __asm__ volatile(
243  "movdqa %%xmm3, %%xmm4\n\t"
244  "movdqa %%xmm3, %%xmm7\n\t"
245  "movl %3, %%ecx\n\t"
246  "mov %0, %%"REG_d" \n\t"\
247  "mov (%%"REG_d"), %%"REG_S" \n\t"\
248  ".p2align 4 \n\t" /* FIXME Unroll? */\
249  "1: \n\t"\
250  "movddup 8(%%"REG_d"), %%xmm0 \n\t" /* filterCoeff */\
251  "movdqa (%%"REG_S", %%"REG_c", 2), %%xmm2 \n\t" /* srcData */\
252  "movdqa 16(%%"REG_S", %%"REG_c", 2), %%xmm5 \n\t" /* srcData */\
253  "add $16, %%"REG_d" \n\t"\
254  "mov (%%"REG_d"), %%"REG_S" \n\t"\
255  "test %%"REG_S", %%"REG_S" \n\t"\
256  "pmulhw %%xmm0, %%xmm2 \n\t"\
257  "pmulhw %%xmm0, %%xmm5 \n\t"\
258  "paddw %%xmm2, %%xmm3 \n\t"\
259  "paddw %%xmm5, %%xmm4 \n\t"\
260  " jnz 1b \n\t"\
261  "psraw $3, %%xmm3 \n\t"\
262  "psraw $3, %%xmm4 \n\t"\
263  "packuswb %%xmm4, %%xmm3 \n\t"
264  "movntdq %%xmm3, (%1, %%"REG_c")\n\t"
265  "add $16, %%"REG_c" \n\t"\
266  "cmp %2, %%"REG_c" \n\t"\
267  "movdqa %%xmm7, %%xmm3\n\t"
268  "movdqa %%xmm7, %%xmm4\n\t"
269  "mov %0, %%"REG_d" \n\t"\
270  "mov (%%"REG_d"), %%"REG_S" \n\t"\
271  "jb 1b \n\t"\
272  :: "g" (filter),
273  "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset)
274  : XMM_CLOBBERS("%xmm0" , "%xmm1" , "%xmm2" , "%xmm3" , "%xmm4" , "%xmm5" , "%xmm7" ,)
275  "%"REG_d, "%"REG_S, "%"REG_c
276  );
277 }
278 #endif
279 
280 #endif /* HAVE_INLINE_ASM */
281 
282 #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
283 extern void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
284  SwsContext *c, int16_t *data, \
285  int dstW, const uint8_t *src, \
286  const int16_t *filter, \
287  const int32_t *filterPos, int filterSize)
288 
289 #define SCALE_FUNCS(filter_n, opt) \
290  SCALE_FUNC(filter_n, 8, 15, opt); \
291  SCALE_FUNC(filter_n, 9, 15, opt); \
292  SCALE_FUNC(filter_n, 10, 15, opt); \
293  SCALE_FUNC(filter_n, 12, 15, opt); \
294  SCALE_FUNC(filter_n, 14, 15, opt); \
295  SCALE_FUNC(filter_n, 16, 15, opt); \
296  SCALE_FUNC(filter_n, 8, 19, opt); \
297  SCALE_FUNC(filter_n, 9, 19, opt); \
298  SCALE_FUNC(filter_n, 10, 19, opt); \
299  SCALE_FUNC(filter_n, 12, 19, opt); \
300  SCALE_FUNC(filter_n, 14, 19, opt); \
301  SCALE_FUNC(filter_n, 16, 19, opt)
302 
303 #define SCALE_FUNCS_MMX(opt) \
304  SCALE_FUNCS(4, opt); \
305  SCALE_FUNCS(8, opt); \
306  SCALE_FUNCS(X, opt)
307 
308 #define SCALE_FUNCS_SSE(opt) \
309  SCALE_FUNCS(4, opt); \
310  SCALE_FUNCS(8, opt); \
311  SCALE_FUNCS(X4, opt); \
312  SCALE_FUNCS(X8, opt)
313 
314 #if ARCH_X86_32
315 SCALE_FUNCS_MMX(mmx);
316 #endif
317 SCALE_FUNCS_SSE(sse2);
318 SCALE_FUNCS_SSE(ssse3);
319 SCALE_FUNCS_SSE(sse4);
320 
321 #define VSCALEX_FUNC(size, opt) \
322 extern void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
323  const int16_t **src, uint8_t *dest, int dstW, \
324  const uint8_t *dither, int offset)
325 #define VSCALEX_FUNCS(opt) \
326  VSCALEX_FUNC(8, opt); \
327  VSCALEX_FUNC(9, opt); \
328  VSCALEX_FUNC(10, opt)
329 
330 #if ARCH_X86_32
331 VSCALEX_FUNCS(mmxext);
332 #endif
333 VSCALEX_FUNCS(sse2);
334 VSCALEX_FUNCS(sse4);
335 VSCALEX_FUNC(16, sse4);
336 VSCALEX_FUNCS(avx);
337 
338 #define VSCALE_FUNC(size, opt) \
339 extern void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
340  const uint8_t *dither, int offset)
341 #define VSCALE_FUNCS(opt1, opt2) \
342  VSCALE_FUNC(8, opt1); \
343  VSCALE_FUNC(9, opt2); \
344  VSCALE_FUNC(10, opt2); \
345  VSCALE_FUNC(16, opt1)
346 
347 #if ARCH_X86_32
348 VSCALE_FUNCS(mmx, mmxext);
349 #endif
350 VSCALE_FUNCS(sse2, sse2);
351 VSCALE_FUNC(16, sse4);
352 VSCALE_FUNCS(avx, avx);
353 
354 #define INPUT_Y_FUNC(fmt, opt) \
355 extern void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
356  const uint8_t *unused1, const uint8_t *unused2, \
357  int w, uint32_t *unused)
358 #define INPUT_UV_FUNC(fmt, opt) \
359 extern void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
360  const uint8_t *unused0, \
361  const uint8_t *src1, \
362  const uint8_t *src2, \
363  int w, uint32_t *unused)
364 #define INPUT_FUNC(fmt, opt) \
365  INPUT_Y_FUNC(fmt, opt); \
366  INPUT_UV_FUNC(fmt, opt)
367 #define INPUT_FUNCS(opt) \
368  INPUT_FUNC(uyvy, opt); \
369  INPUT_FUNC(yuyv, opt); \
370  INPUT_UV_FUNC(nv12, opt); \
371  INPUT_UV_FUNC(nv21, opt); \
372  INPUT_FUNC(rgba, opt); \
373  INPUT_FUNC(bgra, opt); \
374  INPUT_FUNC(argb, opt); \
375  INPUT_FUNC(abgr, opt); \
376  INPUT_FUNC(rgb24, opt); \
377  INPUT_FUNC(bgr24, opt)
378 
379 #if ARCH_X86_32
380 INPUT_FUNCS(mmx);
381 #endif
382 INPUT_FUNCS(sse2);
383 INPUT_FUNCS(ssse3);
384 INPUT_FUNCS(avx);
385 
387 {
388  int cpu_flags = av_get_cpu_flags();
389 
390 #if HAVE_INLINE_ASM
391  if (cpu_flags & AV_CPU_FLAG_MMX)
392  sws_init_swScale_MMX(c);
393 #if HAVE_MMXEXT_INLINE
394  if (cpu_flags & AV_CPU_FLAG_MMXEXT)
395  sws_init_swScale_MMXEXT(c);
396  if (cpu_flags & AV_CPU_FLAG_SSE3){
397  if(c->use_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND))
398  c->yuv2planeX = yuv2yuvX_sse3;
399  }
400 #endif
401 #endif /* HAVE_INLINE_ASM */
402 
403 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
404  if (c->srcBpc == 8) { \
405  hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
406  ff_hscale8to19_ ## filtersize ## _ ## opt1; \
407  } else if (c->srcBpc == 9) { \
408  hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
409  ff_hscale9to19_ ## filtersize ## _ ## opt1; \
410  } else if (c->srcBpc == 10) { \
411  hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
412  ff_hscale10to19_ ## filtersize ## _ ## opt1; \
413  } else if (c->srcBpc == 12) { \
414  hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
415  ff_hscale12to19_ ## filtersize ## _ ## opt1; \
416  } else if (c->srcBpc == 14 || ((c->srcFormat==AV_PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_desc_get(c->srcFormat)->comp[0].depth_minus1<15)) { \
417  hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
418  ff_hscale14to19_ ## filtersize ## _ ## opt1; \
419  } else { /* c->srcBpc == 16 */ \
420  av_assert0(c->srcBpc == 16);\
421  hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
422  ff_hscale16to19_ ## filtersize ## _ ## opt1; \
423  } \
424 } while (0)
425 #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
426  switch (filtersize) { \
427  case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
428  case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
429  default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
430  }
431 #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
432 switch(c->dstBpc){ \
433  case 16: do_16_case; break; \
434  case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
435  case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
436  default: if (condition_8bit) /*vscalefn = ff_yuv2planeX_8_ ## opt;*/ break; \
437  }
438 #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
439  switch(c->dstBpc){ \
440  case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
441  case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
442  case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
443  case 8: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
444  default: av_assert0(c->dstBpc>8); \
445  }
446 #define case_rgb(x, X, opt) \
447  case AV_PIX_FMT_ ## X: \
448  c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
449  if (!c->chrSrcHSubSample) \
450  c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
451  break
452 #if ARCH_X86_32
453  if (EXTERNAL_MMX(cpu_flags)) {
454  ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
455  ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
456  ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmxext, cpu_flags & AV_CPU_FLAG_MMXEXT);
457 
458  switch (c->srcFormat) {
459  case AV_PIX_FMT_Y400A:
460  c->lumToYV12 = ff_yuyvToY_mmx;
461  if (c->alpPixBuf)
462  c->alpToYV12 = ff_uyvyToY_mmx;
463  break;
464  case AV_PIX_FMT_YUYV422:
465  c->lumToYV12 = ff_yuyvToY_mmx;
466  c->chrToYV12 = ff_yuyvToUV_mmx;
467  break;
468  case AV_PIX_FMT_UYVY422:
469  c->lumToYV12 = ff_uyvyToY_mmx;
470  c->chrToYV12 = ff_uyvyToUV_mmx;
471  break;
472  case AV_PIX_FMT_NV12:
473  c->chrToYV12 = ff_nv12ToUV_mmx;
474  break;
475  case AV_PIX_FMT_NV21:
476  c->chrToYV12 = ff_nv21ToUV_mmx;
477  break;
478  case_rgb(rgb24, RGB24, mmx);
479  case_rgb(bgr24, BGR24, mmx);
480  case_rgb(bgra, BGRA, mmx);
481  case_rgb(rgba, RGBA, mmx);
482  case_rgb(abgr, ABGR, mmx);
483  case_rgb(argb, ARGB, mmx);
484  default:
485  break;
486  }
487  }
488  if (EXTERNAL_MMXEXT(cpu_flags)) {
489  ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmxext, , 1);
490  }
491 #endif /* ARCH_X86_32 */
492 #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
493  switch (filtersize) { \
494  case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
495  case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
496  default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
497  else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
498  break; \
499  }
500  if (EXTERNAL_SSE2(cpu_flags)) {
501  ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
502  ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
503  ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, ,
505  ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1);
506 
507  switch (c->srcFormat) {
508  case AV_PIX_FMT_Y400A:
509  c->lumToYV12 = ff_yuyvToY_sse2;
510  if (c->alpPixBuf)
511  c->alpToYV12 = ff_uyvyToY_sse2;
512  break;
513  case AV_PIX_FMT_YUYV422:
514  c->lumToYV12 = ff_yuyvToY_sse2;
515  c->chrToYV12 = ff_yuyvToUV_sse2;
516  break;
517  case AV_PIX_FMT_UYVY422:
518  c->lumToYV12 = ff_uyvyToY_sse2;
519  c->chrToYV12 = ff_uyvyToUV_sse2;
520  break;
521  case AV_PIX_FMT_NV12:
522  c->chrToYV12 = ff_nv12ToUV_sse2;
523  break;
524  case AV_PIX_FMT_NV21:
525  c->chrToYV12 = ff_nv21ToUV_sse2;
526  break;
527  case_rgb(rgb24, RGB24, sse2);
528  case_rgb(bgr24, BGR24, sse2);
529  case_rgb(bgra, BGRA, sse2);
530  case_rgb(rgba, RGBA, sse2);
531  case_rgb(abgr, ABGR, sse2);
532  case_rgb(argb, ARGB, sse2);
533  default:
534  break;
535  }
536  }
537  if (EXTERNAL_SSSE3(cpu_flags)) {
538  ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
539  ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
540  switch (c->srcFormat) {
541  case_rgb(rgb24, RGB24, ssse3);
542  case_rgb(bgr24, BGR24, ssse3);
543  default:
544  break;
545  }
546  }
547  if (EXTERNAL_SSE4(cpu_flags)) {
548  /* Xto15 don't need special sse4 functions */
549  ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
550  ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
552  if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4,
554  if (c->dstBpc == 16 && !isBE(c->dstFormat))
555  c->yuv2plane1 = ff_yuv2plane1_16_sse4;
556  }
557 
558  if (EXTERNAL_AVX(cpu_flags)) {
561  ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1);
562 
563  switch (c->srcFormat) {
564  case AV_PIX_FMT_YUYV422:
565  c->chrToYV12 = ff_yuyvToUV_avx;
566  break;
567  case AV_PIX_FMT_UYVY422:
568  c->chrToYV12 = ff_uyvyToUV_avx;
569  break;
570  case AV_PIX_FMT_NV12:
571  c->chrToYV12 = ff_nv12ToUV_avx;
572  break;
573  case AV_PIX_FMT_NV21:
574  c->chrToYV12 = ff_nv21ToUV_avx;
575  break;
576  case_rgb(rgb24, RGB24, avx);
577  case_rgb(bgr24, BGR24, avx);
578  case_rgb(bgra, BGRA, avx);
579  case_rgb(rgba, RGBA, avx);
580  case_rgb(abgr, ABGR, avx);
581  case_rgb(argb, ARGB, avx);
582  default:
583  break;
584  }
585  }
586 }