44 0x0200020002000200LL,};
48 0x0004000400040004LL,};
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;
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;
70 DECLARE_ALIGNED(8,
const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL;
71 DECLARE_ALIGNED(8,
const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL;
78 #define COMPILE_TEMPLATE_MMXEXT 0
79 #define RENAME(a) a ## _MMX
84 #if HAVE_MMXEXT_INLINE
86 #undef COMPILE_TEMPLATE_MMXEXT
87 #define COMPILE_TEMPLATE_MMXEXT 1
88 #define RENAME(a) a ## _MMXEXT
112 const int firstLumSrcY= vLumFilterPos[
dstY];
113 const int firstChrSrcY= vChrFilterPos[chrDstY];
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;
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];
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];
145 tmpA[i] = tmpA[i - 1];
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];
155 for ( ; i <
end; i++) {
156 tmpU[i] = chrUSrcPtr[i];
159 tmpU[i] = tmpU[i - 1];
167 *(
const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ];
168 *(
const void**)&lumMmxFilter[s*i+
APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)];
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)];
180 *(
const void**)&chrMmxFilter[s*i ]= chrUSrcPtr[i ];
181 *(
const void**)&chrMmxFilter[s*i+
APCK_PTR2/4 ]= chrUSrcPtr[i+(vChrFilterSize>1)];
183 chrMmxFilter[s*i+
APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ]
184 + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0);
188 *(
const void**)&lumMmxFilter[4*i+0]= lumSrcPtr[i];
191 ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001
U;
192 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
193 *(
const void**)&alpMmxFilter[4*i+0]= alpSrcPtr[i];
195 alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2];
199 *(
const void**)&chrMmxFilter[4*i+0]= chrUSrcPtr[i];
202 ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001
U;
209 static void yuv2yuvX_sse3(
const int16_t *
filter,
int filterSize,
213 if(((
int)dest) & 15){
214 return yuv2yuvX_MMXEXT(filter, filterSize, src, dest, dstW, dither, 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"
225 __asm__
volatile(
"movq (%0), %%xmm3\n\t"
230 "pxor %%xmm0, %%xmm0\n\t"
231 "punpcklbw %%xmm0, %%xmm3\n\t"
232 "psraw $4, %%xmm3\n\t"
233 "movdqa %%xmm3, %%xmm4\n\t"
234 "movdqa %%xmm3, %%xmm7\n\t"
236 "mov %0, %%"REG_d
" \n\t"\
237 "mov (%%"REG_d
"), %%"REG_S
" \n\t"\
240 "movddup 8(%%"REG_d
"), %%xmm0 \n\t" \
241 "movdqa (%%"REG_S
", %%"REG_c
", 2), %%xmm2 \n\t" \
242 "movdqa 16(%%"REG_S
", %%"REG_c
", 2), %%xmm5 \n\t" \
243 "add $16, %%"REG_d
" \n\t"\
244 "mov (%%"REG_d
"), %%"REG_S
" \n\t"\
245 "test %%"REG_S
", %%"REG_S
" \n\t"\
246 "pmulhw %%xmm0, %%xmm2 \n\t"\
247 "pmulhw %%xmm0, %%xmm5 \n\t"\
248 "paddw %%xmm2, %%xmm3 \n\t"\
249 "paddw %%xmm5, %%xmm4 \n\t"\
251 "psraw $3, %%xmm3 \n\t"\
252 "psraw $3, %%xmm4 \n\t"\
253 "packuswb %%xmm4, %%xmm3 \n\t"
254 "movntdq %%xmm3, (%1, %%"REG_c
")\n\t"
255 "add $16, %%"REG_c
" \n\t"\
256 "cmp %2, %%"REG_c
" \n\t"\
257 "movdqa %%xmm7, %%xmm3\n\t"
258 "movdqa %%xmm7, %%xmm4\n\t"
259 "mov %0, %%"REG_d
" \n\t"\
260 "mov (%%"REG_d
"), %%"REG_S
" \n\t"\
263 "r" (dest-offset),
"g" ((
x86_reg)(dstW+offset)),
"m" (offset)
264 :
"%"REG_d,
"%"REG_S,
"%"REG_c
271 #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \
272 extern void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \
273 SwsContext *c, int16_t *data, \
274 int dstW, const uint8_t *src, \
275 const int16_t *filter, \
276 const int32_t *filterPos, int filterSize)
278 #define SCALE_FUNCS(filter_n, opt) \
279 SCALE_FUNC(filter_n, 8, 15, opt); \
280 SCALE_FUNC(filter_n, 9, 15, opt); \
281 SCALE_FUNC(filter_n, 10, 15, opt); \
282 SCALE_FUNC(filter_n, 12, 15, opt); \
283 SCALE_FUNC(filter_n, 14, 15, opt); \
284 SCALE_FUNC(filter_n, 16, 15, opt); \
285 SCALE_FUNC(filter_n, 8, 19, opt); \
286 SCALE_FUNC(filter_n, 9, 19, opt); \
287 SCALE_FUNC(filter_n, 10, 19, opt); \
288 SCALE_FUNC(filter_n, 12, 19, opt); \
289 SCALE_FUNC(filter_n, 14, 19, opt); \
290 SCALE_FUNC(filter_n, 16, 19, opt)
292 #define SCALE_FUNCS_MMX(opt) \
293 SCALE_FUNCS(4, opt); \
294 SCALE_FUNCS(8, opt); \
297 #define SCALE_FUNCS_SSE(opt) \
298 SCALE_FUNCS(4, opt); \
299 SCALE_FUNCS(8, opt); \
300 SCALE_FUNCS(X4, opt); \
310 #define VSCALEX_FUNC(size, opt) \
311 extern void ff_yuv2planeX_ ## size ## _ ## opt(const int16_t *filter, int filterSize, \
312 const int16_t **src, uint8_t *dest, int dstW, \
313 const uint8_t *dither, int offset)
314 #define VSCALEX_FUNCS(opt) \
315 VSCALEX_FUNC(8, opt); \
316 VSCALEX_FUNC(9, opt); \
317 VSCALEX_FUNC(10, opt)
327 #define VSCALE_FUNC(size, opt) \
328 extern void ff_yuv2plane1_ ## size ## _ ## opt(const int16_t *src, uint8_t *dst, int dstW, \
329 const uint8_t *dither, int offset)
330 #define VSCALE_FUNCS(opt1, opt2) \
331 VSCALE_FUNC(8, opt1); \
332 VSCALE_FUNC(9, opt2); \
333 VSCALE_FUNC(10, opt2); \
334 VSCALE_FUNC(16, opt1)
343 #define INPUT_Y_FUNC(fmt, opt) \
344 extern void ff_ ## fmt ## ToY_ ## opt(uint8_t *dst, const uint8_t *src, \
345 const uint8_t *unused1, const uint8_t *unused2, \
346 int w, uint32_t *unused)
347 #define INPUT_UV_FUNC(fmt, opt) \
348 extern void ff_ ## fmt ## ToUV_ ## opt(uint8_t *dstU, uint8_t *dstV, \
349 const uint8_t *unused0, \
350 const uint8_t *src1, \
351 const uint8_t *src2, \
352 int w, uint32_t *unused)
353 #define INPUT_FUNC(fmt, opt) \
354 INPUT_Y_FUNC(fmt, opt); \
355 INPUT_UV_FUNC(fmt, opt)
356 #define INPUT_FUNCS(opt) \
357 INPUT_FUNC(uyvy, opt); \
358 INPUT_FUNC(yuyv, opt); \
359 INPUT_UV_FUNC(nv12, opt); \
360 INPUT_UV_FUNC(nv21, opt); \
361 INPUT_FUNC(rgba, opt); \
362 INPUT_FUNC(bgra, opt); \
363 INPUT_FUNC(argb, opt); \
364 INPUT_FUNC(abgr, opt); \
365 INPUT_FUNC(rgb24, opt); \
366 INPUT_FUNC(bgr24, opt)
381 sws_init_swScale_MMX(c);
382 #if HAVE_MMXEXT_INLINE
384 sws_init_swScale_MMXEXT(c);
392 #define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \
393 if (c->srcBpc == 8) { \
394 hscalefn = c->dstBpc <= 14 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \
395 ff_hscale8to19_ ## filtersize ## _ ## opt1; \
396 } else if (c->srcBpc == 9) { \
397 hscalefn = c->dstBpc <= 14 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \
398 ff_hscale9to19_ ## filtersize ## _ ## opt1; \
399 } else if (c->srcBpc == 10) { \
400 hscalefn = c->dstBpc <= 14 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \
401 ff_hscale10to19_ ## filtersize ## _ ## opt1; \
402 } else if (c->srcBpc == 12) { \
403 hscalefn = c->dstBpc <= 14 ? ff_hscale12to15_ ## filtersize ## _ ## opt2 : \
404 ff_hscale12to19_ ## filtersize ## _ ## opt1; \
405 } 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)) { \
406 hscalefn = c->dstBpc <= 14 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \
407 ff_hscale14to19_ ## filtersize ## _ ## opt1; \
409 av_assert0(c->srcBpc == 16);\
410 hscalefn = c->dstBpc <= 14 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \
411 ff_hscale16to19_ ## filtersize ## _ ## opt1; \
414 #define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
415 switch (filtersize) { \
416 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
417 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
418 default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \
420 #define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case, condition_8bit) \
422 case 16: do_16_case; break; \
423 case 10: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_10_ ## opt; break; \
424 case 9: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2planeX_9_ ## opt; break; \
425 default: if (condition_8bit) break; \
427 #define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \
429 case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \
430 case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \
431 case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \
432 case 8: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \
433 default: av_assert0(c->dstBpc>8); \
435 #define case_rgb(x, X, opt) \
436 case AV_PIX_FMT_ ## X: \
437 c->lumToYV12 = ff_ ## x ## ToY_ ## opt; \
438 if (!c->chrSrcHSubSample) \
439 c->chrToYV12 = ff_ ## x ## ToUV_ ## opt; \
481 #define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \
482 switch (filtersize) { \
483 case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \
484 case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \
485 default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \
486 else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \
493 HAVE_ALIGNED_STACK || ARCH_X86_64);
542 HAVE_ALIGNED_STACK || ARCH_X86_64);
549 HAVE_ALIGNED_STACK || ARCH_X86_64);