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

                             int srcStride[], int srcSliceY, int srcSliceH,

                             uint8_t *dst[], int dstStride[])

{

    const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);

    const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);

    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])) {

            int val = (plane == 3) ? 255 : 128;

            if (is16BPS(c->dstFormat))

                length *= 2;

            if (is9_OR_10BPS(c->dstFormat)) {

                fill_plane9or10(dst[plane], dstStride[plane],

                                length, height, y, val,

                                desc_dst->comp[plane].depth_minus1 + 1,

                                isBE(c->dstFormat));

            } else

                fillPlane(dst[plane], dstStride[plane], length, height, y,

                          val);

        } else {

            if (is9_OR_10BPS(c->srcFormat)) {

                const int src_depth = desc_src->comp[plane].depth_minus1 + 1;

                const int dst_depth = desc_dst->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, clip9); \

                    } 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, av_clip_uint8); \

                    } else { \

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

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

                                    dither_8x8_3, 2, av_clip_uint8); \

                    }

                    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 = desc_dst->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, \

                                    ff_dither_8x8_128, 7, clip9); \

                    } else { \

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

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

                                    dither_8x8_64, 6, clip10); \

                    }

                    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, av_clip_uint8);

                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;

                else if (!desc_src->comp[0].depth_minus1)

                    length >>= 3; // monowhite/black

                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[])

{

    const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);

    const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);

    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])) {

            int val = (plane == 3) ? 255 : 128;

            if (is16BPS(c->dstFormat))

                length *= 2;

            if (is9_OR_10BPS(c->dstFormat)) {

                fill_plane9or10(dst[plane], dstStride[plane],

                                length, height, y, val,

                                desc_dst->comp[plane].depth_minus1 + 1,

                                isBE(c->dstFormat));

            } else

                fillPlane(dst[plane], dstStride[plane], length, height, y,

                          val);

        } else {

            if (is9_OR_10BPS(c->srcFormat)) {

                const int src_depth = desc_src->comp[plane].depth_minus1 + 1;

                const int dst_depth = desc_dst->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, clip9); \

                    } 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, av_clip_uint8); \

                    } else { \

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

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

                                    dither_8x8_3, 2, av_clip_uint8); \

                    }

                    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 = desc_dst->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, \

                                    ff_dither_8x8_128, 7, clip9); \

                    } else { \

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

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

                                    dither_8x8_64, 6, clip10); \

                    }

                    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, av_clip_uint8);

                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;

                else if (!desc_src->comp[0].depth_minus1)

                    length >>= 3; 

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

                    memcpy(dstPtr, srcPtr, length);

                    srcPtr += srcStride[plane];

                    dstPtr += dstStride[plane];

                }

            }

        }

    }

    return srcSliceH;

}

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 AVPixFmtDescriptor *VAR_7 = av_pix_fmt_desc_get(VAR_0->srcFormat);

    const AVPixFmtDescriptor *VAR_8 = av_pix_fmt_desc_get(VAR_0->dstFormat);

    int VAR_9, VAR_10, VAR_11;

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

        int VAR_12 = (VAR_9 == 0 || VAR_9 == 3) ? VAR_0->srcW  : -((-VAR_0->srcW  ) >> VAR_0->chrDstHSubSample);

        int VAR_13 =      (VAR_9 == 0 || VAR_9 == 3) ? VAR_3: -((-VAR_3) >> VAR_0->chrDstVSubSample);

        int VAR_14 = (VAR_9 == 0 || VAR_9 == 3) ? VAR_4: -((-VAR_4) >> VAR_0->chrDstVSubSample);

        const uint8_t *VAR_15 = VAR_1[VAR_9];

        uint8_t *dstPtr = VAR_5[VAR_9] + VAR_6[VAR_9] * VAR_13;



        if (!VAR_5[VAR_9])

            continue;

        

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

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

            int VAR_16 = (VAR_9 == 3) ? 255 : 128;

            if (is16BPS(VAR_0->dstFormat))

                VAR_12 *= 2;

            if (is9_OR_10BPS(VAR_0->dstFormat)) {

                fill_plane9or10(VAR_5[VAR_9], VAR_6[VAR_9],

                                VAR_12, VAR_14, VAR_13, VAR_16,

                                VAR_8->comp[VAR_9].depth_minus1 + 1,

                                isBE(VAR_0->dstFormat));

            } else

                fillPlane(VAR_5[VAR_9], VAR_6[VAR_9], VAR_12, VAR_14, VAR_13,

                          VAR_16);

        } else {

            if (is9_OR_10BPS(VAR_0->srcFormat)) {

                const int VAR_17 = VAR_7->comp[VAR_9].depth_minus1 + 1;

                const int VAR_21 = VAR_8->comp[VAR_9].depth_minus1 + 1;

                const uint16_t *VAR_21 = (const uint16_t *) VAR_15;



                if (is16BPS(VAR_0->dstFormat)) {

                    uint16_t *dstPtr2 = (uint16_t *) dstPtr;

#define COPY9_OR_10TO16(rfunc, wfunc) \

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

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

                            int VAR_21 = rfunc(&VAR_21[VAR_11]); \

                            wfunc(&dstPtr2[VAR_11], (VAR_21 << (16 - VAR_17)) | (VAR_21 >> (2 * VAR_17 - 16))); \

                        } \

                        dstPtr2 += VAR_6[VAR_9] / 2; \

                        VAR_21 += VAR_2[VAR_9] / 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_10 = 0; VAR_10 < VAR_14; VAR_10++) { \

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

                            loop; \

                        } \

                        dstPtr2 += VAR_6[VAR_9] / 2; \

                        VAR_21 += VAR_2[VAR_9] / 2; \

                    }

#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \

                    if (VAR_21 > VAR_17) { \

                        COPY9_OR_10TO9_OR_10(int VAR_21 = rfunc(&VAR_21[VAR_11]); \

                            wfunc(&dstPtr2[VAR_11], (VAR_21 << 1) | (VAR_21 >> 9))); \

                    } else if (VAR_21 < VAR_17) { \

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

                                    VAR_21, VAR_2[VAR_9] / 2, rfunc, \

                                    dither_8x8_1, 1, clip9); \

                    } else { \

                        COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[VAR_11], rfunc(&VAR_21[VAR_11]))); \

                    }

                    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_17 == 9) { \

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

                                    VAR_21, VAR_2[VAR_9] / 2, rfunc, \

                                    dither_8x8_1, 1, av_clip_uint8); \

                    } else { \

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

                                    VAR_21, VAR_2[VAR_9] / 2, rfunc, \

                                    dither_8x8_3, 2, av_clip_uint8); \

                    }

                    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_21 = VAR_8->comp[VAR_9].depth_minus1 + 1;

                uint16_t *dstPtr2 = (uint16_t *) dstPtr;



                if (is16BPS(VAR_0->srcFormat)) {

                    const uint16_t *VAR_21 = (const uint16_t *) VAR_15;

#define COPY16TO9_OR_10(rfunc, wfunc) \

                    if (VAR_21 == 9) { \

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

                                    VAR_21, VAR_2[VAR_9] / 2, rfunc, \

                                    ff_dither_8x8_128, 7, clip9); \

                    } else { \

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

                                    VAR_21, VAR_2[VAR_9] / 2, rfunc, \

                                    dither_8x8_64, 6, clip10); \

                    }

                    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_10 = 0; VAR_10 < VAR_14; VAR_10++) { \

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

                            const int VAR_21 = VAR_15[VAR_11]; \

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

                        } \

                        dstPtr2 += VAR_6[VAR_9] / 2; \

                        VAR_15  += VAR_2[VAR_9]; \

                    }

                    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_21 = (const uint16_t *) VAR_15;

#define COPY16TO8(rfunc) \

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

                                VAR_21, VAR_2[VAR_9] / 2, rfunc, \

                                dither_8x8_256, 8, av_clip_uint8);

                if (isBE(VAR_0->srcFormat)) {

                    COPY16TO8(AV_RB16);

                } else {

                    COPY16TO8(AV_RL16);

                }

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

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

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

                        dstPtr[ VAR_11 << 1     ] = VAR_15[VAR_11];

                        dstPtr[(VAR_11 << 1) + 1] = VAR_15[VAR_11];

                    }

                    VAR_15 += VAR_2[VAR_9];

                    dstPtr += VAR_6[VAR_9];

                }

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

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



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

                    for (VAR_11 = 0; VAR_11 < VAR_12; VAR_11++)

                        ((uint16_t *) dstPtr)[VAR_11] = av_bswap16(((const uint16_t *) VAR_15)[VAR_11]);

                    VAR_15 += VAR_2[VAR_9];

                    dstPtr += VAR_6[VAR_9];

                }

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

                       VAR_2[VAR_9] > 0 && VAR_2[VAR_9] == VAR_12) {

                memcpy(VAR_5[VAR_9] + VAR_6[VAR_9] * VAR_13, VAR_1[VAR_9],

                       VAR_14 * VAR_6[VAR_9]);

            } else {

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

                    VAR_12 *= 2;

                else if (!VAR_7->comp[0].depth_minus1)

                    VAR_12 >>= 3; 

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

                    memcpy(dstPtr, VAR_15, VAR_12);

                    VAR_15 += VAR_2[VAR_9];

                    dstPtr += VAR_6[VAR_9];

                }

            }

        }

    }

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