static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,

                  enum PixelFormat srcFormat, enum PixelFormat dstFormat,

                  int srcW, int srcH, int dstW, int dstH, int flags)

{

    static enum PixelFormat cur_srcFormat;

    static int cur_srcW, cur_srcH;

    static uint8_t *src[4];

    static int srcStride[4];

    uint8_t *dst[4] = {0};

    uint8_t *out[4] = {0};

    int dstStride[4];

    int i;

    uint64_t ssdY, ssdU=0, ssdV=0, ssdA=0;

    struct SwsContext *dstContext = NULL, *outContext = NULL;

    uint32_t crc = 0;

    int res = 0;



    if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) {

        struct SwsContext *srcContext = NULL;

        int p;



        for (p = 0; p < 4; p++)

            if (src[p])

                av_freep(&src[p]);



        av_image_fill_linesizes(srcStride, srcFormat, srcW);

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

            if (srcStride[p])

                src[p] = av_mallocz(srcStride[p]*srcH+16);

            if (srcStride[p] && !src[p]) {

                perror("Malloc");

                res = -1;



                goto end;

            }

        }

        srcContext = sws_getContext(w, h, PIX_FMT_YUVA420P, srcW, srcH,

                                    srcFormat, SWS_BILINEAR, NULL, NULL, NULL);

        if (!srcContext) {

            fprintf(stderr, "Failed to get %s ---> %s\n",

                    av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name,

                    av_pix_fmt_descriptors[srcFormat].name);

            res = -1;



            goto end;

        }

        sws_scale(srcContext, ref, refStride, 0, h, src, srcStride);

        sws_freeContext(srcContext);



        cur_srcFormat = srcFormat;

        cur_srcW = srcW;

        cur_srcH = srcH;

    }



    av_image_fill_linesizes(dstStride, dstFormat, dstW);

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

        /* Image buffers passed into libswscale can be allocated any way you

         * prefer, as long as they're aligned enough for the architecture, and

         * they're freed appropriately (such as using av_free for buffers

         * allocated with av_malloc). */

        /* An extra 16 bytes is being allocated because some scalers may write

         * out of bounds. */

        if (dstStride[i])

            dst[i]= av_mallocz(dstStride[i]*dstH+16);

        if (refStride[i])

            out[i]= av_mallocz(refStride[i]*h);

        if ((dstStride[i] && !dst[i]) || (refStride[i] && !out[i])) {

            perror("Malloc");

            res = -1;



            goto end;

        }

    }



    dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL);

    if (!dstContext) {

        fprintf(stderr, "Failed to get %s ---> %s\n",

                av_pix_fmt_descriptors[srcFormat].name,

                av_pix_fmt_descriptors[dstFormat].name);

        res = -1;



        goto end;

    }

    outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUVA420P, flags, NULL, NULL, NULL);

    if (!outContext) {

        fprintf(stderr, "Failed to get %s ---> %s\n",

                av_pix_fmt_descriptors[dstFormat].name,

                av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name);

        res = -1;



        goto end;

    }

//    printf("test %X %X %X -> %X %X %X\n", (int)ref[0], (int)ref[1], (int)ref[2],

//        (int)src[0], (int)src[1], (int)src[2]);



    printf(" %s %dx%d -> %s %3dx%3d flags=%2d",

           av_pix_fmt_descriptors[srcFormat].name, srcW, srcH,

           av_pix_fmt_descriptors[dstFormat].name, dstW, dstH,

           flags);

    fflush(stdout);



    sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride);

    sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride);



    for (i = 0; i < 4 && dstStride[i]; i++) {

        crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], dstStride[i] * dstH);

    }



    ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h);

    if (hasChroma(srcFormat) && hasChroma(dstFormat)) {

        //FIXME check that output is really gray

        ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1);

        ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1);

    }

    if (isALPHA(srcFormat) && isALPHA(dstFormat))

        ssdA= getSSD(ref[3], out[3], refStride[3], refStride[3], w, h);



    ssdY/= w*h;

    ssdU/= w*h/4;

    ssdV/= w*h/4;

    ssdA/= w*h;



    printf(" CRC=%08x SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"\n",

           crc, ssdY, ssdU, ssdV, ssdA);



end:



    sws_freeContext(dstContext);

    sws_freeContext(outContext);



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

        if (dstStride[i])

            av_free(dst[i]);

        if (refStride[i])

            av_free(out[i]);

    }



    return res;

}

static int doTest(uint8_t *ref[4], int refStride[4], int w, int h,

                  enum PixelFormat srcFormat, enum PixelFormat dstFormat,

                  int srcW, int srcH, int dstW, int dstH, int flags)

{

    static enum PixelFormat cur_srcFormat;

    static int cur_srcW, cur_srcH;

    static uint8_t *src[4];

    static int srcStride[4];

    uint8_t *dst[4] = {0};

    uint8_t *out[4] = {0};

    int dstStride[4];

    int i;

    uint64_t ssdY, ssdU=0, ssdV=0, ssdA=0;

    struct SwsContext *dstContext = NULL, *outContext = NULL;

    uint32_t crc = 0;

    int res = 0;



    if (cur_srcFormat != srcFormat || cur_srcW != srcW || cur_srcH != srcH) {

        struct SwsContext *srcContext = NULL;

        int p;



        for (p = 0; p < 4; p++)

            if (src[p])

                av_freep(&src[p]);



        av_image_fill_linesizes(srcStride, srcFormat, srcW);

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

            if (srcStride[p])

                src[p] = av_mallocz(srcStride[p]*srcH+16);

            if (srcStride[p] && !src[p]) {

                perror("Malloc");

                res = -1;



                goto end;

            }

        }

        srcContext = sws_getContext(w, h, PIX_FMT_YUVA420P, srcW, srcH,

                                    srcFormat, SWS_BILINEAR, NULL, NULL, NULL);

        if (!srcContext) {

            fprintf(stderr, "Failed to get %s ---> %s\n",

                    av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name,

                    av_pix_fmt_descriptors[srcFormat].name);

            res = -1;



            goto end;

        }

        sws_scale(srcContext, ref, refStride, 0, h, src, srcStride);

        sws_freeContext(srcContext);



        cur_srcFormat = srcFormat;

        cur_srcW = srcW;

        cur_srcH = srcH;

    }



    av_image_fill_linesizes(dstStride, dstFormat, dstW);

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

        







        



        if (dstStride[i])

            dst[i]= av_mallocz(dstStride[i]*dstH+16);

        if (refStride[i])

            out[i]= av_mallocz(refStride[i]*h);

        if ((dstStride[i] && !dst[i]) || (refStride[i] && !out[i])) {

            perror("Malloc");

            res = -1;



            goto end;

        }

    }



    dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL);

    if (!dstContext) {

        fprintf(stderr, "Failed to get %s ---> %s\n",

                av_pix_fmt_descriptors[srcFormat].name,

                av_pix_fmt_descriptors[dstFormat].name);

        res = -1;



        goto end;

    }

    outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUVA420P, flags, NULL, NULL, NULL);

    if (!outContext) {

        fprintf(stderr, "Failed to get %s ---> %s\n",

                av_pix_fmt_descriptors[dstFormat].name,

                av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name);

        res = -1;



        goto end;

    }







    printf(" %s %dx%d -> %s %3dx%3d flags=%2d",

           av_pix_fmt_descriptors[srcFormat].name, srcW, srcH,

           av_pix_fmt_descriptors[dstFormat].name, dstW, dstH,

           flags);

    fflush(stdout);



    sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride);

    sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride);



    for (i = 0; i < 4 && dstStride[i]; i++) {

        crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], dstStride[i] * dstH);

    }



    ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h);

    if (hasChroma(srcFormat) && hasChroma(dstFormat)) {

        

        ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1);

        ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1);

    }

    if (isALPHA(srcFormat) && isALPHA(dstFormat))

        ssdA= getSSD(ref[3], out[3], refStride[3], refStride[3], w, h);



    ssdY/= w*h;

    ssdU/= w*h/4;

    ssdV/= w*h/4;

    ssdA/= w*h;



    printf(" CRC=%08x SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"\n",

           crc, ssdY, ssdU, ssdV, ssdA);



end:



    sws_freeContext(dstContext);

    sws_freeContext(outContext);



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

        if (dstStride[i])

            av_free(dst[i]);

        if (refStride[i])

            av_free(out[i]);

    }



    return res;

}

static int FUNC_0(uint8_t *VAR_0[4], int VAR_1[4], int VAR_2, int VAR_3,

                  enum PixelFormat VAR_4, enum PixelFormat VAR_5,

                  int VAR_6, int VAR_7, int VAR_8, int VAR_9, int VAR_10)

{

    static enum PixelFormat VAR_11;

    static int VAR_12, VAR_13;

    static uint8_t *VAR_14[4];

    static int VAR_15[4];

    uint8_t *dst[4] = {0};

    uint8_t *out[4] = {0};

    int VAR_16[4];

    int VAR_17;

    uint64_t ssdY, ssdU=0, ssdV=0, ssdA=0;

    struct SwsContext *VAR_18 = NULL, *VAR_19 = NULL;

    uint32_t crc = 0;

    int VAR_20 = 0;



    if (VAR_11 != VAR_4 || VAR_12 != VAR_6 || VAR_13 != VAR_7) {

        struct SwsContext *VAR_21 = NULL;

        int VAR_22;



        for (VAR_22 = 0; VAR_22 < 4; VAR_22++)

            if (VAR_14[VAR_22])

                av_freep(&VAR_14[VAR_22]);



        av_image_fill_linesizes(VAR_15, VAR_4, VAR_6);

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

            if (VAR_15[VAR_22])

                VAR_14[VAR_22] = av_mallocz(VAR_15[VAR_22]*VAR_7+16);

            if (VAR_15[VAR_22] && !VAR_14[VAR_22]) {

                perror("Malloc");

                VAR_20 = -1;



                goto end;

            }

        }

        VAR_21 = sws_getContext(VAR_2, VAR_3, PIX_FMT_YUVA420P, VAR_6, VAR_7,

                                    VAR_4, SWS_BILINEAR, NULL, NULL, NULL);

        if (!VAR_21) {

            fprintf(stderr, "Failed to get %s ---> %s\n",

                    av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name,

                    av_pix_fmt_descriptors[VAR_4].name);

            VAR_20 = -1;



            goto end;

        }

        sws_scale(VAR_21, VAR_0, VAR_1, 0, VAR_3, VAR_14, VAR_15);

        sws_freeContext(VAR_21);



        VAR_11 = VAR_4;

        VAR_12 = VAR_6;

        VAR_13 = VAR_7;

    }



    av_image_fill_linesizes(VAR_16, VAR_5, VAR_8);

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

        







        



        if (VAR_16[VAR_17])

            dst[VAR_17]= av_mallocz(VAR_16[VAR_17]*VAR_9+16);

        if (VAR_1[VAR_17])

            out[VAR_17]= av_mallocz(VAR_1[VAR_17]*VAR_3);

        if ((VAR_16[VAR_17] && !dst[VAR_17]) || (VAR_1[VAR_17] && !out[VAR_17])) {

            perror("Malloc");

            VAR_20 = -1;



            goto end;

        }

    }



    VAR_18= sws_getContext(VAR_6, VAR_7, VAR_4, VAR_8, VAR_9, VAR_5, VAR_10, NULL, NULL, NULL);

    if (!VAR_18) {

        fprintf(stderr, "Failed to get %s ---> %s\n",

                av_pix_fmt_descriptors[VAR_4].name,

                av_pix_fmt_descriptors[VAR_5].name);

        VAR_20 = -1;



        goto end;

    }

    VAR_19= sws_getContext(VAR_8, VAR_9, VAR_5, VAR_2, VAR_3, PIX_FMT_YUVA420P, VAR_10, NULL, NULL, NULL);

    if (!VAR_19) {

        fprintf(stderr, "Failed to get %s ---> %s\n",

                av_pix_fmt_descriptors[VAR_5].name,

                av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name);

        VAR_20 = -1;



        goto end;

    }







    printf(" %s %dx%d -> %s %3dx%3d VAR_10=%2d",

           av_pix_fmt_descriptors[VAR_4].name, VAR_6, VAR_7,

           av_pix_fmt_descriptors[VAR_5].name, VAR_8, VAR_9,

           VAR_10);

    fflush(stdout);



    sws_scale(VAR_18, VAR_14, VAR_15, 0, VAR_7, dst, VAR_16);

    sws_scale(VAR_19, dst, VAR_16, 0, VAR_9, out, VAR_1);



    for (VAR_17 = 0; VAR_17 < 4 && VAR_16[VAR_17]; VAR_17++) {

        crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[VAR_17], VAR_16[VAR_17] * VAR_9);

    }



    ssdY= getSSD(VAR_0[0], out[0], VAR_1[0], VAR_1[0], VAR_2, VAR_3);

    if (hasChroma(VAR_4) && hasChroma(VAR_5)) {

        

        ssdU= getSSD(VAR_0[1], out[1], VAR_1[1], VAR_1[1], (VAR_2+1)>>1, (VAR_3+1)>>1);

        ssdV= getSSD(VAR_0[2], out[2], VAR_1[2], VAR_1[2], (VAR_2+1)>>1, (VAR_3+1)>>1);

    }

    if (isALPHA(VAR_4) && isALPHA(VAR_5))

        ssdA= getSSD(VAR_0[3], out[3], VAR_1[3], VAR_1[3], VAR_2, VAR_3);



    ssdY/= VAR_2*VAR_3;

    ssdU/= VAR_2*VAR_3/4;

    ssdV/= VAR_2*VAR_3/4;

    ssdA/= VAR_2*VAR_3;



    printf(" CRC=%08x SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"\n",

           crc, ssdY, ssdU, ssdV, ssdA);



end:



    sws_freeContext(VAR_18);

    sws_freeContext(VAR_19);



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

        if (VAR_16[VAR_17])

            av_free(dst[VAR_17]);

        if (VAR_1[VAR_17])

            av_free(out[VAR_17]);

    }



    return VAR_20;

}

static int FUNC_0(uint8_t *VAR_0[4], int VAR_1[4], int VAR_2, int VAR_3,
enum PixelFormat VAR_4, enum PixelFormat VAR_5,
int VAR_6, int VAR_7, int VAR_8, int VAR_9, int VAR_10)
{ static enum PixelFormat VAR_11; static int VAR_12, VAR_13; static uint8_t *VAR_14[4]; static int VAR_15[4]; uint8_t *dst[4] = {0}; uint8_t *out[4] = {0}; int VAR_16[4]; int VAR_17; uint64_t ssdY, ssdU=0, ssdV=0, ssdA=0; struct SwsContext *VAR_18 = NULL, *VAR_19 = NULL; uint32_t crc = 0; int VAR_20 = 0; if (VAR_11 != VAR_4 || VAR_12 != VAR_6 || VAR_13 != VAR_7) { struct SwsContext *VAR_21 = NULL; int VAR_22; for (VAR_22 = 0; VAR_22 < 4; VAR_22++) if (VAR_14[VAR_22])
av_freep(&VAR_14[VAR_22]); av_image_fill_linesizes(VAR_15, VAR_4, VAR_6); for (VAR_22 = 0; VAR_22 < 4; VAR_22++) { if (VAR_15[VAR_22])
VAR_14[VAR_22] = av_mallocz(VAR_15[VAR_22]*VAR_7+16); if (VAR_15[VAR_22] && !VAR_14[VAR_22]) { perror("Malloc"); VAR_20 = -1; goto end; } } VAR_21 = sws_getContext(VAR_2, VAR_3, PIX_FMT_YUVA420P, VAR_6, VAR_7,
VAR_4, SWS_BILINEAR, NULL, NULL, NULL); if (!VAR_21) { fprintf(stderr, "Failed to get %s ---> %s\n",
av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name,
av_pix_fmt_descriptors[VAR_4].name); VAR_20 = -1; goto end; } sws_scale(VAR_21, VAR_0, VAR_1, 0, VAR_3, VAR_14, VAR_15); sws_freeContext(VAR_21); VAR_11 = VAR_4; VAR_12 = VAR_6; VAR_13 = VAR_7; } av_image_fill_linesizes(VAR_16, VAR_5, VAR_8); for (VAR_17=0; VAR_17<4; VAR_17++) { if (VAR_16[VAR_17])
dst[VAR_17]= av_mallocz(VAR_16[VAR_17]*VAR_9+16); if (VAR_1[VAR_17])
out[VAR_17]= av_mallocz(VAR_1[VAR_17]*VAR_3); if ((VAR_16[VAR_17] && !dst[VAR_17]) || (VAR_1[VAR_17] && !out[VAR_17])) { perror("Malloc"); VAR_20 = -1; goto end; } } VAR_18= sws_getContext(VAR_6, VAR_7, VAR_4, VAR_8, VAR_9, VAR_5, VAR_10, NULL, NULL, NULL); if (!VAR_18) { fprintf(stderr, "Failed to get %s ---> %s\n",
av_pix_fmt_descriptors[VAR_4].name,
av_pix_fmt_descriptors[VAR_5].name); VAR_20 = -1; goto end; } VAR_19= sws_getContext(VAR_8, VAR_9, VAR_5, VAR_2, VAR_3, PIX_FMT_YUVA420P, VAR_10, NULL, NULL, NULL); if (!VAR_19) { fprintf(stderr, "Failed to get %s ---> %s\n",
av_pix_fmt_descriptors[VAR_5].name,
av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name); VAR_20 = -1; goto end; } printf(" %s %dx%d -> %s %3dx%3d VAR_10=%2d",
av_pix_fmt_descriptors[VAR_4].name, VAR_6, VAR_7,
av_pix_fmt_descriptors[VAR_5].name, VAR_8, VAR_9,
VAR_10); fflush(stdout); sws_scale(VAR_18, VAR_14, VAR_15, 0, VAR_7, dst, VAR_16); sws_scale(VAR_19, dst, VAR_16, 0, VAR_9, out, VAR_1); for (VAR_17 = 0; VAR_17 < 4 && VAR_16[VAR_17]; VAR_17++) { crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[VAR_17], VAR_16[VAR_17] * VAR_9); } ssdY= getSSD(VAR_0[0], out[0], VAR_1[0], VAR_1[0], VAR_2, VAR_3); if (hasChroma(VAR_4) && hasChroma(VAR_5)) { ssdU= getSSD(VAR_0[1], out[1], VAR_1[1], VAR_1[1], (VAR_2+1)>>1, (VAR_3+1)>>1); ssdV= getSSD(VAR_0[2], out[2], VAR_1[2], VAR_1[2], (VAR_2+1)>>1, (VAR_3+1)>>1); } if (isALPHA(VAR_4) && isALPHA(VAR_5))
ssdA= getSSD(VAR_0[3], out[3], VAR_1[3], VAR_1[3], VAR_2, VAR_3); ssdY/= VAR_2*VAR_3; ssdU/= VAR_2*VAR_3/4; ssdV/= VAR_2*VAR_3/4; ssdA/= VAR_2*VAR_3; printf(" CRC=%08x SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"\n",
crc, ssdY, ssdU, ssdV, ssdA); end:
sws_freeContext(VAR_18); sws_freeContext(VAR_19); for (VAR_17=0; VAR_17<4; VAR_17++) { if (VAR_16[VAR_17])
av_free(dst[VAR_17]); if (VAR_1[VAR_17])
av_free(out[VAR_17]); } return VAR_20; }