static int tgq_decode_frame(AVCodecContext *avctx,

                            void *data, int *data_size,

                            AVPacket *avpkt){

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    const uint8_t *buf_start = buf;

    const uint8_t *buf_end = buf + buf_size;

    TgqContext *s = avctx->priv_data;

    int x,y;



    int big_endian = AV_RL32(&buf[4]) > 0x000FFFFF;

    buf += 8;



    if(8>buf_end-buf) {

        av_log(avctx, AV_LOG_WARNING, "truncated header\n");

        return -1;

    }

    s->width  = big_endian ? AV_RB16(&buf[0]) : AV_RL16(&buf[0]);

    s->height = big_endian ? AV_RB16(&buf[2]) : AV_RL16(&buf[2]);



    if (s->avctx->width!=s->width || s->avctx->height!=s->height) {

        avcodec_set_dimensions(s->avctx, s->width, s->height);

        if (s->frame.data[0])

            avctx->release_buffer(avctx, &s->frame);

    }

    tgq_calculate_qtable(s, buf[4]);

    buf += 8;



    if (!s->frame.data[0]) {

        s->frame.key_frame = 1;

        s->frame.pict_type = AV_PICTURE_TYPE_I;

        s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;

        if (avctx->get_buffer(avctx, &s->frame)) {

            av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

            return -1;

        }

    }



    for (y=0; y<(avctx->height+15)/16; y++)

    for (x=0; x<(avctx->width+15)/16; x++)

        tgq_decode_mb(s, y, x, &buf, buf_end);



    *data_size = sizeof(AVFrame);

    *(AVFrame*)data = s->frame;



    return buf-buf_start;

}

static int tgq_decode_frame(AVCodecContext *avctx,

                            void *data, int *data_size,

                            AVPacket *avpkt){

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    const uint8_t *buf_start = buf;

    const uint8_t *buf_end = buf + buf_size;

    TgqContext *s = avctx->priv_data;

    int x,y;



    int big_endian = AV_RL32(&buf[4]) > 0x000FFFFF;

    buf += 8;



    if(8>buf_end-buf) {

        av_log(avctx, AV_LOG_WARNING, "truncated header\n");

        return -1;

    }

    s->width  = big_endian ? AV_RB16(&buf[0]) : AV_RL16(&buf[0]);

    s->height = big_endian ? AV_RB16(&buf[2]) : AV_RL16(&buf[2]);



    if (s->avctx->width!=s->width || s->avctx->height!=s->height) {

        avcodec_set_dimensions(s->avctx, s->width, s->height);

        if (s->frame.data[0])

            avctx->release_buffer(avctx, &s->frame);

    }

    tgq_calculate_qtable(s, buf[4]);

    buf += 8;



    if (!s->frame.data[0]) {

        s->frame.key_frame = 1;

        s->frame.pict_type = AV_PICTURE_TYPE_I;

        s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;

        if (avctx->get_buffer(avctx, &s->frame)) {

            av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

            return -1;

        }

    }



    for (y=0; y<(avctx->height+15)/16; y++)

    for (x=0; x<(avctx->width+15)/16; x++)

        tgq_decode_mb(s, y, x, &buf, buf_end);



    *data_size = sizeof(AVFrame);

    *(AVFrame*)data = s->frame;



    return buf-buf_start;

}

    const uint8_t *buf_start = buf;     const uint8_t *buf_end = buf + buf_size;     buf += 8;     if(8>buf_end-buf) {     s->width  = big_endian ? AV_RB16(&buf[0]) : AV_RL16(&buf[0]);     s->height = big_endian ? AV_RB16(&buf[2]) : AV_RL16(&buf[2]);     tgq_calculate_qtable(s, buf[4]);     buf += 8;     for (y=0; y<(avctx->height+15)/16; y++)     for (x=0; x<(avctx->width+15)/16; x++)         tgq_decode_mb(s, y, x, &buf, buf_end);     return buf-buf_start;
static int FUNC_0(AVCodecContext *VAR_0,

                            void *VAR_1, int *VAR_2,

                            AVPacket *VAR_3){

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    const uint8_t *VAR_6 = VAR_4;

    const uint8_t *VAR_7 = VAR_4 + VAR_5;

    TgqContext *s = VAR_0->priv_data;

    int VAR_8,VAR_9;



    int VAR_10 = AV_RL32(&VAR_4[4]) > 0x000FFFFF;

    VAR_4 += 8;



    if(8>VAR_7-VAR_4) {

        av_log(VAR_0, AV_LOG_WARNING, "truncated header\n");

        return -1;

    }

    s->width  = VAR_10 ? AV_RB16(&VAR_4[0]) : AV_RL16(&VAR_4[0]);

    s->height = VAR_10 ? AV_RB16(&VAR_4[2]) : AV_RL16(&VAR_4[2]);



    if (s->VAR_0->width!=s->width || s->VAR_0->height!=s->height) {

        avcodec_set_dimensions(s->VAR_0, s->width, s->height);

        if (s->frame.VAR_1[0])

            VAR_0->release_buffer(VAR_0, &s->frame);

    }

    tgq_calculate_qtable(s, VAR_4[4]);

    VAR_4 += 8;



    if (!s->frame.VAR_1[0]) {

        s->frame.key_frame = 1;

        s->frame.pict_type = AV_PICTURE_TYPE_I;

        s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;

        if (VAR_0->get_buffer(VAR_0, &s->frame)) {

            av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n");

            return -1;

        }

    }



    for (VAR_9=0; VAR_9<(VAR_0->height+15)/16; VAR_9++)

    for (VAR_8=0; VAR_8<(VAR_0->width+15)/16; VAR_8++)

        tgq_decode_mb(s, VAR_9, VAR_8, &VAR_4, VAR_7);



    *VAR_2 = sizeof(AVFrame);

    *(AVFrame*)VAR_1 = s->frame;



    return VAR_4-VAR_6;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3){ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; const uint8_t *VAR_6 = VAR_4; const uint8_t *VAR_7 = VAR_4 + VAR_5; TgqContext *s = VAR_0->priv_data; int VAR_8,VAR_9; int VAR_10 = AV_RL32(&VAR_4[4]) > 0x000FFFFF; VAR_4 += 8; if(8>VAR_7-VAR_4) { av_log(VAR_0, AV_LOG_WARNING, "truncated header\n"); return -1; } s->width  = VAR_10 ? AV_RB16(&VAR_4[0]) : AV_RL16(&VAR_4[0]); s->height = VAR_10 ? AV_RB16(&VAR_4[2]) : AV_RL16(&VAR_4[2]); if (s->VAR_0->width!=s->width || s->VAR_0->height!=s->height) { avcodec_set_dimensions(s->VAR_0, s->width, s->height); if (s->frame.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->frame); } tgq_calculate_qtable(s, VAR_4[4]); VAR_4 += 8; if (!s->frame.VAR_1[0]) { s->frame.key_frame = 1; s->frame.pict_type = AV_PICTURE_TYPE_I; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; if (VAR_0->get_buffer(VAR_0, &s->frame)) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } } for (VAR_9=0; VAR_9<(VAR_0->height+15)/16; VAR_9++) for (VAR_8=0; VAR_8<(VAR_0->width+15)/16; VAR_8++) tgq_decode_mb(s, VAR_9, VAR_8, &VAR_4, VAR_7); *VAR_2 = sizeof(AVFrame); *(AVFrame*)VAR_1 = s->frame; return VAR_4-VAR_6; }