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, },
48 { 36, 68, 60, 92, 34, 66, 58, 90, },
52 64, 64, 64, 64, 64, 64, 64, 64
60 for (i = 0; i <
height; i++) {
61 memset(ptr, val, width);
68 const int32_t *filterPos,
int filterSize)
73 const uint16_t *
src = (
const uint16_t *) _src;
80 for (i = 0; i <
dstW; i++) {
82 int srcPos = filterPos[i];
85 for (j = 0; j < filterSize; j++) {
86 val += src[srcPos + j] * filter[filterSize * i + j];
89 dst[i] =
FFMIN(val >> sh, (1 << 19) - 1);
95 const int32_t *filterPos,
int filterSize)
99 const uint16_t *
src = (
const uint16_t *) _src;
105 for (i = 0; i <
dstW; i++) {
107 int srcPos = filterPos[i];
110 for (j = 0; j < filterSize; j++) {
111 val += src[srcPos + j] * filter[filterSize * i + j];
114 dst[i] =
FFMIN(val >> sh, (1 << 15) - 1);
121 const int32_t *filterPos,
int filterSize)
124 for (i = 0; i <
dstW; i++) {
126 int srcPos = filterPos[i];
128 for (j = 0; j < filterSize; j++) {
129 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
131 dst[i] =
FFMIN(val >> 7, (1 << 15) - 1);
137 const int32_t *filterPos,
int filterSize)
141 for (i = 0; i <
dstW; i++) {
143 int srcPos = filterPos[i];
145 for (j = 0; j < filterSize; j++) {
146 val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
148 dst[i] =
FFMIN(val >> 3, (1 << 19) - 1);
157 for (i = 0; i <
width; i++) {
158 dstU[i] = (
FFMIN(dstU[i], 30775) * 4663 - 9289992) >> 12;
159 dstV[i] = (
FFMIN(dstV[i], 30775) * 4663 - 9289992) >> 12;
166 for (i = 0; i <
width; i++) {
167 dstU[i] = (dstU[i] * 1799 + 4081085) >> 11;
168 dstV[i] = (dstV[i] * 1799 + 4081085) >> 11;
175 for (i = 0; i <
width; i++)
176 dst[i] = (
FFMIN(dst[i], 30189) * 19077 - 39057361) >> 14;
182 for (i = 0; i <
width; i++)
183 dst[i] = (dst[i] * 14071 + 33561947) >> 14;
191 for (i = 0; i <
width; i++) {
192 dstU[i] = (
FFMIN(dstU[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12;
193 dstV[i] = (
FFMIN(dstV[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12;
202 for (i = 0; i <
width; i++) {
203 dstU[i] = (dstU[i] * 1799 + (4081085 << 4)) >> 11;
204 dstV[i] = (dstV[i] * 1799 + (4081085 << 4)) >> 11;
212 for (i = 0; i <
width; i++) {
213 dst[i] = ((int)(
FFMIN(dst[i], 30189 << 4) * 4769
U - (39057361 << 2))) >> 12;
221 for (i = 0; i <
width; i++)
222 dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
233 uint32_t *pal,
int isAlpha)
235 void (*toYV12)(
uint8_t *,
const uint8_t *,
const uint8_t *,
const uint8_t *, int, uint32_t *) =
238 const uint8_t *
src = src_in[isAlpha ? 3 : 0];
241 toYV12(formatConvBuffer,
src, src_in[1], src_in[2], srcW, pal);
253 hLumFilterPos, hLumFilterSize);
259 convertRange(dst, dstWidth);
263 int16_t *dst2,
int dstWidth,
271 const uint8_t *src1 = src_in[1], *src2 = src_in[2];
273 uint8_t *buf2 = formatConvBuffer +
275 c->
chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal);
279 uint8_t *buf2 = formatConvBuffer +
287 c->
hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
288 c->
hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
290 c->
hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
297 #define DEBUG_SWSCALE_BUFFERS 0
298 #define DEBUG_BUFFERS(...) \
299 if (DEBUG_SWSCALE_BUFFERS) \
300 av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
303 int srcStride[],
int srcSliceY,
304 int srcSliceH,
uint8_t *dst[],
int dstStride[])
369 srcStride[3] = srcStride[0];
374 DEBUG_BUFFERS(
"swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
375 src[0], srcStride[0], src[1], srcStride[1],
376 src[2], srcStride[2], src[3], srcStride[3],
377 dst[0], dstStride[0], dst[1], dstStride[1],
378 dst[2], dstStride[2], dst[3], dstStride[3]);
379 DEBUG_BUFFERS(
"srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
380 srcSliceY, srcSliceH, dstY, dstH);
381 DEBUG_BUFFERS(
"vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
382 vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
384 if (dstStride[0]&15 || dstStride[1]&15 ||
385 dstStride[2]&15 || dstStride[3]&15) {
386 static int warnedAlready = 0;
389 "Warning: dstStride is not aligned!\n"
390 " ->cannot do aligned memory accesses anymore\n");
395 if ( (uintptr_t)dst[0]&15 || (uintptr_t)dst[1]&15 || (uintptr_t)dst[2]&15
396 || (uintptr_t)src[0]&15 || (uintptr_t)src[1]&15 || (uintptr_t)src[2]&15
397 || dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15
398 || srcStride[0]&15 || srcStride[1]&15 || srcStride[2]&15 || srcStride[3]&15
400 static int warnedAlready=0;
411 if (srcSliceY == 0) {
419 if (!should_dither) {
424 for (; dstY <
dstH; dstY++) {
427 dst[0] + dstStride[0] *
dstY,
428 dst[1] + dstStride[1] * chrDstY,
429 dst[2] + dstStride[2] * chrDstY,
430 (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,
435 const int firstLumSrcY =
FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
438 const int firstChrSrcY =
FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
441 int lastLumSrcY =
FFMIN(c->
srcH, firstLumSrcY + vLumFilterSize) - 1;
442 int lastLumSrcY2 =
FFMIN(c->
srcH, firstLumSrcY2 + vLumFilterSize) - 1;
443 int lastChrSrcY =
FFMIN(c->
chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
447 if (firstLumSrcY > lastInLumBuf)
448 lastInLumBuf = firstLumSrcY - 1;
449 if (firstChrSrcY > lastInChrBuf)
450 lastInChrBuf = firstChrSrcY - 1;
451 av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
452 av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
455 DEBUG_BUFFERS(
"\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
456 firstLumSrcY, lastLumSrcY, lastInLumBuf);
457 DEBUG_BUFFERS(
"\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
458 firstChrSrcY, lastChrSrcY, lastInChrBuf);
461 enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
465 lastLumSrcY = srcSliceY + srcSliceH - 1;
466 lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
467 DEBUG_BUFFERS(
"buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
468 lastLumSrcY, lastChrSrcY);
472 while (lastInLumBuf < lastLumSrcY) {
474 src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
475 src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
476 src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
477 src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
481 av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH);
482 av_assert0(lastInLumBuf + 1 - srcSliceY >= 0);
483 hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc,
484 hLumFilter, hLumFilterPos, hLumFilterSize,
485 formatConvBuffer, pal, 0);
486 if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
487 hyscale(c, alpPixBuf[lumBufIndex], dstW, src1, srcW,
488 lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
489 formatConvBuffer, pal, 1);
492 lumBufIndex, lastInLumBuf);
494 while (lastInChrBuf < lastChrSrcY) {
496 src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
497 src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
498 src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
499 src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
503 av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
504 av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0);
508 hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
509 chrDstW, src1, chrSrcW, chrXInc,
510 hChrFilter, hChrFilterPos, hChrFilterSize,
511 formatConvBuffer, pal);
514 chrBufIndex, lastInChrBuf);
517 if (lumBufIndex >= vLumBufSize)
519 if (chrBufIndex >= vChrBufSize)
526 lastInLumBuf, lastInChrBuf);
532 if (dstY >= dstH - 2) {
536 &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
541 const int16_t **lumSrcPtr = (
const int16_t **)(
void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf +
vLumBufSize;
542 const int16_t **chrUSrcPtr = (
const int16_t **)(
void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
543 const int16_t **chrVSrcPtr = (
const int16_t **)(
void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf +
vChrBufSize;
544 const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA &&
alpPixBuf) ?
545 (
const int16_t **)(
void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
570 if (vLumFilterSize == 1) {
578 if (!((dstY & chrSkipMask) ||
isGray(dstFormat))) {
581 vChrFilterSize, chrUSrcPtr, chrVSrcPtr,
583 }
else if (vChrFilterSize == 1) {
588 vChrFilterSize, chrUSrcPtr, dest[1],
591 vChrFilterSize, chrVSrcPtr, dest[2],
596 if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
600 if (vLumFilterSize == 1) {
605 vLumFilterSize, alpSrcPtr, dest[3],
609 }
else if (yuv2packedX) {
610 av_assert1(lumSrcPtr + vLumFilterSize - 1 < (
const int16_t **)lumPixBuf + vLumBufSize * 2);
611 av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (
const int16_t **)chrUPixBuf + vChrBufSize * 2);
613 vChrFilterSize <= 2) {
614 int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
616 alpPixBuf ? *alpSrcPtr : NULL,
617 dest[0], dstW, chrAlpha, dstY);
618 }
else if (c->
yuv2packed2 && vLumFilterSize == 2 &&
619 vChrFilterSize == 2) {
620 int lumAlpha = vLumFilter[2 * dstY + 1];
621 int chrAlpha = vChrFilter[2 * dstY + 1];
623 lumMmxFilter[3] = vLumFilter[2 *
dstY] * 0x10001;
625 chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
627 alpPixBuf ? alpSrcPtr : NULL,
628 dest[0], dstW, lumAlpha, chrAlpha, dstY);
631 lumSrcPtr, vLumFilterSize,
632 vChrFilter + dstY * vChrFilterSize,
633 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
634 alpSrcPtr, dest[0], dstW, dstY);
638 yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
639 lumSrcPtr, vLumFilterSize,
640 vChrFilter + dstY * vChrFilterSize,
641 chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
642 alpSrcPtr, dest, dstW, dstY);
648 int height = dstY - lastDstY;
652 fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
656 fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
659 #if HAVE_MMXEXT_INLINE
661 __asm__
volatile (
"sfence" :::
"memory");
672 return dstY - lastDstY;
750 src[3] = src[2] = NULL;
758 const int linesizes[4])
763 for (i = 0; i < 4; i++) {
765 if (!data[plane] || !linesizes[plane])
773 const uint16_t *src,
int stride,
int h)
778 for (yp=0; yp<h; yp++) {
779 for (xp=0; xp+2<stride; xp+=3) {
780 int x,
y, z,
r,
g,
b;
808 r = av_clip(r, 0, 4095);
809 g = av_clip(g, 0, 4095);
810 b = av_clip(b, 0, 4095);
829 const uint16_t *src,
int stride,
int h)
834 for (yp=0; yp<h; yp++) {
835 for (xp=0; xp+2<stride; xp+=3) {
836 int x,
y, z,
r,
g,
b;
864 x = av_clip(x, 0, 4095);
865 y = av_clip(y, 0, 4095);
866 z = av_clip(z, 0, 4095);
889 const uint8_t *
const srcSlice[],
890 const int srcStride[],
int srcSliceY,
891 int srcSliceH,
uint8_t *
const dst[],
892 const int dstStride[])
899 if (!srcStride || !dstStride || !dst || !srcSlice) {
900 av_log(c,
AV_LOG_ERROR,
"One of the input parameters to sws_scale() is NULL, please check the calling code\n");
905 srcSlice, srcStride, srcSliceY, srcSliceH,
915 memcpy(src2, srcSlice,
sizeof(src2));
916 memcpy(dst2, dst,
sizeof(dst2));
931 if (c->
sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->
srcH) {
940 for (i = 0; i < 256; i++) {
941 int r,
g,
b,
y,
u,
v,
a = 0xff;
943 uint32_t p = ((
const uint32_t *)(srcSlice[1]))[i];
944 a = (p >> 24) & 0xFF;
945 r = (p >> 16) & 0xFF;
950 g = ((i >> 2) & 7) * 36;
954 g = ((i >> 3) & 7) * 36;
957 r = ( i >> 3 ) * 255;
958 g = ((i >> 1) & 3) * 85;
964 b = ( i >> 3 ) * 255;
965 g = ((i >> 1) & 3) * 85;
968 #define RGB2YUV_SHIFT 15
969 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
970 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
971 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
972 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
973 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
974 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
975 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
976 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
977 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
982 c->
pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
989 c->
pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
995 c->
pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
1001 c->
pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
1008 c->
pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
1020 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1021 for (y=0; y<srcSliceH; y++){
1022 memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->
srcW);
1023 for (x=c->
src0Alpha-1; x<4*c->srcW; x+=4) {
1024 base[ srcStride[0]*y + x] = 0xFF;
1036 base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1038 xyz12Torgb48(c, (uint16_t*)base, (
const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
1043 for (i = 0; i < 4; i++)
1050 int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
1052 int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
1059 if (srcSliceY + srcSliceH == c->
srcH)
1062 ret = c->
swscale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
1066 int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
1068 int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
1071 src2[0] += (srcSliceH - 1) * srcStride[0];
1075 src2[3] += (srcSliceH - 1) * srcStride[3];
1076 dst2[0] += ( c->
dstH - 1) * dstStride[0];
1079 dst2[3] += ( c->
dstH - 1) * dstStride[3];
1088 ret = c->
swscale(c, src2, srcStride2, c->
srcH-srcSliceY-srcSliceH,
1089 srcSliceH, dst2, dstStride2);
1095 rgb48Toxyz12(c, (uint16_t*)dst2[0], (
const uint16_t*)dst2[0], dstStride[0]/2, ret);