uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>1)) + (s->mb_y*16 + (my4>>1))*s->linesize + offset;
uint8_t *ref= ref_data[0] + (mx4>>1) + (my4>>1)*stride + offset;
static inline int h263_mv4_search(MpegEncContext *s, int xmin, int ymin, int xmax, int ymax, int mx, int my, int shift){    int block;    int P[10][2];    int dmin_sum=0, mx4_sum=0, my4_sum=0;    uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;    int same=1;    for(block=0; block<4; block++){        int mx4, my4;        int pred_x4, pred_y4;        int dmin4;        static const int off[4]= {2, 1, 1, -1};        const int mot_stride = s->block_wrap[0];        const int mot_xy = s->block_index[block];//        const int block_x= (block&1);//        const int block_y= (block>>1);#if 1 // this saves us a bit of cliping work and shouldnt affect compression in a negative way        const int rel_xmin4= xmin;        const int rel_xmax4= xmax;        const int rel_ymin4= ymin;        const int rel_ymax4= ymax;#else        const int rel_xmin4= xmin - block_x*8;        const int rel_xmax4= xmax - block_x*8 + 8;        const int rel_ymin4= ymin - block_y*8;        const int rel_ymax4= ymax - block_y*8 + 8;#endif        P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];        P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];        if(P_LEFT[0]       > (rel_xmax4<<shift)) P_LEFT[0]       = (rel_xmax4<<shift);        /* special case for first line */        if (s->mb_y == 0 && block<2) {            pred_x4= P_LEFT[0];            pred_y4= P_LEFT[1];        } else {            P_TOP[0]      = s->current_picture.motion_val[0][mot_xy - mot_stride             ][0];            P_TOP[1]      = s->current_picture.motion_val[0][mot_xy - mot_stride             ][1];            P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];            P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];            if(P_TOP[1]      > (rel_ymax4<<shift)) P_TOP[1]     = (rel_ymax4<<shift);            if(P_TOPRIGHT[0] < (rel_xmin4<<shift)) P_TOPRIGHT[0]= (rel_xmin4<<shift);            if(P_TOPRIGHT[0] > (rel_xmax4<<shift)) P_TOPRIGHT[0]= (rel_xmax4<<shift);            if(P_TOPRIGHT[1] > (rel_ymax4<<shift)) P_TOPRIGHT[1]= (rel_ymax4<<shift);                P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);            P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);//            if(s->out_format == FMT_H263){                pred_x4 = P_MEDIAN[0];                pred_y4 = P_MEDIAN[1];#if 0            }else { /* mpeg1 at least */                pred_x4= P_LEFT[0];                pred_y4= P_LEFT[1];            }#endif        }        P_MV1[0]= mx;        P_MV1[1]= my;        dmin4 = s->me.motion_search[1](s, block, &mx4, &my4, P, pred_x4, pred_y4, rel_xmin4, rel_ymin4, rel_xmax4, rel_ymax4,                                        &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);        dmin4= s->me.sub_motion_search(s, &mx4, &my4, dmin4, rel_xmin4, rel_ymin4, rel_xmax4, rel_ymax4, 					  pred_x4, pred_y4, &s->last_picture, block, 1, mv_penalty);                if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){            int dxy;            const int offset= ((block&1) + (block>>1)*s->linesize)*8;            uint8_t *dest_y = s->me.scratchpad + offset;            if(s->quarter_sample){                uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>2)) + (s->mb_y*16 + (my4>>2))*s->linesize + offset;                dxy = ((my4 & 3) << 2) | (mx4 & 3);                if(s->no_rounding)                    s->dsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y   , ref    , s->linesize);                else                    s->dsp.put_qpel_pixels_tab       [1][dxy](dest_y   , ref    , s->linesize);            }else{                uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>1)) + (s->mb_y*16 + (my4>>1))*s->linesize + offset;                dxy = ((my4 & 1) << 1) | (mx4 & 1);                if(s->no_rounding)                    s->dsp.put_no_rnd_pixels_tab[1][dxy](dest_y    , ref    , s->linesize, 8);                else                    s->dsp.put_pixels_tab       [1][dxy](dest_y    , ref    , s->linesize, 8);            }            dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*s->me.mb_penalty_factor;        }else            dmin_sum+= dmin4;        if(s->quarter_sample){            mx4_sum+= mx4/2;            my4_sum+= my4/2;        }else{            mx4_sum+= mx4;            my4_sum+= my4;        }                    s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4;        s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4;        if(mx4 != mx || my4 != my) same=0;    }        if(same)        return INT_MAX;        if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){        dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*s->linesize, s->me.scratchpad, s->linesize);    }        if(s->avctx->mb_cmp&FF_CMP_CHROMA){        int dxy;        int mx, my;        int offset;        mx= ff_h263_round_chroma(mx4_sum);        my= ff_h263_round_chroma(my4_sum);        dxy = ((my & 1) << 1) | (mx & 1);                offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;               if(s->no_rounding){            s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);            s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);        }else{            s->dsp.put_pixels_tab       [1][dxy](s->me.scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);            s->dsp.put_pixels_tab       [1][dxy](s->me.scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);        }        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad  , s->uvlinesize);        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad+8, s->uvlinesize);    }    switch(s->avctx->mb_cmp&0xFF){    /*case FF_CMP_SSE:        return dmin_sum+ 32*s->qscale*s->qscale;*/    case FF_CMP_RD:        return dmin_sum;    default:        return dmin_sum+ 11*s->me.mb_penalty_factor;    }}