static inline void MPV_motion_lowres(MpegEncContext *s,

                              uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,

                              int dir, uint8_t **ref_picture,

                              h264_chroma_mc_func *pix_op)

{

    int mx, my;

    int mb_x, mb_y, i;

    const int lowres= s->avctx->lowres;

    const int block_s= 8>>lowres;



    mb_x = s->mb_x;

    mb_y = s->mb_y;



    switch(s->mv_type) {

    case MV_TYPE_16X16:

        mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                    0, 0, 0,

                    ref_picture, pix_op,

                    s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s);

        break;

    case MV_TYPE_8X8:

        mx = 0;

        my = 0;

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

                hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s,

                            ref_picture[0], 0, 0,

                            (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s,

                            s->width, s->height, s->linesize,

                            s->h_edge_pos >> lowres, s->v_edge_pos >> lowres,

                            block_s, block_s, pix_op,

                            s->mv[dir][i][0], s->mv[dir][i][1]);



                mx += s->mv[dir][i][0];

                my += s->mv[dir][i][1];

            }



        if(!(s->flags&CODEC_FLAG_GRAY))

            chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my);

        break;

    case MV_TYPE_FIELD:

        if (s->picture_structure == PICT_FRAME) {

            /* top field */

            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        1, 0, s->field_select[dir][0],

                        ref_picture, pix_op,

                        s->mv[dir][0][0], s->mv[dir][0][1], block_s);

            /* bottom field */

            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        1, 1, s->field_select[dir][1],

                        ref_picture, pix_op,

                        s->mv[dir][1][0], s->mv[dir][1][1], block_s);

        } else {

            if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){

                ref_picture= s->current_picture_ptr->data;

            }



            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        0, 0, s->field_select[dir][0],

                        ref_picture, pix_op,

                        s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s);

        }

        break;

    case MV_TYPE_16X8:

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

            uint8_t ** ref2picture;



            if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){

                ref2picture= ref_picture;

            }else{

                ref2picture= s->current_picture_ptr->data;

            }



            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        0, 0, s->field_select[dir][i],

                        ref2picture, pix_op,

                        s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s);



            dest_y += 2*block_s*s->linesize;

            dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;

            dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;

        }

        break;

    case MV_TYPE_DMV:

        if(s->picture_structure == PICT_FRAME){

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

                int j;

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

                    mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                                1, j, j^i,

                                ref_picture, pix_op,

                                s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s);

                }

                pix_op = s->dsp.avg_h264_chroma_pixels_tab;

            }

        }else{

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

                mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                            0, 0, s->picture_structure != i+1,

                            ref_picture, pix_op,

                            s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s);



                // after put we make avg of the same block

                pix_op = s->dsp.avg_h264_chroma_pixels_tab;



                //opposite parity is always in the same frame if this is second field

                if(!s->first_field){

                    ref_picture = s->current_picture_ptr->data;

                }

            }

        }

    break;

    default: assert(0);

    }

}

static inline void MPV_motion_lowres(MpegEncContext *s,

                              uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,

                              int dir, uint8_t **ref_picture,

                              h264_chroma_mc_func *pix_op)

{

    int mx, my;

    int mb_x, mb_y, i;

    const int lowres= s->avctx->lowres;

    const int block_s= 8>>lowres;



    mb_x = s->mb_x;

    mb_y = s->mb_y;



    switch(s->mv_type) {

    case MV_TYPE_16X16:

        mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                    0, 0, 0,

                    ref_picture, pix_op,

                    s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s);

        break;

    case MV_TYPE_8X8:

        mx = 0;

        my = 0;

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

                hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s,

                            ref_picture[0], 0, 0,

                            (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s,

                            s->width, s->height, s->linesize,

                            s->h_edge_pos >> lowres, s->v_edge_pos >> lowres,

                            block_s, block_s, pix_op,

                            s->mv[dir][i][0], s->mv[dir][i][1]);



                mx += s->mv[dir][i][0];

                my += s->mv[dir][i][1];

            }



        if(!(s->flags&CODEC_FLAG_GRAY))

            chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my);

        break;

    case MV_TYPE_FIELD:

        if (s->picture_structure == PICT_FRAME) {

            

            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        1, 0, s->field_select[dir][0],

                        ref_picture, pix_op,

                        s->mv[dir][0][0], s->mv[dir][0][1], block_s);

            

            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        1, 1, s->field_select[dir][1],

                        ref_picture, pix_op,

                        s->mv[dir][1][0], s->mv[dir][1][1], block_s);

        } else {

            if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){

                ref_picture= s->current_picture_ptr->data;

            }



            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        0, 0, s->field_select[dir][0],

                        ref_picture, pix_op,

                        s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s);

        }

        break;

    case MV_TYPE_16X8:

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

            uint8_t ** ref2picture;



            if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){

                ref2picture= ref_picture;

            }else{

                ref2picture= s->current_picture_ptr->data;

            }



            mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                        0, 0, s->field_select[dir][i],

                        ref2picture, pix_op,

                        s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s);



            dest_y += 2*block_s*s->linesize;

            dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;

            dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize;

        }

        break;

    case MV_TYPE_DMV:

        if(s->picture_structure == PICT_FRAME){

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

                int j;

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

                    mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                                1, j, j^i,

                                ref_picture, pix_op,

                                s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s);

                }

                pix_op = s->dsp.avg_h264_chroma_pixels_tab;

            }

        }else{

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

                mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,

                            0, 0, s->picture_structure != i+1,

                            ref_picture, pix_op,

                            s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s);



                

                pix_op = s->dsp.avg_h264_chroma_pixels_tab;



                

                if(!s->first_field){

                    ref_picture = s->current_picture_ptr->data;

                }

            }

        }

    break;

    default: assert(0);

    }

}

static inline void FUNC_0(MpegEncContext *VAR_0,

                              uint8_t *VAR_1, uint8_t *VAR_2, uint8_t *VAR_3,

                              int VAR_4, uint8_t **VAR_5,

                              h264_chroma_mc_func *VAR_6)

{

    int VAR_7, VAR_8;

    int VAR_9, VAR_10, VAR_11;

    const int VAR_12= VAR_0->avctx->VAR_12;

    const int VAR_13= 8>>VAR_12;



    VAR_9 = VAR_0->VAR_9;

    VAR_10 = VAR_0->VAR_10;



    switch(VAR_0->mv_type) {

    case MV_TYPE_16X16:

        mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                    0, 0, 0,

                    VAR_5, VAR_6,

                    VAR_0->mv[VAR_4][0][0], VAR_0->mv[VAR_4][0][1], 2*VAR_13);

        break;

    case MV_TYPE_8X8:

        VAR_7 = 0;

        VAR_8 = 0;

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

                hpel_motion_lowres(VAR_0, VAR_1 + ((VAR_11 & 1) + (VAR_11 >> 1) * VAR_0->linesize)*VAR_13,

                            VAR_5[0], 0, 0,

                            (2*VAR_9 + (VAR_11 & 1))*VAR_13, (2*VAR_10 + (VAR_11 >>1))*VAR_13,

                            VAR_0->width, VAR_0->height, VAR_0->linesize,

                            VAR_0->h_edge_pos >> VAR_12, VAR_0->v_edge_pos >> VAR_12,

                            VAR_13, VAR_13, VAR_6,

                            VAR_0->mv[VAR_4][VAR_11][0], VAR_0->mv[VAR_4][VAR_11][1]);



                VAR_7 += VAR_0->mv[VAR_4][VAR_11][0];

                VAR_8 += VAR_0->mv[VAR_4][VAR_11][1];

            }



        if(!(VAR_0->flags&CODEC_FLAG_GRAY))

            chroma_4mv_motion_lowres(VAR_0, VAR_2, VAR_3, VAR_5, VAR_6, VAR_7, VAR_8);

        break;

    case MV_TYPE_FIELD:

        if (VAR_0->picture_structure == PICT_FRAME) {

            

            mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                        1, 0, VAR_0->field_select[VAR_4][0],

                        VAR_5, VAR_6,

                        VAR_0->mv[VAR_4][0][0], VAR_0->mv[VAR_4][0][1], VAR_13);

            

            mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                        1, 1, VAR_0->field_select[VAR_4][1],

                        VAR_5, VAR_6,

                        VAR_0->mv[VAR_4][1][0], VAR_0->mv[VAR_4][1][1], VAR_13);

        } else {

            if(VAR_0->picture_structure != VAR_0->field_select[VAR_4][0] + 1 && VAR_0->pict_type != B_TYPE && !VAR_0->first_field){

                VAR_5= VAR_0->current_picture_ptr->data;

            }



            mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                        0, 0, VAR_0->field_select[VAR_4][0],

                        VAR_5, VAR_6,

                        VAR_0->mv[VAR_4][0][0], VAR_0->mv[VAR_4][0][1], 2*VAR_13);

        }

        break;

    case MV_TYPE_16X8:

        for(VAR_11=0; VAR_11<2; VAR_11++){

            uint8_t ** ref2picture;



            if(VAR_0->picture_structure == VAR_0->field_select[VAR_4][VAR_11] + 1 || VAR_0->pict_type == B_TYPE || VAR_0->first_field){

                ref2picture= VAR_5;

            }else{

                ref2picture= VAR_0->current_picture_ptr->data;

            }



            mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                        0, 0, VAR_0->field_select[VAR_4][VAR_11],

                        ref2picture, VAR_6,

                        VAR_0->mv[VAR_4][VAR_11][0], VAR_0->mv[VAR_4][VAR_11][1] + 2*VAR_13*VAR_11, VAR_13);



            VAR_1 += 2*VAR_13*VAR_0->linesize;

            VAR_2+= (2*VAR_13>>VAR_0->chroma_y_shift)*VAR_0->uvlinesize;

            VAR_3+= (2*VAR_13>>VAR_0->chroma_y_shift)*VAR_0->uvlinesize;

        }

        break;

    case MV_TYPE_DMV:

        if(VAR_0->picture_structure == PICT_FRAME){

            for(VAR_11=0; VAR_11<2; VAR_11++){

                int VAR_14;

                for(VAR_14=0; VAR_14<2; VAR_14++){

                    mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                                1, VAR_14, VAR_14^VAR_11,

                                VAR_5, VAR_6,

                                VAR_0->mv[VAR_4][2*VAR_11 + VAR_14][0], VAR_0->mv[VAR_4][2*VAR_11 + VAR_14][1], VAR_13);

                }

                VAR_6 = VAR_0->dsp.avg_h264_chroma_pixels_tab;

            }

        }else{

            for(VAR_11=0; VAR_11<2; VAR_11++){

                mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,

                            0, 0, VAR_0->picture_structure != VAR_11+1,

                            VAR_5, VAR_6,

                            VAR_0->mv[VAR_4][2*VAR_11][0],VAR_0->mv[VAR_4][2*VAR_11][1],2*VAR_13);



                

                VAR_6 = VAR_0->dsp.avg_h264_chroma_pixels_tab;



                

                if(!VAR_0->first_field){

                    VAR_5 = VAR_0->current_picture_ptr->data;

                }

            }

        }

    break;

    default: assert(0);

    }

}

static inline void FUNC_0(MpegEncContext *VAR_0,
uint8_t *VAR_1, uint8_t *VAR_2, uint8_t *VAR_3,
int VAR_4, uint8_t **VAR_5,
h264_chroma_mc_func *VAR_6)
{ int VAR_7, VAR_8; int VAR_9, VAR_10, VAR_11; const int VAR_12= VAR_0->avctx->VAR_12; const int VAR_13= 8>>VAR_12; VAR_9 = VAR_0->VAR_9; VAR_10 = VAR_0->VAR_10; switch(VAR_0->mv_type) { case MV_TYPE_16X16:
mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
0, 0, 0,
VAR_5, VAR_6,
VAR_0->mv[VAR_4][0][0], VAR_0->mv[VAR_4][0][1], 2*VAR_13); break; case MV_TYPE_8X8:
VAR_7 = 0; VAR_8 = 0; for(VAR_11=0;VAR_11<4;VAR_11++) { hpel_motion_lowres(VAR_0, VAR_1 + ((VAR_11 & 1) + (VAR_11 >> 1) * VAR_0->linesize)*VAR_13,
VAR_5[0], 0, 0,
(2*VAR_9 + (VAR_11 & 1))*VAR_13, (2*VAR_10 + (VAR_11 >>1))*VAR_13,
VAR_0->width, VAR_0->height, VAR_0->linesize,
VAR_0->h_edge_pos >> VAR_12, VAR_0->v_edge_pos >> VAR_12,
VAR_13, VAR_13, VAR_6,
VAR_0->mv[VAR_4][VAR_11][0], VAR_0->mv[VAR_4][VAR_11][1]); VAR_7 += VAR_0->mv[VAR_4][VAR_11][0]; VAR_8 += VAR_0->mv[VAR_4][VAR_11][1]; } if(!(VAR_0->flags&CODEC_FLAG_GRAY))
chroma_4mv_motion_lowres(VAR_0, VAR_2, VAR_3, VAR_5, VAR_6, VAR_7, VAR_8); break; case MV_TYPE_FIELD:
if (VAR_0->picture_structure == PICT_FRAME) { mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
1, 0, VAR_0->field_select[VAR_4][0],
VAR_5, VAR_6,
VAR_0->mv[VAR_4][0][0], VAR_0->mv[VAR_4][0][1], VAR_13); mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
1, 1, VAR_0->field_select[VAR_4][1],
VAR_5, VAR_6,
VAR_0->mv[VAR_4][1][0], VAR_0->mv[VAR_4][1][1], VAR_13); } else { if(VAR_0->picture_structure != VAR_0->field_select[VAR_4][0] + 1 && VAR_0->pict_type != B_TYPE && !VAR_0->first_field){ VAR_5= VAR_0->current_picture_ptr->data; } mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
0, 0, VAR_0->field_select[VAR_4][0],
VAR_5, VAR_6,
VAR_0->mv[VAR_4][0][0], VAR_0->mv[VAR_4][0][1], 2*VAR_13); } break; case MV_TYPE_16X8:
for(VAR_11=0; VAR_11<2; VAR_11++){ uint8_t ** ref2picture; if(VAR_0->picture_structure == VAR_0->field_select[VAR_4][VAR_11] + 1 || VAR_0->pict_type == B_TYPE || VAR_0->first_field){ ref2picture= VAR_5; }else{ ref2picture= VAR_0->current_picture_ptr->data; } mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
0, 0, VAR_0->field_select[VAR_4][VAR_11],
ref2picture, VAR_6,
VAR_0->mv[VAR_4][VAR_11][0], VAR_0->mv[VAR_4][VAR_11][1] + 2*VAR_13*VAR_11, VAR_13); VAR_1 += 2*VAR_13*VAR_0->linesize; VAR_2+= (2*VAR_13>>VAR_0->chroma_y_shift)*VAR_0->uvlinesize; VAR_3+= (2*VAR_13>>VAR_0->chroma_y_shift)*VAR_0->uvlinesize; } break; case MV_TYPE_DMV:
if(VAR_0->picture_structure == PICT_FRAME){ for(VAR_11=0; VAR_11<2; VAR_11++){ int VAR_14; for(VAR_14=0; VAR_14<2; VAR_14++){ mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
1, VAR_14, VAR_14^VAR_11,
VAR_5, VAR_6,
VAR_0->mv[VAR_4][2*VAR_11 + VAR_14][0], VAR_0->mv[VAR_4][2*VAR_11 + VAR_14][1], VAR_13); } VAR_6 = VAR_0->dsp.avg_h264_chroma_pixels_tab; } }else{ for(VAR_11=0; VAR_11<2; VAR_11++){ mpeg_motion_lowres(VAR_0, VAR_1, VAR_2, VAR_3,
0, 0, VAR_0->picture_structure != VAR_11+1,
VAR_5, VAR_6,
VAR_0->mv[VAR_4][2*VAR_11][0],VAR_0->mv[VAR_4][2*VAR_11][1],2*VAR_13); VAR_6 = VAR_0->dsp.avg_h264_chroma_pixels_tab; if(!VAR_0->first_field){ VAR_5 = VAR_0->current_picture_ptr->data; } } } break; default: assert(0); } }