⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swscale.c

📁 ffmpeg移植到symbian的全部源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
                    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;        }    }    /* apply src & dst Filter to filter -> filter2       av_free(filter);    */    assert(filterSize>0);    filter2Size= filterSize;    if (srcFilter) filter2Size+= srcFilter->length - 1;    if (dstFilter) filter2Size+= dstFilter->length - 1;    assert(filter2Size>0);    filter2= av_malloc(filter2Size*dstW*sizeof(double));    for (i=0; i<dstW; i++)    {        int j;        SwsVector scaleFilter;        SwsVector *outVec;        scaleFilter.coeff= filter + i*filterSize;        scaleFilter.length= filterSize;        if (srcFilter) outVec= sws_getConvVec(srcFilter, &scaleFilter);        else           outVec= &scaleFilter;        assert(outVec->length == filter2Size);        //FIXME dstFilter        for (j=0; j<outVec->length; j++)        {            filter2[i*filter2Size + j]= outVec->coeff[j];        }        (*filterPos)[i]+= (filterSize-1)/2 - (filter2Size-1)/2;        if (outVec != &scaleFilter) sws_freeVec(outVec);    }    av_free(filter); filter=NULL;    /* try to reduce the filter-size (step1 find size and shift left) */    // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not).    minFilterSize= 0;    for (i=dstW-1; i>=0; i--)    {        int min= filter2Size;        int j;        double cutOff=0.0;        /* get rid off near zero elements on the left by shifting left */        for (j=0; j<filter2Size; j++)        {            int k;            cutOff += FFABS(filter2[i*filter2Size]);            if (cutOff > SWS_MAX_REDUCE_CUTOFF) break;            /* preserve monotonicity because the core can't handle the filter otherwise */            if (i<dstW-1 && (*filterPos)[i] >= (*filterPos)[i+1]) break;            // Move filter coeffs left            for (k=1; k<filter2Size; k++)                filter2[i*filter2Size + k - 1]= filter2[i*filter2Size + k];            filter2[i*filter2Size + k - 1]= 0.0;            (*filterPos)[i]++;        }        cutOff=0.0;        /* count near zeros on the right */        for (j=filter2Size-1; j>0; j--)        {            cutOff += FFABS(filter2[i*filter2Size + j]);            if (cutOff > SWS_MAX_REDUCE_CUTOFF) break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -