static void calc_diffs(const DecimateContext *dm, struct qitem *q,

                       const AVFrame *f1, const AVFrame *f2)

{

    int64_t maxdiff = -1;

    int64_t *bdiffs = dm->bdiffs;

    int plane, i, j;



    memset(bdiffs, 0, dm->bdiffsize * sizeof(*bdiffs));



    for (plane = 0; plane < (dm->chroma ? 3 : 1); plane++) {

        int x, y, xl;

        const int linesize1 = f1->linesize[plane];

        const int linesize2 = f2->linesize[plane];

        const uint8_t *f1p = f1->data[plane];

        const uint8_t *f2p = f2->data[plane];

        int width    = plane ? FF_CEIL_RSHIFT(f1->width,  dm->hsub) : f1->width;

        int height   = plane ? FF_CEIL_RSHIFT(f1->height, dm->vsub) : f1->height;

        int hblockx  = dm->blockx / 2;

        int hblocky  = dm->blocky / 2;



        if (plane) {

            hblockx >>= dm->hsub;

            hblocky >>= dm->vsub;

        }



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

            int ydest = y / hblocky;

            int xdest = 0;



#define CALC_DIFF(nbits) do {                               \

    for (x = 0; x < width; x += hblockx) {                  \

        int64_t acc = 0;                                    \

        int m = FFMIN(width, x + hblockx);                  \

        for (xl = x; xl < m; xl++)                          \

            acc += abs(((const uint##nbits##_t *)f1p)[xl] - \

                       ((const uint##nbits##_t *)f2p)[xl]); \

        bdiffs[ydest * dm->nxblocks + xdest] += acc;        \

        xdest++;                                            \

    }                                                       \

} while (0)

            if (dm->depth == 8) CALC_DIFF(8);

            else                CALC_DIFF(16);



            f1p += linesize1;

            f2p += linesize2;

        }

    }



    for (i = 0; i < dm->nyblocks - 1; i++) {

        for (j = 0; j < dm->nxblocks - 1; j++) {

            int64_t tmp = bdiffs[      i * dm->nxblocks + j    ]

                        + bdiffs[      i * dm->nxblocks + j + 1]

                        + bdiffs[(i + 1) * dm->nxblocks + j    ]

                        + bdiffs[(i + 1) * dm->nxblocks + j + 1];

            if (tmp > maxdiff)

                maxdiff = tmp;

        }

    }



    q->totdiff = 0;

    for (i = 0; i < dm->bdiffsize; i++)

        q->totdiff += bdiffs[i];

    q->maxbdiff = maxdiff;

}

static void calc_diffs(const DecimateContext *dm, struct qitem *q,

                       const AVFrame *f1, const AVFrame *f2)

{

    int64_t maxdiff = -1;

    int64_t *bdiffs = dm->bdiffs;

    int plane, i, j;



    memset(bdiffs, 0, dm->bdiffsize * sizeof(*bdiffs));



    for (plane = 0; plane < (dm->chroma ? 3 : 1); plane++) {

        int x, y, xl;

        const int linesize1 = f1->linesize[plane];

        const int linesize2 = f2->linesize[plane];

        const uint8_t *f1p = f1->data[plane];

        const uint8_t *f2p = f2->data[plane];

        int width    = plane ? FF_CEIL_RSHIFT(f1->width,  dm->hsub) : f1->width;

        int height   = plane ? FF_CEIL_RSHIFT(f1->height, dm->vsub) : f1->height;

        int hblockx  = dm->blockx / 2;

        int hblocky  = dm->blocky / 2;



        if (plane) {

            hblockx >>= dm->hsub;

            hblocky >>= dm->vsub;

        }



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

            int ydest = y / hblocky;

            int xdest = 0;



#define CALC_DIFF(nbits) do {                               \

    for (x = 0; x < width; x += hblockx) {                  \

        int64_t acc = 0;                                    \

        int m = FFMIN(width, x + hblockx);                  \

        for (xl = x; xl < m; xl++)                          \

            acc += abs(((const uint##nbits##_t *)f1p)[xl] - \

                       ((const uint##nbits##_t *)f2p)[xl]); \

        bdiffs[ydest * dm->nxblocks + xdest] += acc;        \

        xdest++;                                            \

    }                                                       \

} while (0)

            if (dm->depth == 8) CALC_DIFF(8);

            else                CALC_DIFF(16);



            f1p += linesize1;

            f2p += linesize2;

        }

    }



    for (i = 0; i < dm->nyblocks - 1; i++) {

        for (j = 0; j < dm->nxblocks - 1; j++) {

            int64_t tmp = bdiffs[      i * dm->nxblocks + j    ]

                        + bdiffs[      i * dm->nxblocks + j + 1]

                        + bdiffs[(i + 1) * dm->nxblocks + j    ]

                        + bdiffs[(i + 1) * dm->nxblocks + j + 1];

            if (tmp > maxdiff)

                maxdiff = tmp;

        }

    }



    q->totdiff = 0;

    for (i = 0; i < dm->bdiffsize; i++)

        q->totdiff += bdiffs[i];

    q->maxbdiff = maxdiff;

}

    for (plane = 0; plane < (dm->chroma ? 3 : 1); plane++) {
static void FUNC_0(const DecimateContext *VAR_0, struct qitem *VAR_1,

                       const AVFrame *VAR_2, const AVFrame *VAR_3)

{

    int64_t maxdiff = -1;

    int64_t *bdiffs = VAR_0->bdiffs;

    int VAR_4, VAR_5, VAR_6;



    memset(bdiffs, 0, VAR_0->bdiffsize * sizeof(*bdiffs));



    for (VAR_4 = 0; VAR_4 < (VAR_0->chroma ? 3 : 1); VAR_4++) {

        int x, y, xl;

        const int linesize1 = VAR_2->linesize[VAR_4];

        const int linesize2 = VAR_3->linesize[VAR_4];

        const uint8_t *f1p = VAR_2->data[VAR_4];

        const uint8_t *f2p = VAR_3->data[VAR_4];

        int width    = VAR_4 ? FF_CEIL_RSHIFT(VAR_2->width,  VAR_0->hsub) : VAR_2->width;

        int height   = VAR_4 ? FF_CEIL_RSHIFT(VAR_2->height, VAR_0->vsub) : VAR_2->height;

        int hblockx  = VAR_0->blockx / 2;

        int hblocky  = VAR_0->blocky / 2;



        if (VAR_4) {

            hblockx >>= VAR_0->hsub;

            hblocky >>= VAR_0->vsub;

        }



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

            int ydest = y / hblocky;

            int xdest = 0;



#define CALC_DIFF(nbits) do {                               \

    for (x = 0; x < width; x += hblockx) {                  \

        int64_t acc = 0;                                    \

        int m = FFMIN(width, x + hblockx);                  \

        for (xl = x; xl < m; xl++)                          \

            acc += abs(((const uint##nbits##_t *)f1p)[xl] - \

                       ((const uint##nbits##_t *)f2p)[xl]); \

        bdiffs[ydest * VAR_0->nxblocks + xdest] += acc;        \

        xdest++;                                            \

    }                                                       \

} while (0)

            if (VAR_0->depth == 8) CALC_DIFF(8);

            else                CALC_DIFF(16);



            f1p += linesize1;

            f2p += linesize2;

        }

    }



    for (VAR_5 = 0; VAR_5 < VAR_0->nyblocks - 1; VAR_5++) {

        for (VAR_6 = 0; VAR_6 < VAR_0->nxblocks - 1; VAR_6++) {

            int64_t tmp = bdiffs[      VAR_5 * VAR_0->nxblocks + VAR_6    ]

                        + bdiffs[      VAR_5 * VAR_0->nxblocks + VAR_6 + 1]

                        + bdiffs[(VAR_5 + 1) * VAR_0->nxblocks + VAR_6    ]

                        + bdiffs[(VAR_5 + 1) * VAR_0->nxblocks + VAR_6 + 1];

            if (tmp > maxdiff)

                maxdiff = tmp;

        }

    }



    VAR_1->totdiff = 0;

    for (VAR_5 = 0; VAR_5 < VAR_0->bdiffsize; VAR_5++)

        VAR_1->totdiff += bdiffs[VAR_5];

    VAR_1->maxbdiff = maxdiff;

}

static void FUNC_0(const DecimateContext *VAR_0, struct qitem *VAR_1,
const AVFrame *VAR_2, const AVFrame *VAR_3)
{ int64_t maxdiff = -1; int64_t *bdiffs = VAR_0->bdiffs; int VAR_4, VAR_5, VAR_6; memset(bdiffs, 0, VAR_0->bdiffsize * sizeof(*bdiffs)); for (VAR_4 = 0; VAR_4 < (VAR_0->chroma ? 3 : 1); VAR_4++) { int x, y, xl; const int linesize1 = VAR_2->linesize[VAR_4]; const int linesize2 = VAR_3->linesize[VAR_4]; const uint8_t *f1p = VAR_2->data[VAR_4]; const uint8_t *f2p = VAR_3->data[VAR_4]; int width    = VAR_4 ? FF_CEIL_RSHIFT(VAR_2->width,  VAR_0->hsub) : VAR_2->width; int height   = VAR_4 ? FF_CEIL_RSHIFT(VAR_2->height, VAR_0->vsub) : VAR_2->height; int hblockx  = VAR_0->blockx / 2; int hblocky  = VAR_0->blocky / 2; if (VAR_4) { hblockx >>= VAR_0->hsub; hblocky >>= VAR_0->vsub; } for (y = 0; y < height; y++) { int ydest = y / hblocky; int xdest = 0; #define CALC_DIFF(nbits) do {                               \ for (x = 0; x < width; x += hblockx) {                  \ int64_t acc = 0;                                    \ int m = FFMIN(width, x + hblockx);                  \ for (xl = x; xl < m; xl++)                          \ acc += abs(((const uint##nbits##_t *)f1p)[xl] - \
((const uint##nbits##_t *)f2p)[xl]); \ bdiffs[ydest * VAR_0->nxblocks + xdest] += acc;        \ xdest++;                                            \ }                                                       \ } while (0) if (VAR_0->depth == 8) CALC_DIFF(8); else                CALC_DIFF(16); f1p += linesize1; f2p += linesize2; } } for (VAR_5 = 0; VAR_5 < VAR_0->nyblocks - 1; VAR_5++) { for (VAR_6 = 0; VAR_6 < VAR_0->nxblocks - 1; VAR_6++) { int64_t tmp = bdiffs[      VAR_5 * VAR_0->nxblocks + VAR_6    ]
+ bdiffs[      VAR_5 * VAR_0->nxblocks + VAR_6 + 1]
+ bdiffs[(VAR_5 + 1) * VAR_0->nxblocks + VAR_6    ]
+ bdiffs[(VAR_5 + 1) * VAR_0->nxblocks + VAR_6 + 1]; if (tmp > maxdiff)
maxdiff = tmp; } } VAR_1->totdiff = 0; for (VAR_5 = 0; VAR_5 < VAR_0->bdiffsize; VAR_5++) VAR_1->totdiff += bdiffs[VAR_5]; VAR_1->maxbdiff = maxdiff; }