?? swscale.c.svn-base
字號:
const int db2= dither_2x2_8[(y&1)^1][1]; YSCALE_YUV_2_RGBX_C(uint16_t) ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; } } break; case PIX_FMT_RGB8: case PIX_FMT_BGR8: { const uint8_t * const d64= dither_8x8_73[y&7]; const uint8_t * const d32= dither_8x8_32[y&7]; YSCALE_YUV_2_RGBX_C(uint8_t) ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]]; ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]]; } } break; case PIX_FMT_RGB4: case PIX_FMT_BGR4: { const uint8_t * const d64= dither_8x8_73 [y&7]; const uint8_t * const d128=dither_8x8_220[y&7]; YSCALE_YUV_2_RGBX_C(uint8_t) ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]] +((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4); } } break; case PIX_FMT_RGB4_BYTE: case PIX_FMT_BGR4_BYTE: { const uint8_t * const d64= dither_8x8_73 [y&7]; const uint8_t * const d128=dither_8x8_220[y&7]; YSCALE_YUV_2_RGBX_C(uint8_t) ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]; ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]]; } } break; case PIX_FMT_MONOBLACK: { const uint8_t * const d128=dither_8x8_220[y&7]; uint8_t *g= c->table_gU[128] + c->table_gV[128]; int acc=0; for (i=0; i<dstW-1; i+=2){ int j; int Y1=1<<18; int Y2=1<<18; for (j=0; j<lumFilterSize; j++) { Y1 += lumSrc[j][i] * lumFilter[j]; Y2 += lumSrc[j][i+1] * lumFilter[j]; } Y1>>=19; Y2>>=19; if ((Y1|Y2)&256) { if (Y1>255) Y1=255; else if (Y1<0)Y1=0; if (Y2>255) Y2=255; else if (Y2<0)Y2=0; } acc+= acc + g[Y1+d128[(i+0)&7]]; acc+= acc + g[Y2+d128[(i+1)&7]]; if ((i&7)==6){ ((uint8_t*)dest)[0]= acc; dest++; } } } break; case PIX_FMT_YUYV422: YSCALE_YUV_2_PACKEDX_C(void) ((uint8_t*)dest)[2*i2+0]= Y1; ((uint8_t*)dest)[2*i2+1]= U; ((uint8_t*)dest)[2*i2+2]= Y2; ((uint8_t*)dest)[2*i2+3]= V; } break; case PIX_FMT_UYVY422: YSCALE_YUV_2_PACKEDX_C(void) ((uint8_t*)dest)[2*i2+0]= U; ((uint8_t*)dest)[2*i2+1]= Y1; ((uint8_t*)dest)[2*i2+2]= V; ((uint8_t*)dest)[2*i2+3]= Y2; } break; }}//Note: we have C, X86, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one//Plain C versions#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT) || !defined(CONFIG_GPL)#define COMPILE_C#endif#ifdef ARCH_POWERPC#if (defined (HAVE_ALTIVEC) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)#define COMPILE_ALTIVEC#endif //HAVE_ALTIVEC#endif //ARCH_POWERPC#if defined(ARCH_X86)#if ((defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)#define COMPILE_MMX#endif#if (defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)#define COMPILE_MMX2#endif#if ((defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)) && defined (CONFIG_GPL)#define COMPILE_3DNOW#endif#endif //ARCH_X86 || ARCH_X86_64#undef HAVE_MMX#undef HAVE_MMX2#undef HAVE_3DNOW#ifdef COMPILE_C#undef HAVE_MMX#undef HAVE_MMX2#undef HAVE_3DNOW#undef HAVE_ALTIVEC#define RENAME(a) a ## _C#include "swscale_template.c"#endif#ifdef COMPILE_ALTIVEC#undef RENAME#define HAVE_ALTIVEC#define RENAME(a) a ## _altivec#include "swscale_template.c"#endif#if defined(ARCH_X86)//X86 versions/*#undef RENAME#undef HAVE_MMX#undef HAVE_MMX2#undef HAVE_3DNOW#define ARCH_X86#define RENAME(a) a ## _X86#include "swscale_template.c"*///MMX versions#ifdef COMPILE_MMX#undef RENAME#define HAVE_MMX#undef HAVE_MMX2#undef HAVE_3DNOW#define RENAME(a) a ## _MMX#include "swscale_template.c"#endif//MMX2 versions#ifdef COMPILE_MMX2#undef RENAME#define HAVE_MMX#define HAVE_MMX2#undef HAVE_3DNOW#define RENAME(a) a ## _MMX2#include "swscale_template.c"#endif//3DNOW versions#ifdef COMPILE_3DNOW#undef RENAME#define HAVE_MMX#undef HAVE_MMX2#define HAVE_3DNOW#define RENAME(a) a ## _3DNow#include "swscale_template.c"#endif#endif //ARCH_X86 || ARCH_X86_64// minor note: the HAVE_xyz is messed up after that line so don't use itstatic double getSplineCoeff(double a, double b, double c, double d, double dist){// printf("%f %f %f %f %f\n", a,b,c,d,dist); if (dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; else return getSplineCoeff( 0.0, b+ 2.0*c + 3.0*d, c + 3.0*d, -b- 3.0*c - 6.0*d, dist-1.0);}static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, int srcW, int dstW, int filterAlign, int one, int flags, SwsVector *srcFilter, SwsVector *dstFilter, double param[2]){ int i; int filterSize; int filter2Size; int minFilterSize; double *filter=NULL; double *filter2=NULL;#if defined(ARCH_X86) if (flags & SWS_CPU_CAPS_MMX) asm volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)#endif // Note the +1 is for the MMXscaler which reads over the end *filterPos = av_malloc((dstW+1)*sizeof(int16_t)); if (FFABS(xInc - 0x10000) <10) // unscaled { int i; filterSize= 1; filter= av_malloc(dstW*sizeof(double)*filterSize); for (i=0; i<dstW*filterSize; i++) filter[i]=0; for (i=0; i<dstW; i++) { filter[i*filterSize]=1; (*filterPos)[i]=i; } } else if (flags&SWS_POINT) // lame looking point sampling mode { int i; int xDstInSrc; filterSize= 1; filter= av_malloc(dstW*sizeof(double)*filterSize); xDstInSrc= xInc/2 - 0x8000; for (i=0; i<dstW; i++) { int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; (*filterPos)[i]= xx; filter[i]= 1.0; xDstInSrc+= xInc; } } else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) // bilinear upscale { int i; int xDstInSrc; if (flags&SWS_BICUBIC) filterSize= 4; else if (flags&SWS_X ) filterSize= 4; else filterSize= 2; // SWS_BILINEAR / SWS_AREA filter= av_malloc(dstW*sizeof(double)*filterSize); xDstInSrc= xInc/2 - 0x8000; for (i=0; i<dstW; i++) { int xx= (xDstInSrc - ((filterSize-1)<<15) + (1<<15))>>16; int j; (*filterPos)[i]= xx; //Bilinear upscale / linear interpolate / Area averaging for (j=0; j<filterSize; j++) { double d= FFABS((xx<<16) - xDstInSrc)/(double)(1<<16); double coeff= 1.0 - d; if (coeff<0) coeff=0; filter[i*filterSize + j]= coeff; xx++; } xDstInSrc+= xInc; } } else { double xDstInSrc; double sizeFactor, filterSizeInSrc; const double xInc1= (double)xInc / (double)(1<<16); if (flags&SWS_BICUBIC) sizeFactor= 4.0; else if (flags&SWS_X) sizeFactor= 8.0; else if (flags&SWS_AREA) sizeFactor= 1.0; //downscale only, for upscale it is bilinear else if (flags&SWS_GAUSS) sizeFactor= 8.0; // infinite ;) else if (flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? 2.0*param[0] : 6.0; else if (flags&SWS_SINC) sizeFactor= 20.0; // infinite ;) else if (flags&SWS_SPLINE) sizeFactor= 20.0; // infinite ;) else if (flags&SWS_BILINEAR) sizeFactor= 2.0; else { sizeFactor= 0.0; //GCC warning killer assert(0); } if (xInc1 <= 1.0) filterSizeInSrc= sizeFactor; // upscale else filterSizeInSrc= sizeFactor*srcW / (double)dstW; filterSize= (int)ceil(1 + filterSizeInSrc); // will be reduced later if possible if (filterSize > srcW-2) filterSize=srcW-2; filter= av_malloc(dstW*sizeof(double)*filterSize); xDstInSrc= xInc1 / 2.0 - 0.5; for (i=0; i<dstW; i++) { int xx= (int)(xDstInSrc - (filterSize-1)*0.5 + 0.5); int j; (*filterPos)[i]= xx; for (j=0; j<filterSize; j++) { double d= FFABS(xx - xDstInSrc)/filterSizeInSrc*sizeFactor; double coeff; if (flags & SWS_BICUBIC) { double B= param[0] != SWS_PARAM_DEFAULT ? param[0] : 0.0; double C= param[1] != SWS_PARAM_DEFAULT ? param[1] : 0.6; if (d<1.0) coeff = (12-9*B-6*C)*d*d*d + (-18+12*B+6*C)*d*d + 6-2*B; else if (d<2.0) coeff = (-B-6*C)*d*d*d + (6*B+30*C)*d*d + (-12*B-48*C)*d +8*B+24*C; else coeff=0.0; }/* else if (flags & SWS_X) { double p= param ? param*0.01 : 0.3; coeff = d ? sin(d*PI)/(d*PI) : 1.0; coeff*= pow(2.0, - p*d*d); }*/ else if (flags & SWS_X) { double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; if (d<1.0) coeff = cos(d*PI); else coeff=-1.0; if (coeff<0.0) coeff= -pow(-coeff, A); else coeff= pow( coeff, A); coeff= coeff*0.5 + 0.5; } else if (flags & SWS_AREA) { double srcPixelSize= 1.0/xInc1; if (d + srcPixelSize/2 < 0.5) coeff= 1.0; else if (d - srcPixelSize/2 < 0.5) coeff= (0.5-d)/srcPixelSize + 0.5; else coeff=0.0; } else if (flags & SWS_GAUSS) { double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = pow(2.0, - p*d*d); } else if (flags & SWS_SINC) { coeff = d ? sin(d*PI)/(d*PI) : 1.0; } else if (flags & SWS_LANCZOS) { double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; coeff = d ? sin(d*PI)*sin(d*PI/p)/(d*d*PI*PI/p) : 1.0; if (d>p) coeff=0; } else if (flags & SWS_BILINEAR) { coeff= 1.0 - d; if (coeff<0) coeff=0; } else if (flags & SWS_SPLINE) { double p=-2.196152422706632; coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, d); } else { coeff= 0.0; //GCC warning killer assert(0); } filter[i*filterSize + j]= coeff; xx++; } xDstInSrc+= xInc1; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -