static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    VBDecContext * const c = avctx->priv_data;

    uint8_t *outptr, *srcptr;

    int i, j;

    int flags;

    uint32_t size;

    int rest = buf_size;

    int offset = 0;



    if(c->pic.data[0])

        avctx->release_buffer(avctx, &c->pic);

    c->pic.reference = 3;

    if(avctx->get_buffer(avctx, &c->pic) < 0){

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

        return -1;

    }



    c->stream = buf;

    flags = bytestream_get_le16(&c->stream);

    rest -= 2;



    if(flags & VB_HAS_GMC){

        i = (int16_t)bytestream_get_le16(&c->stream);

        j = (int16_t)bytestream_get_le16(&c->stream);

        offset = i + j * avctx->width;

        rest -= 4;

    }

    if(flags & VB_HAS_VIDEO){

        size = bytestream_get_le32(&c->stream);

        if(size > rest){

            av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n");

            return -1;

        }

        vb_decode_framedata(c, c->stream, size, offset);

        c->stream += size - 4;

        rest -= size;

    }

    if(flags & VB_HAS_PALETTE){

        size = bytestream_get_le32(&c->stream);

        if(size > rest){

            av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n");

            return -1;

        }

        vb_decode_palette(c, size);

        rest -= size;

    }



    memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);

    c->pic.palette_has_changed = flags & VB_HAS_PALETTE;



    outptr = c->pic.data[0];

    srcptr = c->frame;



    for(i = 0; i < avctx->height; i++){

        memcpy(outptr, srcptr, avctx->width);

        srcptr += avctx->width;

        outptr += c->pic.linesize[0];

    }



    FFSWAP(uint8_t*, c->frame, c->prev_frame);



    *data_size = sizeof(AVFrame);

    *(AVFrame*)data = c->pic;



    /* always report that the buffer was completely consumed */

    return buf_size;

}

static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    VBDecContext * const c = avctx->priv_data;

    uint8_t *outptr, *srcptr;

    int i, j;

    int flags;

    uint32_t size;

    int rest = buf_size;

    int offset = 0;



    if(c->pic.data[0])

        avctx->release_buffer(avctx, &c->pic);

    c->pic.reference = 3;

    if(avctx->get_buffer(avctx, &c->pic) < 0){

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

        return -1;

    }



    c->stream = buf;

    flags = bytestream_get_le16(&c->stream);

    rest -= 2;



    if(flags & VB_HAS_GMC){

        i = (int16_t)bytestream_get_le16(&c->stream);

        j = (int16_t)bytestream_get_le16(&c->stream);

        offset = i + j * avctx->width;

        rest -= 4;

    }

    if(flags & VB_HAS_VIDEO){

        size = bytestream_get_le32(&c->stream);

        if(size > rest){

            av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n");

            return -1;

        }

        vb_decode_framedata(c, c->stream, size, offset);

        c->stream += size - 4;

        rest -= size;

    }

    if(flags & VB_HAS_PALETTE){

        size = bytestream_get_le32(&c->stream);

        if(size > rest){

            av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n");

            return -1;

        }

        vb_decode_palette(c, size);

        rest -= size;

    }



    memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);

    c->pic.palette_has_changed = flags & VB_HAS_PALETTE;



    outptr = c->pic.data[0];

    srcptr = c->frame;



    for(i = 0; i < avctx->height; i++){

        memcpy(outptr, srcptr, avctx->width);

        srcptr += avctx->width;

        outptr += c->pic.linesize[0];

    }



    FFSWAP(uint8_t*, c->frame, c->prev_frame);



    *data_size = sizeof(AVFrame);

    *(AVFrame*)data = c->pic;



    

    return buf_size;

}

        if(size > rest){             av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n");
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;

    VBDecContext * const c = VAR_0->priv_data;

    uint8_t *outptr, *srcptr;

    int VAR_6, VAR_7;

    int VAR_8;

    uint32_t size;

    int VAR_9 = VAR_5;

    int VAR_10 = 0;



    if(c->pic.VAR_1[0])

        VAR_0->release_buffer(VAR_0, &c->pic);

    c->pic.reference = 3;

    if(VAR_0->get_buffer(VAR_0, &c->pic) < 0){

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

        return -1;

    }



    c->stream = VAR_4;

    VAR_8 = bytestream_get_le16(&c->stream);

    VAR_9 -= 2;



    if(VAR_8 & VB_HAS_GMC){

        VAR_6 = (int16_t)bytestream_get_le16(&c->stream);

        VAR_7 = (int16_t)bytestream_get_le16(&c->stream);

        VAR_10 = VAR_6 + VAR_7 * VAR_0->width;

        VAR_9 -= 4;

    }

    if(VAR_8 & VB_HAS_VIDEO){

        size = bytestream_get_le32(&c->stream);

        if(size > VAR_9){

            av_log(VAR_0, AV_LOG_ERROR, "Frame size is too big\n");

            return -1;

        }

        vb_decode_framedata(c, c->stream, size, VAR_10);

        c->stream += size - 4;

        VAR_9 -= size;

    }

    if(VAR_8 & VB_HAS_PALETTE){

        size = bytestream_get_le32(&c->stream);

        if(size > VAR_9){

            av_log(VAR_0, AV_LOG_ERROR, "Palette size is too big\n");

            return -1;

        }

        vb_decode_palette(c, size);

        VAR_9 -= size;

    }



    memcpy(c->pic.VAR_1[1], c->pal, AVPALETTE_SIZE);

    c->pic.palette_has_changed = VAR_8 & VB_HAS_PALETTE;



    outptr = c->pic.VAR_1[0];

    srcptr = c->frame;



    for(VAR_6 = 0; VAR_6 < VAR_0->height; VAR_6++){

        memcpy(outptr, srcptr, VAR_0->width);

        srcptr += VAR_0->width;

        outptr += c->pic.linesize[0];

    }



    FFSWAP(uint8_t*, c->frame, c->prev_frame);



    *VAR_2 = sizeof(AVFrame);

    *(AVFrame*)VAR_1 = c->pic;



    

    return VAR_5;

}

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; VBDecContext * const c = VAR_0->priv_data; uint8_t *outptr, *srcptr; int VAR_6, VAR_7; int VAR_8; uint32_t size; int VAR_9 = VAR_5; int VAR_10 = 0; if(c->pic.VAR_1[0])
VAR_0->release_buffer(VAR_0, &c->pic); c->pic.reference = 3; if(VAR_0->get_buffer(VAR_0, &c->pic) < 0){ av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } c->stream = VAR_4; VAR_8 = bytestream_get_le16(&c->stream); VAR_9 -= 2; if(VAR_8 & VB_HAS_GMC){ VAR_6 = (int16_t)bytestream_get_le16(&c->stream); VAR_7 = (int16_t)bytestream_get_le16(&c->stream); VAR_10 = VAR_6 + VAR_7 * VAR_0->width; VAR_9 -= 4; } if(VAR_8 & VB_HAS_VIDEO){ size = bytestream_get_le32(&c->stream); if(size > VAR_9){ av_log(VAR_0, AV_LOG_ERROR, "Frame size is too big\n"); return -1; } vb_decode_framedata(c, c->stream, size, VAR_10); c->stream += size - 4; VAR_9 -= size; } if(VAR_8 & VB_HAS_PALETTE){ size = bytestream_get_le32(&c->stream); if(size > VAR_9){ av_log(VAR_0, AV_LOG_ERROR, "Palette size is too big\n"); return -1; } vb_decode_palette(c, size); VAR_9 -= size; } memcpy(c->pic.VAR_1[1], c->pal, AVPALETTE_SIZE); c->pic.palette_has_changed = VAR_8 & VB_HAS_PALETTE; outptr = c->pic.VAR_1[0]; srcptr = c->frame; for(VAR_6 = 0; VAR_6 < VAR_0->height; VAR_6++){ memcpy(outptr, srcptr, VAR_0->width); srcptr += VAR_0->width; outptr += c->pic.linesize[0]; } FFSWAP(uint8_t*, c->frame, c->prev_frame); *VAR_2 = sizeof(AVFrame); *(AVFrame*)VAR_1 = c->pic; return VAR_5; }