static void guess_palette(DVDSubContext* ctx,

                          uint32_t *rgba_palette,

                          uint32_t subtitle_color)

{

    static const uint8_t level_map[4][4] = {

        // this configuration (full range, lowest to highest) in tests

        // seemed most common, so assume this

        {0xff},

        {0x00, 0xff},

        {0x00, 0x80, 0xff},

        {0x00, 0x55, 0xaa, 0xff},

    };

    uint8_t color_used[16] = { 0 };

    int nb_opaque_colors, i, level, j, r, g, b;

    uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha;



    if(ctx->has_palette) {

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

            rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff)

                              | ((alpha[i] * 17U) << 24);

        return;

    }



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

        rgba_palette[i] = 0;



    nb_opaque_colors = 0;

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

        if (alpha[i] != 0 && !color_used[colormap[i]]) {

            color_used[colormap[i]] = 1;

            nb_opaque_colors++;

        }

    }



    if (nb_opaque_colors == 0)

        return;



    j = 0;

    memset(color_used, 0, 16);

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

        if (alpha[i] != 0) {

            if (!color_used[colormap[i]])  {

                level = level_map[nb_opaque_colors - 1][j];

                r = (((subtitle_color >> 16) & 0xff) * level) >> 8;

                g = (((subtitle_color >> 8) & 0xff) * level) >> 8;

                b = (((subtitle_color >> 0) & 0xff) * level) >> 8;

                rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);

                color_used[colormap[i]] = (i + 1);

                j++;

            } else {

                rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |

                                    ((alpha[i] * 17) << 24);

            }

        }

    }

}

static void guess_palette(DVDSubContext* ctx,

                          uint32_t *rgba_palette,

                          uint32_t subtitle_color)

{

    static const uint8_t level_map[4][4] = {

        

        

        {0xff},

        {0x00, 0xff},

        {0x00, 0x80, 0xff},

        {0x00, 0x55, 0xaa, 0xff},

    };

    uint8_t color_used[16] = { 0 };

    int nb_opaque_colors, i, level, j, r, g, b;

    uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha;



    if(ctx->has_palette) {

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

            rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff)

                              | ((alpha[i] * 17U) << 24);

        return;

    }



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

        rgba_palette[i] = 0;



    nb_opaque_colors = 0;

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

        if (alpha[i] != 0 && !color_used[colormap[i]]) {

            color_used[colormap[i]] = 1;

            nb_opaque_colors++;

        }

    }



    if (nb_opaque_colors == 0)

        return;



    j = 0;

    memset(color_used, 0, 16);

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

        if (alpha[i] != 0) {

            if (!color_used[colormap[i]])  {

                level = level_map[nb_opaque_colors - 1][j];

                r = (((subtitle_color >> 16) & 0xff) * level) >> 8;

                g = (((subtitle_color >> 8) & 0xff) * level) >> 8;

                b = (((subtitle_color >> 0) & 0xff) * level) >> 8;

                rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);

                color_used[colormap[i]] = (i + 1);

                j++;

            } else {

                rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) |

                                    ((alpha[i] * 17) << 24);

            }

        }

    }

}

                rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);                                     ((alpha[i] * 17) << 24);
static void FUNC_0(DVDSubContext* VAR_0,

                          uint32_t *VAR_1,

                          uint32_t VAR_2)

{

    static const uint8_t VAR_3[4][4] = {

        

        

        {0xff},

        {0x00, 0xff},

        {0x00, 0x80, 0xff},

        {0x00, 0x55, 0xaa, 0xff},

    };

    uint8_t color_used[16] = { 0 };

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    uint8_t *colormap = VAR_0->colormap, *alpha = VAR_0->alpha;



    if(VAR_0->has_palette) {

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

            VAR_1[VAR_5] = (VAR_0->palette[colormap[VAR_5]] & 0x00ffffff)

                              | ((alpha[VAR_5] * 17U) << 24);

        return;

    }



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

        VAR_1[VAR_5] = 0;



    VAR_4 = 0;

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

        if (alpha[VAR_5] != 0 && !color_used[colormap[VAR_5]]) {

            color_used[colormap[VAR_5]] = 1;

            VAR_4++;

        }

    }



    if (VAR_4 == 0)

        return;



    VAR_7 = 0;

    memset(color_used, 0, 16);

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

        if (alpha[VAR_5] != 0) {

            if (!color_used[colormap[VAR_5]])  {

                VAR_6 = VAR_3[VAR_4 - 1][VAR_7];

                VAR_8 = (((VAR_2 >> 16) & 0xff) * VAR_6) >> 8;

                VAR_9 = (((VAR_2 >> 8) & 0xff) * VAR_6) >> 8;

                VAR_10 = (((VAR_2 >> 0) & 0xff) * VAR_6) >> 8;

                VAR_1[VAR_5] = VAR_10 | (VAR_9 << 8) | (VAR_8 << 16) | ((alpha[VAR_5] * 17) << 24);

                color_used[colormap[VAR_5]] = (VAR_5 + 1);

                VAR_7++;

            } else {

                VAR_1[VAR_5] = (VAR_1[color_used[colormap[VAR_5]] - 1] & 0x00ffffff) |

                                    ((alpha[VAR_5] * 17) << 24);

            }

        }

    }

}

static void FUNC_0(DVDSubContext* VAR_0,
uint32_t *VAR_1,
uint32_t VAR_2)
{ static const uint8_t VAR_3[4][4] = { {0xff}, {0x00, 0xff}, {0x00, 0x80, 0xff}, {0x00, 0x55, 0xaa, 0xff}, }; uint8_t color_used[16] = { 0 }; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; uint8_t *colormap = VAR_0->colormap, *alpha = VAR_0->alpha; if(VAR_0->has_palette) { for(VAR_5 = 0; VAR_5 < 4; VAR_5++) VAR_1[VAR_5] = (VAR_0->palette[colormap[VAR_5]] & 0x00ffffff)
| ((alpha[VAR_5] * 17U) << 24); return; } for(VAR_5 = 0; VAR_5 < 4; VAR_5++) VAR_1[VAR_5] = 0; VAR_4 = 0; for(VAR_5 = 0; VAR_5 < 4; VAR_5++) { if (alpha[VAR_5] != 0 && !color_used[colormap[VAR_5]]) { color_used[colormap[VAR_5]] = 1; VAR_4++; } } if (VAR_4 == 0)
return; VAR_7 = 0; memset(color_used, 0, 16); for(VAR_5 = 0; VAR_5 < 4; VAR_5++) { if (alpha[VAR_5] != 0) { if (!color_used[colormap[VAR_5]])  { VAR_6 = VAR_3[VAR_4 - 1][VAR_7]; VAR_8 = (((VAR_2 >> 16) & 0xff) * VAR_6) >> 8; VAR_9 = (((VAR_2 >> 8) & 0xff) * VAR_6) >> 8; VAR_10 = (((VAR_2 >> 0) & 0xff) * VAR_6) >> 8; VAR_1[VAR_5] = VAR_10 | (VAR_9 << 8) | (VAR_8 << 16) | ((alpha[VAR_5] * 17) << 24); color_used[colormap[VAR_5]] = (VAR_5 + 1); VAR_7++; } else { VAR_1[VAR_5] = (VAR_1[color_used[colormap[VAR_5]] - 1] & 0x00ffffff) |
((alpha[VAR_5] * 17) << 24); } } } }