From f852ff32571bfd5ddd239a8c273445377c6462b4 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Tue, 5 Dec 2006 12:34:52 +0000 Subject: make hex and large 2 small diamond search half their size instead or -1 if the initial size was a power of 2 double the hex size so odd sized hexagons are possible Originally committed as revision 7223 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/motion_est_template.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'libavcodec/motion_est_template.c') diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c index d8feaff5a9..ee3c08295c 100644 --- a/libavcodec/motion_est_template.c +++ b/libavcodec/motion_est_template.c @@ -667,31 +667,28 @@ static int hex_search(MpegEncContext * s, int *best, int dmin, LOAD_COMMON LOAD_COMMON2 int map_generation= c->map_generation; - int x,y,i,d; - static const int hex[6][2]={{-2, 0}, { 2,0}, {-1,-2}, {1,-2}, {-1,2},{1,2}}; + 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--){ + for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){ do{ x= best[0]; y= best[1]; - for(i=0; i<6; i++){ - CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size); + + 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); } - do{ - 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); - }while(best[0] != x || best[1] != y); - return dmin; } @@ -704,14 +701,16 @@ static int l2s_dia_search(MpegEncContext * s, int *best, int dmin, LOAD_COMMON LOAD_COMMON2 int map_generation= c->map_generation; - int x,y,i,d, dia_size; + 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= c->dia_size&0xFF; dia_size; dia_size--){ + for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){ do{ x= best[0]; y= best[1]; -- cgit v1.2.3