35 0x0200020002000200LL,};
39 0x0004000400040004LL,};
60 #define COMPILE_TEMPLATE_MMXEXT 0
61 #define RENAME(a) a ## _mmx
66 #if HAVE_MMXEXT_INLINE
68 #undef COMPILE_TEMPLATE_MMXEXT
69 #define COMPILE_TEMPLATE_MMXEXT 1
70 #define RENAME(a) a ## _mmxext
76 const int dstH=
c->dstH;
79 SwsPlane *lumPlane = &
c->slice[
c->numSlice-2].plane[0];
80 SwsPlane *chrUPlane = &
c->slice[
c->numSlice-2].plane[1];
81 SwsPlane *alpPlane = &
c->slice[
c->numSlice-2].plane[3];
83 int hasAlpha =
c->needAlpha;
93 const int chrDstY=
dstY>>
c->chrDstVSubSample;
104 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPlane->
line + firstLumSrcY - lumPlane->
sliceY;
105 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPlane->
line + firstChrSrcY - chrUPlane->
sliceY;
106 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && hasAlpha) ? (
const int16_t **)(
void*) alpPlane->
line + firstLumSrcY - alpPlane->
sliceY :
NULL;
109 if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize >
c->srcH) {
110 const int16_t **tmpY = (
const int16_t **) lumPlane->
tmp;
113 for (
i = 0;
i < neg;
i++)
114 tmpY[
i] = lumSrcPtr[neg];
115 for ( ;
i < end;
i++)
116 tmpY[
i] = lumSrcPtr[
i];
122 const int16_t **tmpA = (
const int16_t **) alpPlane->
tmp;
124 tmpA[
i] = alpSrcPtr[neg];
125 for ( ;
i < end;
i++)
126 tmpA[
i] = alpSrcPtr[
i];
128 tmpA[
i] = tmpA[
i - 1];
132 if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize >
c->chrSrcH) {
133 const int16_t **tmpU = (
const int16_t **) chrUPlane->
tmp;
135 for (
i = 0;
i < neg;
i++) {
136 tmpU[
i] = chrUSrcPtr[neg];
138 for ( ;
i < end;
i++) {
139 tmpU[
i] = chrUSrcPtr[
i];
142 tmpU[
i] = tmpU[
i - 1];
155 if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
175 if (CONFIG_SWSCALE_ALPHA && hasAlpha) {
192 #define YUV2YUVX_FUNC_MMX(opt, step) \
193 void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
194 uint8_t *dest, int dstW, \
195 const uint8_t *dither, int offset); \
196 static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
197 const int16_t **src, uint8_t *dest, int dstW, \
198 const uint8_t *dither, int offset) \
201 ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, dstW + offset, dither, offset); \
205 #define YUV2YUVX_FUNC(opt, step) \
206 void ff_yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, int srcOffset, \
207 uint8_t *dest, int dstW, \
208 const uint8_t *dither, int offset); \
209 static void yuv2yuvX_ ##opt(const int16_t *filter, int filterSize, \
210 const int16_t **src, uint8_t *dest, int dstW, \
211 const uint8_t *dither, int offset) \
213 int remainder = (dstW % step); \
214 int pixelsProcessed = dstW - remainder; \
215 if(((uintptr_t)dest) & 15){ \
216 yuv2yuvX_mmx(filter, filterSize, src, dest, dstW, dither, offset); \
219 if(pixelsProcessed > 0) \
220 ff_yuv2yuvX_ ##opt(filter, filterSize - 1, 0, dest - offset, pixelsProcessed + offset, dither, offset); \
222 ff_yuv2yuvX_mmx(filter, filterSize - 1, pixelsProcessed, dest - offset, pixelsProcessed + remainder + offset, dither, offset); \
227 #if HAVE_MMX_EXTERNAL
230 #if HAVE_MMXEXT_EXTERNAL
233 #if HAVE_SSE3_EXTERNAL
236 #if HAVE_AVX2_EXTERNAL
240 #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
241 void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
242 SwsContext *c, int16_t *data, \
243 int dstW, const uint8_t *src, \
244 const int16_t *filter, \
245 const int32_t *filterPos, int filterSize)
247 #define SCALE_FUNCS(filter_n, opt) \
248 SCALE_FUNC(filter_n, 8, 15, opt); \
249 SCALE_FUNC(filter_n, 9, 15, opt); \
250 SCALE_FUNC(filter_n, 10, 15, opt); \
251 SCALE_FUNC(filter_n, 12, 15, opt); \
252 SCALE_FUNC(filter_n, 14, 15, opt); \
253 SCALE_FUNC(filter_n, 16, 15, opt); \
254 SCALE_FUNC(filter_n, 8, 19, opt); \
255 SCALE_FUNC(filter_n, 9, 19, opt); \
256 SCALE_FUNC(filter_n, 10, 19, opt); \
257 SCALE_FUNC(filter_n, 12, 19, opt); \
258 SCALE_FUNC(filter_n, 14, 19, opt); \
259 SCALE_FUNC(filter_n, 16, 19, opt)
261 #define SCALE_FUNCS_MMX(opt) \
262 SCALE_FUNCS(4, opt); \
263 SCALE_FUNCS(8, opt); \
266 #define SCALE_FUNCS_SSE(opt) \
267 SCALE_FUNCS(4, opt); \
268 SCALE_FUNCS(8, opt); \
269 SCALE_FUNCS(X4, opt); \
282 #define VSCALEX_FUNC(size, opt) \
283 void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
284 const int16_t **src, uint8_t *dest, int dstW, \
285 const uint8_t *dither, int offset)
286 #define VSCALEX_FUNCS(opt) \
287 VSCALEX_FUNC(8, opt); \
288 VSCALEX_FUNC(9, opt); \
289 VSCALEX_FUNC(10, opt)
299 #define VSCALE_FUNC(size, opt) \
300 void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
301 const uint8_t *dither, int offset)
302 #define VSCALE_FUNCS(opt1, opt2) \
303 VSCALE_FUNC(8, opt1); \
304 VSCALE_FUNC(9, opt2); \
305 VSCALE_FUNC(10, opt2); \
306 VSCALE_FUNC(16, opt1)
315 #define INPUT_Y_FUNC(fmt, opt) \
316 void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
317 const uint8_t *unused1, const uint8_t *unused2, \
318 int w, uint32_t *unused)
319 #define INPUT_UV_FUNC(fmt, opt) \
320 void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
321 const uint8_t *unused0, \
322 const uint8_t *src1, \
323 const uint8_t *src2, \
324 int w, uint32_t *unused)
325 #define INPUT_FUNC(fmt, opt) \
326 INPUT_Y_FUNC(fmt, opt); \
327 INPUT_UV_FUNC(fmt, opt)
328 #define INPUT_FUNCS(opt) \
329 INPUT_FUNC(uyvy, opt); \
330 INPUT_FUNC(yuyv, opt); \
331 INPUT_UV_FUNC(nv12, opt); \
332 INPUT_UV_FUNC(nv21, opt); \
333 INPUT_FUNC(rgba, opt); \
334 INPUT_FUNC(bgra, opt); \
335 INPUT_FUNC(argb, opt); \
336 INPUT_FUNC(abgr, opt); \
337 INPUT_FUNC(rgb24, opt); \
338 INPUT_FUNC(bgr24, opt)
348 #define YUV2NV_DECL(fmt, opt) \
349 void ff_yuv2 ## fmt ## cX_ ## opt(enum AVPixelFormat format, const uint8_t *dither, \
350 const int16_t *filter, int filterSize, \
351 const int16_t **u, const int16_t **v, \
352 uint8_t *dst, int dstWidth)
354 YUV2NV_DECL(nv12, avx2);
355 YUV2NV_DECL(nv21, avx2);
364 sws_init_swscale_mmx(
c);
366 #if HAVE_MMXEXT_INLINE
368 sws_init_swscale_mmxext(
c);
371 #if HAVE_MMX_EXTERNAL
373 c->yuv2planeX = yuv2yuvX_mmx;
375 #if HAVE_MMXEXT_EXTERNAL
377 c->yuv2planeX = yuv2yuvX_mmxext;
379 #if HAVE_SSE3_EXTERNAL
381 c->yuv2planeX = yuv2yuvX_sse3;
383 #if HAVE_AVX2_EXTERNAL
385 c->yuv2planeX = yuv2yuvX_avx2;
389 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
390 if (c->srcBpc == 8) { \
391 hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
392 ff_hscale8to19_ ## filtersize ## _ ## opt1; \
393 } else if (c->srcBpc == 9) { \
394 hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
395 ff_hscale9to19_ ## filtersize ## _ ## opt1; \
396 } else if (c->srcBpc == 10) { \
397 hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
398 ff_hscale10to19_ ## filtersize ## _ ## opt1; \
399 } else if (c->srcBpc == 12) { \
400 hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
401 ff_hscale12to19_ ## filtersize ## _ ## opt1; \
402 } 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)) { \
403 hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
404 ff_hscale14to19_ ## filtersize ## _ ## opt1; \
406 av_assert0(c->srcBpc == 16);\
407 hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
408 ff_hscale16to19_ ## filtersize ## _ ## opt1; \
411 #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
412 switch (filtersize) { \
413 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
414 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
415 default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
417 #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
419 case 16: do_16_case; break; \
420 case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
421 case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
422 case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
424 #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
426 case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
427 case 10: if (!isBE(c->dstFormat) && !isSemiPlanarYUV(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
428 case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
429 case 8: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
430 default: av_assert0(c->dstBpc>8); \
432 #define case_rgb(x, X, opt) \
433 case AV_PIX_FMT_ ## X: \
434 c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
435 if (!c->chrSrcHSubSample) \
436 c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
444 switch (
c->srcFormat) {
446 c->lumToYV12 = ff_yuyvToY_mmx;
448 c->alpToYV12 = ff_uyvyToY_mmx;
451 c->lumToYV12 = ff_yuyvToY_mmx;
452 c->chrToYV12 = ff_yuyvToUV_mmx;
455 c->lumToYV12 = ff_uyvyToY_mmx;
456 c->chrToYV12 = ff_uyvyToUV_mmx;
459 c->chrToYV12 = ff_nv12ToUV_mmx;
462 c->chrToYV12 = ff_nv21ToUV_mmx;
478 #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
479 switch (filtersize) { \
480 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
481 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
482 default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
483 else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
490 HAVE_ALIGNED_STACK || ARCH_X86_64);
493 switch (
c->srcFormat) {
495 c->lumToYV12 = ff_yuyvToY_sse2;
497 c->alpToYV12 = ff_uyvyToY_sse2;
500 c->lumToYV12 = ff_yuyvToY_sse2;
501 c->chrToYV12 = ff_yuyvToUV_sse2;
504 c->lumToYV12 = ff_uyvyToY_sse2;
505 c->chrToYV12 = ff_uyvyToUV_sse2;
508 c->chrToYV12 = ff_nv12ToUV_sse2;
511 c->chrToYV12 = ff_nv21ToUV_sse2;
526 switch (
c->srcFormat) {
538 if (!
isBE(
c->dstFormat))
c->yuv2planeX = ff_yuv2planeX_16_sse4,
539 HAVE_ALIGNED_STACK || ARCH_X86_64);
540 if (
c->dstBpc == 16 && !
isBE(
c->dstFormat))
541 c->yuv2plane1 = ff_yuv2plane1_16_sse4;
546 HAVE_ALIGNED_STACK || ARCH_X86_64);
549 switch (
c->srcFormat) {
551 c->chrToYV12 = ff_yuyvToUV_avx;
554 c->chrToYV12 = ff_uyvyToUV_avx;
557 c->chrToYV12 = ff_nv12ToUV_avx;
560 c->chrToYV12 = ff_nv21ToUV_avx;
574 #define ASSIGN_AVX2_SCALE_FUNC(hscalefn, filtersize) \
575 switch (filtersize) { \
576 case 4: hscalefn = ff_hscale8to15_4_avx2; break; \
577 default: hscalefn = ff_hscale8to15_X4_avx2; break; \
582 if ((
c->srcBpc == 8) && (
c->dstBpc <= 14)) {
583 if (
c->chrDstW % 16 == 0)
584 ASSIGN_AVX2_SCALE_FUNC(
c->hcScale,
c->hChrFilterSize);
585 if (
c->dstW % 16 == 0)
586 ASSIGN_AVX2_SCALE_FUNC(
c->hyScale,
c->hLumFilterSize);
591 switch (
c->dstFormat) {
594 c->yuv2nv12cX = ff_yuv2nv12cX_avx2;
598 c->yuv2nv12cX = ff_yuv2nv21cX_avx2;