int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)

{

    int i;

    int usesVFilter, usesHFilter;

    int unscaled;

    SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};

    int srcW= c->srcW;

    int srcH= c->srcH;

    int dstW= c->dstW;

    int dstH= c->dstH;

    int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 16, 16), dst_stride_px = dst_stride >> 1;

    int flags, cpu_flags;

    enum PixelFormat srcFormat= c->srcFormat;

    enum PixelFormat dstFormat= c->dstFormat;



    cpu_flags = av_get_cpu_flags();

    flags     = c->flags;

    emms_c();

    if (!rgb15to16) sws_rgb2rgb_init();



    unscaled = (srcW == dstW && srcH == dstH);



    if (!isSupportedIn(srcFormat)) {

        av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat));

        return AVERROR(EINVAL);

    }

    if (!isSupportedOut(dstFormat)) {

        av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat));

        return AVERROR(EINVAL);

    }



    i= flags & ( SWS_POINT

                |SWS_AREA

                |SWS_BILINEAR

                |SWS_FAST_BILINEAR

                |SWS_BICUBIC

                |SWS_X

                |SWS_GAUSS

                |SWS_LANCZOS

                |SWS_SINC

                |SWS_SPLINE

                |SWS_BICUBLIN);

    if(!i || (i & (i-1))) {

        av_log(c, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen\n");

        return AVERROR(EINVAL);

    }

    /* sanity check */

    if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code

        av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",

               srcW, srcH, dstW, dstH);

        return AVERROR(EINVAL);

    }



    if (!dstFilter) dstFilter= &dummyFilter;

    if (!srcFilter) srcFilter= &dummyFilter;



    c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW;

    c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH;

    c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]);

    c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]);

    c->vRounder= 4* 0x0001000100010001ULL;



    usesVFilter = (srcFilter->lumV && srcFilter->lumV->length>1) ||

                  (srcFilter->chrV && srcFilter->chrV->length>1) ||

                  (dstFilter->lumV && dstFilter->lumV->length>1) ||

                  (dstFilter->chrV && dstFilter->chrV->length>1);

    usesHFilter = (srcFilter->lumH && srcFilter->lumH->length>1) ||

                  (srcFilter->chrH && srcFilter->chrH->length>1) ||

                  (dstFilter->lumH && dstFilter->lumH->length>1) ||

                  (dstFilter->chrH && dstFilter->chrH->length>1);



    getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat);

    getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);



    // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation

    if (flags & SWS_FULL_CHR_H_INT &&

        dstFormat != PIX_FMT_RGBA &&

        dstFormat != PIX_FMT_ARGB &&

        dstFormat != PIX_FMT_BGRA &&

        dstFormat != PIX_FMT_ABGR &&

        dstFormat != PIX_FMT_RGB24 &&

        dstFormat != PIX_FMT_BGR24) {

        av_log(c, AV_LOG_ERROR,

               "full chroma interpolation for destination format '%s' not yet implemented\n",

               sws_format_name(dstFormat));

        flags &= ~SWS_FULL_CHR_H_INT;

        c->flags = flags;

    }

    if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1;



    // drop some chroma lines if the user wants it

    c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT;

    c->chrSrcVSubSample+= c->vChrDrop;



    // drop every other pixel for chroma calculation unless user wants full chroma

    if (isAnyRGB(srcFormat) && !(flags&SWS_FULL_CHR_H_INP)

      && srcFormat!=PIX_FMT_RGB8      && srcFormat!=PIX_FMT_BGR8

      && srcFormat!=PIX_FMT_RGB4      && srcFormat!=PIX_FMT_BGR4

      && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE

      && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&SWS_FAST_BILINEAR)))

        c->chrSrcHSubSample=1;



    // Note the -((-x)>>y) is so that we always round toward +inf.

    c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample);

    c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample);

    c->chrDstW= -((-dstW) >> c->chrDstHSubSample);

    c->chrDstH= -((-dstH) >> c->chrDstVSubSample);



    /* unscaled special cases */

    if (unscaled && !usesHFilter && !usesVFilter && (c->srcRange == c->dstRange || isAnyRGB(dstFormat))) {

        ff_get_unscaled_swscale(c);



        if (c->swScale) {

            if (flags&SWS_PRINT_INFO)

                av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n",

                       sws_format_name(srcFormat), sws_format_name(dstFormat));

            return 0;

        }

    }



    c->scalingBpp = FFMAX(av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1,

                          av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1) >= 8 ? 16 : 8;

    if (c->scalingBpp == 16)

        dst_stride <<= 1;

    FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW, 16) * 2 * c->scalingBpp >> 3, fail);

    if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->scalingBpp == 8) {

        c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0;

        if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) {

            if (flags&SWS_PRINT_INFO)

                av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n");

        }

        if (usesHFilter) c->canMMX2BeUsed=0;

    }

    else

        c->canMMX2BeUsed=0;



    c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW;

    c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH;



    // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst

    // but only for the FAST_BILINEAR mode otherwise do correct scaling

    // n-2 is the last chrominance sample available

    // this is not perfect, but no one should notice the difference, the more correct variant

    // would be like the vertical one, but that would require some special code for the

    // first and last pixel

    if (flags&SWS_FAST_BILINEAR) {

        if (c->canMMX2BeUsed) {

            c->lumXInc+= 20;

            c->chrXInc+= 20;

        }

        //we don't use the x86 asm scaler if MMX is available

        else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {

            c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20;

            c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20;

        }

    }



    /* precalculate horizontal scaler filter coefficients */

    {

#if HAVE_MMX2

// can't downscale !!!

        if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) {

            c->lumMmx2FilterCodeSize = initMMX2HScaler(      dstW, c->lumXInc, NULL, NULL, NULL, 8);

            c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4);



#ifdef MAP_ANONYMOUS

            c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

            c->chrMmx2FilterCode = mmap(NULL, c->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

#elif HAVE_VIRTUALALLOC

            c->lumMmx2FilterCode = VirtualAlloc(NULL, c->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

            c->chrMmx2FilterCode = VirtualAlloc(NULL, c->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

#else

            c->lumMmx2FilterCode = av_malloc(c->lumMmx2FilterCodeSize);

            c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize);

#endif



            if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode)

                return AVERROR(ENOMEM);

            FF_ALLOCZ_OR_GOTO(c, c->hLumFilter   , (dstW        /8+8)*sizeof(int16_t), fail);

            FF_ALLOCZ_OR_GOTO(c, c->hChrFilter   , (c->chrDstW  /4+8)*sizeof(int16_t), fail);

            FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW      /2/8+8)*sizeof(int32_t), fail);

            FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail);



            initMMX2HScaler(      dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8);

            initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4);



#ifdef MAP_ANONYMOUS

            mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ);

            mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ);

#endif

        } else

#endif /* HAVE_MMX2 */

        {

            const int filterAlign=

                (HAVE_MMX     && cpu_flags & AV_CPU_FLAG_MMX) ? 4 :

                (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :

                1;



            if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc,

                           srcW      ,       dstW, filterAlign, 1<<14,

                           (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC)  : flags, cpu_flags,

                           srcFilter->lumH, dstFilter->lumH, c->param) < 0)

                goto fail;

            if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc,

                           c->chrSrcW, c->chrDstW, filterAlign, 1<<14,

                           (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags,

                           srcFilter->chrH, dstFilter->chrH, c->param) < 0)

                goto fail;

        }

    } // initialize horizontal stuff



    /* precalculate vertical scaler filter coefficients */

    {

        const int filterAlign=

            (HAVE_MMX     && cpu_flags & AV_CPU_FLAG_MMX) && (flags & SWS_ACCURATE_RND) ? 2 :

            (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :

            1;



        if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc,

                       srcH      ,        dstH, filterAlign, (1<<12),

                       (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC)  : flags, cpu_flags,

                       srcFilter->lumV, dstFilter->lumV, c->param) < 0)

            goto fail;

        if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc,

                       c->chrSrcH, c->chrDstH, filterAlign, (1<<12),

                       (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags,

                       srcFilter->chrV, dstFilter->chrV, c->param) < 0)

            goto fail;



#if HAVE_ALTIVEC

        FF_ALLOC_OR_GOTO(c, c->vYCoeffsBank, sizeof (vector signed short)*c->vLumFilterSize*c->dstH, fail);

        FF_ALLOC_OR_GOTO(c, c->vCCoeffsBank, sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH, fail);



        for (i=0;i<c->vLumFilterSize*c->dstH;i++) {

            int j;

            short *p = (short *)&c->vYCoeffsBank[i];

            for (j=0;j<8;j++)

                p[j] = c->vLumFilter[i];

        }



        for (i=0;i<c->vChrFilterSize*c->chrDstH;i++) {

            int j;

            short *p = (short *)&c->vCCoeffsBank[i];

            for (j=0;j<8;j++)

                p[j] = c->vChrFilter[i];

        }

#endif

    }



    // calculate buffer sizes so that they won't run out while handling these damn slices

    c->vLumBufSize= c->vLumFilterSize;

    c->vChrBufSize= c->vChrFilterSize;

    for (i=0; i<dstH; i++) {

        int chrI= i*c->chrDstH / dstH;

        int nextSlice= FFMAX(c->vLumFilterPos[i   ] + c->vLumFilterSize - 1,

                           ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));



        nextSlice>>= c->chrSrcVSubSample;

        nextSlice<<= c->chrSrcVSubSample;

        if (c->vLumFilterPos[i   ] + c->vLumBufSize < nextSlice)

            c->vLumBufSize= nextSlice - c->vLumFilterPos[i];

        if (c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample))

            c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI];

    }



    // allocate pixbufs (we use dynamic allocation because otherwise we would need to

    // allocate several megabytes to handle all possible cases)

    FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail);

    FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail);

    FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail);

    if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat))

        FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail);

    //Note we need at least one pixel more at the end because of the MMX code (just in case someone wanna replace the 4000/8000)

    /* align at 16 bytes for AltiVec */

    for (i=0; i<c->vLumBufSize; i++) {

        FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+1, fail);

        c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize];

    }

    c->uv_off_px   = dst_stride_px;

    c->uv_off_byte = dst_stride;

    for (i=0; i<c->vChrBufSize; i++) {

        FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail);

        c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize];

        c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + (dst_stride >> 1);

    }

    if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf)

        for (i=0; i<c->vLumBufSize; i++) {

            FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+1, fail);

            c->alpPixBuf[i] = c->alpPixBuf[i+c->vLumBufSize];

        }



    //try to avoid drawing green stuff between the right end and the stride end

    for (i=0; i<c->vChrBufSize; i++)

        memset(c->chrUPixBuf[i], 64, dst_stride*2+1);



    assert(c->chrDstH <= dstH);



    if (flags&SWS_PRINT_INFO) {

        if      (flags&SWS_FAST_BILINEAR) av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, ");

        else if (flags&SWS_BILINEAR)      av_log(c, AV_LOG_INFO, "BILINEAR scaler, ");

        else if (flags&SWS_BICUBIC)       av_log(c, AV_LOG_INFO, "BICUBIC scaler, ");

        else if (flags&SWS_X)             av_log(c, AV_LOG_INFO, "Experimental scaler, ");

        else if (flags&SWS_POINT)         av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, ");

        else if (flags&SWS_AREA)          av_log(c, AV_LOG_INFO, "Area Averaging scaler, ");

        else if (flags&SWS_BICUBLIN)      av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, ");

        else if (flags&SWS_GAUSS)         av_log(c, AV_LOG_INFO, "Gaussian scaler, ");

        else if (flags&SWS_SINC)          av_log(c, AV_LOG_INFO, "Sinc scaler, ");

        else if (flags&SWS_LANCZOS)       av_log(c, AV_LOG_INFO, "Lanczos scaler, ");

        else if (flags&SWS_SPLINE)        av_log(c, AV_LOG_INFO, "Bicubic spline scaler, ");

        else                              av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");



        av_log(c, AV_LOG_INFO, "from %s to %s%s ",

               sws_format_name(srcFormat),

#ifdef DITHER1XBPP

               dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 ||

               dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||

               dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE ? "dithered " : "",

#else

               "",

#endif

               sws_format_name(dstFormat));



        if      (HAVE_MMX2     && cpu_flags & AV_CPU_FLAG_MMX2)    av_log(c, AV_LOG_INFO, "using MMX2\n");

        else if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW)   av_log(c, AV_LOG_INFO, "using 3DNOW\n");

        else if (HAVE_MMX      && cpu_flags & AV_CPU_FLAG_MMX)     av_log(c, AV_LOG_INFO, "using MMX\n");

        else if (HAVE_ALTIVEC  && cpu_flags & AV_CPU_FLAG_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n");

        else                                   av_log(c, AV_LOG_INFO, "using C\n");



        if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {

            if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR))

                av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");

            else {

                if (c->hLumFilterSize==4)

                    av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n");

                else if (c->hLumFilterSize==8)

                    av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n");

                else

                    av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n");



                if (c->hChrFilterSize==4)

                    av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n");

                else if (c->hChrFilterSize==8)

                    av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n");

                else

                    av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n");

            }

        } else {

#if HAVE_MMX

            av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n");

#else

            if (flags & SWS_FAST_BILINEAR)

                av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n");

            else

                av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n");

#endif

        }

        if (isPlanarYUV(dstFormat)) {

            if (c->vLumFilterSize==1)

                av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else

                av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        } else {

            if (c->vLumFilterSize==1 && c->vChrFilterSize==2)

                av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"

                       "      2-tap scaler for vertical chrominance scaling (BGR)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else if (c->vLumFilterSize==2 && c->vChrFilterSize==2)

                av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else

                av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        }



        if (dstFormat==PIX_FMT_BGR24)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n",

                   (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) ? "MMX2" :

                   ((HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"));

        else if (dstFormat==PIX_FMT_RGB32)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (dstFormat==PIX_FMT_BGR565)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (dstFormat==PIX_FMT_BGR555)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||

                 dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");



        av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);

        av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",

               c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);

        av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",

               c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc);

    }



    c->swScale= ff_getSwsFunc(c);

    return 0;

fail: //FIXME replace things by appropriate error codes

    return -1;

}

int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter)

{

    int i;

    int usesVFilter, usesHFilter;

    int unscaled;

    SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};

    int srcW= c->srcW;

    int srcH= c->srcH;

    int dstW= c->dstW;

    int dstH= c->dstH;

    int dst_stride = FFALIGN(dstW * sizeof(int16_t) + 16, 16), dst_stride_px = dst_stride >> 1;

    int flags, cpu_flags;

    enum PixelFormat srcFormat= c->srcFormat;

    enum PixelFormat dstFormat= c->dstFormat;



    cpu_flags = av_get_cpu_flags();

    flags     = c->flags;

    emms_c();

    if (!rgb15to16) sws_rgb2rgb_init();



    unscaled = (srcW == dstW && srcH == dstH);



    if (!isSupportedIn(srcFormat)) {

        av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat));

        return AVERROR(EINVAL);

    }

    if (!isSupportedOut(dstFormat)) {

        av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat));

        return AVERROR(EINVAL);

    }



    i= flags & ( SWS_POINT

                |SWS_AREA

                |SWS_BILINEAR

                |SWS_FAST_BILINEAR

                |SWS_BICUBIC

                |SWS_X

                |SWS_GAUSS

                |SWS_LANCZOS

                |SWS_SINC

                |SWS_SPLINE

                |SWS_BICUBLIN);

    if(!i || (i & (i-1))) {

        av_log(c, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen\n");

        return AVERROR(EINVAL);

    }

    

    if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { 

        av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",

               srcW, srcH, dstW, dstH);

        return AVERROR(EINVAL);

    }



    if (!dstFilter) dstFilter= &dummyFilter;

    if (!srcFilter) srcFilter= &dummyFilter;



    c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW;

    c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH;

    c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]);

    c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]);

    c->vRounder= 4* 0x0001000100010001ULL;



    usesVFilter = (srcFilter->lumV && srcFilter->lumV->length>1) ||

                  (srcFilter->chrV && srcFilter->chrV->length>1) ||

                  (dstFilter->lumV && dstFilter->lumV->length>1) ||

                  (dstFilter->chrV && dstFilter->chrV->length>1);

    usesHFilter = (srcFilter->lumH && srcFilter->lumH->length>1) ||

                  (srcFilter->chrH && srcFilter->chrH->length>1) ||

                  (dstFilter->lumH && dstFilter->lumH->length>1) ||

                  (dstFilter->chrH && dstFilter->chrH->length>1);



    getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat);

    getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat);



    

    if (flags & SWS_FULL_CHR_H_INT &&

        dstFormat != PIX_FMT_RGBA &&

        dstFormat != PIX_FMT_ARGB &&

        dstFormat != PIX_FMT_BGRA &&

        dstFormat != PIX_FMT_ABGR &&

        dstFormat != PIX_FMT_RGB24 &&

        dstFormat != PIX_FMT_BGR24) {

        av_log(c, AV_LOG_ERROR,

               "full chroma interpolation for destination format '%s' not yet implemented\n",

               sws_format_name(dstFormat));

        flags &= ~SWS_FULL_CHR_H_INT;

        c->flags = flags;

    }

    if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1;



    

    c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT;

    c->chrSrcVSubSample+= c->vChrDrop;



    

    if (isAnyRGB(srcFormat) && !(flags&SWS_FULL_CHR_H_INP)

      && srcFormat!=PIX_FMT_RGB8      && srcFormat!=PIX_FMT_BGR8

      && srcFormat!=PIX_FMT_RGB4      && srcFormat!=PIX_FMT_BGR4

      && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE

      && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&SWS_FAST_BILINEAR)))

        c->chrSrcHSubSample=1;



    

    c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample);

    c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample);

    c->chrDstW= -((-dstW) >> c->chrDstHSubSample);

    c->chrDstH= -((-dstH) >> c->chrDstVSubSample);



    

    if (unscaled && !usesHFilter && !usesVFilter && (c->srcRange == c->dstRange || isAnyRGB(dstFormat))) {

        ff_get_unscaled_swscale(c);



        if (c->swScale) {

            if (flags&SWS_PRINT_INFO)

                av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n",

                       sws_format_name(srcFormat), sws_format_name(dstFormat));

            return 0;

        }

    }



    c->scalingBpp = FFMAX(av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1,

                          av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1) >= 8 ? 16 : 8;

    if (c->scalingBpp == 16)

        dst_stride <<= 1;

    FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW, 16) * 2 * c->scalingBpp >> 3, fail);

    if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->scalingBpp == 8) {

        c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0;

        if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) {

            if (flags&SWS_PRINT_INFO)

                av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n");

        }

        if (usesHFilter) c->canMMX2BeUsed=0;

    }

    else

        c->canMMX2BeUsed=0;



    c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW;

    c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH;



    

    

    

    

    

    

    if (flags&SWS_FAST_BILINEAR) {

        if (c->canMMX2BeUsed) {

            c->lumXInc+= 20;

            c->chrXInc+= 20;

        }

        

        else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {

            c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20;

            c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20;

        }

    }



    

    {

#if HAVE_MMX2



        if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) {

            c->lumMmx2FilterCodeSize = initMMX2HScaler(      dstW, c->lumXInc, NULL, NULL, NULL, 8);

            c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4);



#ifdef MAP_ANONYMOUS

            c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

            c->chrMmx2FilterCode = mmap(NULL, c->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

#elif HAVE_VIRTUALALLOC

            c->lumMmx2FilterCode = VirtualAlloc(NULL, c->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

            c->chrMmx2FilterCode = VirtualAlloc(NULL, c->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

#else

            c->lumMmx2FilterCode = av_malloc(c->lumMmx2FilterCodeSize);

            c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize);

#endif



            if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode)

                return AVERROR(ENOMEM);

            FF_ALLOCZ_OR_GOTO(c, c->hLumFilter   , (dstW        /8+8)*sizeof(int16_t), fail);

            FF_ALLOCZ_OR_GOTO(c, c->hChrFilter   , (c->chrDstW  /4+8)*sizeof(int16_t), fail);

            FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW      /2/8+8)*sizeof(int32_t), fail);

            FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail);



            initMMX2HScaler(      dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8);

            initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4);



#ifdef MAP_ANONYMOUS

            mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ);

            mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ);

#endif

        } else

#endif 

        {

            const int filterAlign=

                (HAVE_MMX     && cpu_flags & AV_CPU_FLAG_MMX) ? 4 :

                (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :

                1;



            if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc,

                           srcW      ,       dstW, filterAlign, 1<<14,

                           (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC)  : flags, cpu_flags,

                           srcFilter->lumH, dstFilter->lumH, c->param) < 0)

                goto fail;

            if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc,

                           c->chrSrcW, c->chrDstW, filterAlign, 1<<14,

                           (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags,

                           srcFilter->chrH, dstFilter->chrH, c->param) < 0)

                goto fail;

        }

    } 



    

    {

        const int filterAlign=

            (HAVE_MMX     && cpu_flags & AV_CPU_FLAG_MMX) && (flags & SWS_ACCURATE_RND) ? 2 :

            (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 :

            1;



        if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc,

                       srcH      ,        dstH, filterAlign, (1<<12),

                       (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC)  : flags, cpu_flags,

                       srcFilter->lumV, dstFilter->lumV, c->param) < 0)

            goto fail;

        if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc,

                       c->chrSrcH, c->chrDstH, filterAlign, (1<<12),

                       (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags,

                       srcFilter->chrV, dstFilter->chrV, c->param) < 0)

            goto fail;



#if HAVE_ALTIVEC

        FF_ALLOC_OR_GOTO(c, c->vYCoeffsBank, sizeof (vector signed short)*c->vLumFilterSize*c->dstH, fail);

        FF_ALLOC_OR_GOTO(c, c->vCCoeffsBank, sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH, fail);



        for (i=0;i<c->vLumFilterSize*c->dstH;i++) {

            int j;

            short *p = (short *)&c->vYCoeffsBank[i];

            for (j=0;j<8;j++)

                p[j] = c->vLumFilter[i];

        }



        for (i=0;i<c->vChrFilterSize*c->chrDstH;i++) {

            int j;

            short *p = (short *)&c->vCCoeffsBank[i];

            for (j=0;j<8;j++)

                p[j] = c->vChrFilter[i];

        }

#endif

    }



    

    c->vLumBufSize= c->vLumFilterSize;

    c->vChrBufSize= c->vChrFilterSize;

    for (i=0; i<dstH; i++) {

        int chrI= i*c->chrDstH / dstH;

        int nextSlice= FFMAX(c->vLumFilterPos[i   ] + c->vLumFilterSize - 1,

                           ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<<c->chrSrcVSubSample));



        nextSlice>>= c->chrSrcVSubSample;

        nextSlice<<= c->chrSrcVSubSample;

        if (c->vLumFilterPos[i   ] + c->vLumBufSize < nextSlice)

            c->vLumBufSize= nextSlice - c->vLumFilterPos[i];

        if (c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample))

            c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI];

    }



    

    

    FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail);

    FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail);

    FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail);

    if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat))

        FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail);

    

    

    for (i=0; i<c->vLumBufSize; i++) {

        FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+1, fail);

        c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize];

    }

    c->uv_off_px   = dst_stride_px;

    c->uv_off_byte = dst_stride;

    for (i=0; i<c->vChrBufSize; i++) {

        FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail);

        c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize];

        c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + (dst_stride >> 1);

    }

    if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf)

        for (i=0; i<c->vLumBufSize; i++) {

            FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+1, fail);

            c->alpPixBuf[i] = c->alpPixBuf[i+c->vLumBufSize];

        }



    

    for (i=0; i<c->vChrBufSize; i++)

        memset(c->chrUPixBuf[i], 64, dst_stride*2+1);



    assert(c->chrDstH <= dstH);



    if (flags&SWS_PRINT_INFO) {

        if      (flags&SWS_FAST_BILINEAR) av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, ");

        else if (flags&SWS_BILINEAR)      av_log(c, AV_LOG_INFO, "BILINEAR scaler, ");

        else if (flags&SWS_BICUBIC)       av_log(c, AV_LOG_INFO, "BICUBIC scaler, ");

        else if (flags&SWS_X)             av_log(c, AV_LOG_INFO, "Experimental scaler, ");

        else if (flags&SWS_POINT)         av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, ");

        else if (flags&SWS_AREA)          av_log(c, AV_LOG_INFO, "Area Averaging scaler, ");

        else if (flags&SWS_BICUBLIN)      av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, ");

        else if (flags&SWS_GAUSS)         av_log(c, AV_LOG_INFO, "Gaussian scaler, ");

        else if (flags&SWS_SINC)          av_log(c, AV_LOG_INFO, "Sinc scaler, ");

        else if (flags&SWS_LANCZOS)       av_log(c, AV_LOG_INFO, "Lanczos scaler, ");

        else if (flags&SWS_SPLINE)        av_log(c, AV_LOG_INFO, "Bicubic spline scaler, ");

        else                              av_log(c, AV_LOG_INFO, "ehh flags invalid?! ");



        av_log(c, AV_LOG_INFO, "from %s to %s%s ",

               sws_format_name(srcFormat),

#ifdef DITHER1XBPP

               dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 ||

               dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||

               dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE ? "dithered " : "",

#else

               "",

#endif

               sws_format_name(dstFormat));



        if      (HAVE_MMX2     && cpu_flags & AV_CPU_FLAG_MMX2)    av_log(c, AV_LOG_INFO, "using MMX2\n");

        else if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW)   av_log(c, AV_LOG_INFO, "using 3DNOW\n");

        else if (HAVE_MMX      && cpu_flags & AV_CPU_FLAG_MMX)     av_log(c, AV_LOG_INFO, "using MMX\n");

        else if (HAVE_ALTIVEC  && cpu_flags & AV_CPU_FLAG_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n");

        else                                   av_log(c, AV_LOG_INFO, "using C\n");



        if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) {

            if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR))

                av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");

            else {

                if (c->hLumFilterSize==4)

                    av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n");

                else if (c->hLumFilterSize==8)

                    av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n");

                else

                    av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n");



                if (c->hChrFilterSize==4)

                    av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n");

                else if (c->hChrFilterSize==8)

                    av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n");

                else

                    av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n");

            }

        } else {

#if HAVE_MMX

            av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n");

#else

            if (flags & SWS_FAST_BILINEAR)

                av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n");

            else

                av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n");

#endif

        }

        if (isPlanarYUV(dstFormat)) {

            if (c->vLumFilterSize==1)

                av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else

                av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        } else {

            if (c->vLumFilterSize==1 && c->vChrFilterSize==2)

                av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"

                       "      2-tap scaler for vertical chrominance scaling (BGR)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else if (c->vLumFilterSize==2 && c->vChrFilterSize==2)

                av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else

                av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n",

                       (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        }



        if (dstFormat==PIX_FMT_BGR24)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n",

                   (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) ? "MMX2" :

                   ((HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C"));

        else if (dstFormat==PIX_FMT_RGB32)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (dstFormat==PIX_FMT_BGR565)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (dstFormat==PIX_FMT_BGR555)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE ||

                 dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE)

            av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n",

                   (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? "MMX" : "C");



        av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH);

        av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",

               c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc);

        av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n",

               c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc);

    }



    c->swScale= ff_getSwsFunc(c);

    return 0;

fail: 

    return -1;

}

        FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+1, fail);     c->uv_off_px   = dst_stride_px;     c->uv_off_byte = dst_stride;         FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+1, fail);         c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + (dst_stride >> 1);             FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+1, fail);
int FUNC_0(SwsContext *VAR_0, SwsFilter *VAR_1, SwsFilter *VAR_2)

{

    int VAR_3;

    int VAR_4, VAR_5;

    int VAR_6;

    SwsFilter dummyFilter= {NULL, NULL, NULL, NULL};

    int VAR_7= VAR_0->VAR_7;

    int VAR_8= VAR_0->VAR_8;

    int VAR_9= VAR_0->VAR_9;

    int VAR_10= VAR_0->VAR_10;

    int VAR_11 = FFALIGN(VAR_9 * sizeof(int16_t) + 16, 16), VAR_12 = VAR_11 >> 1;

    int VAR_13, VAR_14;

    enum PixelFormat VAR_15= VAR_0->VAR_15;

    enum PixelFormat VAR_16= VAR_0->VAR_16;



    VAR_14 = av_get_cpu_flags();

    VAR_13     = VAR_0->VAR_13;

    emms_c();

    if (!rgb15to16) sws_rgb2rgb_init();



    VAR_6 = (VAR_7 == VAR_9 && VAR_8 == VAR_10);



    if (!isSupportedIn(VAR_15)) {

        av_log(VAR_0, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(VAR_15));

        return AVERROR(EINVAL);

    }

    if (!isSupportedOut(VAR_16)) {

        av_log(VAR_0, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(VAR_16));

        return AVERROR(EINVAL);

    }



    VAR_3= VAR_13 & ( SWS_POINT

                |SWS_AREA

                |SWS_BILINEAR

                |SWS_FAST_BILINEAR

                |SWS_BICUBIC

                |SWS_X

                |SWS_GAUSS

                |SWS_LANCZOS

                |SWS_SINC

                |SWS_SPLINE

                |SWS_BICUBLIN);

    if(!VAR_3 || (VAR_3 & (VAR_3-1))) {

        av_log(VAR_0, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen\n");

        return AVERROR(EINVAL);

    }

    

    if (VAR_7<4 || VAR_8<1 || VAR_9<8 || VAR_10<1) { 

        av_log(VAR_0, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",

               VAR_7, VAR_8, VAR_9, VAR_10);

        return AVERROR(EINVAL);

    }



    if (!VAR_2) VAR_2= &dummyFilter;

    if (!VAR_1) VAR_1= &dummyFilter;



    VAR_0->lumXInc= ((VAR_7<<16) + (VAR_9>>1))/VAR_9;

    VAR_0->lumYInc= ((VAR_8<<16) + (VAR_10>>1))/VAR_10;

    VAR_0->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[VAR_16]);

    VAR_0->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[VAR_15]);

    VAR_0->vRounder= 4* 0x0001000100010001ULL;



    VAR_4 = (VAR_1->lumV && VAR_1->lumV->length>1) ||

                  (VAR_1->chrV && VAR_1->chrV->length>1) ||

                  (VAR_2->lumV && VAR_2->lumV->length>1) ||

                  (VAR_2->chrV && VAR_2->chrV->length>1);

    VAR_5 = (VAR_1->lumH && VAR_1->lumH->length>1) ||

                  (VAR_1->chrH && VAR_1->chrH->length>1) ||

                  (VAR_2->lumH && VAR_2->lumH->length>1) ||

                  (VAR_2->chrH && VAR_2->chrH->length>1);



    getSubSampleFactors(&VAR_0->chrSrcHSubSample, &VAR_0->chrSrcVSubSample, VAR_15);

    getSubSampleFactors(&VAR_0->chrDstHSubSample, &VAR_0->chrDstVSubSample, VAR_16);



    

    if (VAR_13 & SWS_FULL_CHR_H_INT &&

        VAR_16 != PIX_FMT_RGBA &&

        VAR_16 != PIX_FMT_ARGB &&

        VAR_16 != PIX_FMT_BGRA &&

        VAR_16 != PIX_FMT_ABGR &&

        VAR_16 != PIX_FMT_RGB24 &&

        VAR_16 != PIX_FMT_BGR24) {

        av_log(VAR_0, AV_LOG_ERROR,

               "full chroma interpolation for destination format '%s' not yet implemented\n",

               sws_format_name(VAR_16));

        VAR_13 &= ~SWS_FULL_CHR_H_INT;

        VAR_0->VAR_13 = VAR_13;

    }

    if (isAnyRGB(VAR_16) && !(VAR_13&SWS_FULL_CHR_H_INT)) VAR_0->chrDstHSubSample=1;



    

    VAR_0->vChrDrop= (VAR_13&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT;

    VAR_0->chrSrcVSubSample+= VAR_0->vChrDrop;



    

    if (isAnyRGB(VAR_15) && !(VAR_13&SWS_FULL_CHR_H_INP)

      && VAR_15!=PIX_FMT_RGB8      && VAR_15!=PIX_FMT_BGR8

      && VAR_15!=PIX_FMT_RGB4      && VAR_15!=PIX_FMT_BGR4

      && VAR_15!=PIX_FMT_RGB4_BYTE && VAR_15!=PIX_FMT_BGR4_BYTE

      && ((VAR_9>>VAR_0->chrDstHSubSample) <= (VAR_7>>1) || (VAR_13&SWS_FAST_BILINEAR)))

        VAR_0->chrSrcHSubSample=1;



    

    VAR_0->chrSrcW= -((-VAR_7) >> VAR_0->chrSrcHSubSample);

    VAR_0->chrSrcH= -((-VAR_8) >> VAR_0->chrSrcVSubSample);

    VAR_0->chrDstW= -((-VAR_9) >> VAR_0->chrDstHSubSample);

    VAR_0->chrDstH= -((-VAR_10) >> VAR_0->chrDstVSubSample);



    

    if (VAR_6 && !VAR_5 && !VAR_4 && (VAR_0->srcRange == VAR_0->dstRange || isAnyRGB(VAR_16))) {

        ff_get_unscaled_swscale(VAR_0);



        if (VAR_0->swScale) {

            if (VAR_13&SWS_PRINT_INFO)

                av_log(VAR_0, AV_LOG_INFO, "using VAR_6 %s -> %s special converter\n",

                       sws_format_name(VAR_15), sws_format_name(VAR_16));

            return 0;

        }

    }



    VAR_0->scalingBpp = FFMAX(av_pix_fmt_descriptors[VAR_15].comp[0].depth_minus1,

                          av_pix_fmt_descriptors[VAR_16].comp[0].depth_minus1) >= 8 ? 16 : 8;

    if (VAR_0->scalingBpp == 16)

        VAR_11 <<= 1;

    FF_ALLOC_OR_GOTO(VAR_0, VAR_0->formatConvBuffer, FFALIGN(VAR_7, 16) * 2 * VAR_0->scalingBpp >> 3, fail);

    if (HAVE_MMX2 && VAR_14 & AV_CPU_FLAG_MMX2 && VAR_0->scalingBpp == 8) {

        VAR_0->canMMX2BeUsed= (VAR_9 >=VAR_7 && (VAR_9&31)==0 && (VAR_7&15)==0) ? 1 : 0;

        if (!VAR_0->canMMX2BeUsed && VAR_9 >=VAR_7 && (VAR_7&15)==0 && (VAR_13&SWS_FAST_BILINEAR)) {

            if (VAR_13&SWS_PRINT_INFO)

                av_log(VAR_0, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n");

        }

        if (VAR_5) VAR_0->canMMX2BeUsed=0;

    }

    else

        VAR_0->canMMX2BeUsed=0;



    VAR_0->chrXInc= ((VAR_0->chrSrcW<<16) + (VAR_0->chrDstW>>1))/VAR_0->chrDstW;

    VAR_0->chrYInc= ((VAR_0->chrSrcH<<16) + (VAR_0->chrDstH>>1))/VAR_0->chrDstH;



    

    

    

    

    

    

    if (VAR_13&SWS_FAST_BILINEAR) {

        if (VAR_0->canMMX2BeUsed) {

            VAR_0->lumXInc+= 20;

            VAR_0->chrXInc+= 20;

        }

        

        else if (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) {

            VAR_0->lumXInc = ((VAR_7-2)<<16)/(VAR_9-2) - 20;

            VAR_0->chrXInc = ((VAR_0->chrSrcW-2)<<16)/(VAR_0->chrDstW-2) - 20;

        }

    }



    

    {

#if HAVE_MMX2



        if (VAR_0->canMMX2BeUsed && (VAR_13 & SWS_FAST_BILINEAR)) {

            VAR_0->lumMmx2FilterCodeSize = initMMX2HScaler(      VAR_9, VAR_0->lumXInc, NULL, NULL, NULL, 8);

            VAR_0->chrMmx2FilterCodeSize = initMMX2HScaler(VAR_0->chrDstW, VAR_0->chrXInc, NULL, NULL, NULL, 4);



#ifdef MAP_ANONYMOUS

            VAR_0->lumMmx2FilterCode = mmap(NULL, VAR_0->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

            VAR_0->chrMmx2FilterCode = mmap(NULL, VAR_0->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

#elif HAVE_VIRTUALALLOC

            VAR_0->lumMmx2FilterCode = VirtualAlloc(NULL, VAR_0->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

            VAR_0->chrMmx2FilterCode = VirtualAlloc(NULL, VAR_0->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);

#else

            VAR_0->lumMmx2FilterCode = av_malloc(VAR_0->lumMmx2FilterCodeSize);

            VAR_0->chrMmx2FilterCode = av_malloc(VAR_0->chrMmx2FilterCodeSize);

#endif



            if (!VAR_0->lumMmx2FilterCode || !VAR_0->chrMmx2FilterCode)

                return AVERROR(ENOMEM);

            FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hLumFilter   , (VAR_9        /8+8)*sizeof(int16_t), fail);

            FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hChrFilter   , (VAR_0->chrDstW  /4+8)*sizeof(int16_t), fail);

            FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hLumFilterPos, (VAR_9      /2/8+8)*sizeof(int32_t), fail);

            FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hChrFilterPos, (VAR_0->chrDstW/2/4+8)*sizeof(int32_t), fail);



            initMMX2HScaler(      VAR_9, VAR_0->lumXInc, VAR_0->lumMmx2FilterCode, VAR_0->hLumFilter, VAR_0->hLumFilterPos, 8);

            initMMX2HScaler(VAR_0->chrDstW, VAR_0->chrXInc, VAR_0->chrMmx2FilterCode, VAR_0->hChrFilter, VAR_0->hChrFilterPos, 4);



#ifdef MAP_ANONYMOUS

            mprotect(VAR_0->lumMmx2FilterCode, VAR_0->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ);

            mprotect(VAR_0->chrMmx2FilterCode, VAR_0->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ);

#endif

        } else

#endif 

        {

            const int VAR_18=

                (HAVE_MMX     && VAR_14 & AV_CPU_FLAG_MMX) ? 4 :

                (HAVE_ALTIVEC && VAR_14 & AV_CPU_FLAG_ALTIVEC) ? 8 :

                1;



            if (initFilter(&VAR_0->hLumFilter, &VAR_0->hLumFilterPos, &VAR_0->hLumFilterSize, VAR_0->lumXInc,

                           VAR_7      ,       VAR_9, VAR_18, 1<<14,

                           (VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BICUBIC)  : VAR_13, VAR_14,

                           VAR_1->lumH, VAR_2->lumH, VAR_0->param) < 0)

                goto fail;

            if (initFilter(&VAR_0->hChrFilter, &VAR_0->hChrFilterPos, &VAR_0->hChrFilterSize, VAR_0->chrXInc,

                           VAR_0->chrSrcW, VAR_0->chrDstW, VAR_18, 1<<14,

                           (VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BILINEAR) : VAR_13, VAR_14,

                           VAR_1->chrH, VAR_2->chrH, VAR_0->param) < 0)

                goto fail;

        }

    } 



    

    {

        const int VAR_18=

            (HAVE_MMX     && VAR_14 & AV_CPU_FLAG_MMX) && (VAR_13 & SWS_ACCURATE_RND) ? 2 :

            (HAVE_ALTIVEC && VAR_14 & AV_CPU_FLAG_ALTIVEC) ? 8 :

            1;



        if (initFilter(&VAR_0->vLumFilter, &VAR_0->vLumFilterPos, &VAR_0->vLumFilterSize, VAR_0->lumYInc,

                       VAR_8      ,        VAR_10, VAR_18, (1<<12),

                       (VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BICUBIC)  : VAR_13, VAR_14,

                       VAR_1->lumV, VAR_2->lumV, VAR_0->param) < 0)

            goto fail;

        if (initFilter(&VAR_0->vChrFilter, &VAR_0->vChrFilterPos, &VAR_0->vChrFilterSize, VAR_0->chrYInc,

                       VAR_0->chrSrcH, VAR_0->chrDstH, VAR_18, (1<<12),

                       (VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BILINEAR) : VAR_13, VAR_14,

                       VAR_1->chrV, VAR_2->chrV, VAR_0->param) < 0)

            goto fail;



#if HAVE_ALTIVEC

        FF_ALLOC_OR_GOTO(VAR_0, VAR_0->vYCoeffsBank, sizeof (vector signed short)*VAR_0->vLumFilterSize*VAR_0->VAR_10, fail);

        FF_ALLOC_OR_GOTO(VAR_0, VAR_0->vCCoeffsBank, sizeof (vector signed short)*VAR_0->vChrFilterSize*VAR_0->chrDstH, fail);



        for (VAR_3=0;VAR_3<VAR_0->vLumFilterSize*VAR_0->VAR_10;VAR_3++) {

            int j;

            short *p = (short *)&VAR_0->vYCoeffsBank[VAR_3];

            for (j=0;j<8;j++)

                p[j] = VAR_0->vLumFilter[VAR_3];

        }



        for (VAR_3=0;VAR_3<VAR_0->vChrFilterSize*VAR_0->chrDstH;VAR_3++) {

            int j;

            short *p = (short *)&VAR_0->vCCoeffsBank[VAR_3];

            for (j=0;j<8;j++)

                p[j] = VAR_0->vChrFilter[VAR_3];

        }

#endif

    }



    

    VAR_0->vLumBufSize= VAR_0->vLumFilterSize;

    VAR_0->vChrBufSize= VAR_0->vChrFilterSize;

    for (VAR_3=0; VAR_3<VAR_10; VAR_3++) {

        int VAR_18= VAR_3*VAR_0->chrDstH / VAR_10;

        int VAR_19= FFMAX(VAR_0->vLumFilterPos[VAR_3   ] + VAR_0->vLumFilterSize - 1,

                           ((VAR_0->vChrFilterPos[VAR_18] + VAR_0->vChrFilterSize - 1)<<VAR_0->chrSrcVSubSample));



        VAR_19>>= VAR_0->chrSrcVSubSample;

        VAR_19<<= VAR_0->chrSrcVSubSample;

        if (VAR_0->vLumFilterPos[VAR_3   ] + VAR_0->vLumBufSize < VAR_19)

            VAR_0->vLumBufSize= VAR_19 - VAR_0->vLumFilterPos[VAR_3];

        if (VAR_0->vChrFilterPos[VAR_18] + VAR_0->vChrBufSize < (VAR_19>>VAR_0->chrSrcVSubSample))

            VAR_0->vChrBufSize= (VAR_19>>VAR_0->chrSrcVSubSample) - VAR_0->vChrFilterPos[VAR_18];

    }



    

    

    FF_ALLOC_OR_GOTO(VAR_0, VAR_0->lumPixBuf, VAR_0->vLumBufSize*2*sizeof(int16_t*), fail);

    FF_ALLOC_OR_GOTO(VAR_0, VAR_0->chrUPixBuf, VAR_0->vChrBufSize*2*sizeof(int16_t*), fail);

    FF_ALLOC_OR_GOTO(VAR_0, VAR_0->chrVPixBuf, VAR_0->vChrBufSize*2*sizeof(int16_t*), fail);

    if (CONFIG_SWSCALE_ALPHA && isALPHA(VAR_0->VAR_15) && isALPHA(VAR_0->VAR_16))

        FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->alpPixBuf, VAR_0->vLumBufSize*2*sizeof(int16_t*), fail);

    

    

    for (VAR_3=0; VAR_3<VAR_0->vLumBufSize; VAR_3++) {

        FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->lumPixBuf[VAR_3+VAR_0->vLumBufSize], VAR_11+1, fail);

        VAR_0->lumPixBuf[VAR_3] = VAR_0->lumPixBuf[VAR_3+VAR_0->vLumBufSize];

    }

    VAR_0->uv_off_px   = VAR_12;

    VAR_0->uv_off_byte = VAR_11;

    for (VAR_3=0; VAR_3<VAR_0->vChrBufSize; VAR_3++) {

        FF_ALLOC_OR_GOTO(VAR_0, VAR_0->chrUPixBuf[VAR_3+VAR_0->vChrBufSize], VAR_11*2+1, fail);

        VAR_0->chrUPixBuf[VAR_3] = VAR_0->chrUPixBuf[VAR_3+VAR_0->vChrBufSize];

        VAR_0->chrVPixBuf[VAR_3] = VAR_0->chrVPixBuf[VAR_3+VAR_0->vChrBufSize] = VAR_0->chrUPixBuf[VAR_3] + (VAR_11 >> 1);

    }

    if (CONFIG_SWSCALE_ALPHA && VAR_0->alpPixBuf)

        for (VAR_3=0; VAR_3<VAR_0->vLumBufSize; VAR_3++) {

            FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->alpPixBuf[VAR_3+VAR_0->vLumBufSize], VAR_11+1, fail);

            VAR_0->alpPixBuf[VAR_3] = VAR_0->alpPixBuf[VAR_3+VAR_0->vLumBufSize];

        }



    

    for (VAR_3=0; VAR_3<VAR_0->vChrBufSize; VAR_3++)

        memset(VAR_0->chrUPixBuf[VAR_3], 64, VAR_11*2+1);



    assert(VAR_0->chrDstH <= VAR_10);



    if (VAR_13&SWS_PRINT_INFO) {

        if      (VAR_13&SWS_FAST_BILINEAR) av_log(VAR_0, AV_LOG_INFO, "FAST_BILINEAR scaler, ");

        else if (VAR_13&SWS_BILINEAR)      av_log(VAR_0, AV_LOG_INFO, "BILINEAR scaler, ");

        else if (VAR_13&SWS_BICUBIC)       av_log(VAR_0, AV_LOG_INFO, "BICUBIC scaler, ");

        else if (VAR_13&SWS_X)             av_log(VAR_0, AV_LOG_INFO, "Experimental scaler, ");

        else if (VAR_13&SWS_POINT)         av_log(VAR_0, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, ");

        else if (VAR_13&SWS_AREA)          av_log(VAR_0, AV_LOG_INFO, "Area Averaging scaler, ");

        else if (VAR_13&SWS_BICUBLIN)      av_log(VAR_0, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, ");

        else if (VAR_13&SWS_GAUSS)         av_log(VAR_0, AV_LOG_INFO, "Gaussian scaler, ");

        else if (VAR_13&SWS_SINC)          av_log(VAR_0, AV_LOG_INFO, "Sinc scaler, ");

        else if (VAR_13&SWS_LANCZOS)       av_log(VAR_0, AV_LOG_INFO, "Lanczos scaler, ");

        else if (VAR_13&SWS_SPLINE)        av_log(VAR_0, AV_LOG_INFO, "Bicubic spline scaler, ");

        else                              av_log(VAR_0, AV_LOG_INFO, "ehh VAR_13 invalid?! ");



        av_log(VAR_0, AV_LOG_INFO, "from %s to %s%s ",

               sws_format_name(VAR_15),

#ifdef DITHER1XBPP

               VAR_16 == PIX_FMT_BGR555 || VAR_16 == PIX_FMT_BGR565 ||

               VAR_16 == PIX_FMT_RGB444BE || VAR_16 == PIX_FMT_RGB444LE ||

               VAR_16 == PIX_FMT_BGR444BE || VAR_16 == PIX_FMT_BGR444LE ? "dithered " : "",

#else

               "",

#endif

               sws_format_name(VAR_16));



        if      (HAVE_MMX2     && VAR_14 & AV_CPU_FLAG_MMX2)    av_log(VAR_0, AV_LOG_INFO, "using MMX2\n");

        else if (HAVE_AMD3DNOW && VAR_14 & AV_CPU_FLAG_3DNOW)   av_log(VAR_0, AV_LOG_INFO, "using 3DNOW\n");

        else if (HAVE_MMX      && VAR_14 & AV_CPU_FLAG_MMX)     av_log(VAR_0, AV_LOG_INFO, "using MMX\n");

        else if (HAVE_ALTIVEC  && VAR_14 & AV_CPU_FLAG_ALTIVEC) av_log(VAR_0, AV_LOG_INFO, "using AltiVec\n");

        else                                   av_log(VAR_0, AV_LOG_INFO, "using C\n");



        if (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) {

            if (VAR_0->canMMX2BeUsed && (VAR_13&SWS_FAST_BILINEAR))

                av_log(VAR_0, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n");

            else {

                if (VAR_0->hLumFilterSize==4)

                    av_log(VAR_0, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n");

                else if (VAR_0->hLumFilterSize==8)

                    av_log(VAR_0, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n");

                else

                    av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n");



                if (VAR_0->hChrFilterSize==4)

                    av_log(VAR_0, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n");

                else if (VAR_0->hChrFilterSize==8)

                    av_log(VAR_0, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n");

                else

                    av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n");

            }

        } else {

#if HAVE_MMX

            av_log(VAR_0, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n");

#else

            if (VAR_13 & SWS_FAST_BILINEAR)

                av_log(VAR_0, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n");

            else

                av_log(VAR_0, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n");

#endif

        }

        if (isPlanarYUV(VAR_16)) {

            if (VAR_0->vLumFilterSize==1)

                av_log(VAR_0, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n",

                       (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else

                av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n",

                       (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        } else {

            if (VAR_0->vLumFilterSize==1 && VAR_0->vChrFilterSize==2)

                av_log(VAR_0, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"

                       "      2-tap scaler for vertical chrominance scaling (BGR)\n",

                       (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else if (VAR_0->vLumFilterSize==2 && VAR_0->vChrFilterSize==2)

                av_log(VAR_0, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n",

                       (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

            else

                av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n",

                       (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        }



        if (VAR_16==PIX_FMT_BGR24)

            av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n",

                   (HAVE_MMX2 && VAR_14 & AV_CPU_FLAG_MMX2) ? "MMX2" :

                   ((HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"));

        else if (VAR_16==PIX_FMT_RGB32)

            av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n",

                   (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (VAR_16==PIX_FMT_BGR565)

            av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n",

                   (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (VAR_16==PIX_FMT_BGR555)

            av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n",

                   (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");

        else if (VAR_16 == PIX_FMT_RGB444BE || VAR_16 == PIX_FMT_RGB444LE ||

                 VAR_16 == PIX_FMT_BGR444BE || VAR_16 == PIX_FMT_BGR444LE)

            av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n",

                   (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C");



        av_log(VAR_0, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", VAR_7, VAR_8, VAR_9, VAR_10);

        av_log(VAR_0, AV_LOG_DEBUG, "lum VAR_7=%d VAR_8=%d VAR_9=%d VAR_10=%d xInc=%d yInc=%d\n",

               VAR_0->VAR_7, VAR_0->VAR_8, VAR_0->VAR_9, VAR_0->VAR_10, VAR_0->lumXInc, VAR_0->lumYInc);

        av_log(VAR_0, AV_LOG_DEBUG, "chr VAR_7=%d VAR_8=%d VAR_9=%d VAR_10=%d xInc=%d yInc=%d\n",

               VAR_0->chrSrcW, VAR_0->chrSrcH, VAR_0->chrDstW, VAR_0->chrDstH, VAR_0->chrXInc, VAR_0->chrYInc);

    }



    VAR_0->swScale= ff_getSwsFunc(VAR_0);

    return 0;

fail: 

    return -1;

}

int FUNC_0(SwsContext *VAR_0, SwsFilter *VAR_1, SwsFilter *VAR_2)
{ int VAR_3; int VAR_4, VAR_5; int VAR_6; SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; int VAR_7= VAR_0->VAR_7; int VAR_8= VAR_0->VAR_8; int VAR_9= VAR_0->VAR_9; int VAR_10= VAR_0->VAR_10; int VAR_11 = FFALIGN(VAR_9 * sizeof(int16_t) + 16, 16), VAR_12 = VAR_11 >> 1; int VAR_13, VAR_14; enum PixelFormat VAR_15= VAR_0->VAR_15; enum PixelFormat VAR_16= VAR_0->VAR_16; VAR_14 = av_get_cpu_flags(); VAR_13     = VAR_0->VAR_13; emms_c(); if (!rgb15to16) sws_rgb2rgb_init(); VAR_6 = (VAR_7 == VAR_9 && VAR_8 == VAR_10); if (!isSupportedIn(VAR_15)) { av_log(VAR_0, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(VAR_15)); return AVERROR(EINVAL); } if (!isSupportedOut(VAR_16)) { av_log(VAR_0, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(VAR_16)); return AVERROR(EINVAL); } VAR_3= VAR_13 & ( SWS_POINT
|SWS_AREA
|SWS_BILINEAR
|SWS_FAST_BILINEAR
|SWS_BICUBIC
|SWS_X
|SWS_GAUSS
|SWS_LANCZOS
|SWS_SINC
|SWS_SPLINE
|SWS_BICUBLIN); if(!VAR_3 || (VAR_3 & (VAR_3-1))) { av_log(VAR_0, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen\n"); return AVERROR(EINVAL); } if (VAR_7<4 || VAR_8<1 || VAR_9<8 || VAR_10<1) { av_log(VAR_0, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n",
VAR_7, VAR_8, VAR_9, VAR_10); return AVERROR(EINVAL); } if (!VAR_2) VAR_2= &dummyFilter; if (!VAR_1) VAR_1= &dummyFilter; VAR_0->lumXInc= ((VAR_7<<16) + (VAR_9>>1))/VAR_9; VAR_0->lumYInc= ((VAR_8<<16) + (VAR_10>>1))/VAR_10; VAR_0->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[VAR_16]); VAR_0->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[VAR_15]); VAR_0->vRounder= 4* 0x0001000100010001ULL; VAR_4 = (VAR_1->lumV && VAR_1->lumV->length>1) ||
(VAR_1->chrV && VAR_1->chrV->length>1) ||
(VAR_2->lumV && VAR_2->lumV->length>1) ||
(VAR_2->chrV && VAR_2->chrV->length>1); VAR_5 = (VAR_1->lumH && VAR_1->lumH->length>1) ||
(VAR_1->chrH && VAR_1->chrH->length>1) ||
(VAR_2->lumH && VAR_2->lumH->length>1) ||
(VAR_2->chrH && VAR_2->chrH->length>1); getSubSampleFactors(&VAR_0->chrSrcHSubSample, &VAR_0->chrSrcVSubSample, VAR_15); getSubSampleFactors(&VAR_0->chrDstHSubSample, &VAR_0->chrDstVSubSample, VAR_16); if (VAR_13 & SWS_FULL_CHR_H_INT &&
VAR_16 != PIX_FMT_RGBA &&
VAR_16 != PIX_FMT_ARGB &&
VAR_16 != PIX_FMT_BGRA &&
VAR_16 != PIX_FMT_ABGR &&
VAR_16 != PIX_FMT_RGB24 &&
VAR_16 != PIX_FMT_BGR24) { av_log(VAR_0, AV_LOG_ERROR,
"full chroma interpolation for destination format '%s' not yet implemented\n",
sws_format_name(VAR_16)); VAR_13 &= ~SWS_FULL_CHR_H_INT; VAR_0->VAR_13 = VAR_13; } if (isAnyRGB(VAR_16) && !(VAR_13&SWS_FULL_CHR_H_INT)) VAR_0->chrDstHSubSample=1; VAR_0->vChrDrop= (VAR_13&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; VAR_0->chrSrcVSubSample+= VAR_0->vChrDrop; if (isAnyRGB(VAR_15) && !(VAR_13&SWS_FULL_CHR_H_INP)
&& VAR_15!=PIX_FMT_RGB8      && VAR_15!=PIX_FMT_BGR8
&& VAR_15!=PIX_FMT_RGB4      && VAR_15!=PIX_FMT_BGR4
&& VAR_15!=PIX_FMT_RGB4_BYTE && VAR_15!=PIX_FMT_BGR4_BYTE
&& ((VAR_9>>VAR_0->chrDstHSubSample) <= (VAR_7>>1) || (VAR_13&SWS_FAST_BILINEAR)))
VAR_0->chrSrcHSubSample=1; VAR_0->chrSrcW= -((-VAR_7) >> VAR_0->chrSrcHSubSample); VAR_0->chrSrcH= -((-VAR_8) >> VAR_0->chrSrcVSubSample); VAR_0->chrDstW= -((-VAR_9) >> VAR_0->chrDstHSubSample); VAR_0->chrDstH= -((-VAR_10) >> VAR_0->chrDstVSubSample); if (VAR_6 && !VAR_5 && !VAR_4 && (VAR_0->srcRange == VAR_0->dstRange || isAnyRGB(VAR_16))) { ff_get_unscaled_swscale(VAR_0); if (VAR_0->swScale) { if (VAR_13&SWS_PRINT_INFO)
av_log(VAR_0, AV_LOG_INFO, "using VAR_6 %s -> %s special converter\n",
sws_format_name(VAR_15), sws_format_name(VAR_16)); return 0; } } VAR_0->scalingBpp = FFMAX(av_pix_fmt_descriptors[VAR_15].comp[0].depth_minus1,
av_pix_fmt_descriptors[VAR_16].comp[0].depth_minus1) >= 8 ? 16 : 8; if (VAR_0->scalingBpp == 16)
VAR_11 <<= 1; FF_ALLOC_OR_GOTO(VAR_0, VAR_0->formatConvBuffer, FFALIGN(VAR_7, 16) * 2 * VAR_0->scalingBpp >> 3, fail); if (HAVE_MMX2 && VAR_14 & AV_CPU_FLAG_MMX2 && VAR_0->scalingBpp == 8) { VAR_0->canMMX2BeUsed= (VAR_9 >=VAR_7 && (VAR_9&31)==0 && (VAR_7&15)==0) ? 1 : 0; if (!VAR_0->canMMX2BeUsed && VAR_9 >=VAR_7 && (VAR_7&15)==0 && (VAR_13&SWS_FAST_BILINEAR)) { if (VAR_13&SWS_PRINT_INFO)
av_log(VAR_0, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n"); } if (VAR_5) VAR_0->canMMX2BeUsed=0; } else
VAR_0->canMMX2BeUsed=0; VAR_0->chrXInc= ((VAR_0->chrSrcW<<16) + (VAR_0->chrDstW>>1))/VAR_0->chrDstW; VAR_0->chrYInc= ((VAR_0->chrSrcH<<16) + (VAR_0->chrDstH>>1))/VAR_0->chrDstH; if (VAR_13&SWS_FAST_BILINEAR) { if (VAR_0->canMMX2BeUsed) { VAR_0->lumXInc+= 20; VAR_0->chrXInc+= 20; } else if (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) { VAR_0->lumXInc = ((VAR_7-2)<<16)/(VAR_9-2) - 20; VAR_0->chrXInc = ((VAR_0->chrSrcW-2)<<16)/(VAR_0->chrDstW-2) - 20; } } { #if HAVE_MMX2
if (VAR_0->canMMX2BeUsed && (VAR_13 & SWS_FAST_BILINEAR)) { VAR_0->lumMmx2FilterCodeSize = initMMX2HScaler(      VAR_9, VAR_0->lumXInc, NULL, NULL, NULL, 8); VAR_0->chrMmx2FilterCodeSize = initMMX2HScaler(VAR_0->chrDstW, VAR_0->chrXInc, NULL, NULL, NULL, 4); #ifdef MAP_ANONYMOUS
VAR_0->lumMmx2FilterCode = mmap(NULL, VAR_0->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); VAR_0->chrMmx2FilterCode = mmap(NULL, VAR_0->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); #elif HAVE_VIRTUALALLOC
VAR_0->lumMmx2FilterCode = VirtualAlloc(NULL, VAR_0->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); VAR_0->chrMmx2FilterCode = VirtualAlloc(NULL, VAR_0->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); #else
VAR_0->lumMmx2FilterCode = av_malloc(VAR_0->lumMmx2FilterCodeSize); VAR_0->chrMmx2FilterCode = av_malloc(VAR_0->chrMmx2FilterCodeSize); #endif
if (!VAR_0->lumMmx2FilterCode || !VAR_0->chrMmx2FilterCode)
return AVERROR(ENOMEM); FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hLumFilter   , (VAR_9        /8+8)*sizeof(int16_t), fail); FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hChrFilter   , (VAR_0->chrDstW  /4+8)*sizeof(int16_t), fail); FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hLumFilterPos, (VAR_9      /2/8+8)*sizeof(int32_t), fail); FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->hChrFilterPos, (VAR_0->chrDstW/2/4+8)*sizeof(int32_t), fail); initMMX2HScaler(      VAR_9, VAR_0->lumXInc, VAR_0->lumMmx2FilterCode, VAR_0->hLumFilter, VAR_0->hLumFilterPos, 8); initMMX2HScaler(VAR_0->chrDstW, VAR_0->chrXInc, VAR_0->chrMmx2FilterCode, VAR_0->hChrFilter, VAR_0->hChrFilterPos, 4); #ifdef MAP_ANONYMOUS
mprotect(VAR_0->lumMmx2FilterCode, VAR_0->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ); mprotect(VAR_0->chrMmx2FilterCode, VAR_0->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); #endif
} else #endif
{ const int VAR_18=
(HAVE_MMX     && VAR_14 & AV_CPU_FLAG_MMX) ? 4 :
(HAVE_ALTIVEC && VAR_14 & AV_CPU_FLAG_ALTIVEC) ? 8 :
1; if (initFilter(&VAR_0->hLumFilter, &VAR_0->hLumFilterPos, &VAR_0->hLumFilterSize, VAR_0->lumXInc,
VAR_7      ,       VAR_9, VAR_18, 1<<14,
(VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BICUBIC)  : VAR_13, VAR_14,
VAR_1->lumH, VAR_2->lumH, VAR_0->param) < 0)
goto fail; if (initFilter(&VAR_0->hChrFilter, &VAR_0->hChrFilterPos, &VAR_0->hChrFilterSize, VAR_0->chrXInc,
VAR_0->chrSrcW, VAR_0->chrDstW, VAR_18, 1<<14,
(VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BILINEAR) : VAR_13, VAR_14,
VAR_1->chrH, VAR_2->chrH, VAR_0->param) < 0)
goto fail; } } { const int VAR_18=
(HAVE_MMX     && VAR_14 & AV_CPU_FLAG_MMX) && (VAR_13 & SWS_ACCURATE_RND) ? 2 :
(HAVE_ALTIVEC && VAR_14 & AV_CPU_FLAG_ALTIVEC) ? 8 :
1; if (initFilter(&VAR_0->vLumFilter, &VAR_0->vLumFilterPos, &VAR_0->vLumFilterSize, VAR_0->lumYInc,
VAR_8      ,        VAR_10, VAR_18, (1<<12),
(VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BICUBIC)  : VAR_13, VAR_14,
VAR_1->lumV, VAR_2->lumV, VAR_0->param) < 0)
goto fail; if (initFilter(&VAR_0->vChrFilter, &VAR_0->vChrFilterPos, &VAR_0->vChrFilterSize, VAR_0->chrYInc,
VAR_0->chrSrcH, VAR_0->chrDstH, VAR_18, (1<<12),
(VAR_13&SWS_BICUBLIN) ? (VAR_13|SWS_BILINEAR) : VAR_13, VAR_14,
VAR_1->chrV, VAR_2->chrV, VAR_0->param) < 0)
goto fail; #if HAVE_ALTIVEC
FF_ALLOC_OR_GOTO(VAR_0, VAR_0->vYCoeffsBank, sizeof (vector signed short)*VAR_0->vLumFilterSize*VAR_0->VAR_10, fail); FF_ALLOC_OR_GOTO(VAR_0, VAR_0->vCCoeffsBank, sizeof (vector signed short)*VAR_0->vChrFilterSize*VAR_0->chrDstH, fail); for (VAR_3=0;VAR_3<VAR_0->vLumFilterSize*VAR_0->VAR_10;VAR_3++) { int j; short *p = (short *)&VAR_0->vYCoeffsBank[VAR_3]; for (j=0;j<8;j++) p[j] = VAR_0->vLumFilter[VAR_3]; } for (VAR_3=0;VAR_3<VAR_0->vChrFilterSize*VAR_0->chrDstH;VAR_3++) { int j; short *p = (short *)&VAR_0->vCCoeffsBank[VAR_3]; for (j=0;j<8;j++) p[j] = VAR_0->vChrFilter[VAR_3]; } #endif
} VAR_0->vLumBufSize= VAR_0->vLumFilterSize; VAR_0->vChrBufSize= VAR_0->vChrFilterSize; for (VAR_3=0; VAR_3<VAR_10; VAR_3++) { int VAR_18= VAR_3*VAR_0->chrDstH / VAR_10; int VAR_19= FFMAX(VAR_0->vLumFilterPos[VAR_3   ] + VAR_0->vLumFilterSize - 1,
((VAR_0->vChrFilterPos[VAR_18] + VAR_0->vChrFilterSize - 1)<<VAR_0->chrSrcVSubSample)); VAR_19>>= VAR_0->chrSrcVSubSample; VAR_19<<= VAR_0->chrSrcVSubSample; if (VAR_0->vLumFilterPos[VAR_3   ] + VAR_0->vLumBufSize < VAR_19)
VAR_0->vLumBufSize= VAR_19 - VAR_0->vLumFilterPos[VAR_3]; if (VAR_0->vChrFilterPos[VAR_18] + VAR_0->vChrBufSize < (VAR_19>>VAR_0->chrSrcVSubSample))
VAR_0->vChrBufSize= (VAR_19>>VAR_0->chrSrcVSubSample) - VAR_0->vChrFilterPos[VAR_18]; } FF_ALLOC_OR_GOTO(VAR_0, VAR_0->lumPixBuf, VAR_0->vLumBufSize*2*sizeof(int16_t*), fail); FF_ALLOC_OR_GOTO(VAR_0, VAR_0->chrUPixBuf, VAR_0->vChrBufSize*2*sizeof(int16_t*), fail); FF_ALLOC_OR_GOTO(VAR_0, VAR_0->chrVPixBuf, VAR_0->vChrBufSize*2*sizeof(int16_t*), fail); if (CONFIG_SWSCALE_ALPHA && isALPHA(VAR_0->VAR_15) && isALPHA(VAR_0->VAR_16))
FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->alpPixBuf, VAR_0->vLumBufSize*2*sizeof(int16_t*), fail); for (VAR_3=0; VAR_3<VAR_0->vLumBufSize; VAR_3++) { FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->lumPixBuf[VAR_3+VAR_0->vLumBufSize], VAR_11+1, fail); VAR_0->lumPixBuf[VAR_3] = VAR_0->lumPixBuf[VAR_3+VAR_0->vLumBufSize]; } VAR_0->uv_off_px   = VAR_12; VAR_0->uv_off_byte = VAR_11; for (VAR_3=0; VAR_3<VAR_0->vChrBufSize; VAR_3++) { FF_ALLOC_OR_GOTO(VAR_0, VAR_0->chrUPixBuf[VAR_3+VAR_0->vChrBufSize], VAR_11*2+1, fail); VAR_0->chrUPixBuf[VAR_3] = VAR_0->chrUPixBuf[VAR_3+VAR_0->vChrBufSize]; VAR_0->chrVPixBuf[VAR_3] = VAR_0->chrVPixBuf[VAR_3+VAR_0->vChrBufSize] = VAR_0->chrUPixBuf[VAR_3] + (VAR_11 >> 1); } if (CONFIG_SWSCALE_ALPHA && VAR_0->alpPixBuf)
for (VAR_3=0; VAR_3<VAR_0->vLumBufSize; VAR_3++) { FF_ALLOCZ_OR_GOTO(VAR_0, VAR_0->alpPixBuf[VAR_3+VAR_0->vLumBufSize], VAR_11+1, fail); VAR_0->alpPixBuf[VAR_3] = VAR_0->alpPixBuf[VAR_3+VAR_0->vLumBufSize]; } for (VAR_3=0; VAR_3<VAR_0->vChrBufSize; VAR_3++) memset(VAR_0->chrUPixBuf[VAR_3], 64, VAR_11*2+1); assert(VAR_0->chrDstH <= VAR_10); if (VAR_13&SWS_PRINT_INFO) { if      (VAR_13&SWS_FAST_BILINEAR) av_log(VAR_0, AV_LOG_INFO, "FAST_BILINEAR scaler, "); else if (VAR_13&SWS_BILINEAR)      av_log(VAR_0, AV_LOG_INFO, "BILINEAR scaler, "); else if (VAR_13&SWS_BICUBIC)       av_log(VAR_0, AV_LOG_INFO, "BICUBIC scaler, "); else if (VAR_13&SWS_X)             av_log(VAR_0, AV_LOG_INFO, "Experimental scaler, "); else if (VAR_13&SWS_POINT)         av_log(VAR_0, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, "); else if (VAR_13&SWS_AREA)          av_log(VAR_0, AV_LOG_INFO, "Area Averaging scaler, "); else if (VAR_13&SWS_BICUBLIN)      av_log(VAR_0, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, "); else if (VAR_13&SWS_GAUSS)         av_log(VAR_0, AV_LOG_INFO, "Gaussian scaler, "); else if (VAR_13&SWS_SINC)          av_log(VAR_0, AV_LOG_INFO, "Sinc scaler, "); else if (VAR_13&SWS_LANCZOS)       av_log(VAR_0, AV_LOG_INFO, "Lanczos scaler, "); else if (VAR_13&SWS_SPLINE)        av_log(VAR_0, AV_LOG_INFO, "Bicubic spline scaler, "); else                              av_log(VAR_0, AV_LOG_INFO, "ehh VAR_13 invalid?! "); av_log(VAR_0, AV_LOG_INFO, "from %s to %s%s ",
sws_format_name(VAR_15),
#ifdef DITHER1XBPP
VAR_16 == PIX_FMT_BGR555 || VAR_16 == PIX_FMT_BGR565 ||
VAR_16 == PIX_FMT_RGB444BE || VAR_16 == PIX_FMT_RGB444LE ||
VAR_16 == PIX_FMT_BGR444BE || VAR_16 == PIX_FMT_BGR444LE ? "dithered " : "",
#else
"",
#endif
sws_format_name(VAR_16)); if      (HAVE_MMX2     && VAR_14 & AV_CPU_FLAG_MMX2)    av_log(VAR_0, AV_LOG_INFO, "using MMX2\n"); else if (HAVE_AMD3DNOW && VAR_14 & AV_CPU_FLAG_3DNOW)   av_log(VAR_0, AV_LOG_INFO, "using 3DNOW\n"); else if (HAVE_MMX      && VAR_14 & AV_CPU_FLAG_MMX)     av_log(VAR_0, AV_LOG_INFO, "using MMX\n"); else if (HAVE_ALTIVEC  && VAR_14 & AV_CPU_FLAG_ALTIVEC) av_log(VAR_0, AV_LOG_INFO, "using AltiVec\n"); else                                   av_log(VAR_0, AV_LOG_INFO, "using C\n"); if (HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) { if (VAR_0->canMMX2BeUsed && (VAR_13&SWS_FAST_BILINEAR))
av_log(VAR_0, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); else { if (VAR_0->hLumFilterSize==4)
av_log(VAR_0, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n"); else if (VAR_0->hLumFilterSize==8)
av_log(VAR_0, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n"); else
av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n"); if (VAR_0->hChrFilterSize==4)
av_log(VAR_0, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n"); else if (VAR_0->hChrFilterSize==8)
av_log(VAR_0, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n"); else
av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n"); } } else { #if HAVE_MMX
av_log(VAR_0, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n"); #else
if (VAR_13 & SWS_FAST_BILINEAR)
av_log(VAR_0, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n"); else
av_log(VAR_0, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n"); #endif
} if (isPlanarYUV(VAR_16)) { if (VAR_0->vLumFilterSize==1)
av_log(VAR_0, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); else
av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); } else { if (VAR_0->vLumFilterSize==1 && VAR_0->vChrFilterSize==2)
av_log(VAR_0, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n"
"      2-tap scaler for vertical chrominance scaling (BGR)\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); else if (VAR_0->vLumFilterSize==2 && VAR_0->vChrFilterSize==2)
av_log(VAR_0, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); else
av_log(VAR_0, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); } if (VAR_16==PIX_FMT_BGR24)
av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n",
(HAVE_MMX2 && VAR_14 & AV_CPU_FLAG_MMX2) ? "MMX2" :
((HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C")); else if (VAR_16==PIX_FMT_RGB32)
av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); else if (VAR_16==PIX_FMT_BGR565)
av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); else if (VAR_16==PIX_FMT_BGR555)
av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); else if (VAR_16 == PIX_FMT_RGB444BE || VAR_16 == PIX_FMT_RGB444LE ||
VAR_16 == PIX_FMT_BGR444BE || VAR_16 == PIX_FMT_BGR444LE)
av_log(VAR_0, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n",
(HAVE_MMX && VAR_14 & AV_CPU_FLAG_MMX) ? "MMX" : "C"); av_log(VAR_0, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", VAR_7, VAR_8, VAR_9, VAR_10); av_log(VAR_0, AV_LOG_DEBUG, "lum VAR_7=%d VAR_8=%d VAR_9=%d VAR_10=%d xInc=%d yInc=%d\n",
VAR_0->VAR_7, VAR_0->VAR_8, VAR_0->VAR_9, VAR_0->VAR_10, VAR_0->lumXInc, VAR_0->lumYInc); av_log(VAR_0, AV_LOG_DEBUG, "chr VAR_7=%d VAR_8=%d VAR_9=%d VAR_10=%d xInc=%d yInc=%d\n",
VAR_0->chrSrcW, VAR_0->chrSrcH, VAR_0->chrDstW, VAR_0->chrDstH, VAR_0->chrXInc, VAR_0->chrYInc); } VAR_0->swScale= ff_getSwsFunc(VAR_0); return 0; fail:
return -1; }