static int cinvideo_decode_frame(AVCodecContext *avctx,

                                 void *data, int *data_size,

                                 AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    CinVideoContext *cin = avctx->priv_data;

    int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size;



    cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;

    if (avctx->reget_buffer(avctx, &cin->frame)) {

        av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n");

        return -1;

    }



    palette_type = buf[0];

    palette_colors_count = AV_RL16(buf+1);

    bitmap_frame_type = buf[3];

    buf += 4;



    bitmap_frame_size = buf_size - 4;



    /* handle palette */



    if (palette_type == 0) {

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

            cin->palette[i] = bytestream_get_le24(&buf);

            bitmap_frame_size -= 3;

        }

    } else {

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

            cin->palette[buf[0]] = AV_RL24(buf+1);

            buf += 4;

            bitmap_frame_size -= 4;

        }

    }

    memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette));

    cin->frame.palette_has_changed = 1;



    /* note: the decoding routines below assumes that surface.width = surface.pitch */

    switch (bitmap_frame_type) {

    case 9:

        cin_decode_rle(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 34:

        cin_decode_rle(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 35:

        cin_decode_huffman(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);

        cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 36:

        bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);

        cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 37:

        cin_decode_huffman(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 38:

        cin_decode_lzss(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 39:

        cin_decode_lzss(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    }



    for (y = 0; y < cin->avctx->height; ++y)

        memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0],

          cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width,

          cin->avctx->width);



    FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]);



    *data_size = sizeof(AVFrame);

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



    return buf_size;

}
static int cinvideo_decode_frame(AVCodecContext *avctx,

                                 void *data, int *data_size,

                                 AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    CinVideoContext *cin = avctx->priv_data;

    int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size;



    cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;

    if (avctx->reget_buffer(avctx, &cin->frame)) {

        av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n");

        return -1;

    }



    palette_type = buf[0];

    palette_colors_count = AV_RL16(buf+1);

    bitmap_frame_type = buf[3];

    buf += 4;



    bitmap_frame_size = buf_size - 4;



    



    if (palette_type == 0) {

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

            cin->palette[i] = bytestream_get_le24(&buf);

            bitmap_frame_size -= 3;

        }

    } else {

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

            cin->palette[buf[0]] = AV_RL24(buf+1);

            buf += 4;

            bitmap_frame_size -= 4;

        }

    }

    memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette));

    cin->frame.palette_has_changed = 1;



    

    switch (bitmap_frame_type) {

    case 9:

        cin_decode_rle(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 34:

        cin_decode_rle(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 35:

        cin_decode_huffman(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);

        cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 36:

        bitmap_frame_size = cin_decode_huffman(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);

        cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 37:

        cin_decode_huffman(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 38:

        cin_decode_lzss(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 39:

        cin_decode_lzss(buf, bitmap_frame_size,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    }



    for (y = 0; y < cin->avctx->height; ++y)

        memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0],

          cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width,

          cin->avctx->width);



    FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]);



    *data_size = sizeof(AVFrame);

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



    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;

    CinVideoContext *cin = VAR_0->priv_data;

    int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;



    cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;

    if (VAR_0->reget_buffer(VAR_0, &cin->frame)) {

        av_log(cin->VAR_0, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n");

        return -1;

    }



    VAR_8 = VAR_4[0];

    VAR_9 = AV_RL16(VAR_4+1);

    VAR_10 = VAR_4[3];

    VAR_4 += 4;



    VAR_11 = VAR_5 - 4;



    



    if (VAR_8 == 0) {

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

            cin->palette[VAR_6] = bytestream_get_le24(&VAR_4);

            VAR_11 -= 3;

        }

    } else {

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

            cin->palette[VAR_4[0]] = AV_RL24(VAR_4+1);

            VAR_4 += 4;

            VAR_11 -= 4;

        }

    }

    memcpy(cin->frame.VAR_1[1], cin->palette, sizeof(cin->palette));

    cin->frame.palette_has_changed = 1;



    

    switch (VAR_10) {

    case 9:

        cin_decode_rle(VAR_4, VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 34:

        cin_decode_rle(VAR_4, VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 35:

        cin_decode_huffman(VAR_4, VAR_11,

          cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);

        cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 36:

        VAR_11 = cin_decode_huffman(VAR_4, VAR_11,

          cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size);

        cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 37:

        cin_decode_huffman(VAR_4, VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 38:

        cin_decode_lzss(VAR_4, VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    case 39:

        cin_decode_lzss(VAR_4, VAR_11,

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],

          cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size);

        break;

    }



    for (VAR_7 = 0; VAR_7 < cin->VAR_0->height; ++VAR_7)

        memcpy(cin->frame.VAR_1[0] + (cin->VAR_0->height - 1 - VAR_7) * cin->frame.linesize[0],

          cin->bitmap_table[CIN_CUR_BMP] + VAR_7 * cin->VAR_0->width,

          cin->VAR_0->width);



    FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]);



    *VAR_2 = sizeof(AVFrame);

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



    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; CinVideoContext *cin = VAR_0->priv_data; int VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (VAR_0->reget_buffer(VAR_0, &cin->frame)) { av_log(cin->VAR_0, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n"); return -1; } VAR_8 = VAR_4[0]; VAR_9 = AV_RL16(VAR_4+1); VAR_10 = VAR_4[3]; VAR_4 += 4; VAR_11 = VAR_5 - 4; if (VAR_8 == 0) { for (VAR_6 = 0; VAR_6 < VAR_9; ++VAR_6) { cin->palette[VAR_6] = bytestream_get_le24(&VAR_4); VAR_11 -= 3; } } else { for (VAR_6 = 0; VAR_6 < VAR_9; ++VAR_6) { cin->palette[VAR_4[0]] = AV_RL24(VAR_4+1); VAR_4 += 4; VAR_11 -= 4; } } memcpy(cin->frame.VAR_1[1], cin->palette, sizeof(cin->palette)); cin->frame.palette_has_changed = 1; switch (VAR_10) { case 9:
cin_decode_rle(VAR_4, VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 34:
cin_decode_rle(VAR_4, VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 35:
cin_decode_huffman(VAR_4, VAR_11,
cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size); cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 36:
VAR_11 = cin_decode_huffman(VAR_4, VAR_11,
cin->bitmap_table[CIN_INT_BMP], cin->bitmap_size); cin_decode_rle(cin->bitmap_table[CIN_INT_BMP], VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 37:
cin_decode_huffman(VAR_4, VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 38:
cin_decode_lzss(VAR_4, VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; case 39:
cin_decode_lzss(VAR_4, VAR_11,
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP],
cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); break; } for (VAR_7 = 0; VAR_7 < cin->VAR_0->height; ++VAR_7) memcpy(cin->frame.VAR_1[0] + (cin->VAR_0->height - 1 - VAR_7) * cin->frame.linesize[0],
cin->bitmap_table[CIN_CUR_BMP] + VAR_7 * cin->VAR_0->width,
cin->VAR_0->width); FFSWAP(uint8_t *, cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_table[CIN_PRE_BMP]); *VAR_2 = sizeof(AVFrame); *(AVFrame *)VAR_1 = cin->frame; return VAR_5; }