int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
                                    int mb_x, int mb_y)
{
    MotionEstContext * const c= &s->me;
    int mx, my, dmin;
    int P[10][2];
    const int shift= 1+s->quarter_sample;
    const int xy= mb_x + mb_y*s->mb_stride;
    init_ref(c, s->new_picture.f->data, s->last_picture.f->data, NULL, 16*mb_x, 16*mb_y, 0);
    assert(s->quarter_sample==0 || s->quarter_sample==1);
    c->pre_penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);
    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
    get_limits(s, 16*mb_x, 16*mb_y);
    c->skip=0;
    P_LEFT[0]       = s->p_mv_table[xy + 1][0];
    P_LEFT[1]       = s->p_mv_table[xy + 1][1];
    if(P_LEFT[0]       < (c->xmin<<shift)) P_LEFT[0]       = (c->xmin<<shift);
    if (s->first_slice_line) {
        c->pred_x= P_LEFT[0];
        c->pred_y= P_LEFT[1];
        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0;
    } else {
        P_TOP[0]      = s->p_mv_table[xy + s->mb_stride    ][0];
        P_TOP[1]      = s->p_mv_table[xy + s->mb_stride    ][1];
        P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
        P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
        if(P_TOP[1]      < (c->ymin<<shift)) P_TOP[1]     = (c->ymin<<shift);
        if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
        if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<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]);
        c->pred_x = P_MEDIAN[0];
        c->pred_y = P_MEDIAN[1];
    }
    dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);
    s->p_mv_table[xy][0] = mx<<shift;
    s->p_mv_table[xy][1] = my<<shift;
    return dmin;
}
['int ff_pre_estimate_p_frame_motion(MpegEncContext * s,\n                                    int mb_x, int mb_y)\n{\n    MotionEstContext * const c= &s->me;\n    int mx, my, dmin;\n    int P[10][2];\n    const int shift= 1+s->quarter_sample;\n    const int xy= mb_x + mb_y*s->mb_stride;\n    init_ref(c, s->new_picture.f->data, s->last_picture.f->data, NULL, 16*mb_x, 16*mb_y, 0);\n    assert(s->quarter_sample==0 || s->quarter_sample==1);\n    c->pre_penalty_factor    = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);\n    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n    get_limits(s, 16*mb_x, 16*mb_y);\n    c->skip=0;\n    P_LEFT[0]       = s->p_mv_table[xy + 1][0];\n    P_LEFT[1]       = s->p_mv_table[xy + 1][1];\n    if(P_LEFT[0]       < (c->xmin<<shift)) P_LEFT[0]       = (c->xmin<<shift);\n    if (s->first_slice_line) {\n        c->pred_x= P_LEFT[0];\n        c->pred_y= P_LEFT[1];\n        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=\n        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0;\n    } else {\n        P_TOP[0]      = s->p_mv_table[xy + s->mb_stride    ][0];\n        P_TOP[1]      = s->p_mv_table[xy + s->mb_stride    ][1];\n        P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];\n        P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];\n        if(P_TOP[1]      < (c->ymin<<shift)) P_TOP[1]     = (c->ymin<<shift);\n        if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);\n        if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift);\n        P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n        P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n        c->pred_x = P_MEDIAN[0];\n        c->pred_y = P_MEDIAN[1];\n    }\n    dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);\n    s->p_mv_table[xy][0] = mx<<shift;\n    s->p_mv_table[xy][1] = my<<shift;\n    return dmin;\n}', 'static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){\n    const int offset[3]= {\n          y*c->  stride + x,\n        ((y*c->uvstride + x)>>1),\n        ((y*c->uvstride + x)>>1),\n    };\n    int i;\n    for(i=0; i<3; i++){\n        c->src[0][i]= src [i] + offset[i];\n        c->ref[0][i]= ref [i] + offset[i];\n    }\n    if(ref_index){\n        for(i=0; i<3; i++){\n            c->ref[ref_index][i]= ref2[i] + offset[i];\n        }\n    }\n}']