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); \
279 #define VSCALEX_FUNC(size, opt) \
280 void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
281 const int16_t **src, uint8_t *dest, int dstW, \
282 const uint8_t *dither, int offset)
283 #define VSCALEX_FUNCS(opt) \
284 VSCALEX_FUNC(8, opt); \
285 VSCALEX_FUNC(9, opt); \
286 VSCALEX_FUNC(10, opt)
296 #define VSCALE_FUNC(size, opt) \
297 void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
298 const uint8_t *dither, int offset)
299 #define VSCALE_FUNCS(opt1, opt2) \
300 VSCALE_FUNC(8, opt1); \
301 VSCALE_FUNC(9, opt2); \
302 VSCALE_FUNC(10, opt2); \
303 VSCALE_FUNC(16, opt1)
312 #define INPUT_Y_FUNC(fmt, opt) \
313 void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
314 const uint8_t *unused1, const uint8_t *unused2, \
315 int w, uint32_t *unused)
316 #define INPUT_UV_FUNC(fmt, opt) \
317 void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
318 const uint8_t *unused0, \
319 const uint8_t *src1, \
320 const uint8_t *src2, \
321 int w, uint32_t *unused)
322 #define INPUT_FUNC(fmt, opt) \
323 INPUT_Y_FUNC(fmt, opt); \
324 INPUT_UV_FUNC(fmt, opt)
325 #define INPUT_FUNCS(opt) \
326 INPUT_FUNC(uyvy, opt); \
327 INPUT_FUNC(yuyv, opt); \
328 INPUT_UV_FUNC(nv12, opt); \
329 INPUT_UV_FUNC(nv21, opt); \
330 INPUT_FUNC(rgba, opt); \
331 INPUT_FUNC(bgra, opt); \
332 INPUT_FUNC(argb, opt); \
333 INPUT_FUNC(abgr, opt); \
334 INPUT_FUNC(rgb24, opt); \
335 INPUT_FUNC(bgr24, opt)
345 #define YUV2NV_DECL(fmt, opt) \
346 void ff_yuv2 ## fmt ## cX_ ## opt(enum AVPixelFormat format, const uint8_t *dither, \
347 const int16_t *filter, int filterSize, \
348 const int16_t **u, const int16_t **v, \
349 uint8_t *dst, int dstWidth)
351 YUV2NV_DECL(nv12, avx2);
352 YUV2NV_DECL(nv21, avx2);
361 sws_init_swscale_mmx(
c);
363 #if HAVE_MMXEXT_INLINE
365 sws_init_swscale_mmxext(
c);
368 #if HAVE_MMX_EXTERNAL
370 c->yuv2planeX = yuv2yuvX_mmx;
372 #if HAVE_MMXEXT_EXTERNAL
374 c->yuv2planeX = yuv2yuvX_mmxext;
376 #if HAVE_SSE3_EXTERNAL
378 c->yuv2planeX = yuv2yuvX_sse3;
380 #if HAVE_AVX2_EXTERNAL
382 c->yuv2planeX = yuv2yuvX_avx2;
386 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
387 if (c->srcBpc == 8) { \
388 hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
389 ff_hscale8to19_ ## filtersize ## _ ## opt1; \
390 } else if (c->srcBpc == 9) { \
391 hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
392 ff_hscale9to19_ ## filtersize ## _ ## opt1; \
393 } else if (c->srcBpc == 10) { \
394 hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
395 ff_hscale10to19_ ## filtersize ## _ ## opt1; \
396 } else if (c->srcBpc == 12) { \
397 hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
398 ff_hscale12to19_ ## filtersize ## _ ## opt1; \
399 } 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)) { \
400 hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
401 ff_hscale14to19_ ## filtersize ## _ ## opt1; \
403 av_assert0(c->srcBpc == 16);\
404 hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
405 ff_hscale16to19_ ## filtersize ## _ ## opt1; \
408 #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
409 switch (filtersize) { \
410 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
411 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
412 default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
414 #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
416 case 16: do_16_case; break; \
417 case 10: if (!isBE(c->dstFormat) && c->dstFormat != AV_PIX_FMT_P010LE) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
418 case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
419 case 8: if ((condition_8bit) && !c->use_mmx_vfilter) vscalefn = ff_yuv2planeX_8_ ## opt; break; \
421 #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
423 case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
424 case 10: if (!isBE(c->dstFormat) && c->dstFormat != AV_PIX_FMT_P010LE && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
425 case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
426 case 8: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
427 default: av_assert0(c->dstBpc>8); \
429 #define case_rgb(x, X, opt) \
430 case AV_PIX_FMT_ ## X: \
431 c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
432 if (!c->chrSrcHSubSample) \
433 c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
441 switch (
c->srcFormat) {
443 c->lumToYV12 = ff_yuyvToY_mmx;
445 c->alpToYV12 = ff_uyvyToY_mmx;
448 c->lumToYV12 = ff_yuyvToY_mmx;
449 c->chrToYV12 = ff_yuyvToUV_mmx;
452 c->lumToYV12 = ff_uyvyToY_mmx;
453 c->chrToYV12 = ff_uyvyToUV_mmx;
456 c->chrToYV12 = ff_nv12ToUV_mmx;
459 c->chrToYV12 = ff_nv21ToUV_mmx;
475 #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
476 switch (filtersize) { \
477 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
478 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
479 default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
480 else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
487 HAVE_ALIGNED_STACK || ARCH_X86_64);
490 switch (
c->srcFormat) {
492 c->lumToYV12 = ff_yuyvToY_sse2;
494 c->alpToYV12 = ff_uyvyToY_sse2;
497 c->lumToYV12 = ff_yuyvToY_sse2;
498 c->chrToYV12 = ff_yuyvToUV_sse2;
501 c->lumToYV12 = ff_uyvyToY_sse2;
502 c->chrToYV12 = ff_uyvyToUV_sse2;
505 c->chrToYV12 = ff_nv12ToUV_sse2;
508 c->chrToYV12 = ff_nv21ToUV_sse2;
523 switch (
c->srcFormat) {
535 if (!
isBE(
c->dstFormat))
c->yuv2planeX = ff_yuv2planeX_16_sse4,
536 HAVE_ALIGNED_STACK || ARCH_X86_64);
537 if (
c->dstBpc == 16 && !
isBE(
c->dstFormat))
538 c->yuv2plane1 = ff_yuv2plane1_16_sse4;
543 HAVE_ALIGNED_STACK || ARCH_X86_64);
546 switch (
c->srcFormat) {
548 c->chrToYV12 = ff_yuyvToUV_avx;
551 c->chrToYV12 = ff_uyvyToUV_avx;
554 c->chrToYV12 = ff_nv12ToUV_avx;
557 c->chrToYV12 = ff_nv21ToUV_avx;
572 switch (
c->dstFormat) {
575 c->yuv2nv12cX = ff_yuv2nv12cX_avx2;
579 c->yuv2nv12cX = ff_yuv2nv21cX_avx2;