static void vc1_mc_4mv_chroma4(VC1Context *v)

{

    MpegEncContext *s = &v->s;

    DSPContext *dsp = &v->s.dsp;

    uint8_t *srcU, *srcV;

    int uvsrc_x, uvsrc_y;

    int uvmx_field[4], uvmy_field[4];

    int i, off, tx, ty;

    int fieldmv = v->blk_mv_type[s->block_index[0]];

    static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };

    int v_dist = fieldmv ? 1 : 4; // vertical offset for lower sub-blocks

    int v_edge_pos = s->v_edge_pos >> 1;



    if (!v->s.last_picture.f.data[0])

        return;

    if (s->flags & CODEC_FLAG_GRAY)

        return;



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

        tx = s->mv[0][i][0];

        uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;

        ty = s->mv[0][i][1];

        if (fieldmv)

            uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];

        else

            uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;

    }



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

        off = (i & 1) * 4 + ((i & 2) ? v_dist * s->uvlinesize : 0);

        uvsrc_x = s->mb_x * 8 +  (i & 1) * 4           + (uvmx_field[i] >> 2);

        uvsrc_y = s->mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);

        // FIXME: implement proper pull-back (see vc1cropmv.c, vc1CROPMV_ChromaPullBack())

        uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width  >> 1);

        uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);

        srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;

        srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;

        uvmx_field[i] = (uvmx_field[i] & 3) << 1;

        uvmy_field[i] = (uvmy_field[i] & 3) << 1;



        if (fieldmv && !(uvsrc_y & 1))

            v_edge_pos--;

        if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)

            uvsrc_y--;

        if ((v->mv_mode == MV_PMODE_INTENSITY_COMP)

            || s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)

            || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5

            || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {

            s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize,

                                    5, (5 << fieldmv), uvsrc_x, uvsrc_y,

                                    s->h_edge_pos >> 1, v_edge_pos);

            s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,

                                    5, (5 << fieldmv), uvsrc_x, uvsrc_y,

                                    s->h_edge_pos >> 1, v_edge_pos);

            srcU = s->edge_emu_buffer;

            srcV = s->edge_emu_buffer + 16;



            /* if we deal with intensity compensation we need to scale source blocks */

            if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {

                int i, j;

                uint8_t *src, *src2;



                src  = srcU;

                src2 = srcV;

                for (j = 0; j < 5; j++) {

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

                        src[i]  = v->lutuv[src[i]];

                        src2[i] = v->lutuv[src2[i]];

                    }

                    src  += s->uvlinesize << 1;

                    src2 += s->uvlinesize << 1;

                }

            }

        }

        if (!v->rnd) {

            dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

            dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

        } else {

            v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

            v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

        }

    }

}

static void vc1_mc_4mv_chroma4(VC1Context *v)

{

    MpegEncContext *s = &v->s;

    DSPContext *dsp = &v->s.dsp;

    uint8_t *srcU, *srcV;

    int uvsrc_x, uvsrc_y;

    int uvmx_field[4], uvmy_field[4];

    int i, off, tx, ty;

    int fieldmv = v->blk_mv_type[s->block_index[0]];

    static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };

    int v_dist = fieldmv ? 1 : 4; 

    int v_edge_pos = s->v_edge_pos >> 1;



    if (!v->s.last_picture.f.data[0])

        return;

    if (s->flags & CODEC_FLAG_GRAY)

        return;



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

        tx = s->mv[0][i][0];

        uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1;

        ty = s->mv[0][i][1];

        if (fieldmv)

            uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF];

        else

            uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1;

    }



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

        off = (i & 1) * 4 + ((i & 2) ? v_dist * s->uvlinesize : 0);

        uvsrc_x = s->mb_x * 8 +  (i & 1) * 4           + (uvmx_field[i] >> 2);

        uvsrc_y = s->mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2);

        

        uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width  >> 1);

        uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);

        srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;

        srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;

        uvmx_field[i] = (uvmx_field[i] & 3) << 1;

        uvmy_field[i] = (uvmy_field[i] & 3) << 1;



        if (fieldmv && !(uvsrc_y & 1))

            v_edge_pos--;

        if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2)

            uvsrc_y--;

        if ((v->mv_mode == MV_PMODE_INTENSITY_COMP)

            || s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)

            || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5

            || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {

            s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize,

                                    5, (5 << fieldmv), uvsrc_x, uvsrc_y,

                                    s->h_edge_pos >> 1, v_edge_pos);

            s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,

                                    5, (5 << fieldmv), uvsrc_x, uvsrc_y,

                                    s->h_edge_pos >> 1, v_edge_pos);

            srcU = s->edge_emu_buffer;

            srcV = s->edge_emu_buffer + 16;



            

            if (v->mv_mode == MV_PMODE_INTENSITY_COMP) {

                int i, j;

                uint8_t *src, *src2;



                src  = srcU;

                src2 = srcV;

                for (j = 0; j < 5; j++) {

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

                        src[i]  = v->lutuv[src[i]];

                        src2[i] = v->lutuv[src2[i]];

                    }

                    src  += s->uvlinesize << 1;

                    src2 += s->uvlinesize << 1;

                }

            }

        }

        if (!v->rnd) {

            dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

            dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

        } else {

            v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

            v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]);

        }

    }

}

            v_edge_pos--;
static void FUNC_0(VC1Context *VAR_0)

{

    MpegEncContext *s = &VAR_0->s;

    DSPContext *dsp = &VAR_0->s.dsp;

    uint8_t *srcU, *srcV;

    int VAR_1, VAR_2;

    int VAR_3[4], VAR_4[4];

    int VAR_13, VAR_6, VAR_7, VAR_8;

    int VAR_9 = VAR_0->blk_mv_type[s->block_index[0]];

    static const int VAR_10[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 };

    int VAR_11 = VAR_9 ? 1 : 4; 

    int VAR_12 = s->VAR_12 >> 1;



    if (!VAR_0->s.last_picture.f.data[0])

        return;

    if (s->flags & CODEC_FLAG_GRAY)

        return;



    for (VAR_13 = 0; VAR_13 < 4; VAR_13++) {

        VAR_7 = s->mv[0][VAR_13][0];

        VAR_3[VAR_13] = (VAR_7 + ((VAR_7 & 3) == 3)) >> 1;

        VAR_8 = s->mv[0][VAR_13][1];

        if (VAR_9)

            VAR_4[VAR_13] = (VAR_8 >> 4) * 8 + VAR_10[VAR_8 & 0xF];

        else

            VAR_4[VAR_13] = (VAR_8 + ((VAR_8 & 3) == 3)) >> 1;

    }



    for (VAR_13 = 0; VAR_13 < 4; VAR_13++) {

        VAR_6 = (VAR_13 & 1) * 4 + ((VAR_13 & 2) ? VAR_11 * s->uvlinesize : 0);

        VAR_1 = s->mb_x * 8 +  (VAR_13 & 1) * 4           + (VAR_3[VAR_13] >> 2);

        VAR_2 = s->mb_y * 8 + ((VAR_13 & 2) ? VAR_11 : 0) + (VAR_4[VAR_13] >> 2);

        

        VAR_1 = av_clip(VAR_1, -8, s->avctx->coded_width  >> 1);

        VAR_2 = av_clip(VAR_2, -8, s->avctx->coded_height >> 1);

        srcU = s->last_picture.f.data[1] + VAR_2 * s->uvlinesize + VAR_1;

        srcV = s->last_picture.f.data[2] + VAR_2 * s->uvlinesize + VAR_1;

        VAR_3[VAR_13] = (VAR_3[VAR_13] & 3) << 1;

        VAR_4[VAR_13] = (VAR_4[VAR_13] & 3) << 1;



        if (VAR_9 && !(VAR_2 & 1))

            VAR_12--;

        if (VAR_9 && (VAR_2 & 1) && VAR_2 < 2)

            VAR_2--;

        if ((VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP)

            || s->h_edge_pos < 10 || VAR_12 < (5 << VAR_9)

            || (unsigned)VAR_1 > (s->h_edge_pos >> 1) - 5

            || (unsigned)VAR_2 > VAR_12 - (5 << VAR_9)) {

            s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize,

                                    5, (5 << VAR_9), VAR_1, VAR_2,

                                    s->h_edge_pos >> 1, VAR_12);

            s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,

                                    5, (5 << VAR_9), VAR_1, VAR_2,

                                    s->h_edge_pos >> 1, VAR_12);

            srcU = s->edge_emu_buffer;

            srcV = s->edge_emu_buffer + 16;



            

            if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) {

                int VAR_13, VAR_13;

                uint8_t *src, *src2;



                src  = srcU;

                src2 = srcV;

                for (VAR_13 = 0; VAR_13 < 5; VAR_13++) {

                    for (VAR_13 = 0; VAR_13 < 5; VAR_13++) {

                        src[VAR_13]  = VAR_0->lutuv[src[VAR_13]];

                        src2[VAR_13] = VAR_0->lutuv[src2[VAR_13]];

                    }

                    src  += s->uvlinesize << 1;

                    src2 += s->uvlinesize << 1;

                }

            }

        }

        if (!VAR_0->rnd) {

            dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + VAR_6, srcU, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]);

            dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + VAR_6, srcV, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]);

        } else {

            VAR_0->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + VAR_6, srcU, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]);

            VAR_0->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + VAR_6, srcV, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]);

        }

    }

}

static void FUNC_0(VC1Context *VAR_0)
{ MpegEncContext *s = &VAR_0->s; DSPContext *dsp = &VAR_0->s.dsp; uint8_t *srcU, *srcV; int VAR_1, VAR_2; int VAR_3[4], VAR_4[4]; int VAR_13, VAR_6, VAR_7, VAR_8; int VAR_9 = VAR_0->blk_mv_type[s->block_index[0]]; static const int VAR_10[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 }; int VAR_11 = VAR_9 ? 1 : 4; int VAR_12 = s->VAR_12 >> 1; if (!VAR_0->s.last_picture.f.data[0])
return; if (s->flags & CODEC_FLAG_GRAY)
return; for (VAR_13 = 0; VAR_13 < 4; VAR_13++) { VAR_7 = s->mv[0][VAR_13][0]; VAR_3[VAR_13] = (VAR_7 + ((VAR_7 & 3) == 3)) >> 1; VAR_8 = s->mv[0][VAR_13][1]; if (VAR_9)
VAR_4[VAR_13] = (VAR_8 >> 4) * 8 + VAR_10[VAR_8 & 0xF]; else
VAR_4[VAR_13] = (VAR_8 + ((VAR_8 & 3) == 3)) >> 1; } for (VAR_13 = 0; VAR_13 < 4; VAR_13++) { VAR_6 = (VAR_13 & 1) * 4 + ((VAR_13 & 2) ? VAR_11 * s->uvlinesize : 0); VAR_1 = s->mb_x * 8 +  (VAR_13 & 1) * 4           + (VAR_3[VAR_13] >> 2); VAR_2 = s->mb_y * 8 + ((VAR_13 & 2) ? VAR_11 : 0) + (VAR_4[VAR_13] >> 2); VAR_1 = av_clip(VAR_1, -8, s->avctx->coded_width  >> 1); VAR_2 = av_clip(VAR_2, -8, s->avctx->coded_height >> 1); srcU = s->last_picture.f.data[1] + VAR_2 * s->uvlinesize + VAR_1; srcV = s->last_picture.f.data[2] + VAR_2 * s->uvlinesize + VAR_1; VAR_3[VAR_13] = (VAR_3[VAR_13] & 3) << 1; VAR_4[VAR_13] = (VAR_4[VAR_13] & 3) << 1; if (VAR_9 && !(VAR_2 & 1))
VAR_12--; if (VAR_9 && (VAR_2 & 1) && VAR_2 < 2)
VAR_2--; if ((VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP)
|| s->h_edge_pos < 10 || VAR_12 < (5 << VAR_9)
|| (unsigned)VAR_1 > (s->h_edge_pos >> 1) - 5
|| (unsigned)VAR_2 > VAR_12 - (5 << VAR_9)) { s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize,
5, (5 << VAR_9), VAR_1, VAR_2,
s->h_edge_pos >> 1, VAR_12); s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize,
5, (5 << VAR_9), VAR_1, VAR_2,
s->h_edge_pos >> 1, VAR_12); srcU = s->edge_emu_buffer; srcV = s->edge_emu_buffer + 16; if (VAR_0->mv_mode == MV_PMODE_INTENSITY_COMP) { int VAR_13, VAR_13; uint8_t *src, *src2; src  = srcU; src2 = srcV; for (VAR_13 = 0; VAR_13 < 5; VAR_13++) { for (VAR_13 = 0; VAR_13 < 5; VAR_13++) { src[VAR_13]  = VAR_0->lutuv[src[VAR_13]]; src2[VAR_13] = VAR_0->lutuv[src2[VAR_13]]; } src  += s->uvlinesize << 1; src2 += s->uvlinesize << 1; } } } if (!VAR_0->rnd) { dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + VAR_6, srcU, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]); dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + VAR_6, srcV, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]); } else { VAR_0->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + VAR_6, srcU, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]); VAR_0->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + VAR_6, srcV, s->uvlinesize << VAR_9, 4, VAR_3[VAR_13], VAR_4[VAR_13]); } } }