40 { 36, 68, 60, 92, 34, 66, 58, 90, },
41 { 100, 4, 124, 28, 98, 2, 122, 26, },
42 { 52, 84, 44, 76, 50, 82, 42, 74, },
43 { 116, 20, 108, 12, 114, 18, 106, 10, },
44 { 32, 64, 56, 88, 38, 70, 62, 94, },
45 { 96, 0, 120, 24, 102, 6, 126, 30, },
46 { 48, 80, 40, 72, 54, 86, 46, 78, },
47 { 112, 16, 104, 8, 118, 22, 110, 14, },
51 64, 64, 64, 64, 64, 64, 64, 64
59 for (i = 0; i <
height; i++) {
60 memset(ptr, val, width);
67 const int32_t *filterPos,
int filterSize)
72 const uint16_t *
src = (
const uint16_t *) _src;
79 for (i = 0; i <
dstW; i++) {
81 int srcPos = filterPos[i];
84 for (j = 0; j < filterSize; j++) {
85 val += src[srcPos + j] * filter[filterSize * i + j];
88 dst[i] =
FFMIN(val >> sh, (1 << 19) - 1);
94 const int32_t *filterPos,
int filterSize)
98 const uint16_t *
src = (
const uint16_t *) _src;
104 for (i = 0; i <
dstW; i++) {
106 int srcPos = filterPos[i];
109 for (j = 0; j < filterSize; j++) {
110 val += src[srcPos + j] * filter[filterSize * i + j];
113 dst[i] =
FFMIN(val >> sh, (1 << 15) - 1);
120 const int32_t *filterPos,
int filterSize)
123 for (i = 0; i <
dstW; i++) {
125 int srcPos = filterPos[i];
127 for (j = 0; j < filterSize; j++) {
128 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
130 dst[i] =
FFMIN(val >> 7, (1 << 15) - 1);
136 const int32_t *filterPos,
int filterSize)
140 for (i = 0; i <
dstW; i++) {
142 int srcPos = filterPos[i];
144 for (j = 0; j < filterSize; j++) {
145 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
147 dst[i] =
FFMIN(val >> 3, (1 << 19) - 1);
156 for (i = 0; i <
width; i++) {
157 dstU[i] = (
FFMIN(dstU[i], 30775) * 4663 - 9289992) >> 12;
158 dstV[i] = (
FFMIN(dstV[i], 30775) * 4663 - 9289992) >> 12;
165 for (i = 0; i <
width; i++) {
166 dstU[i] = (dstU[i] * 1799 + 4081085) >> 11;
167 dstV[i] = (dstV[i] * 1799 + 4081085) >> 11;
174 for (i = 0; i <
width; i++)
175 dst[i] = (
FFMIN(dst[i], 30189) * 19077 - 39057361) >> 14;
181 for (i = 0; i <
width; i++)
182 dst[i] = (dst[i] * 14071 + 33561947) >> 14;
190 for (i = 0; i <
width; i++) {
191 dstU[i] = (
FFMIN(dstU[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12;
192 dstV[i] = (
FFMIN(dstV[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12;
201 for (i = 0; i <
width; i++) {
202 dstU[i] = (dstU[i] * 1799 + (4081085 << 4)) >> 11;
203 dstV[i] = (dstV[i] * 1799 + (4081085 << 4)) >> 11;
211 for (i = 0; i <
width; i++)
212 dst[i] = (
FFMIN(dst[i], 30189 << 4) * 4769 - (39057361 << 2)) >> 12;
219 for (i = 0; i <
width; i++)
220 dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
227 unsigned int xpos = 0;
228 for (i = 0; i < dstWidth; i++) {
229 register unsigned int xx = xpos >> 16;
230 register unsigned int xalpha = (xpos & 0xFFFF) >> 9;
231 dst[i] = (src[xx] << 7) + (src[xx + 1] - src[xx]) * xalpha;
234 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--)
235 dst[i] = src[srcW-1]*128;
246 uint32_t *pal,
int isAlpha)
248 void (*toYV12)(
uint8_t *,
const uint8_t *,
const uint8_t *,
const uint8_t *, int, uint32_t *) =
251 const uint8_t *
src = src_in[isAlpha ? 3 : 0];
254 toYV12(formatConvBuffer,
src, src_in[1], src_in[2], srcW, pal);
266 hLumFilterPos, hLumFilterSize);
272 convertRange(dst, dstWidth);
276 int dstWidth,
const uint8_t *src1,
280 unsigned int xpos = 0;
281 for (i = 0; i < dstWidth; i++) {
282 register unsigned int xx = xpos >> 16;
283 register unsigned int xalpha = (xpos & 0xFFFF) >> 9;
284 dst1[i] = (src1[xx] * (xalpha ^ 127) + src1[xx + 1] * xalpha);
285 dst2[i] = (src2[xx] * (xalpha ^ 127) + src2[xx + 1] * xalpha);
288 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
289 dst1[i] = src1[srcW-1]*128;
290 dst2[i] = src2[srcW-1]*128;
295 int16_t *dst2,
int dstWidth,
303 const uint8_t *src1 = src_in[1], *src2 = src_in[2];
305 uint8_t *buf2 = formatConvBuffer +
307 c->
chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal);
311 uint8_t *buf2 = formatConvBuffer +
319 c->
hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
320 c->
hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
322 c->
hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
329 #define DEBUG_SWSCALE_BUFFERS 0
330 #define DEBUG_BUFFERS(...) \
331 if (DEBUG_SWSCALE_BUFFERS) \
332 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
335 int srcStride[],
int srcSliceY,
336 int srcSliceH,
uint8_t *dst[],
int dstStride[])
401 srcStride[3] = srcStride[0];
406 DEBUG_BUFFERS(
"swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
407 src[0], srcStride[0], src[1], srcStride[1],
408 src[2], srcStride[2], src[3], srcStride[3],
409 dst[0], dstStride[0], dst[1], dstStride[1],
410 dst[2], dstStride[2], dst[3], dstStride[3]);
411 DEBUG_BUFFERS(
"srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
412 srcSliceY, srcSliceH, dstY, dstH);
413 DEBUG_BUFFERS(
"vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
414 vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
416 if (dstStride[0]%16 !=0 || dstStride[1]%16 !=0 ||
417 dstStride[2]%16 !=0 || dstStride[3]%16 != 0) {
418 static int warnedAlready = 0;
421 "Warning: dstStride is not aligned!\n"
422 " ->cannot do aligned memory accesses anymore\n");
427 if ( (uintptr_t)dst[0]%16 || (uintptr_t)dst[1]%16 || (uintptr_t)dst[2]%16
428 || (uintptr_t)src[0]%16 || (uintptr_t)src[1]%16 || (uintptr_t)src[2]%16
429 || dstStride[0]%16 || dstStride[1]%16 || dstStride[2]%16 || dstStride[3]%16
430 || srcStride[0]%16 || srcStride[1]%16 || srcStride[2]%16 || srcStride[3]%16
432 static int warnedAlready=0;
443 if (srcSliceY == 0) {
451 if (!should_dither) {
456 for (; dstY <
dstH; dstY++) {
459 dst[0] + dstStride[0] *
dstY,
460 dst[1] + dstStride[1] * chrDstY,
461 dst[2] + dstStride[2] * chrDstY,
462 (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,
467 const int firstLumSrcY =
FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
470 const int firstChrSrcY =
FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
473 int lastLumSrcY =
FFMIN(c->
srcH, firstLumSrcY + vLumFilterSize) - 1;
474 int lastLumSrcY2 =
FFMIN(c->
srcH, firstLumSrcY2 + vLumFilterSize) - 1;
475 int lastChrSrcY =
FFMIN(c->
chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
479 if (firstLumSrcY > lastInLumBuf)
480 lastInLumBuf = firstLumSrcY - 1;
481 if (firstChrSrcY > lastInChrBuf)
482 lastInChrBuf = firstChrSrcY - 1;
483 av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
484 av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
487 DEBUG_BUFFERS(
"\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
488 firstLumSrcY, lastLumSrcY, lastInLumBuf);
489 DEBUG_BUFFERS(
"\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
490 firstChrSrcY, lastChrSrcY, lastInChrBuf);
493 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
497 lastLumSrcY = srcSliceY + srcSliceH - 1;
498 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
499 DEBUG_BUFFERS(
"buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
500 lastLumSrcY, lastChrSrcY);
504 while (lastInLumBuf < lastLumSrcY) {
506 src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
507 src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
508 src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
509 src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
513 av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH);
514 av_assert0(lastInLumBuf + 1 - srcSliceY >= 0);
515 hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc,
516 hLumFilter, hLumFilterPos, hLumFilterSize,
517 formatConvBuffer, pal, 0);
518 if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
519 hyscale(c, alpPixBuf[lumBufIndex], dstW, src1, srcW,
520 lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
521 formatConvBuffer, pal, 1);
524 lumBufIndex, lastInLumBuf);
526 while (lastInChrBuf < lastChrSrcY) {
528 src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
529 src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
530 src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
531 src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
535 av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
536 av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0);
540 hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
541 chrDstW, src1, chrSrcW, chrXInc,
542 hChrFilter, hChrFilterPos, hChrFilterSize,
543 formatConvBuffer, pal);
546 chrBufIndex, lastInChrBuf);
549 if (lumBufIndex >= vLumBufSize)
551 if (chrBufIndex >= vChrBufSize)
558 lastInLumBuf, lastInChrBuf);
564 if (dstY >= dstH - 2) {
568 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
573 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf +
vLumBufSize;
574 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
575 const int16_t **chrVSrcPtr = (
const int16_t **)(
void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
576 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ?
577 (
const int16_t **)(
void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
602 if (vLumFilterSize == 1) {
610 if (!((dstY & chrSkipMask) ||
isGray(dstFormat))) {
613 vChrFilterSize, chrUSrcPtr, chrVSrcPtr,
615 }
else if (vChrFilterSize == 1) {
620 vChrFilterSize, chrUSrcPtr, dest[1],
623 vChrFilterSize, chrVSrcPtr, dest[2],
628 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
632 if (vLumFilterSize == 1) {
637 vLumFilterSize, alpSrcPtr, dest[3],
641 }
else if (yuv2packedX) {
642 av_assert1(lumSrcPtr + vLumFilterSize - 1 < (
const int16_t **)lumPixBuf + vLumBufSize * 2);
643 av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (
const int16_t **)chrUPixBuf + vChrBufSize * 2);
645 vChrFilterSize <= 2) {
646 int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
648 alpPixBuf ? *alpSrcPtr : NULL,
649 dest[0], dstW, chrAlpha, dstY);
650 }
else if (c->
yuv2packed2 && vLumFilterSize == 2 &&
651 vChrFilterSize == 2) {
652 int lumAlpha = vLumFilter[2 * dstY + 1];
653 int chrAlpha = vChrFilter[2 * dstY + 1];
655 lumMmxFilter[3] = vLumFilter[2 *
dstY] * 0x10001;
657 chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
659 alpPixBuf ? alpSrcPtr : NULL,
660 dest[0], dstW, lumAlpha, chrAlpha, dstY);
663 lumSrcPtr, vLumFilterSize,
664 vChrFilter + dstY * vChrFilterSize,
665 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
666 alpSrcPtr, dest[0], dstW, dstY);
670 yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
671 lumSrcPtr, vLumFilterSize,
672 vChrFilter + dstY * vChrFilterSize,
673 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
674 alpSrcPtr, dest, dstW, dstY);
680 int height = dstY - lastDstY;
684 fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
688 fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
691 #if HAVE_MMXEXT_INLINE
693 __asm__
volatile (
"sfence" :::
"memory");
704 return dstY - lastDstY;
775 src[3] = src[2] = NULL;
783 const int linesizes[4])
788 for (i = 0; i < 4; i++) {
790 if (!data[plane] || !linesizes[plane])
798 const uint16_t *src,
int stride,
int h)
803 for (yp=0; yp<h; yp++) {
804 for (xp=0; xp+2<
stride; xp+=3) {
805 int x,
y, z,
r,
g,
b;
858 const uint8_t *
const srcSlice[],
859 const int srcStride[],
int srcSliceY,
860 int srcSliceH,
uint8_t *
const dst[],
861 const int dstStride[])
868 if (!srcSlice || !dstStride || !dst || !srcSlice) {
869 av_log(c,
AV_LOG_ERROR,
"One of the input parameters to sws_scale() is NULL, please check the calling code\n");
872 memcpy(src2, srcSlice,
sizeof(src2));
873 memcpy(dst2, dst,
sizeof(dst2));
888 if (c->
sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->
srcH) {
897 for (i = 0; i < 256; i++) {
898 int p,
r,
g,
b,
y,
u,
v,
a = 0xff;
900 p = ((
const uint32_t *)(srcSlice[1]))[i];
901 a = (p >> 24) & 0xFF;
902 r = (p >> 16) & 0xFF;
907 g = ((i >> 2) & 7) * 36;
911 g = ((i >> 3) & 7) * 36;
914 r = ( i >> 3 ) * 255;
915 g = ((i >> 1) & 3) * 85;
921 b = ( i >> 3 ) * 255;
922 g = ((i >> 1) & 3) * 85;
925 #define RGB2YUV_SHIFT 15
926 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
927 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
928 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
929 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
930 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
931 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
932 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
933 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
934 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
939 c->
pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
946 c->
pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
952 c->
pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
958 c->
pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
965 c->
pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
977 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
978 for (y=0; y<srcSliceH; y++){
979 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->
srcW);
980 for (x=c->
src0Alpha-1; x<4*c->srcW; x+=4) {
981 base[ srcStride[0]*y + x] = 0xFF;
993 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
995 xyz12Torgb48(c, (uint16_t*)base, (
const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
1000 for (i = 0; i < 4; i++)
1007 int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
1009 int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
1016 if (srcSliceY + srcSliceH == c->
srcH)
1019 ret = c->
swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
1023 int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
1025 int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
1028 src2[0] += (srcSliceH - 1) * srcStride[0];
1032 src2[3] += (srcSliceH - 1) * srcStride[3];
1033 dst2[0] += ( c->
dstH - 1) * dstStride[0];
1036 dst2[3] += ( c->
dstH - 1) * dstStride[3];
1045 ret = c->
swScale(c, src2, srcStride2, c->
srcH-srcSliceY-srcSliceH,
1046 srcSliceH, dst2, dstStride2);