static void count_colors(AVCodecContext *avctx, unsigned hits[33],

                         const AVSubtitleRect *r)

{

    DVDSubtitleContext *dvdc = avctx->priv_data;

    unsigned count[256] = { 0 };

    uint32_t *palette = (uint32_t *)r->pict.data[1];

    uint32_t color;

    int x, y, i, j, match, d, best_d, av_uninit(best_j);

    uint8_t *p = r->pict.data[0];



    for (y = 0; y < r->h; y++) {

        for (x = 0; x < r->w; x++)

            count[*(p++)]++;

        p += r->pict.linesize[0] - r->w;

    }

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

        if (!count[i]) /* avoid useless search */

            continue;

        color = palette[i];

        /* 0: transparent, 1-16: semi-transparent, 17-33 opaque */

        match = color < 0x33000000 ? 0 : color < 0xCC000000 ? 1 : 17;

        if (match) {

            best_d = INT_MAX;

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

                d = color_distance(color & 0xFFFFFF, dvdc->global_palette[j]);

                if (d < best_d) {

                    best_d = d;

                    best_j = j;

                }

            }

            match += best_j;

        }

        hits[match] += count[i];

    }

}

static void count_colors(AVCodecContext *avctx, unsigned hits[33],

                         const AVSubtitleRect *r)

{

    DVDSubtitleContext *dvdc = avctx->priv_data;

    unsigned count[256] = { 0 };

    uint32_t *palette = (uint32_t *)r->pict.data[1];

    uint32_t color;

    int x, y, i, j, match, d, best_d, av_uninit(best_j);

    uint8_t *p = r->pict.data[0];



    for (y = 0; y < r->h; y++) {

        for (x = 0; x < r->w; x++)

            count[*(p++)]++;

        p += r->pict.linesize[0] - r->w;

    }

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

        if (!count[i]) 

            continue;

        color = palette[i];

        

        match = color < 0x33000000 ? 0 : color < 0xCC000000 ? 1 : 17;

        if (match) {

            best_d = INT_MAX;

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

                d = color_distance(color & 0xFFFFFF, dvdc->global_palette[j]);

                if (d < best_d) {

                    best_d = d;

                    best_j = j;

                }

            }

            match += best_j;

        }

        hits[match] += count[i];

    }

}

                d = color_distance(color & 0xFFFFFF, dvdc->global_palette[j]);
static void FUNC_0(AVCodecContext *VAR_0, unsigned VAR_1[33],

                         const AVSubtitleRect *VAR_2)

{

    DVDSubtitleContext *dvdc = VAR_0->priv_data;

    unsigned VAR_3[256] = { 0 };

    uint32_t *palette = (uint32_t *)VAR_2->pict.data[1];

    uint32_t color;

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, FUNC_1(best_j);

    uint8_t *p = VAR_2->pict.data[0];



    for (VAR_5 = 0; VAR_5 < VAR_2->h; VAR_5++) {

        for (VAR_4 = 0; VAR_4 < VAR_2->w; VAR_4++)

            VAR_3[*(p++)]++;

        p += VAR_2->pict.linesize[0] - VAR_2->w;

    }

    for (VAR_6 = 0; VAR_6 < 256; VAR_6++) {

        if (!VAR_3[VAR_6]) 

            continue;

        color = palette[VAR_6];

        

        VAR_8 = color < 0x33000000 ? 0 : color < 0xCC000000 ? 1 : 17;

        if (VAR_8) {

            VAR_10 = INT_MAX;

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

                VAR_9 = color_distance(color & 0xFFFFFF, dvdc->global_palette[VAR_7]);

                if (VAR_9 < VAR_10) {

                    VAR_10 = VAR_9;

                    best_j = VAR_7;

                }

            }

            VAR_8 += best_j;

        }

        VAR_1[VAR_8] += VAR_3[VAR_6];

    }

}

static void FUNC_0(AVCodecContext *VAR_0, unsigned VAR_1[33],
const AVSubtitleRect *VAR_2)
{ DVDSubtitleContext *dvdc = VAR_0->priv_data; unsigned VAR_3[256] = { 0 }; uint32_t *palette = (uint32_t *)VAR_2->pict.data[1]; uint32_t color; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, FUNC_1(best_j); uint8_t *p = VAR_2->pict.data[0]; for (VAR_5 = 0; VAR_5 < VAR_2->h; VAR_5++) { for (VAR_4 = 0; VAR_4 < VAR_2->w; VAR_4++) VAR_3[*(p++)]++; p += VAR_2->pict.linesize[0] - VAR_2->w; } for (VAR_6 = 0; VAR_6 < 256; VAR_6++) { if (!VAR_3[VAR_6])
continue; color = palette[VAR_6]; VAR_8 = color < 0x33000000 ? 0 : color < 0xCC000000 ? 1 : 17; if (VAR_8) { VAR_10 = INT_MAX; for (VAR_7 = 0; VAR_7 < 16; VAR_7++) { VAR_9 = color_distance(color & 0xFFFFFF, dvdc->global_palette[VAR_7]); if (VAR_9 < VAR_10) { VAR_10 = VAR_9; best_j = VAR_7; } } VAR_8 += best_j; } VAR_1[VAR_8] += VAR_3[VAR_6]; } }