FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL;
62 DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL;
63 DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL;
64 
65 
66 //MMX versions
67 #if HAVE_MMX_INLINE
68 #undef RENAME
69 #define COMPILE_TEMPLATE_MMXEXT 0
70 #define RENAME(a) a ## _mmx
71 #include "swscale_template.c"
72 #endif
73 
74 // MMXEXT versions
75 #if HAVE_MMXEXT_INLINE
76 #undef RENAME
77 #undef COMPILE_TEMPLATE_MMXEXT
78 #define COMPILE_TEMPLATE_MMXEXT 1
79 #define RENAME(a) a ## _mmxext
80 #include "swscale_template.c"
81 #endif
82 
83 void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex,
84  int lastInLumBuf, int lastInChrBuf)
85 {
86  const int dstH= c->dstH;
87  const int flags= c->flags;
88 
89  SwsPlane *lumPlane = &c->slice[c->numSlice-2].plane[0];
90  SwsPlane *chrUPlane = &c->slice[c->numSlice-2].plane[1];
91  SwsPlane *alpPlane = &c->slice[c->numSlice-2].plane[3];
92 
93  int hasAlpha = c->needAlpha;
94  int32_t *vLumFilterPos= c->vLumFilterPos;
95  int32_t *vChrFilterPos= c->vChrFilterPos;
96  int16_t *vLumFilter= c->vLumFilter;
97  int16_t *vChrFilter= c->vChrFilter;
98  int32_t *lumMmxFilter= c->lumMmxFilter;
99  int32_t *chrMmxFilter= c->chrMmxFilter;
100  int32_t av_unused *alpMmxFilter= c->alpMmxFilter;
101  const int vLumFilterSize= c->vLumFilterSize;
102  const int vChrFilterSize= c->vChrFilterSize;
103  const int chrDstY= dstY>>c->chrDstVSubSample;
104  const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input
105  const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input
106 
107  c->blueDither= ff_dither8[dstY&1];
109  c->greenDither= ff_dither8[dstY&1];
110  else
111  c->greenDither= ff_dither4[dstY&1];
112  c->redDither= ff_dither8[(dstY+1)&1];
113  if (dstY < dstH - 2) {
114  const int16_t **lumSrcPtr = (const int16_t **)(void*) lumPlane->line + firstLumSrcY - lumPlane->sliceY;
115  const int16_t **chrUSrcPtr = (const int16_t **)(void*) chrUPlane->line + firstChrSrcY - chrUPlane->sliceY;
116  const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && hasAlpha) ? (const int16_t **)(void*) alpPlane->line + firstLumSrcY - alpPlane->sliceY : NULL;
117 
118  int i;
119  if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {
120  const int16_t **tmpY = (const int16_t **) lumPlane->tmp;
121 
122  int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);
123  for (i = 0; i < neg; i++)
124  tmpY[i] = lumSrcPtr[neg];
125  for ( ; i < end; i++)
126  tmpY[i] = lumSrcPtr[i];
127  for ( ; i < vLumFilterSize; i++)
128  tmpY[i] = tmpY[i-1];
129  lumSrcPtr = tmpY;
130 
131  if (alpSrcPtr) {
132  const int16_t **tmpA = (const int16_t **) alpPlane->tmp;
133  for (i = 0; i < neg; i++)
134  tmpA[i] = alpSrcPtr[neg];
135  for ( ; i < end; i++)
136  tmpA[i] = alpSrcPtr[i];
137  for ( ; i < vLumFilterSize; i++)
138  tmpA[i] = tmpA[i - 1];
139  alpSrcPtr = tmpA;
140  }
141  }
142  if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {
143  const int16_t **tmpU = (const int16_t **) chrUPlane->tmp;
144  int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);
145  for (i = 0; i < neg; i++) {
146  tmpU[i] = chrUSrcPtr[neg];
147  }
148  for ( ; i < end; i++) {
149  tmpU[i] = chrUSrcPtr[i];
150  }
151  for ( ; i < vChrFilterSize; i++) {
152  tmpU[i] = tmpU[i - 1];
153  }
154  chrUSrcPtr = tmpU;
155  }
156 
157  if (flags & SWS_ACCURATE_RND) {
158  int s= APCK_SIZE / 8;
159  for (i=0; i<vLumFilterSize; i+=2) {
160  *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
161  *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
162  lumMmxFilter[s*i+APCK_COEF/4 ]=
163  lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ]
164  + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0);
165  if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
166  *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ];
167  *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)];
168  alpMmxFilter[s*i+APCK_COEF/4 ]=
169  alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ];
170  }
171  }
172  for (i=0; i<vChrFilterSize; i+=2) {
173  *(const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
174  *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
175  chrMmxFilter[s*i+APCK_COEF/4 ]=
176  chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
177  + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
178  }
179  } else {
180  for (i=0; i<vLumFilterSize; i++) {
181  *(const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
182  lumMmxFilter[4*i+2]=
183  lumMmxFilter[4*i+3]=
184  ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001U;
185  if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
186  *(const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
187  alpMmxFilter[4*i+2]=
188  alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
189  }
190  }
191  for (i=0; i<vChrFilterSize; i++) {
192  *(const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
193  chrMmxFilter[4*i+2]=
194  chrMmxFilter[4*i+3]=
195  ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001U;
196  }
197  }
198  }
199 }
200 
201 #if HAVE_MMXEXT
202 static void yuv2yuvX_sse3(const int16_t *filter, int filterSize,
203  const int16_t **src, uint8_t *dest, int dstW,
204  const uint8_t *dither, int offset)
205 {
206  if(((uintptr_t)dest) & 15){
207  yuv2yuvX_mmxext(filter, filterSize, src, dest, dstW, dither, offset);
208  return;
209  }
210  filterSize--;
211 #define MAIN_FUNCTION \
212  "pxor %%xmm0, %%xmm0 \n\t" \
213  "punpcklbw %%xmm0, %%xmm3 \n\t" \
214  "movd %4, %%xmm1 \n\t" \
215  "punpcklwd %%xmm1, %%xmm1 \n\t" \
216  "punpckldq %%xmm1, %%xmm1 \n\t" \
217  "punpcklqdq %%xmm1, %%xmm1 \n\t" \
218  "psllw $3, %%xmm1 \n\t" \
219  "paddw %%xmm1, %%xmm3 \n\t" \
220  "psraw $4, %%xmm3 \n\t" \
221  "movdqa %%xmm3, %%xmm4 \n\t" \
222  "movdqa %%xmm3, %%xmm7 \n\t" \
223  "movl %3, %%ecx \n\t" \
224  "mov %0, %%"REG_d" \n\t"\
225  "mov (%%"REG_d"), %%"REG_S" \n\t"\
226  ".p2align 4 \n\t" /* FIXME Unroll? */\
227  "1: \n\t"\
228  "movddup 8(%%"REG_d"), %%xmm0 \n\t" /* filterCoeff */\
229  "movdqa (%%"REG_S", %%"REG_c", 2), %%xmm2 \n\t" /* srcData */\
230  "movdqa 16(%%"REG_S", %%"REG_c", 2), %%xmm5 \n\t" /* srcData */\
231  "add $16, %%"REG_d" \n\t"\
232  "mov (%%"REG_d"), %%"REG_S" \n\t"\
233  "test %%"REG_S", %%"REG_S" \n\t"\
234  "pmulhw %%xmm0, %%xmm2 \n\t"\
235  "pmulhw %%xmm0, %%xmm5 \n\t"\
236  "paddw %%xmm2, %%xmm3 \n\t"\
237  "paddw %%xmm5, %%xmm4 \n\t"\
238  " jnz 1b \n\t"\
239  "psraw $3, %%xmm3 \n\t"\
240  "psraw $3, %%xmm4 \n\t"\
241  "packuswb %%xmm4, %%xmm3 \n\t"\
242  "movntdq %%xmm3, (%1, %%"REG_c")\n\t"\
243  "add $16, %%"REG_c" \n\t"\
244  "cmp %2, %%"REG_c" \n\t"\
245  "movdqa %%xmm7, %%xmm3 \n\t" \
246  "movdqa %%xmm7, %%xmm4 \n\t" \
247  "mov %0, %%"REG_d" \n\t"\
248  "mov (%%"REG_d"), %%"REG_S" \n\t"\
249  "jb 1b \n\t"
250 
251  if (offset) {
252  __asm__ volatile(
253  "movq %5, %%xmm3 \n\t"
254  "movdqa %%xmm3, %%xmm4 \n\t"
255  "psrlq $24, %%xmm3 \n\t"
256  "psllq $40, %%xmm4 \n\t"
257  "por %%xmm4, %%xmm3 \n\t"
258  MAIN_FUNCTION
259  :: "g" (filter),
260  "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset),
261  "m"(filterSize), "m"(((uint64_t *) dither)[0])
262  : XMM_CLOBBERS("%xmm0" , "%xmm1" , "%xmm2" , "%xmm3" , "%xmm4" , "%xmm5" , "%xmm7" ,)
263  "%"REG_d, "%"REG_S, "%"REG_c
264  );
265  } else {
266  __asm__ volatile(
267  "movq %5, %%xmm3 \n\t"
268  MAIN_FUNCTION
269  :: "g" (filter),
270  "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset),
271  "m"(filterSize), "m"(((uint64_t *) dither)[0])
272  : XMM_CLOBBERS("%xmm0" , "%xmm1" , "%xmm2" , "%xmm3" , "%xmm4" , "%xmm5" , "%xmm7" ,)
273  "%"REG_d, "%"REG_S, "%"REG_c
274  );
275  }
276 }
277 #endif
278 
279 #endif /* HAVE_INLINE_ASM */
280 
281 #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
282 void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
283  SwsContext *c, int16_t *data, \
284  int dstW, const uint8_t *src, \
285  const int16_t *filter, \
286  const int32_t *filterPos, int filterSize)
287 
288 #define SCALE_FUNCS(filter_n, opt) \
289  SCALE_FUNC(filter_n, 8, 15, opt); \
290  SCALE_FUNC(filter_n, 9, 15, opt); \
291  SCALE_FUNC(filter_n, 10, 15, opt); \
292  SCALE_FUNC(filter_n, 12, 15, opt); \
293  SCALE_FUNC(filter_n, 14, 15, opt); \
294  SCALE_FUNC(filter_n, 16, 15, opt); \
295  SCALE_FUNC(filter_n, 8, 19, opt); \
296  SCALE_FUNC(filter_n, 9, 19, opt); \
297  SCALE_FUNC(filter_n, 10, 19, opt); \
298  SCALE_FUNC(filter_n, 12, 19, opt); \
299  SCALE_FUNC(filter_n, 14, 19, opt); \
300  SCALE_FUNC(filter_n, 16, 19, opt)
301 
302 #define SCALE_FUNCS_MMX(opt) \
303  SCALE_FUNCS(4, opt); \
304  SCALE_FUNCS(8, opt); \
305  SCALE_FUNCS(X, opt)
306 
307 #define SCALE_FUNCS_SSE(opt) \
308  SCALE_FUNCS(4, opt); \
309  SCALE_FUNCS(8, opt); \
310  SCALE_FUNCS(X4, opt); \
311  SCALE_FUNCS(X8, opt)
312 
313 #if ARCH_X86_32
314 SCALE_FUNCS_MMX(mmx);
315 #endif
316 SCALE_FUNCS_SSE(sse2);
317 SCALE_FUNCS_SSE(ssse3);
318 SCALE_FUNCS_SSE(sse4);
319 
320 #define VSCALEX_FUNC(size, opt) \
321 void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
322  const int16_t **src, uint8_t *dest, int dstW, \
323  const uint8_t *dither, int offset)
324 #define VSCALEX_FUNCS(opt) \
325  VSCALEX_FUNC(8, opt); \
326  VSCALEX_FUNC(9, opt); \
327  VSCALEX_FUNC(10, opt)
328 
329 #if ARCH_X86_32
330 VSCALEX_FUNCS(mmxext);
331 #endif
332 VSCALEX_FUNCS(sse2);
333 VSCALEX_FUNCS(sse4);
334 VSCALEX_FUNC(16, sse4);
335 VSCALEX_FUNCS(avx);
336 
337 #define VSCALE_FUNC(size, opt) \
338 void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
339  const uint8_t *dither, int offset)
340 #define VSCALE_FUNCS(opt1, opt2) \
341  VSCALE_FUNC(8, opt1); \
342  VSCALE_FUNC(9, opt2); \
343  VSCALE_FUNC(10, opt2); \
344  VSCALE_FUNC(16, opt1)
345 
346 #if ARCH_X86_32
347 VSCALE_FUNCS(mmx, mmxext);
348 #endif
349 VSCALE_FUNCS(sse2, sse2);
350 VSCALE_FUNC(16, sse4);
351 VSCALE_FUNCS(avx, avx);
352 
353 #define INPUT_Y_FUNC(fmt, opt) \
354 void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
355  const uint8_t *unused1, const uint8_t *unused2, \
356  int w, uint32_t *unused)
357 #define INPUT_UV_FUNC(fmt, opt) \
358 void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
359  const uint8_t *unused0, \
360  const uint8_t *src1, \
361  const uint8_t *src2, \
362  int w, uint32_t *unused)
363 #define INPUT_FUNC(fmt, opt) \
364  INPUT_Y_FUNC(fmt, opt); \
365  INPUT_UV_FUNC(fmt, opt)
366 #define INPUT_FUNCS(opt) \
367  INPUT_FUNC(uyvy, opt); \
368  INPUT_FUNC(yuyv, opt); \
369  INPUT_UV_FUNC(nv12, opt); \
370  INPUT_UV_FUNC(nv21, opt); \
371  INPUT_FUNC(rgba, opt); \
372  INPUT_FUNC(bgra, opt); \
373  INPUT_FUNC(argb, opt); \
374  INPUT_FUNC(abgr, opt); \
375  INPUT_FUNC(rgb24, opt); \
376  INPUT_FUNC(bgr24, opt)
377 
378 #if ARCH_X86_32
379 INPUT_FUNCS(mmx);
380 #endif
381 INPUT_FUNCS(sse2);
382 INPUT_FUNCS(ssse3);
383 INPUT_FUNCS(avx);
384 
386 {
387  int cpu_flags = av_get_cpu_flags();
388 
389 #if HAVE_MMX_INLINE
390  if (INLINE_MMX(cpu_flags))
391  sws_init_swscale_mmx(c);
392 #endif
393 #if HAVE_MMXEXT_INLINE
394  if (INLINE_MMXEXT(cpu_flags))
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 
402 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
403  if (c->srcBpc == 8) { \
404  hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
405  ff_hscale8to19_ ## filtersize ## _ ## opt1; \
406  } else if (c->srcBpc == 9) { \
407  hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
408  ff_hscale9to19_ ## filtersize ## _ ## opt1; \
409  } else if (c->srcBpc == 10) { \
410  hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
411  ff_hscale10to19_ ## filtersize ## _ ## opt1; \
412  } else if (c->srcBpc == 12) { \
413  hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
414  ff_hscale12to19_ ## filtersize ## _ ## opt1; \
415  } else if (c->srcBpc == 14 || ((c->srcFormat==AV_PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_desc_get(c->srcFormat)->comp[0].depth<16)) { \
416  hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
417  ff_hscale14to19_ ## filtersize ## _ ## opt1; \
418  } else { /* c->srcBpc == 16 */ \
419  av_assert0(c->srcBpc == 16);\
420  hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
421  ff_hscale16to19_ ## filtersize ## _ ## opt1; \
422  } \
423 } while (0)
424 #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
425  switch (filtersize) { \
426  case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
427  case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
428  default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
429  }
430 #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
431 switch(c->dstBpc){ \
432  case 16: do_16_case; break; \
433  case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
434  case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
435  case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
436  }
437 #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
438  switch(c->dstBpc){ \
439  case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
440  case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
441  case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
442  case 8: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
443  default: av_assert0(c->dstBpc>8); \
444  }
445 #define case_rgb(x, X, opt) \
446  case AV_PIX_FMT_ ## X: \
447  c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
448  if (!c->chrSrcHSubSample) \
449  c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
450  break
451 #if ARCH_X86_32
452  if (EXTERNAL_MMX(cpu_flags)) {
453  ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx);
454  ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx);
455  ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmxext, cpu_flags & AV_CPU_FLAG_MMXEXT);
456 
457  switch (c->srcFormat) {
458  case AV_PIX_FMT_YA8:
459  c->lumToYV12 = ff_yuyvToY_mmx;
460  if (c->needAlpha)
461  c->alpToYV12 = ff_uyvyToY_mmx;
462  break;
463  case AV_PIX_FMT_YUYV422:
464  c->lumToYV12 = ff_yuyvToY_mmx;
465  c->chrToYV12 = ff_yuyvToUV_mmx;
466  break;
467  case AV_PIX_FMT_UYVY422:
468  c->lumToYV12 = ff_uyvyToY_mmx;
469  c->chrToYV12 = ff_uyvyToUV_mmx;
470  break;
471  case AV_PIX_FMT_NV12:
472  c->chrToYV12 = ff_nv12ToUV_mmx;
473  break;
474  case AV_PIX_FMT_NV21:
475  c->chrToYV12 = ff_nv21ToUV_mmx;
476  break;
477  case_rgb(rgb24, RGB24, mmx);
478  case_rgb(bgr24, BGR24, mmx);
479  case_rgb(bgra, BGRA, mmx);
480  case_rgb(rgba, RGBA, mmx);
481  case_rgb(abgr, ABGR, mmx);
482  case_rgb(argb, ARGB, mmx);
483  default:
484  break;
485  }
486  }
487  if (EXTERNAL_MMXEXT(cpu_flags)) {
488  ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmxext, , 1);
489  }
490 #endif /* ARCH_X86_32 */
491 #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
492  switch (filtersize) { \
493  case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
494  case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
495  default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
496  else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
497  break; \
498  }
499  if (EXTERNAL_SSE2(cpu_flags)) {
500  ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2);
501  ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2);
502  ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2, ,
503  HAVE_ALIGNED_STACK || ARCH_X86_64);
504  ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1);
505 
506  switch (c->srcFormat) {
507  case AV_PIX_FMT_YA8:
508  c->lumToYV12 = ff_yuyvToY_sse2;
509  if (c->needAlpha)
510  c->alpToYV12 = ff_uyvyToY_sse2;
511  break;
512  case AV_PIX_FMT_YUYV422:
513  c->lumToYV12 = ff_yuyvToY_sse2;
514  c->chrToYV12 = ff_yuyvToUV_sse2;
515  break;
516  case AV_PIX_FMT_UYVY422:
517  c->lumToYV12 = ff_uyvyToY_sse2;
518  c->chrToYV12 = ff_uyvyToUV_sse2;
519  break;
520  case AV_PIX_FMT_NV12:
521  c->chrToYV12 = ff_nv12ToUV_sse2;
522  break;
523  case AV_PIX_FMT_NV21:
524  c->chrToYV12 = ff_nv21ToUV_sse2;
525  break;
526  case_rgb(rgb24, RGB24, sse2);
527  case_rgb(bgr24, BGR24, sse2);
528  case_rgb(bgra, BGRA, sse2);
529  case_rgb(rgba, RGBA, sse2);
530  case_rgb(abgr, ABGR, sse2);
531  case_rgb(argb, ARGB, sse2);
532  default:
533  break;
534  }
535  }
536  if (EXTERNAL_SSSE3(cpu_flags)) {
537  ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3);
538  ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3);
539  switch (c->srcFormat) {
540  case_rgb(rgb24, RGB24, ssse3);
541  case_rgb(bgr24, BGR24, ssse3);
542  default:
543  break;
544  }
545  }
546  if (EXTERNAL_SSE4(cpu_flags)) {
547  /* Xto15 don't need special sse4 functions */
548  ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3);
549  ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3);
551  if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4,
552  HAVE_ALIGNED_STACK || ARCH_X86_64);
553  if (c->dstBpc == 16 && !isBE(c->dstFormat))
554  c->yuv2plane1 = ff_yuv2plane1_16_sse4;
555  }
556 
557  if (EXTERNAL_AVX(cpu_flags)) {
559  HAVE_ALIGNED_STACK || ARCH_X86_64);
560  ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1);
561 
562  switch (c->srcFormat) {
563  case AV_PIX_FMT_YUYV422:
564  c->chrToYV12 = ff_yuyvToUV_avx;
565  break;
566  case AV_PIX_FMT_UYVY422:
567  c->chrToYV12 = ff_uyvyToUV_avx;
568  break;
569  case AV_PIX_FMT_NV12:
570  c->chrToYV12 = ff_nv12ToUV_avx;
571  break;
572  case AV_PIX_FMT_NV21:
573  c->chrToYV12 = ff_nv21ToUV_avx;
574  break;
575  case_rgb(rgb24, RGB24, avx);
576  case_rgb(bgr24, BGR24, avx);
577  case_rgb(bgra, BGRA, avx);
578  case_rgb(rgba, RGBA, avx);
579  case_rgb(abgr, ABGR, avx);
580  case_rgb(argb, ARGB, avx);
581  default:
582  break;
583  }
584  }
585 }
#define EXTERNAL_MMX(flags)
Definition: cpu.h:54
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:82
#define NULL
Definition: coverity.c:32
const uint64_t ff_dither8[2]
const char * s
Definition: avisynth_c.h:631
int chrSrcH
Height of source chroma planes.
8bit gray, 8bit alpha
Definition: pixfmt.h:154
#define VSCALE_FUNC(size, opt)
Definition: swscale.c:337
#define SCALE_FUNCS_MMX(opt)
Definition: swscale.c:302
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:53
uint64_t redDither
#define RGBA(r, g, b, a)
Definition: dvbsubdec.c:153
uint64_t blueDither
#define case_rgb(x, X, opt)
Macro definitions for various function/variable attributes.
#define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2)
int srcH
Height of source luma/alpha planes.
#define VSCALE_FUNCS(opt1, opt2)
Definition: swscale.c:340
#define EXTERNAL_SSE4(flags)
Definition: cpu.h:64
#define DECLARE_ASM_CONST(n, t, v)
Definition: mem.h:54
int chrDstVSubSample
Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination i...
uint8_t
#define av_cold
Definition: attributes.h:82
uint8_t ** line
line buffer
int vChrFilterSize
Vertical filter size for chroma pixels.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
void(* lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, int width, uint32_t *pal)
Unscaled conversion of luma plane to YV12 for horizontal scaler.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
Definition: cfhd.c:80
av_cold void ff_sws_init_swscale_x86(SwsContext *c)
Definition: swscale.c:385
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:57
#define VSCALEX_FUNCS(opt)
Definition: swscale.c:324
int32_t * vChrFilterPos
Array of vertical filter starting positions for each dst[i] for chroma planes.
int dstH
Height of destination luma/alpha planes.
#define U(x)
Definition: vp56_arith.h:37
#define INLINE_MMX(flags)
Definition: cpu.h:81
const uint64_t ff_dither4[2]
int hLumFilterSize
Horizontal filter size for luma/alpha pixels.
static const uint8_t dither[8][8]
Definition: vf_fspp.c:57
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:90
simple assert() macros that are a bit more flexible than ISO C assert().
Slice plane.
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
SwsPlane plane[MAX_SLICE_PLANES]
color planes
int32_t alpMmxFilter[4 *MAX_FILTER_SIZE]
int hChrFilterSize
Horizontal filter size for chroma pixels.
as above, but U and V bytes are swapped
Definition: pixfmt.h:91
#define APCK_SIZE
#define FFMIN(a, b)
Definition: common.h:96
#define AV_CPU_FLAG_SSE3
Prescott SSE3 functions.
Definition: cpu.h:38
yuv2planar1_fn yuv2plane1
#define SCALE_FUNCS_SSE(opt)
Definition: swscale.c:307
int32_t
void(* hcScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
#define XMM_CLOBBERS(...)
Definition: asm.h:98
#define src
Definition: vp9dsp.c:530
int32_t * vLumFilterPos
Array of vertical filter starting positions for each dst[i] for luma/alpha planes.
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:331
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
int32_t lumMmxFilter[4 *MAX_FILTER_SIZE]
#define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2)
yuv2planarX_fn yuv2planeX
struct SwsSlice * slice
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:63
#define APCK_COEF
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:63
int vLumFilterSize
Vertical filter size for luma/alpha pixels.
#define SWS_ACCURATE_RND
Definition: swscale.h:81
int16_t * vChrFilter
Array of vertical filter coefficients for chroma planes.
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
#define INPUT_FUNCS(opt)
Definition: swscale.c:366
static int flags
Definition: cpu.c:47
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:55
#define VSCALEX_FUNC(size, opt)
Definition: swscale.c:320
#define INLINE_MMXEXT(flags)
Definition: cpu.h:82
if(ret< 0)
Definition: vf_mcdeint.c:282
static double c[64]
enum AVPixelFormat srcFormat
Source pixel format.
int32_t chrMmxFilter[4 *MAX_FILTER_SIZE]
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:326
#define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit)
uint64_t greenDither
#define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk)
uint8_t ** tmp
Tmp line buffer used by mmx code.
int x86_reg
Definition: asm.h:72
void(* alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, int width, uint32_t *pal)
Unscaled conversion of alpha plane to YV12 for horizontal scaler.
void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, int lastInLumBuf, int lastInChrBuf)
void(* chrToYV12)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, int width, uint32_t *pal)
Unscaled conversion of chroma planes to YV12 for horizontal scaler.
int16_t * vLumFilter
Array of vertical filter coefficients for luma/alpha planes.
#define APCK_PTR2
int sliceY
index of first line
int flags
Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
#define EXTERNAL_AVX(flags)
Definition: cpu.h:66
void(* hyScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Scale one horizontal line of input data using a filter over the input lines, to produce one (differen...
for(j=16;j >0;--j)
#define av_unused
Definition: attributes.h:126