+static int hex_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags, int dia_size)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+ int x,y,d;
+ const int dec= dia_size & (dia_size-1);
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
+ do{
+ x= best[0];
+ y= best[1];
+
+ CHECK_CLIPPED_MV(x -dia_size , y);
+ CHECK_CLIPPED_MV(x+ dia_size , y);
+ CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
+ CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
+ if(dia_size>1){
+ CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
+ CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
+ }
+ }while(best[0] != x || best[1] != y);
+ }
+
+ return dmin;
+}
+
+static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+ int x,y,i,d;
+ int dia_size= c->dia_size&0xFF;
+ const int dec= dia_size & (dia_size-1);
+ static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
+ { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
+ do{
+ x= best[0];
+ y= best[1];
+ for(i=0; i<8; i++){
+ CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
+ }
+ }while(best[0] != x || best[1] != y);
+ }
+
+ x= best[0];
+ y= best[1];
+ CHECK_CLIPPED_MV(x+1, y);
+ CHECK_CLIPPED_MV(x, y+1);
+ CHECK_CLIPPED_MV(x-1, y);
+ CHECK_CLIPPED_MV(x, y-1);
+
+ return dmin;
+}
+
+static int umh_search(MpegEncContext * s, int *best, int dmin,
+ int src_index, int ref_index, int const penalty_factor,
+ int size, int h, int flags)
+{
+ MotionEstContext * const c= &s->me;
+ me_cmp_func cmpf, chroma_cmpf;
+ LOAD_COMMON
+ LOAD_COMMON2
+ int map_generation= c->map_generation;
+ int x,y,x2,y2, i, j, d;
+ const int dia_size= c->dia_size&0xFE;
+ static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
+ { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
+ {-2, 3}, { 0, 4}, { 2, 3},
+ {-2,-3}, { 0,-4}, { 2,-3},};
+
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+
+ x= best[0];
+ y= best[1];
+ for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
+ CHECK_MV(x2, y);
+ }
+ for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
+ CHECK_MV(x, y2);
+ }
+
+ x= best[0];
+ y= best[1];
+ for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
+ for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
+ CHECK_MV(x2, y2);
+ }
+ }
+
+//FIXME prevent the CLIP stuff
+
+ for(j=1; j<=dia_size/4; j++){
+ for(i=0; i<16; i++){
+ CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
+ }
+ }
+
+ return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
+}
+