static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,

                                   const uint8_t **srcbuf, int buf_size,

                                   int non_mod, uint8_t *map_table)

{

    GetBitContext gb;



    int bits;

    int run_length;

    int pixels_read = 0;



    init_get_bits(&gb, *srcbuf, buf_size << 3);



    while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {

        bits = get_bits(&gb, 2);



        if (bits) {

            if (non_mod != 1 || bits != 1) {

                if (map_table)

                    *destbuf++ = map_table[bits];

                else

                    *destbuf++ = bits;

            }

            pixels_read++;

        } else {

            bits = get_bits1(&gb);

            if (bits == 1) {

                run_length = get_bits(&gb, 3) + 3;

                bits = get_bits(&gb, 2);



                if (non_mod == 1 && bits == 1)

                    pixels_read += run_length;

                else {

                    if (map_table)

                        bits = map_table[bits];

                    while (run_length-- > 0 && pixels_read < dbuf_len) {

                        *destbuf++ = bits;

                        pixels_read++;

                    }

                }

            } else {

                bits = get_bits1(&gb);

                if (bits == 0) {

                    bits = get_bits(&gb, 2);

                    if (bits == 2) {

                        run_length = get_bits(&gb, 4) + 12;

                        bits = get_bits(&gb, 2);



                        if (non_mod == 1 && bits == 1)

                            pixels_read += run_length;

                        else {

                            if (map_table)

                                bits = map_table[bits];

                            while (run_length-- > 0 && pixels_read < dbuf_len) {

                                *destbuf++ = bits;

                                pixels_read++;

                            }

                        }

                    } else if (bits == 3) {

                        run_length = get_bits(&gb, 8) + 29;

                        bits = get_bits(&gb, 2);



                        if (non_mod == 1 && bits == 1)

                            pixels_read += run_length;

                        else {

                            if (map_table)

                                bits = map_table[bits];

                            while (run_length-- > 0 && pixels_read < dbuf_len) {

                                *destbuf++ = bits;

                                pixels_read++;

                            }

                        }

                    } else if (bits == 1) {

                        pixels_read += 2;

                        if (map_table)

                            bits = map_table[0];

                        else

                            bits = 0;

                        if (pixels_read <= dbuf_len) {

                            *destbuf++ = bits;

                            *destbuf++ = bits;

                        }

                    } else {

                        (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;

                        return pixels_read;

                    }

                } else {

                    if (map_table)

                        bits = map_table[0];

                    else

                        bits = 0;

                    *destbuf++ = bits;

                    pixels_read++;

                }

            }

        }

    }



    if (get_bits(&gb, 6))

        av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");



    (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;



    return pixels_read;

}

static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,

                                   const uint8_t **srcbuf, int buf_size,

                                   int non_mod, uint8_t *map_table)

{

    GetBitContext gb;



    int bits;

    int run_length;

    int pixels_read = 0;



    init_get_bits(&gb, *srcbuf, buf_size << 3);



    while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {

        bits = get_bits(&gb, 2);



        if (bits) {

            if (non_mod != 1 || bits != 1) {

                if (map_table)

                    *destbuf++ = map_table[bits];

                else

                    *destbuf++ = bits;

            }

            pixels_read++;

        } else {

            bits = get_bits1(&gb);

            if (bits == 1) {

                run_length = get_bits(&gb, 3) + 3;

                bits = get_bits(&gb, 2);



                if (non_mod == 1 && bits == 1)

                    pixels_read += run_length;

                else {

                    if (map_table)

                        bits = map_table[bits];

                    while (run_length-- > 0 && pixels_read < dbuf_len) {

                        *destbuf++ = bits;

                        pixels_read++;

                    }

                }

            } else {

                bits = get_bits1(&gb);

                if (bits == 0) {

                    bits = get_bits(&gb, 2);

                    if (bits == 2) {

                        run_length = get_bits(&gb, 4) + 12;

                        bits = get_bits(&gb, 2);



                        if (non_mod == 1 && bits == 1)

                            pixels_read += run_length;

                        else {

                            if (map_table)

                                bits = map_table[bits];

                            while (run_length-- > 0 && pixels_read < dbuf_len) {

                                *destbuf++ = bits;

                                pixels_read++;

                            }

                        }

                    } else if (bits == 3) {

                        run_length = get_bits(&gb, 8) + 29;

                        bits = get_bits(&gb, 2);



                        if (non_mod == 1 && bits == 1)

                            pixels_read += run_length;

                        else {

                            if (map_table)

                                bits = map_table[bits];

                            while (run_length-- > 0 && pixels_read < dbuf_len) {

                                *destbuf++ = bits;

                                pixels_read++;

                            }

                        }

                    } else if (bits == 1) {

                        pixels_read += 2;

                        if (map_table)

                            bits = map_table[0];

                        else

                            bits = 0;

                        if (pixels_read <= dbuf_len) {

                            *destbuf++ = bits;

                            *destbuf++ = bits;

                        }

                    } else {

                        (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;

                        return pixels_read;

                    }

                } else {

                    if (map_table)

                        bits = map_table[0];

                    else

                        bits = 0;

                    *destbuf++ = bits;

                    pixels_read++;

                }

            }

        }

    }



    if (get_bits(&gb, 6))

        av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");



    (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;



    return pixels_read;

}

static int FUNC_0(uint8_t *VAR_0, int VAR_1,

                                   const uint8_t **VAR_2, int VAR_3,

                                   int VAR_4, uint8_t *VAR_5)

{

    GetBitContext gb;



    int VAR_6;

    int VAR_7;

    int VAR_8 = 0;



    init_get_bits(&gb, *VAR_2, VAR_3 << 3);



    while (get_bits_count(&gb) < VAR_3 << 3 && VAR_8 < VAR_1) {

        VAR_6 = get_bits(&gb, 2);



        if (VAR_6) {

            if (VAR_4 != 1 || VAR_6 != 1) {

                if (VAR_5)

                    *VAR_0++ = VAR_5[VAR_6];

                else

                    *VAR_0++ = VAR_6;

            }

            VAR_8++;

        } else {

            VAR_6 = get_bits1(&gb);

            if (VAR_6 == 1) {

                VAR_7 = get_bits(&gb, 3) + 3;

                VAR_6 = get_bits(&gb, 2);



                if (VAR_4 == 1 && VAR_6 == 1)

                    VAR_8 += VAR_7;

                else {

                    if (VAR_5)

                        VAR_6 = VAR_5[VAR_6];

                    while (VAR_7-- > 0 && VAR_8 < VAR_1) {

                        *VAR_0++ = VAR_6;

                        VAR_8++;

                    }

                }

            } else {

                VAR_6 = get_bits1(&gb);

                if (VAR_6 == 0) {

                    VAR_6 = get_bits(&gb, 2);

                    if (VAR_6 == 2) {

                        VAR_7 = get_bits(&gb, 4) + 12;

                        VAR_6 = get_bits(&gb, 2);



                        if (VAR_4 == 1 && VAR_6 == 1)

                            VAR_8 += VAR_7;

                        else {

                            if (VAR_5)

                                VAR_6 = VAR_5[VAR_6];

                            while (VAR_7-- > 0 && VAR_8 < VAR_1) {

                                *VAR_0++ = VAR_6;

                                VAR_8++;

                            }

                        }

                    } else if (VAR_6 == 3) {

                        VAR_7 = get_bits(&gb, 8) + 29;

                        VAR_6 = get_bits(&gb, 2);



                        if (VAR_4 == 1 && VAR_6 == 1)

                            VAR_8 += VAR_7;

                        else {

                            if (VAR_5)

                                VAR_6 = VAR_5[VAR_6];

                            while (VAR_7-- > 0 && VAR_8 < VAR_1) {

                                *VAR_0++ = VAR_6;

                                VAR_8++;

                            }

                        }

                    } else if (VAR_6 == 1) {

                        VAR_8 += 2;

                        if (VAR_5)

                            VAR_6 = VAR_5[0];

                        else

                            VAR_6 = 0;

                        if (VAR_8 <= VAR_1) {

                            *VAR_0++ = VAR_6;

                            *VAR_0++ = VAR_6;

                        }

                    } else {

                        (*VAR_2) += (get_bits_count(&gb) + 7) >> 3;

                        return VAR_8;

                    }

                } else {

                    if (VAR_5)

                        VAR_6 = VAR_5[0];

                    else

                        VAR_6 = 0;

                    *VAR_0++ = VAR_6;

                    VAR_8++;

                }

            }

        }

    }



    if (get_bits(&gb, 6))

        av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");



    (*VAR_2) += (get_bits_count(&gb) + 7) >> 3;



    return VAR_8;

}

static int FUNC_0(uint8_t *VAR_0, int VAR_1,
const uint8_t **VAR_2, int VAR_3,
int VAR_4, uint8_t *VAR_5)
{ GetBitContext gb; int VAR_6; int VAR_7; int VAR_8 = 0; init_get_bits(&gb, *VAR_2, VAR_3 << 3); while (get_bits_count(&gb) < VAR_3 << 3 && VAR_8 < VAR_1) { VAR_6 = get_bits(&gb, 2); if (VAR_6) { if (VAR_4 != 1 || VAR_6 != 1) { if (VAR_5)
*VAR_0++ = VAR_5[VAR_6]; else
*VAR_0++ = VAR_6; } VAR_8++; } else { VAR_6 = get_bits1(&gb); if (VAR_6 == 1) { VAR_7 = get_bits(&gb, 3) + 3; VAR_6 = get_bits(&gb, 2); if (VAR_4 == 1 && VAR_6 == 1)
VAR_8 += VAR_7; else { if (VAR_5)
VAR_6 = VAR_5[VAR_6]; while (VAR_7-- > 0 && VAR_8 < VAR_1) { *VAR_0++ = VAR_6; VAR_8++; } } } else { VAR_6 = get_bits1(&gb); if (VAR_6 == 0) { VAR_6 = get_bits(&gb, 2); if (VAR_6 == 2) { VAR_7 = get_bits(&gb, 4) + 12; VAR_6 = get_bits(&gb, 2); if (VAR_4 == 1 && VAR_6 == 1)
VAR_8 += VAR_7; else { if (VAR_5)
VAR_6 = VAR_5[VAR_6]; while (VAR_7-- > 0 && VAR_8 < VAR_1) { *VAR_0++ = VAR_6; VAR_8++; } } } else if (VAR_6 == 3) { VAR_7 = get_bits(&gb, 8) + 29; VAR_6 = get_bits(&gb, 2); if (VAR_4 == 1 && VAR_6 == 1)
VAR_8 += VAR_7; else { if (VAR_5)
VAR_6 = VAR_5[VAR_6]; while (VAR_7-- > 0 && VAR_8 < VAR_1) { *VAR_0++ = VAR_6; VAR_8++; } } } else if (VAR_6 == 1) { VAR_8 += 2; if (VAR_5)
VAR_6 = VAR_5[0]; else
VAR_6 = 0; if (VAR_8 <= VAR_1) { *VAR_0++ = VAR_6; *VAR_0++ = VAR_6; } } else { (*VAR_2) += (get_bits_count(&gb) + 7) >> 3; return VAR_8; } } else { if (VAR_5)
VAR_6 = VAR_5[0]; else
VAR_6 = 0; *VAR_0++ = VAR_6; VAR_8++; } } } } if (get_bits(&gb, 6))
av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); (*VAR_2) += (get_bits_count(&gb) + 7) >> 3; return VAR_8; }