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);
262 c->
hyScale(c, dst, dstWidth, src, hLumFilter,
263 hLumFilterPos, hLumFilterSize);
269 convertRange(dst, dstWidth);
273 int dstWidth,
const uint8_t *src1,
277 unsigned int xpos = 0;
278 for (i = 0; i < dstWidth; i++) {
279 register unsigned int xx = xpos >> 16;
280 register unsigned int xalpha = (xpos & 0xFFFF) >> 9;
281 dst1[i] = (src1[xx] * (xalpha ^ 127) + src1[xx + 1] * xalpha);
282 dst2[i] = (src2[xx] * (xalpha ^ 127) + src2[xx + 1] * xalpha);
285 for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) {
286 dst1[i] = src1[srcW-1]*128;
287 dst2[i] = src2[srcW-1]*128;
292 int16_t *dst2,
int dstWidth,
300 const uint8_t *src1 = src_in[1], *src2 = src_in[2];
302 uint8_t *buf2 = formatConvBuffer +
304 c->
chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal);
308 uint8_t *buf2 = formatConvBuffer +
316 c->
hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
317 c->
hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
319 c->
hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
326 #define DEBUG_SWSCALE_BUFFERS 0
327 #define DEBUG_BUFFERS(...) \
328 if (DEBUG_SWSCALE_BUFFERS) \
329 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
332 int srcStride[],
int srcSliceY,
333 int srcSliceH,
uint8_t *
dst[],
int dstStride[])
394 srcStride[3] = srcStride[0];
399 DEBUG_BUFFERS(
"swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
400 src[0], srcStride[0], src[1], srcStride[1],
401 src[2], srcStride[2], src[3], srcStride[3],
402 dst[0], dstStride[0], dst[1], dstStride[1],
403 dst[2], dstStride[2], dst[3], dstStride[3]);
404 DEBUG_BUFFERS(
"srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
405 srcSliceY, srcSliceH, dstY, dstH);
406 DEBUG_BUFFERS(
"vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
407 vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
409 if (dstStride[0]%16 !=0 || dstStride[1]%16 !=0 ||
410 dstStride[2]%16 !=0 || dstStride[3]%16 != 0) {
411 static int warnedAlready = 0;
414 "Warning: dstStride is not aligned!\n"
415 " ->cannot do aligned memory accesses anymore\n");
420 if ( (uintptr_t)dst[0]%16 || (uintptr_t)dst[1]%16 || (uintptr_t)dst[2]%16
421 || (uintptr_t)src[0]%16 || (uintptr_t)src[1]%16 || (uintptr_t)src[2]%16
422 || dstStride[0]%16 || dstStride[1]%16 || dstStride[2]%16 || dstStride[3]%16
423 || srcStride[0]%16 || srcStride[1]%16 || srcStride[2]%16 || srcStride[3]%16
425 static int warnedAlready=0;
436 if (srcSliceY == 0) {
444 if (!should_dither) {
449 for (; dstY <
dstH; dstY++) {
452 dst[0] + dstStride[0] *
dstY,
453 dst[1] + dstStride[1] * chrDstY,
454 dst[2] + dstStride[2] * chrDstY,
455 (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ? dst[3] + dstStride[3] * dstY :
NULL,
460 const int firstLumSrcY =
FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
463 const int firstChrSrcY =
FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
466 int lastLumSrcY =
FFMIN(c->
srcH, firstLumSrcY + vLumFilterSize) - 1;
467 int lastLumSrcY2 =
FFMIN(c->
srcH, firstLumSrcY2 + vLumFilterSize) - 1;
468 int lastChrSrcY =
FFMIN(c->
chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
472 if (firstLumSrcY > lastInLumBuf)
473 lastInLumBuf = firstLumSrcY - 1;
474 if (firstChrSrcY > lastInChrBuf)
475 lastInChrBuf = firstChrSrcY - 1;
476 av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
477 av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
480 DEBUG_BUFFERS(
"\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
481 firstLumSrcY, lastLumSrcY, lastInLumBuf);
482 DEBUG_BUFFERS(
"\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
483 firstChrSrcY, lastChrSrcY, lastInChrBuf);
486 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
490 lastLumSrcY = srcSliceY + srcSliceH - 1;
491 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
492 DEBUG_BUFFERS(
"buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
493 lastLumSrcY, lastChrSrcY);
497 while (lastInLumBuf < lastLumSrcY) {
499 src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
500 src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
501 src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
502 src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
506 av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH);
507 av_assert0(lastInLumBuf + 1 - srcSliceY >= 0);
508 hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc,
509 hLumFilter, hLumFilterPos, hLumFilterSize,
510 formatConvBuffer, pal, 0);
511 if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
512 hyscale(c, alpPixBuf[lumBufIndex], dstW, src1, srcW,
513 lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
514 formatConvBuffer, pal, 1);
517 lumBufIndex, lastInLumBuf);
519 while (lastInChrBuf < lastChrSrcY) {
521 src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
522 src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
523 src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
524 src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
528 av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
529 av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0);
533 hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
534 chrDstW, src1, chrSrcW, chrXInc,
535 hChrFilter, hChrFilterPos, hChrFilterSize,
536 formatConvBuffer, pal);
539 chrBufIndex, lastInChrBuf);
542 if (lumBufIndex >= vLumBufSize)
544 if (chrBufIndex >= vChrBufSize)
551 lastInLumBuf, lastInChrBuf);
557 if (dstY >= dstH - 2) {
561 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
566 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf +
vLumBufSize;
567 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
568 const int16_t **chrVSrcPtr = (
const int16_t **)(
void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
569 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ?
570 (
const int16_t **)(
void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
595 if (vLumFilterSize == 1) {
603 if (!((dstY & chrSkipMask) ||
isGray(dstFormat))) {
606 vChrFilterSize, chrUSrcPtr, chrVSrcPtr,
608 }
else if (vChrFilterSize == 1) {
613 vChrFilterSize, chrUSrcPtr, dest[1],
616 vChrFilterSize, chrVSrcPtr, dest[2],
621 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
625 if (vLumFilterSize == 1) {
630 vLumFilterSize, alpSrcPtr, dest[3],
634 }
else if (yuv2packedX) {
635 av_assert1(lumSrcPtr + vLumFilterSize - 1 < (
const int16_t **)lumPixBuf + vLumBufSize * 2);
636 av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (
const int16_t **)chrUPixBuf + vChrBufSize * 2);
638 vChrFilterSize <= 2) {
639 int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
641 alpPixBuf ? *alpSrcPtr : NULL,
642 dest[0], dstW, chrAlpha, dstY);
643 }
else if (c->
yuv2packed2 && vLumFilterSize == 2 &&
644 vChrFilterSize == 2) {
645 int lumAlpha = vLumFilter[2 * dstY + 1];
646 int chrAlpha = vChrFilter[2 * dstY + 1];
648 lumMmxFilter[3] = vLumFilter[2 *
dstY] * 0x10001;
650 chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
652 alpPixBuf ? alpSrcPtr : NULL,
653 dest[0], dstW, lumAlpha, chrAlpha, dstY);
656 lumSrcPtr, vLumFilterSize,
657 vChrFilter + dstY * vChrFilterSize,
658 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
659 alpSrcPtr, dest[0], dstW, dstY);
663 yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
664 lumSrcPtr, vLumFilterSize,
665 vChrFilter + dstY * vChrFilterSize,
666 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
667 alpSrcPtr, dest, dstW, dstY);
673 int height = dstY - lastDstY;
677 fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
681 fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
684 #if HAVE_MMXEXT_INLINE
686 __asm__
volatile (
"sfence" :::
"memory");
697 return dstY - lastDstY;
768 src[3] = src[2] =
NULL;
776 const int linesizes[4])
781 for (i = 0; i < 4; i++) {
783 if (!data[plane] || !linesizes[plane])
795 const uint8_t *
const srcSlice[],
796 const int srcStride[],
int srcSliceY,
797 int srcSliceH,
uint8_t *
const dst[],
798 const int dstStride[])
805 if (!srcSlice || !dstStride || !dst || !srcSlice) {
806 av_log(c,
AV_LOG_ERROR,
"One of the input parameters to sws_scale() is NULL, please check the calling code\n");
809 memcpy(src2, srcSlice,
sizeof(src2));
810 memcpy(dst2, dst,
sizeof(dst2));
825 if (c->
sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->
srcH) {
834 for (i = 0; i < 256; i++) {
835 int p,
r,
g,
b,
y,
u,
v,
a = 0xff;
837 p = ((
const uint32_t *)(srcSlice[1]))[i];
838 a = (p >> 24) & 0xFF;
839 r = (p >> 16) & 0xFF;
844 g = ((i >> 2) & 7) * 36;
848 g = ((i >> 3) & 7) * 36;
851 r = ( i >> 3 ) * 255;
852 g = ((i >> 1) & 3) * 85;
858 b = ( i >> 3 ) * 255;
859 g = ((i >> 1) & 3) * 85;
862 #define RGB2YUV_SHIFT 15
863 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
864 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
865 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
866 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
867 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
868 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
869 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
870 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
871 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
876 c->
pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
883 c->
pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
889 c->
pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
895 c->
pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
902 c->
pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
911 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
912 for (y=0; y<srcSliceH; y++){
913 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->
srcW);
914 for (x=c->
src0Alpha-1; x<4*c->srcW; x+=4) {
915 base[ srcStride[0]*y + x] = 0xFF;
922 for (i = 0; i < 4; i++)
929 int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
931 int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
938 if (srcSliceY + srcSliceH == c->
srcH)
941 ret = c->
swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
945 int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
947 int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
950 src2[0] += (srcSliceH - 1) * srcStride[0];
954 src2[3] += (srcSliceH - 1) * srcStride[3];
955 dst2[0] += ( c->
dstH - 1) * dstStride[0];
958 dst2[3] += ( c->
dstH - 1) * dstStride[3];
967 ret = c->
swScale(c, src2, srcStride2, c->
srcH-srcSliceY-srcSliceH,
968 srcSliceH, dst2, dstStride2);