static int swScale(SwsContext *c, const uint8_t* src[],

                   int srcStride[], int srcSliceY,

                   int srcSliceH, uint8_t* dst[], int dstStride[])

{

    /* load a few things into local vars to make the code more readable? and faster */

    const int srcW= c->srcW;

    const int dstW= c->dstW;

    const int dstH= c->dstH;

    const int chrDstW= c->chrDstW;

    const int chrSrcW= c->chrSrcW;

    const int lumXInc= c->lumXInc;

    const int chrXInc= c->chrXInc;

    const enum PixelFormat dstFormat= c->dstFormat;

    const int flags= c->flags;

    int16_t *vLumFilterPos= c->vLumFilterPos;

    int16_t *vChrFilterPos= c->vChrFilterPos;

    int16_t *hLumFilterPos= c->hLumFilterPos;

    int16_t *hChrFilterPos= c->hChrFilterPos;

    int16_t *vLumFilter= c->vLumFilter;

    int16_t *vChrFilter= c->vChrFilter;

    int16_t *hLumFilter= c->hLumFilter;

    int16_t *hChrFilter= c->hChrFilter;

    int32_t *lumMmxFilter= c->lumMmxFilter;

    int32_t *chrMmxFilter= c->chrMmxFilter;

    const int vLumFilterSize= c->vLumFilterSize;

    const int vChrFilterSize= c->vChrFilterSize;

    const int hLumFilterSize= c->hLumFilterSize;

    const int hChrFilterSize= c->hChrFilterSize;

    int16_t **lumPixBuf= c->lumPixBuf;

    int16_t **chrUPixBuf= c->chrUPixBuf;

    int16_t **chrVPixBuf= c->chrVPixBuf;

    int16_t **alpPixBuf= c->alpPixBuf;

    const int vLumBufSize= c->vLumBufSize;

    const int vChrBufSize= c->vChrBufSize;

    uint8_t *formatConvBuffer= c->formatConvBuffer;

    const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample;

    const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);

    int lastDstY;

    uint32_t *pal=c->pal_yuv;

    yuv2planar1_fn yuv2plane1 = c->yuv2plane1;

    yuv2planarX_fn yuv2planeX = c->yuv2planeX;

    yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX;

    yuv2packed1_fn yuv2packed1 = c->yuv2packed1;

    yuv2packed2_fn yuv2packed2 = c->yuv2packed2;

    yuv2packedX_fn yuv2packedX = c->yuv2packedX;

    int should_dither = is9_OR_10BPS(c->srcFormat) || is16BPS(c->srcFormat);



    /* vars which will change and which we need to store back in the context */

    int dstY= c->dstY;

    int lumBufIndex= c->lumBufIndex;

    int chrBufIndex= c->chrBufIndex;

    int lastInLumBuf= c->lastInLumBuf;

    int lastInChrBuf= c->lastInChrBuf;



    if (isPacked(c->srcFormat)) {

        src[0]=

        src[1]=

        src[2]=

        src[3]= src[0];

        srcStride[0]=

        srcStride[1]=

        srcStride[2]=

        srcStride[3]= srcStride[0];

    }

    srcStride[1]<<= c->vChrDrop;

    srcStride[2]<<= c->vChrDrop;



    DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",

                  src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3],

                  dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]);

    DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",

                   srcSliceY,    srcSliceH,    dstY,    dstH);

    DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",

                   vLumFilterSize,    vLumBufSize,    vChrFilterSize,    vChrBufSize);



    if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) {

        static int warnedAlready=0; //FIXME move this into the context perhaps

        if (flags & SWS_PRINT_INFO && !warnedAlready) {

            av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n"

                   "         ->cannot do aligned memory accesses anymore\n");

            warnedAlready=1;

        }

    }



    /* Note the user might start scaling the picture in the middle so this

       will not get executed. This is not really intended but works

       currently, so people might do it. */

    if (srcSliceY ==0) {

        lumBufIndex=-1;

        chrBufIndex=-1;

        dstY=0;

        lastInLumBuf= -1;

        lastInChrBuf= -1;

    }



    if (!should_dither) {

        c->chrDither8 = c->lumDither8 = ff_sws_pb_64;

    }

    lastDstY= dstY;



    for (;dstY < dstH; dstY++) {

        const int chrDstY= dstY>>c->chrDstVSubSample;

        uint8_t *dest[4] = {

            dst[0] + dstStride[0] * dstY,

            dst[1] + dstStride[1] * chrDstY,

            dst[2] + dstStride[2] * chrDstY,

            (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,

        };



        const int firstLumSrcY= FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]); //First line needed as input

        const int firstLumSrcY2= FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1<<c->chrDstVSubSample) - 1), dstH-1)]);

        const int firstChrSrcY= FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]); //First line needed as input



        // Last line needed as input

        int lastLumSrcY  = FFMIN(c->srcH,    firstLumSrcY  + vLumFilterSize) - 1;

        int lastLumSrcY2 = FFMIN(c->srcH,    firstLumSrcY2 + vLumFilterSize) - 1;

        int lastChrSrcY  = FFMIN(c->chrSrcH, firstChrSrcY  + vChrFilterSize) - 1;

        int enough_lines;



        //handle holes (FAST_BILINEAR & weird filters)

        if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1;

        if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1;

        assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);

        assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);



        DEBUG_BUFFERS("dstY: %d\n", dstY);

        DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",

                         firstLumSrcY,    lastLumSrcY,    lastInLumBuf);

        DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",

                         firstChrSrcY,    lastChrSrcY,    lastInChrBuf);



        // Do we have enough lines in this slice to output the dstY line

        enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample);



        if (!enough_lines) {

            lastLumSrcY = srcSliceY + srcSliceH - 1;

            lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;

            DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",

                                            lastLumSrcY, lastChrSrcY);

        }



        //Do horizontal scaling

        while(lastInLumBuf < lastLumSrcY) {

            const uint8_t *src1[4] = {

                src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],

                src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],

                src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],

                src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],

            };

            lumBufIndex++;

            assert(lumBufIndex < 2*vLumBufSize);

            assert(lastInLumBuf + 1 - srcSliceY < srcSliceH);

            assert(lastInLumBuf + 1 - srcSliceY >= 0);

            hyscale(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc,

                    hLumFilter, hLumFilterPos, hLumFilterSize,

                    formatConvBuffer,

                    pal, 0);

            if (CONFIG_SWSCALE_ALPHA && alpPixBuf)

                hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src1, srcW,

                        lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,

                        formatConvBuffer,

                        pal, 1);

            lastInLumBuf++;

            DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n",

                               lumBufIndex,    lastInLumBuf);

        }

        while(lastInChrBuf < lastChrSrcY) {

            const uint8_t *src1[4] = {

                src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],

                src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],

                src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],

                src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],

            };

            chrBufIndex++;

            assert(chrBufIndex < 2*vChrBufSize);

            assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));

            assert(lastInChrBuf + 1 - chrSrcSliceY >= 0);

            //FIXME replace parameters through context struct (some at least)



            if (c->needs_hcscale)

                hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],

                          chrDstW, src1, chrSrcW, chrXInc,

                          hChrFilter, hChrFilterPos, hChrFilterSize,

                          formatConvBuffer, pal);

            lastInChrBuf++;

            DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n",

                               chrBufIndex,    lastInChrBuf);

        }

        //wrap buf index around to stay inside the ring buffer

        if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize;

        if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize;

        if (!enough_lines)

            break; //we can't output a dstY line so let's try with the next slice



#if HAVE_MMX

        updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf);

#endif

        if (should_dither) {

            c->chrDither8 = dither_8x8_128[chrDstY & 7];

            c->lumDither8 = dither_8x8_128[dstY & 7];

        }

        if (dstY >= dstH-2) {

            // hmm looks like we can't use MMX here without overwriting this array's tail

            ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX,  &yuv2nv12cX,

                                     &yuv2packed1, &yuv2packed2, &yuv2packedX);

        }



        {

            const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;

            const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;

            const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;

            const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;



            if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {

                const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize;

                int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);

                for (i = 0; i < neg;            i++)

                    tmpY[i] = lumSrcPtr[neg];

                for (     ; i < end;            i++)

                    tmpY[i] = lumSrcPtr[i];

                for (     ; i < vLumFilterSize; i++)

                    tmpY[i] = tmpY[i-1];

                lumSrcPtr = tmpY;



                if (alpSrcPtr) {

                    const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize;

                    for (i = 0; i < neg;            i++)

                        tmpA[i] = alpSrcPtr[neg];

                    for (     ; i < end;            i++)

                        tmpA[i] = alpSrcPtr[i];

                    for (     ; i < vLumFilterSize; i++)

                        tmpA[i] = tmpA[i - 1];

                    alpSrcPtr = tmpA;

                }

            }

            if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {

                const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize,

                              **tmpV = (const int16_t **) chrVPixBuf + 2 * vChrBufSize;

                int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);

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

                    tmpU[i] = chrUSrcPtr[neg];

                    tmpV[i] = chrVSrcPtr[neg];

                }

                for (     ; i < end;            i++) {

                    tmpU[i] = chrUSrcPtr[i];

                    tmpV[i] = chrVSrcPtr[i];

                }

                for (     ; i < vChrFilterSize; i++) {

                    tmpU[i] = tmpU[i - 1];

                    tmpV[i] = tmpV[i - 1];

                }

                chrUSrcPtr = tmpU;

                chrVSrcPtr = tmpV;

            }



            if (isPlanarYUV(dstFormat) || (isGray(dstFormat) && !isALPHA(dstFormat))) { //YV12 like

                const int chrSkipMask= (1<<c->chrDstVSubSample)-1;



                if (vLumFilterSize == 1) {

                    yuv2plane1(lumSrcPtr[0], dest[0], dstW, c->lumDither8, 0);

                } else {

                    yuv2planeX(vLumFilter + dstY * vLumFilterSize, vLumFilterSize,

                               lumSrcPtr, dest[0], dstW, c->lumDither8, 0);

                }



                if (!((dstY&chrSkipMask) || isGray(dstFormat))) {

                    if (yuv2nv12cX) {

                        yuv2nv12cX(c, vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize, chrUSrcPtr, chrVSrcPtr, dest[1], chrDstW);

                    } else if (vChrFilterSize == 1) {

                        yuv2plane1(chrUSrcPtr[0], dest[1], chrDstW, c->chrDither8, 0);

                        yuv2plane1(chrVSrcPtr[0], dest[2], chrDstW, c->chrDither8, 3);

                    } else {

                        yuv2planeX(vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize,

                                   chrUSrcPtr, dest[1], chrDstW, c->chrDither8, 0);

                        yuv2planeX(vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize,

                                   chrVSrcPtr, dest[2], chrDstW, c->chrDither8, 3);

                    }

                }



                if (CONFIG_SWSCALE_ALPHA && alpPixBuf){

                    if (vLumFilterSize == 1) {

                        yuv2plane1(alpSrcPtr[0], dest[3], dstW, c->lumDither8, 0);

                    } else {

                        yuv2planeX(vLumFilter + dstY * vLumFilterSize, vLumFilterSize,

                                   alpSrcPtr, dest[3], dstW, c->lumDither8, 0);

                    }

                }

            } else {

                assert(lumSrcPtr  + vLumFilterSize - 1 < lumPixBuf  + vLumBufSize*2);

                assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2);

                if (c->yuv2packed1 && vLumFilterSize == 1 && vChrFilterSize <= 2) { //unscaled RGB

                    int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];

                    yuv2packed1(c, *lumSrcPtr, chrUSrcPtr, chrVSrcPtr,

                                alpPixBuf ? *alpSrcPtr : NULL,

                                dest[0], dstW, chrAlpha, dstY);

                } else if (c->yuv2packed2 && vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB

                    int lumAlpha = vLumFilter[2 * dstY + 1];

                    int chrAlpha = vChrFilter[2 * dstY + 1];

                    lumMmxFilter[2] =

                    lumMmxFilter[3] = vLumFilter[2 * dstY   ] * 0x10001;

                    chrMmxFilter[2] =

                    chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;

                    yuv2packed2(c, lumSrcPtr, chrUSrcPtr, chrVSrcPtr,

                                alpPixBuf ? alpSrcPtr : NULL,

                                dest[0], dstW, lumAlpha, chrAlpha, dstY);

                } else { //general RGB

                    yuv2packedX(c, vLumFilter + dstY * vLumFilterSize,

                                lumSrcPtr, vLumFilterSize,

                                vChrFilter + dstY * vChrFilterSize,

                                chrUSrcPtr, chrVSrcPtr, vChrFilterSize,

                                alpSrcPtr, dest[0], dstW, dstY);

                }

            }

        }

    }



    if (isPlanar(dstFormat) && isALPHA(dstFormat) && !alpPixBuf)

        fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255);



#if HAVE_MMX2

    if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2)

        __asm__ volatile("sfence":::"memory");

#endif

    emms_c();



    /* store changed local vars back in the context */

    c->dstY= dstY;

    c->lumBufIndex= lumBufIndex;

    c->chrBufIndex= chrBufIndex;

    c->lastInLumBuf= lastInLumBuf;

    c->lastInChrBuf= lastInChrBuf;



    return dstY - lastDstY;

}

static int swScale(SwsContext *c, const uint8_t* src[],

                   int srcStride[], int srcSliceY,

                   int srcSliceH, uint8_t* dst[], int dstStride[])

{

    

    const int srcW= c->srcW;

    const int dstW= c->dstW;

    const int dstH= c->dstH;

    const int chrDstW= c->chrDstW;

    const int chrSrcW= c->chrSrcW;

    const int lumXInc= c->lumXInc;

    const int chrXInc= c->chrXInc;

    const enum PixelFormat dstFormat= c->dstFormat;

    const int flags= c->flags;

    int16_t *vLumFilterPos= c->vLumFilterPos;

    int16_t *vChrFilterPos= c->vChrFilterPos;

    int16_t *hLumFilterPos= c->hLumFilterPos;

    int16_t *hChrFilterPos= c->hChrFilterPos;

    int16_t *vLumFilter= c->vLumFilter;

    int16_t *vChrFilter= c->vChrFilter;

    int16_t *hLumFilter= c->hLumFilter;

    int16_t *hChrFilter= c->hChrFilter;

    int32_t *lumMmxFilter= c->lumMmxFilter;

    int32_t *chrMmxFilter= c->chrMmxFilter;

    const int vLumFilterSize= c->vLumFilterSize;

    const int vChrFilterSize= c->vChrFilterSize;

    const int hLumFilterSize= c->hLumFilterSize;

    const int hChrFilterSize= c->hChrFilterSize;

    int16_t **lumPixBuf= c->lumPixBuf;

    int16_t **chrUPixBuf= c->chrUPixBuf;

    int16_t **chrVPixBuf= c->chrVPixBuf;

    int16_t **alpPixBuf= c->alpPixBuf;

    const int vLumBufSize= c->vLumBufSize;

    const int vChrBufSize= c->vChrBufSize;

    uint8_t *formatConvBuffer= c->formatConvBuffer;

    const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample;

    const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample);

    int lastDstY;

    uint32_t *pal=c->pal_yuv;

    yuv2planar1_fn yuv2plane1 = c->yuv2plane1;

    yuv2planarX_fn yuv2planeX = c->yuv2planeX;

    yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX;

    yuv2packed1_fn yuv2packed1 = c->yuv2packed1;

    yuv2packed2_fn yuv2packed2 = c->yuv2packed2;

    yuv2packedX_fn yuv2packedX = c->yuv2packedX;

    int should_dither = is9_OR_10BPS(c->srcFormat) || is16BPS(c->srcFormat);



    

    int dstY= c->dstY;

    int lumBufIndex= c->lumBufIndex;

    int chrBufIndex= c->chrBufIndex;

    int lastInLumBuf= c->lastInLumBuf;

    int lastInChrBuf= c->lastInChrBuf;



    if (isPacked(c->srcFormat)) {

        src[0]=

        src[1]=

        src[2]=

        src[3]= src[0];

        srcStride[0]=

        srcStride[1]=

        srcStride[2]=

        srcStride[3]= srcStride[0];

    }

    srcStride[1]<<= c->vChrDrop;

    srcStride[2]<<= c->vChrDrop;



    DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",

                  src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3],

                  dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]);

    DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",

                   srcSliceY,    srcSliceH,    dstY,    dstH);

    DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",

                   vLumFilterSize,    vLumBufSize,    vChrFilterSize,    vChrBufSize);



    if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) {

        static int warnedAlready=0; 

        if (flags & SWS_PRINT_INFO && !warnedAlready) {

            av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n"

                   "         ->cannot do aligned memory accesses anymore\n");

            warnedAlready=1;

        }

    }



    





    if (srcSliceY ==0) {

        lumBufIndex=-1;

        chrBufIndex=-1;

        dstY=0;

        lastInLumBuf= -1;

        lastInChrBuf= -1;

    }



    if (!should_dither) {

        c->chrDither8 = c->lumDither8 = ff_sws_pb_64;

    }

    lastDstY= dstY;



    for (;dstY < dstH; dstY++) {

        const int chrDstY= dstY>>c->chrDstVSubSample;

        uint8_t *dest[4] = {

            dst[0] + dstStride[0] * dstY,

            dst[1] + dstStride[1] * chrDstY,

            dst[2] + dstStride[2] * chrDstY,

            (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,

        };



        const int firstLumSrcY= FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]); 

        const int firstLumSrcY2= FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1<<c->chrDstVSubSample) - 1), dstH-1)]);

        const int firstChrSrcY= FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]); 



        

        int lastLumSrcY  = FFMIN(c->srcH,    firstLumSrcY  + vLumFilterSize) - 1;

        int lastLumSrcY2 = FFMIN(c->srcH,    firstLumSrcY2 + vLumFilterSize) - 1;

        int lastChrSrcY  = FFMIN(c->chrSrcH, firstChrSrcY  + vChrFilterSize) - 1;

        int enough_lines;



        

        if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1;

        if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1;

        assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);

        assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);



        DEBUG_BUFFERS("dstY: %d\n", dstY);

        DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",

                         firstLumSrcY,    lastLumSrcY,    lastInLumBuf);

        DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",

                         firstChrSrcY,    lastChrSrcY,    lastInChrBuf);



        

        enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample);



        if (!enough_lines) {

            lastLumSrcY = srcSliceY + srcSliceH - 1;

            lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;

            DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",

                                            lastLumSrcY, lastChrSrcY);

        }



        

        while(lastInLumBuf < lastLumSrcY) {

            const uint8_t *src1[4] = {

                src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],

                src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],

                src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],

                src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],

            };

            lumBufIndex++;

            assert(lumBufIndex < 2*vLumBufSize);

            assert(lastInLumBuf + 1 - srcSliceY < srcSliceH);

            assert(lastInLumBuf + 1 - srcSliceY >= 0);

            hyscale(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc,

                    hLumFilter, hLumFilterPos, hLumFilterSize,

                    formatConvBuffer,

                    pal, 0);

            if (CONFIG_SWSCALE_ALPHA && alpPixBuf)

                hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src1, srcW,

                        lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,

                        formatConvBuffer,

                        pal, 1);

            lastInLumBuf++;

            DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n",

                               lumBufIndex,    lastInLumBuf);

        }

        while(lastInChrBuf < lastChrSrcY) {

            const uint8_t *src1[4] = {

                src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],

                src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],

                src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],

                src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],

            };

            chrBufIndex++;

            assert(chrBufIndex < 2*vChrBufSize);

            assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));

            assert(lastInChrBuf + 1 - chrSrcSliceY >= 0);

            



            if (c->needs_hcscale)

                hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],

                          chrDstW, src1, chrSrcW, chrXInc,

                          hChrFilter, hChrFilterPos, hChrFilterSize,

                          formatConvBuffer, pal);

            lastInChrBuf++;

            DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n",

                               chrBufIndex,    lastInChrBuf);

        }

        

        if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize;

        if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize;

        if (!enough_lines)

            break; 



#if HAVE_MMX

        updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf);

#endif

        if (should_dither) {

            c->chrDither8 = dither_8x8_128[chrDstY & 7];

            c->lumDither8 = dither_8x8_128[dstY & 7];

        }

        if (dstY >= dstH-2) {

            

            ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX,  &yuv2nv12cX,

                                     &yuv2packed1, &yuv2packed2, &yuv2packedX);

        }



        {

            const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;

            const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;

            const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;

            const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;



            if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) {

                const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize;

                int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize);

                for (i = 0; i < neg;            i++)

                    tmpY[i] = lumSrcPtr[neg];

                for (     ; i < end;            i++)

                    tmpY[i] = lumSrcPtr[i];

                for (     ; i < vLumFilterSize; i++)

                    tmpY[i] = tmpY[i-1];

                lumSrcPtr = tmpY;



                if (alpSrcPtr) {

                    const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize;

                    for (i = 0; i < neg;            i++)

                        tmpA[i] = alpSrcPtr[neg];

                    for (     ; i < end;            i++)

                        tmpA[i] = alpSrcPtr[i];

                    for (     ; i < vLumFilterSize; i++)

                        tmpA[i] = tmpA[i - 1];

                    alpSrcPtr = tmpA;

                }

            }

            if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) {

                const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize,

                              **tmpV = (const int16_t **) chrVPixBuf + 2 * vChrBufSize;

                int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize);

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

                    tmpU[i] = chrUSrcPtr[neg];

                    tmpV[i] = chrVSrcPtr[neg];

                }

                for (     ; i < end;            i++) {

                    tmpU[i] = chrUSrcPtr[i];

                    tmpV[i] = chrVSrcPtr[i];

                }

                for (     ; i < vChrFilterSize; i++) {

                    tmpU[i] = tmpU[i - 1];

                    tmpV[i] = tmpV[i - 1];

                }

                chrUSrcPtr = tmpU;

                chrVSrcPtr = tmpV;

            }



            if (isPlanarYUV(dstFormat) || (isGray(dstFormat) && !isALPHA(dstFormat))) { 

                const int chrSkipMask= (1<<c->chrDstVSubSample)-1;



                if (vLumFilterSize == 1) {

                    yuv2plane1(lumSrcPtr[0], dest[0], dstW, c->lumDither8, 0);

                } else {

                    yuv2planeX(vLumFilter + dstY * vLumFilterSize, vLumFilterSize,

                               lumSrcPtr, dest[0], dstW, c->lumDither8, 0);

                }



                if (!((dstY&chrSkipMask) || isGray(dstFormat))) {

                    if (yuv2nv12cX) {

                        yuv2nv12cX(c, vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize, chrUSrcPtr, chrVSrcPtr, dest[1], chrDstW);

                    } else if (vChrFilterSize == 1) {

                        yuv2plane1(chrUSrcPtr[0], dest[1], chrDstW, c->chrDither8, 0);

                        yuv2plane1(chrVSrcPtr[0], dest[2], chrDstW, c->chrDither8, 3);

                    } else {

                        yuv2planeX(vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize,

                                   chrUSrcPtr, dest[1], chrDstW, c->chrDither8, 0);

                        yuv2planeX(vChrFilter + chrDstY * vChrFilterSize, vChrFilterSize,

                                   chrVSrcPtr, dest[2], chrDstW, c->chrDither8, 3);

                    }

                }



                if (CONFIG_SWSCALE_ALPHA && alpPixBuf){

                    if (vLumFilterSize == 1) {

                        yuv2plane1(alpSrcPtr[0], dest[3], dstW, c->lumDither8, 0);

                    } else {

                        yuv2planeX(vLumFilter + dstY * vLumFilterSize, vLumFilterSize,

                                   alpSrcPtr, dest[3], dstW, c->lumDither8, 0);

                    }

                }

            } else {

                assert(lumSrcPtr  + vLumFilterSize - 1 < lumPixBuf  + vLumBufSize*2);

                assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2);

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

                    int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];

                    yuv2packed1(c, *lumSrcPtr, chrUSrcPtr, chrVSrcPtr,

                                alpPixBuf ? *alpSrcPtr : NULL,

                                dest[0], dstW, chrAlpha, dstY);

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

                    int lumAlpha = vLumFilter[2 * dstY + 1];

                    int chrAlpha = vChrFilter[2 * dstY + 1];

                    lumMmxFilter[2] =

                    lumMmxFilter[3] = vLumFilter[2 * dstY   ] * 0x10001;

                    chrMmxFilter[2] =

                    chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;

                    yuv2packed2(c, lumSrcPtr, chrUSrcPtr, chrVSrcPtr,

                                alpPixBuf ? alpSrcPtr : NULL,

                                dest[0], dstW, lumAlpha, chrAlpha, dstY);

                } else { 

                    yuv2packedX(c, vLumFilter + dstY * vLumFilterSize,

                                lumSrcPtr, vLumFilterSize,

                                vChrFilter + dstY * vChrFilterSize,

                                chrUSrcPtr, chrVSrcPtr, vChrFilterSize,

                                alpSrcPtr, dest[0], dstW, dstY);

                }

            }

        }

    }



    if (isPlanar(dstFormat) && isALPHA(dstFormat) && !alpPixBuf)

        fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255);



#if HAVE_MMX2

    if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2)

        __asm__ volatile("sfence":::"memory");

#endif

    emms_c();



    

    c->dstY= dstY;

    c->lumBufIndex= lumBufIndex;

    c->chrBufIndex= chrBufIndex;

    c->lastInLumBuf= lastInLumBuf;

    c->lastInChrBuf= lastInChrBuf;



    return dstY - lastDstY;

}

    int16_t *vLumFilterPos= c->vLumFilterPos;     int16_t *vChrFilterPos= c->vChrFilterPos;     int16_t *hLumFilterPos= c->hLumFilterPos;     int16_t *hChrFilterPos= c->hChrFilterPos;     int16_t *vLumFilterPos= c->vLumFilterPos;     int16_t *vChrFilterPos= c->vChrFilterPos;
static int FUNC_0(SwsContext *VAR_0, const uint8_t* VAR_1[],

                   int VAR_2[], int VAR_3,

                   int VAR_4, uint8_t* VAR_5[], int VAR_6[])

{

    

    const int VAR_7= VAR_0->VAR_7;

    const int VAR_8= VAR_0->VAR_8;

    const int VAR_9= VAR_0->VAR_9;

    const int VAR_10= VAR_0->VAR_10;

    const int VAR_11= VAR_0->VAR_11;

    const int VAR_12= VAR_0->VAR_12;

    const int VAR_13= VAR_0->VAR_13;

    const enum PixelFormat VAR_14= VAR_0->VAR_14;

    const int VAR_15= VAR_0->VAR_15;

    int16_t *vLumFilterPos= VAR_0->vLumFilterPos;

    int16_t *vChrFilterPos= VAR_0->vChrFilterPos;

    int16_t *hLumFilterPos= VAR_0->hLumFilterPos;

    int16_t *hChrFilterPos= VAR_0->hChrFilterPos;

    int16_t *vLumFilter= VAR_0->vLumFilter;

    int16_t *vChrFilter= VAR_0->vChrFilter;

    int16_t *hLumFilter= VAR_0->hLumFilter;

    int16_t *hChrFilter= VAR_0->hChrFilter;

    int32_t *lumMmxFilter= VAR_0->lumMmxFilter;

    int32_t *chrMmxFilter= VAR_0->chrMmxFilter;

    const int VAR_16= VAR_0->VAR_16;

    const int VAR_17= VAR_0->VAR_17;

    const int VAR_18= VAR_0->VAR_18;

    const int VAR_19= VAR_0->VAR_19;

    int16_t **lumPixBuf= VAR_0->lumPixBuf;

    int16_t **chrUPixBuf= VAR_0->chrUPixBuf;

    int16_t **chrVPixBuf= VAR_0->chrVPixBuf;

    int16_t **alpPixBuf= VAR_0->alpPixBuf;

    const int VAR_20= VAR_0->VAR_20;

    const int VAR_21= VAR_0->VAR_21;

    uint8_t *formatConvBuffer= VAR_0->formatConvBuffer;

    const int VAR_22= VAR_3 >> VAR_0->chrSrcVSubSample;

    const int VAR_23= -((-VAR_4) >> VAR_0->chrSrcVSubSample);

    int VAR_24;

    uint32_t *pal=VAR_0->pal_yuv;

    yuv2planar1_fn yuv2plane1 = VAR_0->yuv2plane1;

    yuv2planarX_fn yuv2planeX = VAR_0->yuv2planeX;

    yuv2interleavedX_fn yuv2nv12cX = VAR_0->yuv2nv12cX;

    yuv2packed1_fn yuv2packed1 = VAR_0->yuv2packed1;

    yuv2packed2_fn yuv2packed2 = VAR_0->yuv2packed2;

    yuv2packedX_fn yuv2packedX = VAR_0->yuv2packedX;

    int VAR_25 = is9_OR_10BPS(VAR_0->srcFormat) || is16BPS(VAR_0->srcFormat);



    

    int VAR_26= VAR_0->VAR_26;

    int VAR_27= VAR_0->VAR_27;

    int VAR_28= VAR_0->VAR_28;

    int VAR_29= VAR_0->VAR_29;

    int VAR_30= VAR_0->VAR_30;



    if (isPacked(VAR_0->srcFormat)) {

        VAR_1[0]=

        VAR_1[1]=

        VAR_1[2]=

        VAR_1[3]= VAR_1[0];

        VAR_2[0]=

        VAR_2[1]=

        VAR_2[2]=

        VAR_2[3]= VAR_2[0];

    }

    VAR_2[1]<<= VAR_0->vChrDrop;

    VAR_2[2]<<= VAR_0->vChrDrop;



    DEBUG_BUFFERS("FUNC_0() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",

                  VAR_1[0], VAR_2[0], VAR_1[1], VAR_2[1], VAR_1[2], VAR_2[2], VAR_1[3], VAR_2[3],

                  VAR_5[0], VAR_6[0], VAR_5[1], VAR_6[1], VAR_5[2], VAR_6[2], VAR_5[3], VAR_6[3]);

    DEBUG_BUFFERS("VAR_3: %d VAR_4: %d VAR_26: %d VAR_9: %d\n",

                   VAR_3,    VAR_4,    VAR_26,    VAR_9);

    DEBUG_BUFFERS("VAR_16: %d VAR_20: %d VAR_17: %d VAR_21: %d\n",

                   VAR_16,    VAR_20,    VAR_17,    VAR_21);



    if (VAR_6[0]%8 !=0 || VAR_6[1]%8 !=0 || VAR_6[2]%8 !=0 || VAR_6[3]%8 != 0) {

        static int VAR_31=0; 

        if (VAR_15 & SWS_PRINT_INFO && !VAR_31) {

            av_log(VAR_0, AV_LOG_WARNING, "Warning: VAR_6 is not aligned!\n"

                   "         ->cannot do aligned memory accesses anymore\n");

            VAR_31=1;

        }

    }



    





    if (VAR_3 ==0) {

        VAR_27=-1;

        VAR_28=-1;

        VAR_26=0;

        VAR_29= -1;

        VAR_30= -1;

    }



    if (!VAR_25) {

        VAR_0->chrDither8 = VAR_0->lumDither8 = ff_sws_pb_64;

    }

    VAR_24= VAR_26;



    for (;VAR_26 < VAR_9; VAR_26++) {

        const int VAR_32= VAR_26>>VAR_0->chrDstVSubSample;

        uint8_t *dest[4] = {

            VAR_5[0] + VAR_6[0] * VAR_26,

            VAR_5[1] + VAR_6[1] * VAR_32,

            VAR_5[2] + VAR_6[2] * VAR_32,

            (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? VAR_5[3] + VAR_6[3] * VAR_26 : NULL,

        };



        const int VAR_33= FFMAX(1 - VAR_16, vLumFilterPos[VAR_26]); 

        const int VAR_34= FFMAX(1 - VAR_16, vLumFilterPos[FFMIN(VAR_26 | ((1<<VAR_0->chrDstVSubSample) - 1), VAR_9-1)]);

        const int VAR_35= FFMAX(1 - VAR_17, vChrFilterPos[VAR_32]); 



        

        int VAR_36  = FFMIN(VAR_0->srcH,    VAR_33  + VAR_16) - 1;

        int VAR_37 = FFMIN(VAR_0->srcH,    VAR_34 + VAR_16) - 1;

        int VAR_38  = FFMIN(VAR_0->chrSrcH, VAR_35  + VAR_17) - 1;

        int VAR_39;



        

        if (VAR_33 > VAR_29) VAR_29= VAR_33-1;

        if (VAR_35 > VAR_30) VAR_30= VAR_35-1;

        assert(VAR_33 >= VAR_29 - VAR_20 + 1);

        assert(VAR_35 >= VAR_30 - VAR_21 + 1);



        DEBUG_BUFFERS("VAR_26: %d\n", VAR_26);

        DEBUG_BUFFERS("\tfirstLumSrcY: %d VAR_36: %d VAR_29: %d\n",

                         VAR_33,    VAR_36,    VAR_29);

        DEBUG_BUFFERS("\tfirstChrSrcY: %d VAR_38: %d VAR_30: %d\n",

                         VAR_35,    VAR_38,    VAR_30);



        

        VAR_39 = VAR_37 < VAR_3 + VAR_4 && VAR_38 < -((-VAR_3 - VAR_4)>>VAR_0->chrSrcVSubSample);



        if (!VAR_39) {

            VAR_36 = VAR_3 + VAR_4 - 1;

            VAR_38 = VAR_22 + VAR_23 - 1;

            DEBUG_BUFFERS("buffering slice: VAR_36 %d VAR_38 %d\n",

                                            VAR_36, VAR_38);

        }



        

        while(VAR_29 < VAR_36) {

            const uint8_t *VAR_41[4] = {

                VAR_1[0] + (VAR_29 + 1 - VAR_3) * VAR_2[0],

                VAR_1[1] + (VAR_29 + 1 - VAR_3) * VAR_2[1],

                VAR_1[2] + (VAR_29 + 1 - VAR_3) * VAR_2[2],

                VAR_1[3] + (VAR_29 + 1 - VAR_3) * VAR_2[3],

            };

            VAR_27++;

            assert(VAR_27 < 2*VAR_20);

            assert(VAR_29 + 1 - VAR_3 < VAR_4);

            assert(VAR_29 + 1 - VAR_3 >= 0);

            hyscale(VAR_0, lumPixBuf[ VAR_27 ], VAR_8, VAR_41, VAR_7, VAR_12,

                    hLumFilter, hLumFilterPos, VAR_18,

                    formatConvBuffer,

                    pal, 0);

            if (CONFIG_SWSCALE_ALPHA && alpPixBuf)

                hyscale(VAR_0, alpPixBuf[ VAR_27 ], VAR_8, VAR_41, VAR_7,

                        VAR_12, hLumFilter, hLumFilterPos, VAR_18,

                        formatConvBuffer,

                        pal, 1);

            VAR_29++;

            DEBUG_BUFFERS("\t\tlumBufIndex %d: VAR_29: %d\n",

                               VAR_27,    VAR_29);

        }

        while(VAR_30 < VAR_38) {

            const uint8_t *VAR_41[4] = {

                VAR_1[0] + (VAR_30 + 1 - VAR_22) * VAR_2[0],

                VAR_1[1] + (VAR_30 + 1 - VAR_22) * VAR_2[1],

                VAR_1[2] + (VAR_30 + 1 - VAR_22) * VAR_2[2],

                VAR_1[3] + (VAR_30 + 1 - VAR_22) * VAR_2[3],

            };

            VAR_28++;

            assert(VAR_28 < 2*VAR_21);

            assert(VAR_30 + 1 - VAR_22 < (VAR_23));

            assert(VAR_30 + 1 - VAR_22 >= 0);

            



            if (VAR_0->needs_hcscale)

                hcscale(VAR_0, chrUPixBuf[VAR_28], chrVPixBuf[VAR_28],

                          VAR_10, VAR_41, VAR_11, VAR_13,

                          hChrFilter, hChrFilterPos, VAR_19,

                          formatConvBuffer, pal);

            VAR_30++;

            DEBUG_BUFFERS("\t\tchrBufIndex %d: VAR_30: %d\n",

                               VAR_28,    VAR_30);

        }

        

        if (VAR_27 >= VAR_20) VAR_27-= VAR_20;

        if (VAR_28 >= VAR_21) VAR_28-= VAR_21;

        if (!VAR_39)

            break; 



#if HAVE_MMX

        updateMMXDitherTables(VAR_0, VAR_26, VAR_27, VAR_28, VAR_29, VAR_30);

#endif

        if (VAR_25) {

            VAR_0->chrDither8 = dither_8x8_128[VAR_32 & 7];

            VAR_0->lumDither8 = dither_8x8_128[VAR_26 & 7];

        }

        if (VAR_26 >= VAR_9-2) {

            

            ff_sws_init_output_funcs(VAR_0, &yuv2plane1, &yuv2planeX,  &yuv2nv12cX,

                                     &yuv2packed1, &yuv2packed2, &yuv2packedX);

        }



        {

            const int16_t **VAR_41= (const int16_t **) lumPixBuf + VAR_27 + VAR_33 - VAR_29 + VAR_20;

            const int16_t **VAR_42= (const int16_t **) chrUPixBuf + VAR_28 + VAR_35 - VAR_30 + VAR_21;

            const int16_t **VAR_43= (const int16_t **) chrVPixBuf + VAR_28 + VAR_35 - VAR_30 + VAR_21;

            const int16_t **VAR_44= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + VAR_27 + VAR_33 - VAR_29 + VAR_20 : NULL;



            if (VAR_33 < 0 || VAR_33 + VAR_16 > VAR_0->srcH) {

                const int16_t **VAR_45 = (const int16_t **) lumPixBuf + 2 * VAR_20;

                int VAR_51 = -VAR_33, VAR_51, VAR_51 = FFMIN(VAR_0->srcH - VAR_33, VAR_16);

                for (VAR_51 = 0; VAR_51 < VAR_51;            VAR_51++)

                    VAR_45[VAR_51] = VAR_41[VAR_51];

                for (     ; VAR_51 < VAR_51;            VAR_51++)

                    VAR_45[VAR_51] = VAR_41[VAR_51];

                for (     ; VAR_51 < VAR_16; VAR_51++)

                    VAR_45[VAR_51] = VAR_45[VAR_51-1];

                VAR_41 = VAR_45;



                if (VAR_44) {

                    const int16_t **VAR_49 = (const int16_t **) alpPixBuf + 2 * VAR_20;

                    for (VAR_51 = 0; VAR_51 < VAR_51;            VAR_51++)

                        VAR_49[VAR_51] = VAR_44[VAR_51];

                    for (     ; VAR_51 < VAR_51;            VAR_51++)

                        VAR_49[VAR_51] = VAR_44[VAR_51];

                    for (     ; VAR_51 < VAR_16; VAR_51++)

                        VAR_49[VAR_51] = VAR_49[VAR_51 - 1];

                    VAR_44 = VAR_49;

                }

            }

            if (VAR_35 < 0 || VAR_35 + VAR_17 > VAR_0->chrSrcH) {

                const int16_t **VAR_50 = (const int16_t **) chrUPixBuf + 2 * VAR_21,

                              **tmpV = (const int16_t **) chrVPixBuf + 2 * VAR_21;

                int VAR_51 = -VAR_35, VAR_51, VAR_51 = FFMIN(VAR_0->chrSrcH - VAR_35, VAR_17);

                for (VAR_51 = 0; VAR_51 < VAR_51;            VAR_51++) {

                    VAR_50[VAR_51] = VAR_42[VAR_51];

                    tmpV[VAR_51] = VAR_43[VAR_51];

                }

                for (     ; VAR_51 < VAR_51;            VAR_51++) {

                    VAR_50[VAR_51] = VAR_42[VAR_51];

                    tmpV[VAR_51] = VAR_43[VAR_51];

                }

                for (     ; VAR_51 < VAR_17; VAR_51++) {

                    VAR_50[VAR_51] = VAR_50[VAR_51 - 1];

                    tmpV[VAR_51] = tmpV[VAR_51 - 1];

                }

                VAR_42 = VAR_50;

                VAR_43 = tmpV;

            }



            if (isPlanarYUV(VAR_14) || (isGray(VAR_14) && !isALPHA(VAR_14))) { 

                const int VAR_51= (1<<VAR_0->chrDstVSubSample)-1;



                if (VAR_16 == 1) {

                    yuv2plane1(VAR_41[0], dest[0], VAR_8, VAR_0->lumDither8, 0);

                } else {

                    yuv2planeX(vLumFilter + VAR_26 * VAR_16, VAR_16,

                               VAR_41, dest[0], VAR_8, VAR_0->lumDither8, 0);

                }



                if (!((VAR_26&VAR_51) || isGray(VAR_14))) {

                    if (yuv2nv12cX) {

                        yuv2nv12cX(VAR_0, vChrFilter + VAR_32 * VAR_17, VAR_17, VAR_42, VAR_43, dest[1], VAR_10);

                    } else if (VAR_17 == 1) {

                        yuv2plane1(VAR_42[0], dest[1], VAR_10, VAR_0->chrDither8, 0);

                        yuv2plane1(VAR_43[0], dest[2], VAR_10, VAR_0->chrDither8, 3);

                    } else {

                        yuv2planeX(vChrFilter + VAR_32 * VAR_17, VAR_17,

                                   VAR_42, dest[1], VAR_10, VAR_0->chrDither8, 0);

                        yuv2planeX(vChrFilter + VAR_32 * VAR_17, VAR_17,

                                   VAR_43, dest[2], VAR_10, VAR_0->chrDither8, 3);

                    }

                }



                if (CONFIG_SWSCALE_ALPHA && alpPixBuf){

                    if (VAR_16 == 1) {

                        yuv2plane1(VAR_44[0], dest[3], VAR_8, VAR_0->lumDither8, 0);

                    } else {

                        yuv2planeX(vLumFilter + VAR_26 * VAR_16, VAR_16,

                                   VAR_44, dest[3], VAR_8, VAR_0->lumDither8, 0);

                    }

                }

            } else {

                assert(VAR_41  + VAR_16 - 1 < lumPixBuf  + VAR_20*2);

                assert(VAR_42 + VAR_17 - 1 < chrUPixBuf + VAR_21*2);

                if (VAR_0->yuv2packed1 && VAR_16 == 1 && VAR_17 <= 2) { 

                    int VAR_54 = VAR_17 == 1 ? 0 : vChrFilter[2 * VAR_26 + 1];

                    yuv2packed1(VAR_0, *VAR_41, VAR_42, VAR_43,

                                alpPixBuf ? *VAR_44 : NULL,

                                dest[0], VAR_8, VAR_54, VAR_26);

                } else if (VAR_0->yuv2packed2 && VAR_16 == 2 && VAR_17 == 2) { 

                    int VAR_53 = vLumFilter[2 * VAR_26 + 1];

                    int VAR_54 = vChrFilter[2 * VAR_26 + 1];

                    lumMmxFilter[2] =

                    lumMmxFilter[3] = vLumFilter[2 * VAR_26   ] * 0x10001;

                    chrMmxFilter[2] =

                    chrMmxFilter[3] = vChrFilter[2 * VAR_32] * 0x10001;

                    yuv2packed2(VAR_0, VAR_41, VAR_42, VAR_43,

                                alpPixBuf ? VAR_44 : NULL,

                                dest[0], VAR_8, VAR_53, VAR_54, VAR_26);

                } else { 

                    yuv2packedX(VAR_0, vLumFilter + VAR_26 * VAR_16,

                                VAR_41, VAR_16,

                                vChrFilter + VAR_26 * VAR_17,

                                VAR_42, VAR_43, VAR_17,

                                VAR_44, dest[0], VAR_8, VAR_26);

                }

            }

        }

    }



    if (isPlanar(VAR_14) && isALPHA(VAR_14) && !alpPixBuf)

        fillPlane(VAR_5[3], VAR_6[3], VAR_8, VAR_26-VAR_24, VAR_24, 255);



#if HAVE_MMX2

    if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2)

        __asm__ volatile("sfence":::"memory");

#endif

    emms_c();



    

    VAR_0->VAR_26= VAR_26;

    VAR_0->VAR_27= VAR_27;

    VAR_0->VAR_28= VAR_28;

    VAR_0->VAR_29= VAR_29;

    VAR_0->VAR_30= VAR_30;



    return VAR_26 - VAR_24;

}

static int FUNC_0(SwsContext *VAR_0, const uint8_t* VAR_1[],
int VAR_2[], int VAR_3,
int VAR_4, uint8_t* VAR_5[], int VAR_6[])
{ const int VAR_7= VAR_0->VAR_7; const int VAR_8= VAR_0->VAR_8; const int VAR_9= VAR_0->VAR_9; const int VAR_10= VAR_0->VAR_10; const int VAR_11= VAR_0->VAR_11; const int VAR_12= VAR_0->VAR_12; const int VAR_13= VAR_0->VAR_13; const enum PixelFormat VAR_14= VAR_0->VAR_14; const int VAR_15= VAR_0->VAR_15; int16_t *vLumFilterPos= VAR_0->vLumFilterPos; int16_t *vChrFilterPos= VAR_0->vChrFilterPos; int16_t *hLumFilterPos= VAR_0->hLumFilterPos; int16_t *hChrFilterPos= VAR_0->hChrFilterPos; int16_t *vLumFilter= VAR_0->vLumFilter; int16_t *vChrFilter= VAR_0->vChrFilter; int16_t *hLumFilter= VAR_0->hLumFilter; int16_t *hChrFilter= VAR_0->hChrFilter; int32_t *lumMmxFilter= VAR_0->lumMmxFilter; int32_t *chrMmxFilter= VAR_0->chrMmxFilter; const int VAR_16= VAR_0->VAR_16; const int VAR_17= VAR_0->VAR_17; const int VAR_18= VAR_0->VAR_18; const int VAR_19= VAR_0->VAR_19; int16_t **lumPixBuf= VAR_0->lumPixBuf; int16_t **chrUPixBuf= VAR_0->chrUPixBuf; int16_t **chrVPixBuf= VAR_0->chrVPixBuf; int16_t **alpPixBuf= VAR_0->alpPixBuf; const int VAR_20= VAR_0->VAR_20; const int VAR_21= VAR_0->VAR_21; uint8_t *formatConvBuffer= VAR_0->formatConvBuffer; const int VAR_22= VAR_3 >> VAR_0->chrSrcVSubSample; const int VAR_23= -((-VAR_4) >> VAR_0->chrSrcVSubSample); int VAR_24; uint32_t *pal=VAR_0->pal_yuv; yuv2planar1_fn yuv2plane1 = VAR_0->yuv2plane1; yuv2planarX_fn yuv2planeX = VAR_0->yuv2planeX; yuv2interleavedX_fn yuv2nv12cX = VAR_0->yuv2nv12cX; yuv2packed1_fn yuv2packed1 = VAR_0->yuv2packed1; yuv2packed2_fn yuv2packed2 = VAR_0->yuv2packed2; yuv2packedX_fn yuv2packedX = VAR_0->yuv2packedX; int VAR_25 = is9_OR_10BPS(VAR_0->srcFormat) || is16BPS(VAR_0->srcFormat); int VAR_26= VAR_0->VAR_26; int VAR_27= VAR_0->VAR_27; int VAR_28= VAR_0->VAR_28; int VAR_29= VAR_0->VAR_29; int VAR_30= VAR_0->VAR_30; if (isPacked(VAR_0->srcFormat)) { VAR_1[0]=
VAR_1[1]=
VAR_1[2]=
VAR_1[3]= VAR_1[0]; VAR_2[0]=
VAR_2[1]=
VAR_2[2]=
VAR_2[3]= VAR_2[0]; } VAR_2[1]<<= VAR_0->vChrDrop; VAR_2[2]<<= VAR_0->vChrDrop; DEBUG_BUFFERS("FUNC_0() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
VAR_1[0], VAR_2[0], VAR_1[1], VAR_2[1], VAR_1[2], VAR_2[2], VAR_1[3], VAR_2[3],
VAR_5[0], VAR_6[0], VAR_5[1], VAR_6[1], VAR_5[2], VAR_6[2], VAR_5[3], VAR_6[3]); DEBUG_BUFFERS("VAR_3: %d VAR_4: %d VAR_26: %d VAR_9: %d\n",
VAR_3,    VAR_4,    VAR_26,    VAR_9); DEBUG_BUFFERS("VAR_16: %d VAR_20: %d VAR_17: %d VAR_21: %d\n",
VAR_16,    VAR_20,    VAR_17,    VAR_21); if (VAR_6[0]%8 !=0 || VAR_6[1]%8 !=0 || VAR_6[2]%8 !=0 || VAR_6[3]%8 != 0) { static int VAR_31=0; if (VAR_15 & SWS_PRINT_INFO && !VAR_31) { av_log(VAR_0, AV_LOG_WARNING, "Warning: VAR_6 is not aligned!\n"
"         ->cannot do aligned memory accesses anymore\n"); VAR_31=1; } } if (VAR_3 ==0) { VAR_27=-1; VAR_28=-1; VAR_26=0; VAR_29= -1; VAR_30= -1; } if (!VAR_25) { VAR_0->chrDither8 = VAR_0->lumDither8 = ff_sws_pb_64; } VAR_24= VAR_26; for (;VAR_26 < VAR_9; VAR_26++) { const int VAR_32= VAR_26>>VAR_0->chrDstVSubSample; uint8_t *dest[4] = { VAR_5[0] + VAR_6[0] * VAR_26,
VAR_5[1] + VAR_6[1] * VAR_32,
VAR_5[2] + VAR_6[2] * VAR_32,
(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? VAR_5[3] + VAR_6[3] * VAR_26 : NULL,
}; const int VAR_33= FFMAX(1 - VAR_16, vLumFilterPos[VAR_26]); const int VAR_34= FFMAX(1 - VAR_16, vLumFilterPos[FFMIN(VAR_26 | ((1<<VAR_0->chrDstVSubSample) - 1), VAR_9-1)]); const int VAR_35= FFMAX(1 - VAR_17, vChrFilterPos[VAR_32]); int VAR_36  = FFMIN(VAR_0->srcH,    VAR_33  + VAR_16) - 1; int VAR_37 = FFMIN(VAR_0->srcH,    VAR_34 + VAR_16) - 1; int VAR_38  = FFMIN(VAR_0->chrSrcH, VAR_35  + VAR_17) - 1; int VAR_39; if (VAR_33 > VAR_29) VAR_29= VAR_33-1; if (VAR_35 > VAR_30) VAR_30= VAR_35-1; assert(VAR_33 >= VAR_29 - VAR_20 + 1); assert(VAR_35 >= VAR_30 - VAR_21 + 1); DEBUG_BUFFERS("VAR_26: %d\n", VAR_26); DEBUG_BUFFERS("\tfirstLumSrcY: %d VAR_36: %d VAR_29: %d\n",
VAR_33,    VAR_36,    VAR_29); DEBUG_BUFFERS("\tfirstChrSrcY: %d VAR_38: %d VAR_30: %d\n",
VAR_35,    VAR_38,    VAR_30); VAR_39 = VAR_37 < VAR_3 + VAR_4 && VAR_38 < -((-VAR_3 - VAR_4)>>VAR_0->chrSrcVSubSample); if (!VAR_39) { VAR_36 = VAR_3 + VAR_4 - 1; VAR_38 = VAR_22 + VAR_23 - 1; DEBUG_BUFFERS("buffering slice: VAR_36 %d VAR_38 %d\n",
VAR_36, VAR_38); } while(VAR_29 < VAR_36) { const uint8_t *VAR_41[4] = { VAR_1[0] + (VAR_29 + 1 - VAR_3) * VAR_2[0],
VAR_1[1] + (VAR_29 + 1 - VAR_3) * VAR_2[1],
VAR_1[2] + (VAR_29 + 1 - VAR_3) * VAR_2[2],
VAR_1[3] + (VAR_29 + 1 - VAR_3) * VAR_2[3],
}; VAR_27++; assert(VAR_27 < 2*VAR_20); assert(VAR_29 + 1 - VAR_3 < VAR_4); assert(VAR_29 + 1 - VAR_3 >= 0); hyscale(VAR_0, lumPixBuf[ VAR_27 ], VAR_8, VAR_41, VAR_7, VAR_12,
hLumFilter, hLumFilterPos, VAR_18,
formatConvBuffer,
pal, 0); if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
hyscale(VAR_0, alpPixBuf[ VAR_27 ], VAR_8, VAR_41, VAR_7,
VAR_12, hLumFilter, hLumFilterPos, VAR_18,
formatConvBuffer,
pal, 1); VAR_29++; DEBUG_BUFFERS("\t\tlumBufIndex %d: VAR_29: %d\n",
VAR_27,    VAR_29); } while(VAR_30 < VAR_38) { const uint8_t *VAR_41[4] = { VAR_1[0] + (VAR_30 + 1 - VAR_22) * VAR_2[0],
VAR_1[1] + (VAR_30 + 1 - VAR_22) * VAR_2[1],
VAR_1[2] + (VAR_30 + 1 - VAR_22) * VAR_2[2],
VAR_1[3] + (VAR_30 + 1 - VAR_22) * VAR_2[3],
}; VAR_28++; assert(VAR_28 < 2*VAR_21); assert(VAR_30 + 1 - VAR_22 < (VAR_23)); assert(VAR_30 + 1 - VAR_22 >= 0); if (VAR_0->needs_hcscale)
hcscale(VAR_0, chrUPixBuf[VAR_28], chrVPixBuf[VAR_28],
VAR_10, VAR_41, VAR_11, VAR_13,
hChrFilter, hChrFilterPos, VAR_19,
formatConvBuffer, pal); VAR_30++; DEBUG_BUFFERS("\t\tchrBufIndex %d: VAR_30: %d\n",
VAR_28,    VAR_30); } if (VAR_27 >= VAR_20) VAR_27-= VAR_20; if (VAR_28 >= VAR_21) VAR_28-= VAR_21; if (!VAR_39)
break; #if HAVE_MMX
updateMMXDitherTables(VAR_0, VAR_26, VAR_27, VAR_28, VAR_29, VAR_30); #endif
if (VAR_25) { VAR_0->chrDither8 = dither_8x8_128[VAR_32 & 7]; VAR_0->lumDither8 = dither_8x8_128[VAR_26 & 7]; } if (VAR_26 >= VAR_9-2) { ff_sws_init_output_funcs(VAR_0, &yuv2plane1, &yuv2planeX,  &yuv2nv12cX,
&yuv2packed1, &yuv2packed2, &yuv2packedX); } { const int16_t **VAR_41= (const int16_t **) lumPixBuf + VAR_27 + VAR_33 - VAR_29 + VAR_20; const int16_t **VAR_42= (const int16_t **) chrUPixBuf + VAR_28 + VAR_35 - VAR_30 + VAR_21; const int16_t **VAR_43= (const int16_t **) chrVPixBuf + VAR_28 + VAR_35 - VAR_30 + VAR_21; const int16_t **VAR_44= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + VAR_27 + VAR_33 - VAR_29 + VAR_20 : NULL; if (VAR_33 < 0 || VAR_33 + VAR_16 > VAR_0->srcH) { const int16_t **VAR_45 = (const int16_t **) lumPixBuf + 2 * VAR_20; int VAR_51 = -VAR_33, VAR_51, VAR_51 = FFMIN(VAR_0->srcH - VAR_33, VAR_16); for (VAR_51 = 0; VAR_51 < VAR_51;            VAR_51++) VAR_45[VAR_51] = VAR_41[VAR_51]; for (     ; VAR_51 < VAR_51;            VAR_51++) VAR_45[VAR_51] = VAR_41[VAR_51]; for (     ; VAR_51 < VAR_16; VAR_51++) VAR_45[VAR_51] = VAR_45[VAR_51-1]; VAR_41 = VAR_45; if (VAR_44) { const int16_t **VAR_49 = (const int16_t **) alpPixBuf + 2 * VAR_20; for (VAR_51 = 0; VAR_51 < VAR_51;            VAR_51++) VAR_49[VAR_51] = VAR_44[VAR_51]; for (     ; VAR_51 < VAR_51;            VAR_51++) VAR_49[VAR_51] = VAR_44[VAR_51]; for (     ; VAR_51 < VAR_16; VAR_51++) VAR_49[VAR_51] = VAR_49[VAR_51 - 1]; VAR_44 = VAR_49; } } if (VAR_35 < 0 || VAR_35 + VAR_17 > VAR_0->chrSrcH) { const int16_t **VAR_50 = (const int16_t **) chrUPixBuf + 2 * VAR_21,
**tmpV = (const int16_t **) chrVPixBuf + 2 * VAR_21; int VAR_51 = -VAR_35, VAR_51, VAR_51 = FFMIN(VAR_0->chrSrcH - VAR_35, VAR_17); for (VAR_51 = 0; VAR_51 < VAR_51;            VAR_51++) { VAR_50[VAR_51] = VAR_42[VAR_51]; tmpV[VAR_51] = VAR_43[VAR_51]; } for (     ; VAR_51 < VAR_51;            VAR_51++) { VAR_50[VAR_51] = VAR_42[VAR_51]; tmpV[VAR_51] = VAR_43[VAR_51]; } for (     ; VAR_51 < VAR_17; VAR_51++) { VAR_50[VAR_51] = VAR_50[VAR_51 - 1]; tmpV[VAR_51] = tmpV[VAR_51 - 1]; } VAR_42 = VAR_50; VAR_43 = tmpV; } if (isPlanarYUV(VAR_14) || (isGray(VAR_14) && !isALPHA(VAR_14))) { const int VAR_51= (1<<VAR_0->chrDstVSubSample)-1; if (VAR_16 == 1) { yuv2plane1(VAR_41[0], dest[0], VAR_8, VAR_0->lumDither8, 0); } else { yuv2planeX(vLumFilter + VAR_26 * VAR_16, VAR_16,
VAR_41, dest[0], VAR_8, VAR_0->lumDither8, 0); } if (!((VAR_26&VAR_51) || isGray(VAR_14))) { if (yuv2nv12cX) { yuv2nv12cX(VAR_0, vChrFilter + VAR_32 * VAR_17, VAR_17, VAR_42, VAR_43, dest[1], VAR_10); } else if (VAR_17 == 1) { yuv2plane1(VAR_42[0], dest[1], VAR_10, VAR_0->chrDither8, 0); yuv2plane1(VAR_43[0], dest[2], VAR_10, VAR_0->chrDither8, 3); } else { yuv2planeX(vChrFilter + VAR_32 * VAR_17, VAR_17,
VAR_42, dest[1], VAR_10, VAR_0->chrDither8, 0); yuv2planeX(vChrFilter + VAR_32 * VAR_17, VAR_17,
VAR_43, dest[2], VAR_10, VAR_0->chrDither8, 3); } } if (CONFIG_SWSCALE_ALPHA && alpPixBuf){ if (VAR_16 == 1) { yuv2plane1(VAR_44[0], dest[3], VAR_8, VAR_0->lumDither8, 0); } else { yuv2planeX(vLumFilter + VAR_26 * VAR_16, VAR_16,
VAR_44, dest[3], VAR_8, VAR_0->lumDither8, 0); } } } else { assert(VAR_41  + VAR_16 - 1 < lumPixBuf  + VAR_20*2); assert(VAR_42 + VAR_17 - 1 < chrUPixBuf + VAR_21*2); if (VAR_0->yuv2packed1 && VAR_16 == 1 && VAR_17 <= 2) { int VAR_54 = VAR_17 == 1 ? 0 : vChrFilter[2 * VAR_26 + 1]; yuv2packed1(VAR_0, *VAR_41, VAR_42, VAR_43,
alpPixBuf ? *VAR_44 : NULL,
dest[0], VAR_8, VAR_54, VAR_26); } else if (VAR_0->yuv2packed2 && VAR_16 == 2 && VAR_17 == 2) { int VAR_53 = vLumFilter[2 * VAR_26 + 1]; int VAR_54 = vChrFilter[2 * VAR_26 + 1]; lumMmxFilter[2] =
lumMmxFilter[3] = vLumFilter[2 * VAR_26   ] * 0x10001; chrMmxFilter[2] =
chrMmxFilter[3] = vChrFilter[2 * VAR_32] * 0x10001; yuv2packed2(VAR_0, VAR_41, VAR_42, VAR_43,
alpPixBuf ? VAR_44 : NULL,
dest[0], VAR_8, VAR_53, VAR_54, VAR_26); } else { yuv2packedX(VAR_0, vLumFilter + VAR_26 * VAR_16,
VAR_41, VAR_16,
vChrFilter + VAR_26 * VAR_17,
VAR_42, VAR_43, VAR_17,
VAR_44, dest[0], VAR_8, VAR_26); } } } } if (isPlanar(VAR_14) && isALPHA(VAR_14) && !alpPixBuf)
fillPlane(VAR_5[3], VAR_6[3], VAR_8, VAR_26-VAR_24, VAR_24, 255); #if HAVE_MMX2
if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2)
__asm__ volatile("sfence":::"memory"); #endif
emms_c(); VAR_0->VAR_26= VAR_26; VAR_0->VAR_27= VAR_27; VAR_0->VAR_28= VAR_28; VAR_0->VAR_29= VAR_29; VAR_0->VAR_30= VAR_30; return VAR_26 - VAR_24; }