static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,

                                          const uint8_t *buf, int buf_size, int top_bottom, int non_mod)

{

    DVBSubContext *ctx = avctx->priv_data;



    DVBSubRegion *region = get_region(ctx, display->region_id);

    const uint8_t *buf_end = buf + buf_size;

    uint8_t *pbuf;

    int x_pos, y_pos;

    int i;



    uint8_t map2to4[] = { 0x0,  0x7,  0x8,  0xf};

    uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};

    uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,

                         0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};

    uint8_t *map_table;



#if 0

    av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,

            top_bottom ? "bottom" : "top");



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

        if (i % 16 == 0)

            av_dlog(avctx, "0x%8p: ", buf+i);



        av_dlog(avctx, "%02x ", buf[i]);

        if (i % 16 == 15)

            av_dlog(avctx, "\n");

    }



    if (i % 16)

        av_dlog(avctx, "\n");

#endif



    if (region == 0)

        return;



    pbuf = region->pbuf;

    region->dirty = 1;



    x_pos = display->x_pos;

    y_pos = display->y_pos;



    if ((y_pos & 1) != top_bottom)

        y_pos++;



    while (buf < buf_end) {

        if (x_pos > region->width || y_pos > region->height) {

            av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n");

            return;

        }



        switch (*buf++) {

        case 0x10:

            if (region->depth == 8)

                map_table = map2to8;

            else if (region->depth == 4)

                map_table = map2to4;

            else

                map_table = NULL;



            x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos,

                                                region->width - x_pos, &buf, buf_end - buf,

                                                non_mod, map_table);

            break;

        case 0x11:

            if (region->depth < 4) {

                av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);

                return;

            }



            if (region->depth == 8)

                map_table = map4to8;

            else

                map_table = NULL;



            x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos,

                                                region->width - x_pos, &buf, buf_end - buf,

                                                non_mod, map_table);

            break;

        case 0x12:

            if (region->depth < 8) {

                av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);

                return;

            }



            x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos,

                                                region->width - x_pos, &buf, buf_end - buf,

                                                non_mod, NULL);

            break;



        case 0x20:

            map2to4[0] = (*buf) >> 4;

            map2to4[1] = (*buf++) & 0xf;

            map2to4[2] = (*buf) >> 4;

            map2to4[3] = (*buf++) & 0xf;

            break;

        case 0x21:

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

                map2to8[i] = *buf++;

            break;

        case 0x22:

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

                map4to8[i] = *buf++;

            break;



        case 0xf0:

            x_pos = display->x_pos;

            y_pos += 2;

            break;

        default:

            av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));

        }

    }



}

static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,

                                          const uint8_t *buf, int buf_size, int top_bottom, int non_mod)

{

    DVBSubContext *ctx = avctx->priv_data;



    DVBSubRegion *region = get_region(ctx, display->region_id);

    const uint8_t *buf_end = buf + buf_size;

    uint8_t *pbuf;

    int x_pos, y_pos;

    int i;



    uint8_t map2to4[] = { 0x0,  0x7,  0x8,  0xf};

    uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};

    uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,

                         0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};

    uint8_t *map_table;



#if 0

    av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size,

            top_bottom ? "bottom" : "top");



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

        if (i % 16 == 0)

            av_dlog(avctx, "0x%8p: ", buf+i);



        av_dlog(avctx, "%02x ", buf[i]);

        if (i % 16 == 15)

            av_dlog(avctx, "\n");

    }



    if (i % 16)

        av_dlog(avctx, "\n");

#endif



    if (region == 0)

        return;



    pbuf = region->pbuf;

    region->dirty = 1;



    x_pos = display->x_pos;

    y_pos = display->y_pos;



    if ((y_pos & 1) != top_bottom)

        y_pos++;



    while (buf < buf_end) {

        if (x_pos > region->width || y_pos > region->height) {

            av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n");

            return;

        }



        switch (*buf++) {

        case 0x10:

            if (region->depth == 8)

                map_table = map2to8;

            else if (region->depth == 4)

                map_table = map2to4;

            else

                map_table = NULL;



            x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos,

                                                region->width - x_pos, &buf, buf_end - buf,

                                                non_mod, map_table);

            break;

        case 0x11:

            if (region->depth < 4) {

                av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);

                return;

            }



            if (region->depth == 8)

                map_table = map4to8;

            else

                map_table = NULL;



            x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos,

                                                region->width - x_pos, &buf, buf_end - buf,

                                                non_mod, map_table);

            break;

        case 0x12:

            if (region->depth < 8) {

                av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);

                return;

            }



            x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos,

                                                region->width - x_pos, &buf, buf_end - buf,

                                                non_mod, NULL);

            break;



        case 0x20:

            map2to4[0] = (*buf) >> 4;

            map2to4[1] = (*buf++) & 0xf;

            map2to4[2] = (*buf) >> 4;

            map2to4[3] = (*buf++) & 0xf;

            break;

        case 0x21:

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

                map2to8[i] = *buf++;

            break;

        case 0x22:

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

                map4to8[i] = *buf++;

            break;



        case 0xf0:

            x_pos = display->x_pos;

            y_pos += 2;

            break;

        default:

            av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));

        }

    }



}

static void FUNC_0(AVCodecContext *VAR_0, DVBSubObjectDisplay *VAR_1,

                                          const uint8_t *VAR_2, int VAR_3, int VAR_4, int VAR_5)

{

    DVBSubContext *ctx = VAR_0->priv_data;



    DVBSubRegion *region = get_region(ctx, VAR_1->region_id);

    const uint8_t *VAR_6 = VAR_2 + VAR_3;

    uint8_t *pbuf;

    int VAR_7, VAR_8;

    int VAR_9;



    uint8_t map2to4[] = { 0x0,  0x7,  0x8,  0xf};

    uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};

    uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,

                         0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};

    uint8_t *map_table;



#if 0

    av_dlog(VAR_0, "DVB pixel block size %d, %s field:\n", VAR_3,

            VAR_4 ? "bottom" : "top");



    for (VAR_9 = 0; VAR_9 < VAR_3; VAR_9++) {

        if (VAR_9 % 16 == 0)

            av_dlog(VAR_0, "0x%8p: ", VAR_2+VAR_9);



        av_dlog(VAR_0, "%02x ", VAR_2[VAR_9]);

        if (VAR_9 % 16 == 15)

            av_dlog(VAR_0, "\n");

    }



    if (VAR_9 % 16)

        av_dlog(VAR_0, "\n");

#endif



    if (region == 0)

        return;



    pbuf = region->pbuf;

    region->dirty = 1;



    VAR_7 = VAR_1->VAR_7;

    VAR_8 = VAR_1->VAR_8;



    if ((VAR_8 & 1) != VAR_4)

        VAR_8++;



    while (VAR_2 < VAR_6) {

        if (VAR_7 > region->width || VAR_8 > region->height) {

            av_log(VAR_0, AV_LOG_ERROR, "Invalid object location!\n");

            return;

        }



        switch (*VAR_2++) {

        case 0x10:

            if (region->depth == 8)

                map_table = map2to8;

            else if (region->depth == 4)

                map_table = map2to4;

            else

                map_table = NULL;



            VAR_7 += dvbsub_read_2bit_string(pbuf + (VAR_8 * region->width) + VAR_7,

                                                region->width - VAR_7, &VAR_2, VAR_6 - VAR_2,

                                                VAR_5, map_table);

            break;

        case 0x11:

            if (region->depth < 4) {

                av_log(VAR_0, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);

                return;

            }



            if (region->depth == 8)

                map_table = map4to8;

            else

                map_table = NULL;



            VAR_7 += dvbsub_read_4bit_string(pbuf + (VAR_8 * region->width) + VAR_7,

                                                region->width - VAR_7, &VAR_2, VAR_6 - VAR_2,

                                                VAR_5, map_table);

            break;

        case 0x12:

            if (region->depth < 8) {

                av_log(VAR_0, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);

                return;

            }



            VAR_7 += dvbsub_read_8bit_string(pbuf + (VAR_8 * region->width) + VAR_7,

                                                region->width - VAR_7, &VAR_2, VAR_6 - VAR_2,

                                                VAR_5, NULL);

            break;



        case 0x20:

            map2to4[0] = (*VAR_2) >> 4;

            map2to4[1] = (*VAR_2++) & 0xf;

            map2to4[2] = (*VAR_2) >> 4;

            map2to4[3] = (*VAR_2++) & 0xf;

            break;

        case 0x21:

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

                map2to8[VAR_9] = *VAR_2++;

            break;

        case 0x22:

            for (VAR_9 = 0; VAR_9 < 16; VAR_9++)

                map4to8[VAR_9] = *VAR_2++;

            break;



        case 0xf0:

            VAR_7 = VAR_1->VAR_7;

            VAR_8 += 2;

            break;

        default:

            av_log(VAR_0, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(VAR_2-1));

        }

    }



}

static void FUNC_0(AVCodecContext *VAR_0, DVBSubObjectDisplay *VAR_1,
const uint8_t *VAR_2, int VAR_3, int VAR_4, int VAR_5)
{ DVBSubContext *ctx = VAR_0->priv_data; DVBSubRegion *region = get_region(ctx, VAR_1->region_id); const uint8_t *VAR_6 = VAR_2 + VAR_3; uint8_t *pbuf; int VAR_7, VAR_8; int VAR_9; uint8_t map2to4[] = { 0x0,  0x7,  0x8,  0xf}; uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff}; uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; uint8_t *map_table; #if 0
av_dlog(VAR_0, "DVB pixel block size %d, %s field:\n", VAR_3,
VAR_4 ? "bottom" : "top"); for (VAR_9 = 0; VAR_9 < VAR_3; VAR_9++) { if (VAR_9 % 16 == 0)
av_dlog(VAR_0, "0x%8p: ", VAR_2+VAR_9); av_dlog(VAR_0, "%02x ", VAR_2[VAR_9]); if (VAR_9 % 16 == 15)
av_dlog(VAR_0, "\n"); } if (VAR_9 % 16)
av_dlog(VAR_0, "\n"); #endif
if (region == 0)
return; pbuf = region->pbuf; region->dirty = 1; VAR_7 = VAR_1->VAR_7; VAR_8 = VAR_1->VAR_8; if ((VAR_8 & 1) != VAR_4)
VAR_8++; while (VAR_2 < VAR_6) { if (VAR_7 > region->width || VAR_8 > region->height) { av_log(VAR_0, AV_LOG_ERROR, "Invalid object location!\n"); return; } switch (*VAR_2++) { case 0x10:
if (region->depth == 8)
map_table = map2to8; else if (region->depth == 4)
map_table = map2to4; else
map_table = NULL; VAR_7 += dvbsub_read_2bit_string(pbuf + (VAR_8 * region->width) + VAR_7,
region->width - VAR_7, &VAR_2, VAR_6 - VAR_2,
VAR_5, map_table); break; case 0x11:
if (region->depth < 4) { av_log(VAR_0, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth); return; } if (region->depth == 8)
map_table = map4to8; else
map_table = NULL; VAR_7 += dvbsub_read_4bit_string(pbuf + (VAR_8 * region->width) + VAR_7,
region->width - VAR_7, &VAR_2, VAR_6 - VAR_2,
VAR_5, map_table); break; case 0x12:
if (region->depth < 8) { av_log(VAR_0, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth); return; } VAR_7 += dvbsub_read_8bit_string(pbuf + (VAR_8 * region->width) + VAR_7,
region->width - VAR_7, &VAR_2, VAR_6 - VAR_2,
VAR_5, NULL); break; case 0x20:
map2to4[0] = (*VAR_2) >> 4; map2to4[1] = (*VAR_2++) & 0xf; map2to4[2] = (*VAR_2) >> 4; map2to4[3] = (*VAR_2++) & 0xf; break; case 0x21:
for (VAR_9 = 0; VAR_9 < 4; VAR_9++) map2to8[VAR_9] = *VAR_2++; break; case 0x22:
for (VAR_9 = 0; VAR_9 < 16; VAR_9++) map4to8[VAR_9] = *VAR_2++; break; case 0xf0:
VAR_7 = VAR_1->VAR_7; VAR_8 += 2; break; default:
av_log(VAR_0, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(VAR_2-1)); } } }