static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)

{

    BinkContext * const c = avctx->priv_data;

    GetBitContext gb;

    int plane, plane_idx, ret;

    int bits_count = pkt->size << 3;



    if (c->version > 'b') {

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

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



        if ((ret = ff_get_buffer(avctx, c->pic)) < 0) {

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

            return ret;

        }

    } else {

        if ((ret = avctx->reget_buffer(avctx, c->pic)) < 0) {

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

            return ret;

        }

    }



    init_get_bits(&gb, pkt->data, bits_count);

    if (c->has_alpha) {

        if (c->version >= 'i')

            skip_bits_long(&gb, 32);

        if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0)

            return ret;

    }

    if (c->version >= 'i')

        skip_bits_long(&gb, 32);



    for (plane = 0; plane < 3; plane++) {

        plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3);



        if (c->version > 'b') {

            if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0)

                return ret;

        } else {

            if ((ret = binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane)) < 0)

                return ret;

        }

        if (get_bits_count(&gb) >= bits_count)

            break;

    }

    emms_c();



    *got_frame = 1;

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



    if (c->version > 'b')

        FFSWAP(AVFrame*, c->pic, c->last);



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

    return pkt->size;

}

static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)

{

    BinkContext * const c = avctx->priv_data;

    GetBitContext gb;

    int plane, plane_idx, ret;

    int bits_count = pkt->size << 3;



    if (c->version > 'b') {

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

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



        if ((ret = ff_get_buffer(avctx, c->pic)) < 0) {

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

            return ret;

        }

    } else {

        if ((ret = avctx->reget_buffer(avctx, c->pic)) < 0) {

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

            return ret;

        }

    }



    init_get_bits(&gb, pkt->data, bits_count);

    if (c->has_alpha) {

        if (c->version >= 'i')

            skip_bits_long(&gb, 32);

        if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0)

            return ret;

    }

    if (c->version >= 'i')

        skip_bits_long(&gb, 32);



    for (plane = 0; plane < 3; plane++) {

        plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3);



        if (c->version > 'b') {

            if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0)

                return ret;

        } else {

            if ((ret = binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane)) < 0)

                return ret;

        }

        if (get_bits_count(&gb) >= bits_count)

            break;

    }

    emms_c();



    *got_frame = 1;

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



    if (c->version > 'b')

        FFSWAP(AVFrame*, c->pic, c->last);



    

    return pkt->size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1, int *VAR_2, AVPacket *VAR_3)

{

    BinkContext * const c = VAR_0->priv_data;

    GetBitContext gb;

    int VAR_4, VAR_5, VAR_6;

    int VAR_7 = VAR_3->size << 3;



    if (c->version > 'b') {

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

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



        if ((VAR_6 = ff_get_buffer(VAR_0, c->pic)) < 0) {

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

            return VAR_6;

        }

    } else {

        if ((VAR_6 = VAR_0->reget_buffer(VAR_0, c->pic)) < 0) {

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

            return VAR_6;

        }

    }



    init_get_bits(&gb, VAR_3->VAR_1, VAR_7);

    if (c->has_alpha) {

        if (c->version >= 'i')

            skip_bits_long(&gb, 32);

        if ((VAR_6 = bink_decode_plane(c, &gb, 3, 0)) < 0)

            return VAR_6;

    }

    if (c->version >= 'i')

        skip_bits_long(&gb, 32);



    for (VAR_4 = 0; VAR_4 < 3; VAR_4++) {

        VAR_5 = (!VAR_4 || !c->swap_planes) ? VAR_4 : (VAR_4 ^ 3);



        if (c->version > 'b') {

            if ((VAR_6 = bink_decode_plane(c, &gb, VAR_5, !!VAR_4)) < 0)

                return VAR_6;

        } else {

            if ((VAR_6 = binkb_decode_plane(c, &gb, VAR_5, !VAR_3->pts, !!VAR_4)) < 0)

                return VAR_6;

        }

        if (get_bits_count(&gb) >= VAR_7)

            break;

    }

    emms_c();



    *VAR_2 = 1;

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



    if (c->version > 'b')

        FFSWAP(AVFrame*, c->pic, c->last);



    

    return VAR_3->size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1, int *VAR_2, AVPacket *VAR_3)
{ BinkContext * const c = VAR_0->priv_data; GetBitContext gb; int VAR_4, VAR_5, VAR_6; int VAR_7 = VAR_3->size << 3; if (c->version > 'b') { if(c->pic->VAR_1[0])
VAR_0->release_buffer(VAR_0, c->pic); if ((VAR_6 = ff_get_buffer(VAR_0, c->pic)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return VAR_6; } } else { if ((VAR_6 = VAR_0->reget_buffer(VAR_0, c->pic)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "reget_buffer() failed\n"); return VAR_6; } } init_get_bits(&gb, VAR_3->VAR_1, VAR_7); if (c->has_alpha) { if (c->version >= 'i')
skip_bits_long(&gb, 32); if ((VAR_6 = bink_decode_plane(c, &gb, 3, 0)) < 0)
return VAR_6; } if (c->version >= 'i')
skip_bits_long(&gb, 32); for (VAR_4 = 0; VAR_4 < 3; VAR_4++) { VAR_5 = (!VAR_4 || !c->swap_planes) ? VAR_4 : (VAR_4 ^ 3); if (c->version > 'b') { if ((VAR_6 = bink_decode_plane(c, &gb, VAR_5, !!VAR_4)) < 0)
return VAR_6; } else { if ((VAR_6 = binkb_decode_plane(c, &gb, VAR_5, !VAR_3->pts, !!VAR_4)) < 0)
return VAR_6; } if (get_bits_count(&gb) >= VAR_7)
break; } emms_c(); *VAR_2 = 1; *(AVFrame*)VAR_1 = *c->pic; if (c->version > 'b')
FFSWAP(AVFrame*, c->pic, c->last); return VAR_3->size; }