static int encode_slice(AVCodecContext *c, void *arg)

{

    FFV1Context *fs  = *(void **)arg;

    FFV1Context *f   = fs->avctx->priv_data;

    int width        = fs->slice_width;

    int height       = fs->slice_height;

    int x            = fs->slice_x;

    int y            = fs->slice_y;

    const AVFrame *const p = f->frame;

    const int ps     = (av_pix_fmt_desc_get(c->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR)

                       ? (f->bits_per_raw_sample > 8) + 1

                       : 4;



    if (f->key_frame)

        ffv1_clear_slice_state(f, fs);

    if (f->version > 2) {

        encode_slice_header(f, fs);

    }

    if (!fs->ac) {

        if (f->version > 2)

            put_rac(&fs->c, (uint8_t[]) { 129 }, 0);

        fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate( &fs->c) : 0;

        init_put_bits(&fs->pb, fs->c.bytestream_start + fs->ac_byte_count,

                      fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);

    }



    if (f->colorspace == 0) {

        const int chroma_width  = -((-width) >> f->chroma_h_shift);

        const int chroma_height = -((-height) >> f->chroma_v_shift);

        const int cx            = x >> f->chroma_h_shift;

        const int cy            = y >> f->chroma_v_shift;



        encode_plane(fs, p->data[0] + ps * x + y * p->linesize[0],

                     width, height, p->linesize[0], 0);



        if (f->chroma_planes) {

            encode_plane(fs, p->data[1] + ps * cx + cy * p->linesize[1],

                         chroma_width, chroma_height, p->linesize[1], 1);

            encode_plane(fs, p->data[2] + ps * cx + cy * p->linesize[2],

                         chroma_width, chroma_height, p->linesize[2], 1);

        }

        if (fs->transparency)

            encode_plane(fs, p->data[3] + ps * x + y * p->linesize[3], width,

                         height, p->linesize[3], 2);

    } else {

        const uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],

                                     p->data[1] + ps * x + y * p->linesize[1],

                                     p->data[2] + ps * x + y * p->linesize[2] };

        encode_rgb_frame(fs, planes, width, height, p->linesize);

    }

    emms_c();



    return 0;

}

static int encode_slice(AVCodecContext *c, void *arg)

{

    FFV1Context *fs  = *(void **)arg;

    FFV1Context *f   = fs->avctx->priv_data;

    int width        = fs->slice_width;

    int height       = fs->slice_height;

    int x            = fs->slice_x;

    int y            = fs->slice_y;

    const AVFrame *const p = f->frame;

    const int ps     = (av_pix_fmt_desc_get(c->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR)

                       ? (f->bits_per_raw_sample > 8) + 1

                       : 4;



    if (f->key_frame)

        ffv1_clear_slice_state(f, fs);

    if (f->version > 2) {

        encode_slice_header(f, fs);

    }

    if (!fs->ac) {

        if (f->version > 2)

            put_rac(&fs->c, (uint8_t[]) { 129 }, 0);

        fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate( &fs->c) : 0;

        init_put_bits(&fs->pb, fs->c.bytestream_start + fs->ac_byte_count,

                      fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count);

    }



    if (f->colorspace == 0) {

        const int chroma_width  = -((-width) >> f->chroma_h_shift);

        const int chroma_height = -((-height) >> f->chroma_v_shift);

        const int cx            = x >> f->chroma_h_shift;

        const int cy            = y >> f->chroma_v_shift;



        encode_plane(fs, p->data[0] + ps * x + y * p->linesize[0],

                     width, height, p->linesize[0], 0);



        if (f->chroma_planes) {

            encode_plane(fs, p->data[1] + ps * cx + cy * p->linesize[1],

                         chroma_width, chroma_height, p->linesize[1], 1);

            encode_plane(fs, p->data[2] + ps * cx + cy * p->linesize[2],

                         chroma_width, chroma_height, p->linesize[2], 1);

        }

        if (fs->transparency)

            encode_plane(fs, p->data[3] + ps * x + y * p->linesize[3], width,

                         height, p->linesize[3], 2);

    } else {

        const uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],

                                     p->data[1] + ps * x + y * p->linesize[1],

                                     p->data[2] + ps * x + y * p->linesize[2] };

        encode_rgb_frame(fs, planes, width, height, p->linesize);

    }

    emms_c();



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1)

{

    FFV1Context *fs  = *(void **)VAR_1;

    FFV1Context *f   = fs->avctx->priv_data;

    int VAR_2        = fs->slice_width;

    int VAR_3       = fs->slice_height;

    int VAR_4            = fs->slice_x;

    int VAR_5            = fs->slice_y;

    const AVFrame *const VAR_6 = f->frame;

    const int VAR_7     = (av_pix_fmt_desc_get(VAR_0->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR)

                       ? (f->bits_per_raw_sample > 8) + 1

                       : 4;



    if (f->key_frame)

        ffv1_clear_slice_state(f, fs);

    if (f->version > 2) {

        encode_slice_header(f, fs);

    }

    if (!fs->ac) {

        if (f->version > 2)

            put_rac(&fs->VAR_0, (uint8_t[]) { 129 }, 0);

        fs->ac_byte_count = f->version > 2 || (!VAR_4 && !VAR_5) ? ff_rac_terminate( &fs->VAR_0) : 0;

        init_put_bits(&fs->pb, fs->VAR_0.bytestream_start + fs->ac_byte_count,

                      fs->VAR_0.bytestream_end - fs->VAR_0.bytestream_start - fs->ac_byte_count);

    }



    if (f->colorspace == 0) {

        const int VAR_8  = -((-VAR_2) >> f->chroma_h_shift);

        const int VAR_9 = -((-VAR_3) >> f->chroma_v_shift);

        const int VAR_10            = VAR_4 >> f->chroma_h_shift;

        const int VAR_11            = VAR_5 >> f->chroma_v_shift;



        encode_plane(fs, VAR_6->data[0] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[0],

                     VAR_2, VAR_3, VAR_6->linesize[0], 0);



        if (f->chroma_planes) {

            encode_plane(fs, VAR_6->data[1] + VAR_7 * VAR_10 + VAR_11 * VAR_6->linesize[1],

                         VAR_8, VAR_9, VAR_6->linesize[1], 1);

            encode_plane(fs, VAR_6->data[2] + VAR_7 * VAR_10 + VAR_11 * VAR_6->linesize[2],

                         VAR_8, VAR_9, VAR_6->linesize[2], 1);

        }

        if (fs->transparency)

            encode_plane(fs, VAR_6->data[3] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[3], VAR_2,

                         VAR_3, VAR_6->linesize[3], 2);

    } else {

        const uint8_t *VAR_12[3] = { VAR_6->data[0] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[0],

                                     VAR_6->data[1] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[1],

                                     VAR_6->data[2] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[2] };

        encode_rgb_frame(fs, VAR_12, VAR_2, VAR_3, VAR_6->linesize);

    }

    emms_c();



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1)
{ FFV1Context *fs  = *(void **)VAR_1; FFV1Context *f   = fs->avctx->priv_data; int VAR_2        = fs->slice_width; int VAR_3       = fs->slice_height; int VAR_4            = fs->slice_x; int VAR_5            = fs->slice_y; const AVFrame *const VAR_6 = f->frame; const int VAR_7     = (av_pix_fmt_desc_get(VAR_0->pix_fmt)->flags & AV_PIX_FMT_FLAG_PLANAR)
? (f->bits_per_raw_sample > 8) + 1
: 4; if (f->key_frame)
ffv1_clear_slice_state(f, fs); if (f->version > 2) { encode_slice_header(f, fs); } if (!fs->ac) { if (f->version > 2)
put_rac(&fs->VAR_0, (uint8_t[]) { 129 }, 0); fs->ac_byte_count = f->version > 2 || (!VAR_4 && !VAR_5) ? ff_rac_terminate( &fs->VAR_0) : 0; init_put_bits(&fs->pb, fs->VAR_0.bytestream_start + fs->ac_byte_count,
fs->VAR_0.bytestream_end - fs->VAR_0.bytestream_start - fs->ac_byte_count); } if (f->colorspace == 0) { const int VAR_8  = -((-VAR_2) >> f->chroma_h_shift); const int VAR_9 = -((-VAR_3) >> f->chroma_v_shift); const int VAR_10            = VAR_4 >> f->chroma_h_shift; const int VAR_11            = VAR_5 >> f->chroma_v_shift; encode_plane(fs, VAR_6->data[0] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[0],
VAR_2, VAR_3, VAR_6->linesize[0], 0); if (f->chroma_planes) { encode_plane(fs, VAR_6->data[1] + VAR_7 * VAR_10 + VAR_11 * VAR_6->linesize[1],
VAR_8, VAR_9, VAR_6->linesize[1], 1); encode_plane(fs, VAR_6->data[2] + VAR_7 * VAR_10 + VAR_11 * VAR_6->linesize[2],
VAR_8, VAR_9, VAR_6->linesize[2], 1); } if (fs->transparency)
encode_plane(fs, VAR_6->data[3] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[3], VAR_2,
VAR_3, VAR_6->linesize[3], 2); } else { const uint8_t *VAR_12[3] = { VAR_6->data[0] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[0], VAR_6->data[1] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[1],
VAR_6->data[2] + VAR_7 * VAR_4 + VAR_5 * VAR_6->linesize[2] }; encode_rgb_frame(fs, VAR_12, VAR_2, VAR_3, VAR_6->linesize); } emms_c(); return 0; }