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

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    KmvcContext *const ctx = avctx->priv_data;

    uint8_t *out, *src;

    int i;

    int header;

    int blocksize;

    const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);



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

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



    ctx->pic.reference = 1;

    ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;

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

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

        return -1;

    }



    header = *buf++;



    /* blocksize 127 is really palette change event */

    if (buf[0] == 127) {

        buf += 3;

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

            ctx->pal[i + (header & 0x81)] = AV_RB24(buf);

            buf += 4;

        }

        buf -= 127 * 4 + 3;

    }



    if (header & KMVC_KEYFRAME) {

        ctx->pic.key_frame = 1;

        ctx->pic.pict_type = AV_PICTURE_TYPE_I;

    } else {

        ctx->pic.key_frame = 0;

        ctx->pic.pict_type = AV_PICTURE_TYPE_P;

    }



    if (header & KMVC_PALETTE) {

        ctx->pic.palette_has_changed = 1;

        // palette starts from index 1 and has 127 entries

        for (i = 1; i <= ctx->palsize; i++) {

            ctx->pal[i] = bytestream_get_be24(&buf);

        }

    }



    if (pal) {

        ctx->pic.palette_has_changed = 1;

        memcpy(ctx->pal, pal, AVPALETTE_SIZE);

    }



    if (ctx->setpal) {

        ctx->setpal = 0;

        ctx->pic.palette_has_changed = 1;

    }



    /* make the palette available on the way out */

    memcpy(ctx->pic.data[1], ctx->pal, 1024);



    blocksize = *buf++;



    if (blocksize != 8 && blocksize != 127) {

        av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);

        return -1;

    }

    memset(ctx->cur, 0, 320 * 200);

    switch (header & KMVC_METHOD) {

    case 0:

    case 1: // used in palette changed event

        memcpy(ctx->cur, ctx->prev, 320 * 200);

        break;

    case 3:

        kmvc_decode_intra_8x8(ctx, buf, buf_size, avctx->width, avctx->height);

        break;

    case 4:

        kmvc_decode_inter_8x8(ctx, buf, buf_size, avctx->width, avctx->height);

        break;

    default:

        av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);

        return -1;

    }



    out = ctx->pic.data[0];

    src = ctx->cur;

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

        memcpy(out, src, avctx->width);

        src += 320;

        out += ctx->pic.linesize[0];

    }



    /* flip buffers */

    if (ctx->cur == ctx->frm0) {

        ctx->cur = ctx->frm1;

        ctx->prev = ctx->frm0;

    } else {

        ctx->cur = ctx->frm0;

        ctx->prev = ctx->frm1;

    }



    *data_size = sizeof(AVFrame);

    *(AVFrame *) data = ctx->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;

    KmvcContext *const ctx = avctx->priv_data;

    uint8_t *out, *src;

    int i;

    int header;

    int blocksize;

    const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);



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

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



    ctx->pic.reference = 1;

    ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;

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

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

        return -1;

    }



    header = *buf++;



    

    if (buf[0] == 127) {

        buf += 3;

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

            ctx->pal[i + (header & 0x81)] = AV_RB24(buf);

            buf += 4;

        }

        buf -= 127 * 4 + 3;

    }



    if (header & KMVC_KEYFRAME) {

        ctx->pic.key_frame = 1;

        ctx->pic.pict_type = AV_PICTURE_TYPE_I;

    } else {

        ctx->pic.key_frame = 0;

        ctx->pic.pict_type = AV_PICTURE_TYPE_P;

    }



    if (header & KMVC_PALETTE) {

        ctx->pic.palette_has_changed = 1;

        

        for (i = 1; i <= ctx->palsize; i++) {

            ctx->pal[i] = bytestream_get_be24(&buf);

        }

    }



    if (pal) {

        ctx->pic.palette_has_changed = 1;

        memcpy(ctx->pal, pal, AVPALETTE_SIZE);

    }



    if (ctx->setpal) {

        ctx->setpal = 0;

        ctx->pic.palette_has_changed = 1;

    }



    

    memcpy(ctx->pic.data[1], ctx->pal, 1024);



    blocksize = *buf++;



    if (blocksize != 8 && blocksize != 127) {

        av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);

        return -1;

    }

    memset(ctx->cur, 0, 320 * 200);

    switch (header & KMVC_METHOD) {

    case 0:

    case 1: 

        memcpy(ctx->cur, ctx->prev, 320 * 200);

        break;

    case 3:

        kmvc_decode_intra_8x8(ctx, buf, buf_size, avctx->width, avctx->height);

        break;

    case 4:

        kmvc_decode_inter_8x8(ctx, buf, buf_size, avctx->width, avctx->height);

        break;

    default:

        av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);

        return -1;

    }



    out = ctx->pic.data[0];

    src = ctx->cur;

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

        memcpy(out, src, avctx->width);

        src += 320;

        out += ctx->pic.linesize[0];

    }



    

    if (ctx->cur == ctx->frm0) {

        ctx->cur = ctx->frm1;

        ctx->prev = ctx->frm0;

    } else {

        ctx->cur = ctx->frm0;

        ctx->prev = ctx->frm1;

    }



    *data_size = sizeof(AVFrame);

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



    

    return buf_size;

}

    const uint8_t *buf = avpkt->data;     int buf_size = avpkt->size;     header = *buf++;     if (buf[0] == 127) {         buf += 3;             ctx->pal[i + (header & 0x81)] = AV_RB24(buf);             buf += 4;         buf -= 127 * 4 + 3;             ctx->pal[i] = bytestream_get_be24(&buf);     blocksize = *buf++;         kmvc_decode_intra_8x8(ctx, buf, buf_size, avctx->width, avctx->height);         kmvc_decode_inter_8x8(ctx, buf, buf_size, avctx->width, avctx->height);     return buf_size;
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;

    KmvcContext *const ctx = VAR_0->priv_data;

    uint8_t *out, *src;

    int VAR_6;

    int VAR_7;

    int VAR_8;

    const uint8_t *VAR_9 = av_packet_get_side_data(VAR_3, AV_PKT_DATA_PALETTE, NULL);



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

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



    ctx->pic.reference = 1;

    ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;

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

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

        return -1;

    }



    VAR_7 = *VAR_4++;



    

    if (VAR_4[0] == 127) {

        VAR_4 += 3;

        for (VAR_6 = 0; VAR_6 < 127; VAR_6++) {

            ctx->VAR_9[VAR_6 + (VAR_7 & 0x81)] = AV_RB24(VAR_4);

            VAR_4 += 4;

        }

        VAR_4 -= 127 * 4 + 3;

    }



    if (VAR_7 & KMVC_KEYFRAME) {

        ctx->pic.key_frame = 1;

        ctx->pic.pict_type = AV_PICTURE_TYPE_I;

    } else {

        ctx->pic.key_frame = 0;

        ctx->pic.pict_type = AV_PICTURE_TYPE_P;

    }



    if (VAR_7 & KMVC_PALETTE) {

        ctx->pic.palette_has_changed = 1;

        

        for (VAR_6 = 1; VAR_6 <= ctx->palsize; VAR_6++) {

            ctx->VAR_9[VAR_6] = bytestream_get_be24(&VAR_4);

        }

    }



    if (VAR_9) {

        ctx->pic.palette_has_changed = 1;

        memcpy(ctx->VAR_9, VAR_9, AVPALETTE_SIZE);

    }



    if (ctx->setpal) {

        ctx->setpal = 0;

        ctx->pic.palette_has_changed = 1;

    }



    

    memcpy(ctx->pic.VAR_1[1], ctx->VAR_9, 1024);



    VAR_8 = *VAR_4++;



    if (VAR_8 != 8 && VAR_8 != 127) {

        av_log(VAR_0, AV_LOG_ERROR, "Block size = %VAR_6\n", VAR_8);

        return -1;

    }

    memset(ctx->cur, 0, 320 * 200);

    switch (VAR_7 & KMVC_METHOD) {

    case 0:

    case 1: 

        memcpy(ctx->cur, ctx->prev, 320 * 200);

        break;

    case 3:

        kmvc_decode_intra_8x8(ctx, VAR_4, VAR_5, VAR_0->width, VAR_0->height);

        break;

    case 4:

        kmvc_decode_inter_8x8(ctx, VAR_4, VAR_5, VAR_0->width, VAR_0->height);

        break;

    default:

        av_log(VAR_0, AV_LOG_ERROR, "Unknown compression method %VAR_6\n", VAR_7 & KMVC_METHOD);

        return -1;

    }



    out = ctx->pic.VAR_1[0];

    src = ctx->cur;

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

        memcpy(out, src, VAR_0->width);

        src += 320;

        out += ctx->pic.linesize[0];

    }



    

    if (ctx->cur == ctx->frm0) {

        ctx->cur = ctx->frm1;

        ctx->prev = ctx->frm0;

    } else {

        ctx->cur = ctx->frm0;

        ctx->prev = ctx->frm1;

    }



    *VAR_2 = sizeof(AVFrame);

    *(AVFrame *) VAR_1 = ctx->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; KmvcContext *const ctx = VAR_0->priv_data; uint8_t *out, *src; int VAR_6; int VAR_7; int VAR_8; const uint8_t *VAR_9 = av_packet_get_side_data(VAR_3, AV_PKT_DATA_PALETTE, NULL); if (ctx->pic.VAR_1[0])
VAR_0->release_buffer(VAR_0, &ctx->pic); ctx->pic.reference = 1; ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID; if (VAR_0->get_buffer(VAR_0, &ctx->pic) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } VAR_7 = *VAR_4++; if (VAR_4[0] == 127) { VAR_4 += 3; for (VAR_6 = 0; VAR_6 < 127; VAR_6++) { ctx->VAR_9[VAR_6 + (VAR_7 & 0x81)] = AV_RB24(VAR_4); VAR_4 += 4; } VAR_4 -= 127 * 4 + 3; } if (VAR_7 & KMVC_KEYFRAME) { ctx->pic.key_frame = 1; ctx->pic.pict_type = AV_PICTURE_TYPE_I; } else { ctx->pic.key_frame = 0; ctx->pic.pict_type = AV_PICTURE_TYPE_P; } if (VAR_7 & KMVC_PALETTE) { ctx->pic.palette_has_changed = 1; for (VAR_6 = 1; VAR_6 <= ctx->palsize; VAR_6++) { ctx->VAR_9[VAR_6] = bytestream_get_be24(&VAR_4); } } if (VAR_9) { ctx->pic.palette_has_changed = 1; memcpy(ctx->VAR_9, VAR_9, AVPALETTE_SIZE); } if (ctx->setpal) { ctx->setpal = 0; ctx->pic.palette_has_changed = 1; } memcpy(ctx->pic.VAR_1[1], ctx->VAR_9, 1024); VAR_8 = *VAR_4++; if (VAR_8 != 8 && VAR_8 != 127) { av_log(VAR_0, AV_LOG_ERROR, "Block size = %VAR_6\n", VAR_8); return -1; } memset(ctx->cur, 0, 320 * 200); switch (VAR_7 & KMVC_METHOD) { case 0:
case 1:
memcpy(ctx->cur, ctx->prev, 320 * 200); break; case 3:
kmvc_decode_intra_8x8(ctx, VAR_4, VAR_5, VAR_0->width, VAR_0->height); break; case 4:
kmvc_decode_inter_8x8(ctx, VAR_4, VAR_5, VAR_0->width, VAR_0->height); break; default:
av_log(VAR_0, AV_LOG_ERROR, "Unknown compression method %VAR_6\n", VAR_7 & KMVC_METHOD); return -1; } out = ctx->pic.VAR_1[0]; src = ctx->cur; for (VAR_6 = 0; VAR_6 < VAR_0->height; VAR_6++) { memcpy(out, src, VAR_0->width); src += 320; out += ctx->pic.linesize[0]; } if (ctx->cur == ctx->frm0) { ctx->cur = ctx->frm1; ctx->prev = ctx->frm0; } else { ctx->cur = ctx->frm0; ctx->prev = ctx->frm1; } *VAR_2 = sizeof(AVFrame); *(AVFrame *) VAR_1 = ctx->pic; return VAR_5; }