P_LAST_RIGHT[0]  = mv_table[mot_xy + 1][0]; P_LAST_RIGHT[1]  = mv_table[mot_xy + 1][1]; P_LAST_BOTTOM[0] = mv_table[mot_xy + mot_stride][0]; P_LAST_BOTTOM[1] = mv_table[mot_xy + mot_stride][1];
static inline int direct_search(MpegEncContext * s,                                int mb_x, int mb_y){    int P[10][2];    const int mot_stride = s->mb_width + 2;    const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1;    const int shift= 1+s->quarter_sample;    int dmin, i;    const int time_pp= s->pp_time;    const int time_pb= s->pb_time;    int mx, my, xmin, xmax, ymin, ymax;    int16_t (*mv_table)[2]= s->b_direct_mv_table;    uint16_t * const mv_penalty= s->me.mv_penalty[1] + MAX_MV;        P_LAST[0]        = mv_table[mot_xy    ][0];    P_LAST[1]        = mv_table[mot_xy    ][1];    P_LEFT[0]        = mv_table[mot_xy - 1][0];    P_LEFT[1]        = mv_table[mot_xy - 1][1];    P_LAST_RIGHT[0]  = mv_table[mot_xy + 1][0];    P_LAST_RIGHT[1]  = mv_table[mot_xy + 1][1];    P_LAST_BOTTOM[0] = mv_table[mot_xy + mot_stride][0];    P_LAST_BOTTOM[1] = mv_table[mot_xy + mot_stride][1];/*    if(P_LEFT[0]       > (rel_xmax<<shift)) P_LEFT[0]       = (rel_xmax<<shift);    if(P_LAST_RIGHT[0] < (rel_xmin<<shift)) P_LAST_RIGHT[0] = (rel_xmin<<shift);    if(P_LAST_BOTTOM[1]< (rel_ymin<<shift)) P_LAST_BOTTOM[1]= (rel_ymin<<shift);*/    /* special case for first line */    if ((mb_y == 0 || s->first_slice_line)) {    } else {        P_TOP[0] = mv_table[mot_xy - mot_stride             ][0];        P_TOP[1] = mv_table[mot_xy - mot_stride             ][1];        P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1         ][0];        P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1         ][1];            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]);    }    ymin= xmin=(-32)>>shift;    ymax= xmax=   31>>shift;    if(s->co_located_type_table[mb_x + mb_y*s->mb_width]==CO_LOCATED_TYPE_4MV){        s->mv_type= MV_TYPE_8X8;    }else{        s->mv_type= MV_TYPE_16X16;    }    for(i=0; i<4; i++){        int index= s->block_index[i];        int min, max;            s->me.co_located_mv[i][0]= s->motion_val[index][0];        s->me.co_located_mv[i][1]= s->motion_val[index][1];        s->me.direct_basis_mv[i][0]= s->me.co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));        s->me.direct_basis_mv[i][1]= s->me.co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));//        s->me.direct_basis_mv[1][i][0]= s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);//        s->me.direct_basis_mv[1][i][1]= s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);        max= FFMAX(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift;        min= FFMIN(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift;        max+= (2*mb_x + (i& 1))*8 - 1; // +-1 is for the simpler rounding        min+= (2*mb_x + (i& 1))*8 + 1;        if(max >= s->width) xmax= s->width - max - 1;        if(min < -16      ) xmin= - 32 - min;        max= FFMAX(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift;        min= FFMIN(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift;        max+= (2*mb_y + (i>>1))*8 - 1; // +-1 is for the simpler rounding        min+= (2*mb_y + (i>>1))*8 + 1;        if(max >= s->height) ymax= s->height - max - 1;        if(min < -16       ) ymin= - 32 - min;                if(s->mv_type == MV_TYPE_16X16) break;    }        assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);        if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){        s->b_direct_mv_table[mot_xy][0]= 0;        s->b_direct_mv_table[mot_xy][1]= 0;        return 256*256*256*64;    }    if(s->flags&CODEC_FLAG_QPEL){        dmin = simple_direct_qpel_epzs_motion_search(s, 0, &mx, &my, P, 0, 0, xmin, ymin, xmax, ymax,                                                      &s->last_picture, mv_penalty);        dmin = simple_direct_qpel_qpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax,                                                0, 0, &s->last_picture, 0, 0, mv_penalty);    }else{        dmin = simple_direct_hpel_epzs_motion_search(s, 0, &mx, &my, P, 0, 0, xmin, ymin, xmax, ymax,                                                      &s->last_picture, mv_penalty);        dmin = simple_direct_hpel_hpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax,                                                0, 0, &s->last_picture, 0, 0, mv_penalty);    }    s->b_direct_mv_table[mot_xy][0]= mx;    s->b_direct_mv_table[mot_xy][1]= my;    return dmin;}