39 { 36, 68, 60, 92, 34, 66, 58, 90, },
40 { 100, 4, 124, 28, 98, 2, 122, 26, },
41 { 52, 84, 44, 76, 50, 82, 42, 74, },
42 { 116, 20, 108, 12, 114, 18, 106, 10, },
43 { 32, 64, 56, 88, 38, 70, 62, 94, },
44 { 96, 0, 120, 24, 102, 6, 126, 30, },
45 { 48, 80, 40, 72, 54, 86, 46, 78, },
46 { 112, 16, 104, 8, 118, 22, 110, 14, },
47 { 36, 68, 60, 92, 34, 66, 58, 90, },
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] = ((int)(
FFMIN(dst[i], 30189 << 4) * 4769
U - (39057361 << 2))) >> 12;
220 for (i = 0; i <
width; i++)
221 dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
232 uint32_t *pal,
int isAlpha)
234 void (*toYV12)(
uint8_t *,
const uint8_t *,
const uint8_t *,
const uint8_t *, int, uint32_t *) =
237 const uint8_t *
src = src_in[isAlpha ? 3 : 0];
240 toYV12(formatConvBuffer,
src, src_in[1], src_in[2], srcW, pal);
252 hLumFilterPos, hLumFilterSize);
258 convertRange(dst, dstWidth);
262 int16_t *dst2,
int dstWidth,
270 const uint8_t *src1 = src_in[1], *src2 = src_in[2];
272 uint8_t *buf2 = formatConvBuffer +
274 c->
chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal);
278 uint8_t *buf2 = formatConvBuffer +
286 c->
hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
287 c->
hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
289 c->
hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
296 #define DEBUG_SWSCALE_BUFFERS 0
297 #define DEBUG_BUFFERS(...) \
298 if (DEBUG_SWSCALE_BUFFERS) \
299 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
302 int srcStride[],
int srcSliceY,
303 int srcSliceH,
uint8_t *dst[],
int dstStride[])
368 srcStride[3] = srcStride[0];
373 DEBUG_BUFFERS(
"swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
374 src[0], srcStride[0], src[1], srcStride[1],
375 src[2], srcStride[2], src[3], srcStride[3],
376 dst[0], dstStride[0], dst[1], dstStride[1],
377 dst[2], dstStride[2], dst[3], dstStride[3]);
378 DEBUG_BUFFERS(
"srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
379 srcSliceY, srcSliceH, dstY, dstH);
380 DEBUG_BUFFERS(
"vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
381 vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
383 if (dstStride[0]&15 || dstStride[1]&15 ||
384 dstStride[2]&15 || dstStride[3]&15) {
385 static int warnedAlready = 0;
388 "Warning: dstStride is not aligned!\n"
389 " ->cannot do aligned memory accesses anymore\n");
394 if ( (uintptr_t)dst[0]&15 || (uintptr_t)dst[1]&15 || (uintptr_t)dst[2]&15
395 || (uintptr_t)src[0]&15 || (uintptr_t)src[1]&15 || (uintptr_t)src[2]&15
396 || dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15
397 || srcStride[0]&15 || srcStride[1]&15 || srcStride[2]&15 || srcStride[3]&15
399 static int warnedAlready=0;
410 if (srcSliceY == 0) {
418 if (!should_dither) {
423 for (; dstY <
dstH; dstY++) {
426 dst[0] + dstStride[0] *
dstY,
427 dst[1] + dstStride[1] * chrDstY,
428 dst[2] + dstStride[2] * chrDstY,
429 (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,
434 const int firstLumSrcY =
FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
437 const int firstChrSrcY =
FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
440 int lastLumSrcY =
FFMIN(c->
srcH, firstLumSrcY + vLumFilterSize) - 1;
441 int lastLumSrcY2 =
FFMIN(c->
srcH, firstLumSrcY2 + vLumFilterSize) - 1;
442 int lastChrSrcY =
FFMIN(c->
chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
446 if (firstLumSrcY > lastInLumBuf)
447 lastInLumBuf = firstLumSrcY - 1;
448 if (firstChrSrcY > lastInChrBuf)
449 lastInChrBuf = firstChrSrcY - 1;
450 av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
451 av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
454 DEBUG_BUFFERS(
"\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
455 firstLumSrcY, lastLumSrcY, lastInLumBuf);
456 DEBUG_BUFFERS(
"\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
457 firstChrSrcY, lastChrSrcY, lastInChrBuf);
460 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
464 lastLumSrcY = srcSliceY + srcSliceH - 1;
465 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
466 DEBUG_BUFFERS(
"buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
467 lastLumSrcY, lastChrSrcY);
471 while (lastInLumBuf < lastLumSrcY) {
473 src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
474 src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
475 src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
476 src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
480 av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH);
481 av_assert0(lastInLumBuf + 1 - srcSliceY >= 0);
482 hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc,
483 hLumFilter, hLumFilterPos, hLumFilterSize,
484 formatConvBuffer, pal, 0);
485 if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
486 hyscale(c, alpPixBuf[lumBufIndex], dstW, src1, srcW,
487 lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
488 formatConvBuffer, pal, 1);
491 lumBufIndex, lastInLumBuf);
493 while (lastInChrBuf < lastChrSrcY) {
495 src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
496 src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
497 src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
498 src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
502 av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
503 av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0);
507 hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
508 chrDstW, src1, chrSrcW, chrXInc,
509 hChrFilter, hChrFilterPos, hChrFilterSize,
510 formatConvBuffer, pal);
513 chrBufIndex, lastInChrBuf);
516 if (lumBufIndex >= vLumBufSize)
518 if (chrBufIndex >= vChrBufSize)
525 lastInLumBuf, lastInChrBuf);
531 if (dstY >= dstH - 2) {
535 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
540 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf +
vLumBufSize;
541 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
542 const int16_t **chrVSrcPtr = (
const int16_t **)(
void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
543 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ?
544 (
const int16_t **)(
void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
569 if (vLumFilterSize == 1) {
577 if (!((dstY & chrSkipMask) ||
isGray(dstFormat))) {
580 vChrFilterSize, chrUSrcPtr, chrVSrcPtr,
582 }
else if (vChrFilterSize == 1) {
587 vChrFilterSize, chrUSrcPtr, dest[1],
590 vChrFilterSize, chrVSrcPtr, dest[2],
595 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
599 if (vLumFilterSize == 1) {
604 vLumFilterSize, alpSrcPtr, dest[3],
608 }
else if (yuv2packedX) {
609 av_assert1(lumSrcPtr + vLumFilterSize - 1 < (
const int16_t **)lumPixBuf + vLumBufSize * 2);
610 av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (
const int16_t **)chrUPixBuf + vChrBufSize * 2);
612 vChrFilterSize <= 2) {
613 int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
615 alpPixBuf ? *alpSrcPtr : NULL,
616 dest[0], dstW, chrAlpha, dstY);
617 }
else if (c->
yuv2packed2 && vLumFilterSize == 2 &&
618 vChrFilterSize == 2) {
619 int lumAlpha = vLumFilter[2 * dstY + 1];
620 int chrAlpha = vChrFilter[2 * dstY + 1];
622 lumMmxFilter[3] = vLumFilter[2 *
dstY] * 0x10001;
624 chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
626 alpPixBuf ? alpSrcPtr : NULL,
627 dest[0], dstW, lumAlpha, chrAlpha, dstY);
630 lumSrcPtr, vLumFilterSize,
631 vChrFilter + dstY * vChrFilterSize,
632 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
633 alpSrcPtr, dest[0], dstW, dstY);
637 yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
638 lumSrcPtr, vLumFilterSize,
639 vChrFilter + dstY * vChrFilterSize,
640 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
641 alpSrcPtr, dest, dstW, dstY);
647 int height = dstY - lastDstY;
651 fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
655 fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
658 #if HAVE_MMXEXT_INLINE
660 __asm__
volatile (
"sfence" :::
"memory");
671 return dstY - lastDstY;
749 src[3] = src[2] = NULL;
757 const int linesizes[4])
762 for (i = 0; i < 4; i++) {
764 if (!data[plane] || !linesizes[plane])
772 const uint16_t *src,
int stride,
int h)
777 for (yp=0; yp<h; yp++) {
778 for (xp=0; xp+2<stride; xp+=3) {
779 int x,
y, z,
r,
g,
b;
828 const uint16_t *src,
int stride,
int h)
833 for (yp=0; yp<h; yp++) {
834 for (xp=0; xp+2<stride; xp+=3) {
835 int x,
y, z,
r,
g,
b;
888 const uint8_t *
const srcSlice[],
889 const int srcStride[],
int srcSliceY,
890 int srcSliceH,
uint8_t *
const dst[],
891 const int dstStride[])
898 if (!srcStride || !dstStride || !dst || !srcSlice) {
899 av_log(c,
AV_LOG_ERROR,
"One of the input parameters to sws_scale() is NULL, please check the calling code\n");
902 memcpy(src2, srcSlice,
sizeof(src2));
903 memcpy(dst2, dst,
sizeof(dst2));
918 if (c->
sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->
srcH) {
927 for (i = 0; i < 256; i++) {
928 int r,
g,
b,
y,
u,
v,
a = 0xff;
930 uint32_t p = ((
const uint32_t *)(srcSlice[1]))[i];
931 a = (p >> 24) & 0xFF;
932 r = (p >> 16) & 0xFF;
937 g = ((i >> 2) & 7) * 36;
941 g = ((i >> 3) & 7) * 36;
944 r = ( i >> 3 ) * 255;
945 g = ((i >> 1) & 3) * 85;
951 b = ( i >> 3 ) * 255;
952 g = ((i >> 1) & 3) * 85;
955 #define RGB2YUV_SHIFT 15
956 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
957 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
958 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
959 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
960 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
961 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
962 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
963 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
964 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
969 c->
pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
976 c->
pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
982 c->
pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
988 c->
pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
995 c->
pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
1007 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1008 for (y=0; y<srcSliceH; y++){
1009 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->
srcW);
1010 for (x=c->
src0Alpha-1; x<4*c->srcW; x+=4) {
1011 base[ srcStride[0]*y + x] = 0xFF;
1023 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1025 xyz12Torgb48(c, (uint16_t*)base, (
const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
1030 for (i = 0; i < 4; i++)
1037 int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
1039 int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
1046 if (srcSliceY + srcSliceH == c->
srcH)
1049 ret = c->
swscale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
1053 int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
1055 int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
1058 src2[0] += (srcSliceH - 1) * srcStride[0];
1062 src2[3] += (srcSliceH - 1) * srcStride[3];
1063 dst2[0] += ( c->
dstH - 1) * dstStride[0];
1066 dst2[3] += ( c->
dstH - 1) * dstStride[3];
1075 ret = c->
swscale(c, src2, srcStride2, c->
srcH-srcSliceY-srcSliceH,
1076 srcSliceH, dst2, dstStride2);
1082 rgb48Toxyz12(c, (uint16_t*)dst2[0], (
const uint16_t*)dst2[0], dstStride[0]/2, ret);