static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,

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

{

    int plane, i, j;

    for (plane=0; plane<4; plane++) {

        int length= (plane==0 || plane==3) ? c->srcW  : -((-c->srcW  )>>c->chrDstHSubSample);

        int y=      (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);

        int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);

        const uint8_t *srcPtr= src[plane];

        uint8_t *dstPtr= dst[plane] + dstStride[plane]*y;



        if (!dst[plane]) continue;

        // ignore palette for GRAY8

        if (plane == 1 && !dst[2]) continue;

        if (!src[plane] || (plane == 1 && !src[2])) {

            if(is16BPS(c->dstFormat))

                length*=2;

            fillPlane(dst[plane], dstStride[plane], length, height, y, (plane==3) ? 255 : 128);

        } else {

            if(is9_OR_10BPS(c->srcFormat)) {

                const int src_depth = av_pix_fmt_descriptors[c->srcFormat].comp[plane].depth_minus1+1;

                const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1+1;

                const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;



                if (is16BPS(c->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t*)dstPtr;

#define COPY9_OR_10TO16(rfunc, wfunc) \

                    for (i = 0; i < height; i++) { \

                        for (j = 0; j < length; j++) { \

                            int srcpx = rfunc(&srcPtr2[j]); \

                            wfunc(&dstPtr2[j], (srcpx<<(16-src_depth)) | (srcpx>>(2*src_depth-16))); \

                        } \

                        dstPtr2 += dstStride[plane]/2; \

                        srcPtr2 += srcStride[plane]/2; \

                    }

                    if (isBE(c->dstFormat)) {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO16(AV_RB16, AV_WB16);

                        } else {

                            COPY9_OR_10TO16(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO16(AV_RB16, AV_WL16);

                        } else {

                            COPY9_OR_10TO16(AV_RL16, AV_WL16);

                        }

                    }

                } else if (is9_OR_10BPS(c->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t*)dstPtr;

#define COPY9_OR_10TO9_OR_10(loop) \

                    for (i = 0; i < height; i++) { \

                        for (j = 0; j < length; j++) { \

                            loop; \

                        } \

                        dstPtr2 += dstStride[plane]/2; \

                        srcPtr2 += srcStride[plane]/2; \

                    }

#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \

                    if (dst_depth > src_depth) { \

                        COPY9_OR_10TO9_OR_10(int srcpx = rfunc(&srcPtr2[j]); \

                            wfunc(&dstPtr2[j], (srcpx << 1) | (srcpx >> 9))); \

                    } else if (dst_depth < src_depth) { \

                        DITHER_COPY(dstPtr2, dstStride[plane]/2, wfunc, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_1, 1); \

                    } else { \

                        COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[j], rfunc(&srcPtr2[j]))); \

                    }

                    if (isBE(c->dstFormat)) {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WB16);

                        } else {

                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WL16);

                        } else {

                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WL16);

                        }

                    }

                } else {

#define W8(a, b) { *(a) = (b); }

#define COPY9_OR_10TO8(rfunc) \

                    if (src_depth == 9) { \

                        DITHER_COPY(dstPtr,  dstStride[plane],   W8, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_1, 1); \

                    } else { \

                        DITHER_COPY(dstPtr,  dstStride[plane],   W8, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_3, 2); \

                    }

                    if (isBE(c->srcFormat)) {

                        COPY9_OR_10TO8(AV_RB16);

                    } else {

                        COPY9_OR_10TO8(AV_RL16);

                    }

                }

            } else if(is9_OR_10BPS(c->dstFormat)) {

                const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1+1;

                uint16_t *dstPtr2 = (uint16_t*)dstPtr;



                if (is16BPS(c->srcFormat)) {

                    const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;

#define COPY16TO9_OR_10(rfunc, wfunc) \

                    if (dst_depth == 9) { \

                        DITHER_COPY(dstPtr2, dstStride[plane]/2, wfunc, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_128, 7); \

                    } else { \

                        DITHER_COPY(dstPtr2, dstStride[plane]/2, wfunc, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_64, 6); \

                    }

                    if (isBE(c->dstFormat)) {

                        if (isBE(c->srcFormat)) {

                            COPY16TO9_OR_10(AV_RB16, AV_WB16);

                        } else {

                            COPY16TO9_OR_10(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(c->srcFormat)) {

                            COPY16TO9_OR_10(AV_RB16, AV_WL16);

                        } else {

                            COPY16TO9_OR_10(AV_RL16, AV_WL16);

                        }

                    }

                } else /* 8bit */ {

#define COPY8TO9_OR_10(wfunc) \

                    for (i = 0; i < height; i++) { \

                        for (j = 0; j < length; j++) { \

                            const int srcpx = srcPtr[j]; \

                            wfunc(&dstPtr2[j], (srcpx<<(dst_depth-8)) | (srcpx >> (16-dst_depth))); \

                        } \

                        dstPtr2 += dstStride[plane]/2; \

                        srcPtr  += srcStride[plane]; \

                    }

                    if (isBE(c->dstFormat)) {

                        COPY8TO9_OR_10(AV_WB16);

                    } else {

                        COPY8TO9_OR_10(AV_WL16);

                    }

                }

            } else if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {

                const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;

#define COPY16TO8(rfunc) \

                    DITHER_COPY(dstPtr,  dstStride[plane],   W8, \

                                srcPtr2, srcStride[plane]/2, rfunc, \

                                dither_8x8_256, 8);

                if (isBE(c->srcFormat)) {

                    COPY16TO8(AV_RB16);

                } else {

                    COPY16TO8(AV_RL16);

                }

            } else if(!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) {

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

                    for (j=0; j<length; j++) {

                        dstPtr[ j<<1   ] = srcPtr[j];

                        dstPtr[(j<<1)+1] = srcPtr[j];

                    }

                    srcPtr+= srcStride[plane];

                    dstPtr+= dstStride[plane];

                }

            } else if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat)

                  && isBE(c->srcFormat) != isBE(c->dstFormat)) {



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

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

                        ((uint16_t*)dstPtr)[j] = av_bswap16(((const uint16_t*)srcPtr)[j]);

                    srcPtr+= srcStride[plane];

                    dstPtr+= dstStride[plane];

                }

            } else if (dstStride[plane] == srcStride[plane] &&

                       srcStride[plane] > 0 && srcStride[plane] == length) {

                memcpy(dst[plane] + dstStride[plane]*y, src[plane],

                       height*dstStride[plane]);

            } else {

                if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat))

                    length*=2;

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

                    memcpy(dstPtr, srcPtr, length);

                    srcPtr+= srcStride[plane];

                    dstPtr+= dstStride[plane];

                }

            }

        }

    }

    return srcSliceH;

}

static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,

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

{

    int plane, i, j;

    for (plane=0; plane<4; plane++) {

        int length= (plane==0 || plane==3) ? c->srcW  : -((-c->srcW  )>>c->chrDstHSubSample);

        int y=      (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample);

        int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample);

        const uint8_t *srcPtr= src[plane];

        uint8_t *dstPtr= dst[plane] + dstStride[plane]*y;



        if (!dst[plane]) continue;

        

        if (plane == 1 && !dst[2]) continue;

        if (!src[plane] || (plane == 1 && !src[2])) {

            if(is16BPS(c->dstFormat))

                length*=2;

            fillPlane(dst[plane], dstStride[plane], length, height, y, (plane==3) ? 255 : 128);

        } else {

            if(is9_OR_10BPS(c->srcFormat)) {

                const int src_depth = av_pix_fmt_descriptors[c->srcFormat].comp[plane].depth_minus1+1;

                const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1+1;

                const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;



                if (is16BPS(c->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t*)dstPtr;

#define COPY9_OR_10TO16(rfunc, wfunc) \

                    for (i = 0; i < height; i++) { \

                        for (j = 0; j < length; j++) { \

                            int srcpx = rfunc(&srcPtr2[j]); \

                            wfunc(&dstPtr2[j], (srcpx<<(16-src_depth)) | (srcpx>>(2*src_depth-16))); \

                        } \

                        dstPtr2 += dstStride[plane]/2; \

                        srcPtr2 += srcStride[plane]/2; \

                    }

                    if (isBE(c->dstFormat)) {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO16(AV_RB16, AV_WB16);

                        } else {

                            COPY9_OR_10TO16(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO16(AV_RB16, AV_WL16);

                        } else {

                            COPY9_OR_10TO16(AV_RL16, AV_WL16);

                        }

                    }

                } else if (is9_OR_10BPS(c->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t*)dstPtr;

#define COPY9_OR_10TO9_OR_10(loop) \

                    for (i = 0; i < height; i++) { \

                        for (j = 0; j < length; j++) { \

                            loop; \

                        } \

                        dstPtr2 += dstStride[plane]/2; \

                        srcPtr2 += srcStride[plane]/2; \

                    }

#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \

                    if (dst_depth > src_depth) { \

                        COPY9_OR_10TO9_OR_10(int srcpx = rfunc(&srcPtr2[j]); \

                            wfunc(&dstPtr2[j], (srcpx << 1) | (srcpx >> 9))); \

                    } else if (dst_depth < src_depth) { \

                        DITHER_COPY(dstPtr2, dstStride[plane]/2, wfunc, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_1, 1); \

                    } else { \

                        COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[j], rfunc(&srcPtr2[j]))); \

                    }

                    if (isBE(c->dstFormat)) {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WB16);

                        } else {

                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(c->srcFormat)) {

                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WL16);

                        } else {

                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WL16);

                        }

                    }

                } else {

#define W8(a, b) { *(a) = (b); }

#define COPY9_OR_10TO8(rfunc) \

                    if (src_depth == 9) { \

                        DITHER_COPY(dstPtr,  dstStride[plane],   W8, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_1, 1); \

                    } else { \

                        DITHER_COPY(dstPtr,  dstStride[plane],   W8, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_3, 2); \

                    }

                    if (isBE(c->srcFormat)) {

                        COPY9_OR_10TO8(AV_RB16);

                    } else {

                        COPY9_OR_10TO8(AV_RL16);

                    }

                }

            } else if(is9_OR_10BPS(c->dstFormat)) {

                const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1+1;

                uint16_t *dstPtr2 = (uint16_t*)dstPtr;



                if (is16BPS(c->srcFormat)) {

                    const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;

#define COPY16TO9_OR_10(rfunc, wfunc) \

                    if (dst_depth == 9) { \

                        DITHER_COPY(dstPtr2, dstStride[plane]/2, wfunc, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_128, 7); \

                    } else { \

                        DITHER_COPY(dstPtr2, dstStride[plane]/2, wfunc, \

                                    srcPtr2, srcStride[plane]/2, rfunc, \

                                    dither_8x8_64, 6); \

                    }

                    if (isBE(c->dstFormat)) {

                        if (isBE(c->srcFormat)) {

                            COPY16TO9_OR_10(AV_RB16, AV_WB16);

                        } else {

                            COPY16TO9_OR_10(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(c->srcFormat)) {

                            COPY16TO9_OR_10(AV_RB16, AV_WL16);

                        } else {

                            COPY16TO9_OR_10(AV_RL16, AV_WL16);

                        }

                    }

                } else  {

#define COPY8TO9_OR_10(wfunc) \

                    for (i = 0; i < height; i++) { \

                        for (j = 0; j < length; j++) { \

                            const int srcpx = srcPtr[j]; \

                            wfunc(&dstPtr2[j], (srcpx<<(dst_depth-8)) | (srcpx >> (16-dst_depth))); \

                        } \

                        dstPtr2 += dstStride[plane]/2; \

                        srcPtr  += srcStride[plane]; \

                    }

                    if (isBE(c->dstFormat)) {

                        COPY8TO9_OR_10(AV_WB16);

                    } else {

                        COPY8TO9_OR_10(AV_WL16);

                    }

                }

            } else if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {

                const uint16_t *srcPtr2 = (const uint16_t*)srcPtr;

#define COPY16TO8(rfunc) \

                    DITHER_COPY(dstPtr,  dstStride[plane],   W8, \

                                srcPtr2, srcStride[plane]/2, rfunc, \

                                dither_8x8_256, 8);

                if (isBE(c->srcFormat)) {

                    COPY16TO8(AV_RB16);

                } else {

                    COPY16TO8(AV_RL16);

                }

            } else if(!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) {

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

                    for (j=0; j<length; j++) {

                        dstPtr[ j<<1   ] = srcPtr[j];

                        dstPtr[(j<<1)+1] = srcPtr[j];

                    }

                    srcPtr+= srcStride[plane];

                    dstPtr+= dstStride[plane];

                }

            } else if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat)

                  && isBE(c->srcFormat) != isBE(c->dstFormat)) {



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

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

                        ((uint16_t*)dstPtr)[j] = av_bswap16(((const uint16_t*)srcPtr)[j]);

                    srcPtr+= srcStride[plane];

                    dstPtr+= dstStride[plane];

                }

            } else if (dstStride[plane] == srcStride[plane] &&

                       srcStride[plane] > 0 && srcStride[plane] == length) {

                memcpy(dst[plane] + dstStride[plane]*y, src[plane],

                       height*dstStride[plane]);

            } else {

                if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat))

                    length*=2;

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

                    memcpy(dstPtr, srcPtr, length);

                    srcPtr+= srcStride[plane];

                    dstPtr+= dstStride[plane];

                }

            }

        }

    }

    return srcSliceH;

}

                                    dither_8x8_1, 1); \                                     dither_8x8_1, 1); \                                     dither_8x8_3, 2); \                                     dither_8x8_128, 7); \                                     dither_8x8_64, 6); \                                 dither_8x8_256, 8);
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[])

{

    int VAR_7, VAR_8, VAR_9;

    for (VAR_7=0; VAR_7<4; VAR_7++) {

        int VAR_10= (VAR_7==0 || VAR_7==3) ? VAR_0->srcW  : -((-VAR_0->srcW  )>>VAR_0->chrDstHSubSample);

        int VAR_11=      (VAR_7==0 || VAR_7==3) ? VAR_3: -((-VAR_3)>>VAR_0->chrDstVSubSample);

        int VAR_12= (VAR_7==0 || VAR_7==3) ? VAR_4: -((-VAR_4)>>VAR_0->chrDstVSubSample);

        const uint8_t *VAR_13= VAR_1[VAR_7];

        uint8_t *dstPtr= VAR_5[VAR_7] + VAR_6[VAR_7]*VAR_11;



        if (!VAR_5[VAR_7]) continue;

        

        if (VAR_7 == 1 && !VAR_5[2]) continue;

        if (!VAR_1[VAR_7] || (VAR_7 == 1 && !VAR_1[2])) {

            if(is16BPS(VAR_0->dstFormat))

                VAR_10*=2;

            fillPlane(VAR_5[VAR_7], VAR_6[VAR_7], VAR_10, VAR_12, VAR_11, (VAR_7==3) ? 255 : 128);

        } else {

            if(is9_OR_10BPS(VAR_0->srcFormat)) {

                const int VAR_14 = av_pix_fmt_descriptors[VAR_0->srcFormat].comp[VAR_7].depth_minus1+1;

                const int VAR_18 = av_pix_fmt_descriptors[VAR_0->dstFormat].comp[VAR_7].depth_minus1+1;

                const uint16_t *VAR_18 = (const uint16_t*)VAR_13;



                if (is16BPS(VAR_0->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t*)dstPtr;

#define COPY9_OR_10TO16(rfunc, wfunc) \

                    for (VAR_8 = 0; VAR_8 < VAR_12; VAR_8++) { \

                        for (VAR_9 = 0; VAR_9 < VAR_10; VAR_9++) { \

                            int VAR_18 = rfunc(&VAR_18[VAR_9]); \

                            wfunc(&dstPtr2[VAR_9], (VAR_18<<(16-VAR_14)) | (VAR_18>>(2*VAR_14-16))); \

                        } \

                        dstPtr2 += VAR_6[VAR_7]/2; \

                        VAR_18 += VAR_2[VAR_7]/2; \

                    }

                    if (isBE(VAR_0->dstFormat)) {

                        if (isBE(VAR_0->srcFormat)) {

                            COPY9_OR_10TO16(AV_RB16, AV_WB16);

                        } else {

                            COPY9_OR_10TO16(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(VAR_0->srcFormat)) {

                            COPY9_OR_10TO16(AV_RB16, AV_WL16);

                        } else {

                            COPY9_OR_10TO16(AV_RL16, AV_WL16);

                        }

                    }

                } else if (is9_OR_10BPS(VAR_0->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t*)dstPtr;

#define COPY9_OR_10TO9_OR_10(loop) \

                    for (VAR_8 = 0; VAR_8 < VAR_12; VAR_8++) { \

                        for (VAR_9 = 0; VAR_9 < VAR_10; VAR_9++) { \

                            loop; \

                        } \

                        dstPtr2 += VAR_6[VAR_7]/2; \

                        VAR_18 += VAR_2[VAR_7]/2; \

                    }

#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \

                    if (VAR_18 > VAR_14) { \

                        COPY9_OR_10TO9_OR_10(int VAR_18 = rfunc(&VAR_18[VAR_9]); \

                            wfunc(&dstPtr2[VAR_9], (VAR_18 << 1) | (VAR_18 >> 9))); \

                    } else if (VAR_18 < VAR_14) { \

                        DITHER_COPY(dstPtr2, VAR_6[VAR_7]/2, wfunc, \

                                    VAR_18, VAR_2[VAR_7]/2, rfunc, \

                                    dither_8x8_1, 1); \

                    } else { \

                        COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[VAR_9], rfunc(&VAR_18[VAR_9]))); \

                    }

                    if (isBE(VAR_0->dstFormat)) {

                        if (isBE(VAR_0->srcFormat)) {

                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WB16);

                        } else {

                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(VAR_0->srcFormat)) {

                            COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WL16);

                        } else {

                            COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WL16);

                        }

                    }

                } else {

#define W8(a, b) { *(a) = (b); }

#define COPY9_OR_10TO8(rfunc) \

                    if (VAR_14 == 9) { \

                        DITHER_COPY(dstPtr,  VAR_6[VAR_7],   W8, \

                                    VAR_18, VAR_2[VAR_7]/2, rfunc, \

                                    dither_8x8_1, 1); \

                    } else { \

                        DITHER_COPY(dstPtr,  VAR_6[VAR_7],   W8, \

                                    VAR_18, VAR_2[VAR_7]/2, rfunc, \

                                    dither_8x8_3, 2); \

                    }

                    if (isBE(VAR_0->srcFormat)) {

                        COPY9_OR_10TO8(AV_RB16);

                    } else {

                        COPY9_OR_10TO8(AV_RL16);

                    }

                }

            } else if(is9_OR_10BPS(VAR_0->dstFormat)) {

                const int VAR_18 = av_pix_fmt_descriptors[VAR_0->dstFormat].comp[VAR_7].depth_minus1+1;

                uint16_t *dstPtr2 = (uint16_t*)dstPtr;



                if (is16BPS(VAR_0->srcFormat)) {

                    const uint16_t *VAR_18 = (const uint16_t*)VAR_13;

#define COPY16TO9_OR_10(rfunc, wfunc) \

                    if (VAR_18 == 9) { \

                        DITHER_COPY(dstPtr2, VAR_6[VAR_7]/2, wfunc, \

                                    VAR_18, VAR_2[VAR_7]/2, rfunc, \

                                    dither_8x8_128, 7); \

                    } else { \

                        DITHER_COPY(dstPtr2, VAR_6[VAR_7]/2, wfunc, \

                                    VAR_18, VAR_2[VAR_7]/2, rfunc, \

                                    dither_8x8_64, 6); \

                    }

                    if (isBE(VAR_0->dstFormat)) {

                        if (isBE(VAR_0->srcFormat)) {

                            COPY16TO9_OR_10(AV_RB16, AV_WB16);

                        } else {

                            COPY16TO9_OR_10(AV_RL16, AV_WB16);

                        }

                    } else {

                        if (isBE(VAR_0->srcFormat)) {

                            COPY16TO9_OR_10(AV_RB16, AV_WL16);

                        } else {

                            COPY16TO9_OR_10(AV_RL16, AV_WL16);

                        }

                    }

                } else  {

#define COPY8TO9_OR_10(wfunc) \

                    for (VAR_8 = 0; VAR_8 < VAR_12; VAR_8++) { \

                        for (VAR_9 = 0; VAR_9 < VAR_10; VAR_9++) { \

                            const int VAR_18 = VAR_13[VAR_9]; \

                            wfunc(&dstPtr2[VAR_9], (VAR_18<<(VAR_18-8)) | (VAR_18 >> (16-VAR_18))); \

                        } \

                        dstPtr2 += VAR_6[VAR_7]/2; \

                        VAR_13  += VAR_2[VAR_7]; \

                    }

                    if (isBE(VAR_0->dstFormat)) {

                        COPY8TO9_OR_10(AV_WB16);

                    } else {

                        COPY8TO9_OR_10(AV_WL16);

                    }

                }

            } else if(is16BPS(VAR_0->srcFormat) && !is16BPS(VAR_0->dstFormat)) {

                const uint16_t *VAR_18 = (const uint16_t*)VAR_13;

#define COPY16TO8(rfunc) \

                    DITHER_COPY(dstPtr,  VAR_6[VAR_7],   W8, \

                                VAR_18, VAR_2[VAR_7]/2, rfunc, \

                                dither_8x8_256, 8);

                if (isBE(VAR_0->srcFormat)) {

                    COPY16TO8(AV_RB16);

                } else {

                    COPY16TO8(AV_RL16);

                }

            } else if(!is16BPS(VAR_0->srcFormat) && is16BPS(VAR_0->dstFormat)) {

                for (VAR_8=0; VAR_8<VAR_12; VAR_8++) {

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

                        dstPtr[ VAR_9<<1   ] = VAR_13[VAR_9];

                        dstPtr[(VAR_9<<1)+1] = VAR_13[VAR_9];

                    }

                    VAR_13+= VAR_2[VAR_7];

                    dstPtr+= VAR_6[VAR_7];

                }

            } else if(is16BPS(VAR_0->srcFormat) && is16BPS(VAR_0->dstFormat)

                  && isBE(VAR_0->srcFormat) != isBE(VAR_0->dstFormat)) {



                for (VAR_8=0; VAR_8<VAR_12; VAR_8++) {

                    for (VAR_9=0; VAR_9<VAR_10; VAR_9++)

                        ((uint16_t*)dstPtr)[VAR_9] = av_bswap16(((const uint16_t*)VAR_13)[VAR_9]);

                    VAR_13+= VAR_2[VAR_7];

                    dstPtr+= VAR_6[VAR_7];

                }

            } else if (VAR_6[VAR_7] == VAR_2[VAR_7] &&

                       VAR_2[VAR_7] > 0 && VAR_2[VAR_7] == VAR_10) {

                memcpy(VAR_5[VAR_7] + VAR_6[VAR_7]*VAR_11, VAR_1[VAR_7],

                       VAR_12*VAR_6[VAR_7]);

            } else {

                if(is16BPS(VAR_0->srcFormat) && is16BPS(VAR_0->dstFormat))

                    VAR_10*=2;

                for (VAR_8=0; VAR_8<VAR_12; VAR_8++) {

                    memcpy(dstPtr, VAR_13, VAR_10);

                    VAR_13+= VAR_2[VAR_7];

                    dstPtr+= VAR_6[VAR_7];

                }

            }

        }

    }

    return VAR_4;

}

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[])
{ int VAR_7, VAR_8, VAR_9; for (VAR_7=0; VAR_7<4; VAR_7++) { int VAR_10= (VAR_7==0 || VAR_7==3) ? VAR_0->srcW  : -((-VAR_0->srcW  )>>VAR_0->chrDstHSubSample); int VAR_11=      (VAR_7==0 || VAR_7==3) ? VAR_3: -((-VAR_3)>>VAR_0->chrDstVSubSample); int VAR_12= (VAR_7==0 || VAR_7==3) ? VAR_4: -((-VAR_4)>>VAR_0->chrDstVSubSample); const uint8_t *VAR_13= VAR_1[VAR_7]; uint8_t *dstPtr= VAR_5[VAR_7] + VAR_6[VAR_7]*VAR_11; if (!VAR_5[VAR_7]) continue; if (VAR_7 == 1 && !VAR_5[2]) continue; if (!VAR_1[VAR_7] || (VAR_7 == 1 && !VAR_1[2])) { if(is16BPS(VAR_0->dstFormat))
VAR_10*=2; fillPlane(VAR_5[VAR_7], VAR_6[VAR_7], VAR_10, VAR_12, VAR_11, (VAR_7==3) ? 255 : 128); } else { if(is9_OR_10BPS(VAR_0->srcFormat)) { const int VAR_14 = av_pix_fmt_descriptors[VAR_0->srcFormat].comp[VAR_7].depth_minus1+1; const int VAR_18 = av_pix_fmt_descriptors[VAR_0->dstFormat].comp[VAR_7].depth_minus1+1; const uint16_t *VAR_18 = (const uint16_t*)VAR_13; if (is16BPS(VAR_0->dstFormat)) { uint16_t *dstPtr2 = (uint16_t*)dstPtr; #define COPY9_OR_10TO16(rfunc, wfunc) \
for (VAR_8 = 0; VAR_8 < VAR_12; VAR_8++) { \ for (VAR_9 = 0; VAR_9 < VAR_10; VAR_9++) { \ int VAR_18 = rfunc(&VAR_18[VAR_9]); \ wfunc(&dstPtr2[VAR_9], (VAR_18<<(16-VAR_14)) | (VAR_18>>(2*VAR_14-16))); \ } \ dstPtr2 += VAR_6[VAR_7]/2; \ VAR_18 += VAR_2[VAR_7]/2; \ } if (isBE(VAR_0->dstFormat)) { if (isBE(VAR_0->srcFormat)) { COPY9_OR_10TO16(AV_RB16, AV_WB16); } else { COPY9_OR_10TO16(AV_RL16, AV_WB16); } } else { if (isBE(VAR_0->srcFormat)) { COPY9_OR_10TO16(AV_RB16, AV_WL16); } else { COPY9_OR_10TO16(AV_RL16, AV_WL16); } } } else if (is9_OR_10BPS(VAR_0->dstFormat)) { uint16_t *dstPtr2 = (uint16_t*)dstPtr; #define COPY9_OR_10TO9_OR_10(loop) \
for (VAR_8 = 0; VAR_8 < VAR_12; VAR_8++) { \ for (VAR_9 = 0; VAR_9 < VAR_10; VAR_9++) { \ loop; \ } \ dstPtr2 += VAR_6[VAR_7]/2; \ VAR_18 += VAR_2[VAR_7]/2; \ } #define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \
if (VAR_18 > VAR_14) { \ COPY9_OR_10TO9_OR_10(int VAR_18 = rfunc(&VAR_18[VAR_9]); \ wfunc(&dstPtr2[VAR_9], (VAR_18 << 1) | (VAR_18 >> 9))); \ } else if (VAR_18 < VAR_14) { \ DITHER_COPY(dstPtr2, VAR_6[VAR_7]/2, wfunc, \
VAR_18, VAR_2[VAR_7]/2, rfunc, \
dither_8x8_1, 1); \ } else { \ COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[VAR_9], rfunc(&VAR_18[VAR_9]))); \ } if (isBE(VAR_0->dstFormat)) { if (isBE(VAR_0->srcFormat)) { COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WB16); } else { COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WB16); } } else { if (isBE(VAR_0->srcFormat)) { COPY9_OR_10TO9_OR_10_2(AV_RB16, AV_WL16); } else { COPY9_OR_10TO9_OR_10_2(AV_RL16, AV_WL16); } } } else { #define W8(a, b) { *(a) = (b); } #define COPY9_OR_10TO8(rfunc) \
if (VAR_14 == 9) { \ DITHER_COPY(dstPtr,  VAR_6[VAR_7],   W8, \
VAR_18, VAR_2[VAR_7]/2, rfunc, \
dither_8x8_1, 1); \ } else { \ DITHER_COPY(dstPtr,  VAR_6[VAR_7],   W8, \
VAR_18, VAR_2[VAR_7]/2, rfunc, \
dither_8x8_3, 2); \ } if (isBE(VAR_0->srcFormat)) { COPY9_OR_10TO8(AV_RB16); } else { COPY9_OR_10TO8(AV_RL16); } } } else if(is9_OR_10BPS(VAR_0->dstFormat)) { const int VAR_18 = av_pix_fmt_descriptors[VAR_0->dstFormat].comp[VAR_7].depth_minus1+1; uint16_t *dstPtr2 = (uint16_t*)dstPtr; if (is16BPS(VAR_0->srcFormat)) { const uint16_t *VAR_18 = (const uint16_t*)VAR_13; #define COPY16TO9_OR_10(rfunc, wfunc) \
if (VAR_18 == 9) { \ DITHER_COPY(dstPtr2, VAR_6[VAR_7]/2, wfunc, \
VAR_18, VAR_2[VAR_7]/2, rfunc, \
dither_8x8_128, 7); \ } else { \ DITHER_COPY(dstPtr2, VAR_6[VAR_7]/2, wfunc, \
VAR_18, VAR_2[VAR_7]/2, rfunc, \
dither_8x8_64, 6); \ } if (isBE(VAR_0->dstFormat)) { if (isBE(VAR_0->srcFormat)) { COPY16TO9_OR_10(AV_RB16, AV_WB16); } else { COPY16TO9_OR_10(AV_RL16, AV_WB16); } } else { if (isBE(VAR_0->srcFormat)) { COPY16TO9_OR_10(AV_RB16, AV_WL16); } else { COPY16TO9_OR_10(AV_RL16, AV_WL16); } } } else  { #define COPY8TO9_OR_10(wfunc) \
for (VAR_8 = 0; VAR_8 < VAR_12; VAR_8++) { \ for (VAR_9 = 0; VAR_9 < VAR_10; VAR_9++) { \ const int VAR_18 = VAR_13[VAR_9]; \ wfunc(&dstPtr2[VAR_9], (VAR_18<<(VAR_18-8)) | (VAR_18 >> (16-VAR_18))); \ } \ dstPtr2 += VAR_6[VAR_7]/2; \ VAR_13  += VAR_2[VAR_7]; \ } if (isBE(VAR_0->dstFormat)) { COPY8TO9_OR_10(AV_WB16); } else { COPY8TO9_OR_10(AV_WL16); } } } else if(is16BPS(VAR_0->srcFormat) && !is16BPS(VAR_0->dstFormat)) { const uint16_t *VAR_18 = (const uint16_t*)VAR_13; #define COPY16TO8(rfunc) \
DITHER_COPY(dstPtr,  VAR_6[VAR_7],   W8, \
VAR_18, VAR_2[VAR_7]/2, rfunc, \
dither_8x8_256, 8); if (isBE(VAR_0->srcFormat)) { COPY16TO8(AV_RB16); } else { COPY16TO8(AV_RL16); } } else if(!is16BPS(VAR_0->srcFormat) && is16BPS(VAR_0->dstFormat)) { for (VAR_8=0; VAR_8<VAR_12; VAR_8++) { for (VAR_9=0; VAR_9<VAR_10; VAR_9++) { dstPtr[ VAR_9<<1   ] = VAR_13[VAR_9]; dstPtr[(VAR_9<<1)+1] = VAR_13[VAR_9]; } VAR_13+= VAR_2[VAR_7]; dstPtr+= VAR_6[VAR_7]; } } else if(is16BPS(VAR_0->srcFormat) && is16BPS(VAR_0->dstFormat) && isBE(VAR_0->srcFormat) != isBE(VAR_0->dstFormat)) { for (VAR_8=0; VAR_8<VAR_12; VAR_8++) { for (VAR_9=0; VAR_9<VAR_10; VAR_9++) ((uint16_t*)dstPtr)[VAR_9] = av_bswap16(((const uint16_t*)VAR_13)[VAR_9]); VAR_13+= VAR_2[VAR_7]; dstPtr+= VAR_6[VAR_7]; } } else if (VAR_6[VAR_7] == VAR_2[VAR_7] && VAR_2[VAR_7] > 0 && VAR_2[VAR_7] == VAR_10) { memcpy(VAR_5[VAR_7] + VAR_6[VAR_7]*VAR_11, VAR_1[VAR_7],
VAR_12*VAR_6[VAR_7]); } else { if(is16BPS(VAR_0->srcFormat) && is16BPS(VAR_0->dstFormat))
VAR_10*=2; for (VAR_8=0; VAR_8<VAR_12; VAR_8++) { memcpy(dstPtr, VAR_13, VAR_10); VAR_13+= VAR_2[VAR_7]; dstPtr+= VAR_6[VAR_7]; } } } } return VAR_4; }