00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027
00028 #define LOAD_COMMON\
00029 uint32_t av_unused * const score_map= c->score_map;\
00030 const int av_unused xmin= c->xmin;\
00031 const int av_unused ymin= c->ymin;\
00032 const int av_unused xmax= c->xmax;\
00033 const int av_unused ymax= c->ymax;\
00034 uint8_t *mv_penalty= c->current_mv_penalty;\
00035 const int pred_x= c->pred_x;\
00036 const int pred_y= c->pred_y;\
00037
00038 #define CHECK_HALF_MV(dx, dy, x, y)\
00039 {\
00040 const int hx= 2*(x)+(dx);\
00041 const int hy= 2*(y)+(dy);\
00042 d= cmp_hpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
00043 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
00044 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
00045 }
00046
00047 static int hpel_motion_search(MpegEncContext * s,
00048 int *mx_ptr, int *my_ptr, int dmin,
00049 int src_index, int ref_index,
00050 int size, int h)
00051 {
00052 MotionEstContext * const c= &s->me;
00053 const int mx = *mx_ptr;
00054 const int my = *my_ptr;
00055 const int penalty_factor= c->sub_penalty_factor;
00056 me_cmp_func cmp_sub, chroma_cmp_sub;
00057 int bx=2*mx, by=2*my;
00058
00059 LOAD_COMMON
00060 int flags= c->sub_flags;
00061
00062
00063
00064 cmp_sub= s->dsp.me_sub_cmp[size];
00065 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
00066
00067 if(c->skip){
00068 *mx_ptr = 0;
00069 *my_ptr = 0;
00070 return dmin;
00071 }
00072
00073 if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
00074 dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
00075 if(mx || my || size>0)
00076 dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
00077 }
00078
00079 if (mx > xmin && mx < xmax &&
00080 my > ymin && my < ymax) {
00081 int d= dmin;
00082 const int index= (my<<ME_MAP_SHIFT) + mx;
00083 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
00084 + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;
00085 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
00086 + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
00087 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
00088 + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
00089 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
00090 + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
00091
00092 #if 1
00093 unsigned key;
00094 unsigned map_generation= c->map_generation;
00095 key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
00096 av_assert2(c->map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
00097 key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
00098 av_assert2(c->map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
00099 key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
00100 av_assert2(c->map[(index+1)&(ME_MAP_SIZE-1)] == key);
00101 key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
00102 av_assert2(c->map[(index-1)&(ME_MAP_SIZE-1)] == key);
00103 #endif
00104 if(t<=b){
00105 CHECK_HALF_MV(0, 1, mx ,my-1)
00106 if(l<=r){
00107 CHECK_HALF_MV(1, 1, mx-1, my-1)
00108 if(t+r<=b+l){
00109 CHECK_HALF_MV(1, 1, mx , my-1)
00110 }else{
00111 CHECK_HALF_MV(1, 1, mx-1, my )
00112 }
00113 CHECK_HALF_MV(1, 0, mx-1, my )
00114 }else{
00115 CHECK_HALF_MV(1, 1, mx , my-1)
00116 if(t+l<=b+r){
00117 CHECK_HALF_MV(1, 1, mx-1, my-1)
00118 }else{
00119 CHECK_HALF_MV(1, 1, mx , my )
00120 }
00121 CHECK_HALF_MV(1, 0, mx , my )
00122 }
00123 }else{
00124 if(l<=r){
00125 if(t+l<=b+r){
00126 CHECK_HALF_MV(1, 1, mx-1, my-1)
00127 }else{
00128 CHECK_HALF_MV(1, 1, mx , my )
00129 }
00130 CHECK_HALF_MV(1, 0, mx-1, my)
00131 CHECK_HALF_MV(1, 1, mx-1, my)
00132 }else{
00133 if(t+r<=b+l){
00134 CHECK_HALF_MV(1, 1, mx , my-1)
00135 }else{
00136 CHECK_HALF_MV(1, 1, mx-1, my)
00137 }
00138 CHECK_HALF_MV(1, 0, mx , my)
00139 CHECK_HALF_MV(1, 1, mx , my)
00140 }
00141 CHECK_HALF_MV(0, 1, mx , my)
00142 }
00143 av_assert2(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
00144 }
00145
00146 *mx_ptr = bx;
00147 *my_ptr = by;
00148
00149 return dmin;
00150 }
00151
00152 static int no_sub_motion_search(MpegEncContext * s,
00153 int *mx_ptr, int *my_ptr, int dmin,
00154 int src_index, int ref_index,
00155 int size, int h)
00156 {
00157 (*mx_ptr)<<=1;
00158 (*my_ptr)<<=1;
00159 return dmin;
00160 }
00161
00162 static inline int get_mb_score(MpegEncContext *s, int mx, int my,
00163 int src_index, int ref_index, int size,
00164 int h, int add_rate)
00165 {
00166
00167 MotionEstContext * const c= &s->me;
00168 const int penalty_factor= c->mb_penalty_factor;
00169 const int flags= c->mb_flags;
00170 const int qpel= flags & FLAG_QPEL;
00171 const int mask= 1+2*qpel;
00172 me_cmp_func cmp_sub, chroma_cmp_sub;
00173 int d;
00174
00175 LOAD_COMMON
00176
00177
00178
00179 cmp_sub= s->dsp.mb_cmp[size];
00180 chroma_cmp_sub= s->dsp.mb_cmp[size+1];
00181
00182 d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
00183
00184 if(add_rate && (mx || my || size>0))
00185 d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
00186
00187 return d;
00188 }
00189
00190 int ff_get_mb_score(MpegEncContext *s, int mx, int my, int src_index,
00191 int ref_index, int size, int h, int add_rate)
00192 {
00193 return get_mb_score(s, mx, my, src_index, ref_index, size, h, add_rate);
00194 }
00195
00196 #define CHECK_QUARTER_MV(dx, dy, x, y)\
00197 {\
00198 const int hx= 4*(x)+(dx);\
00199 const int hy= 4*(y)+(dy);\
00200 d= cmp_qpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00201 d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
00202 COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
00203 }
00204
00205 static int qpel_motion_search(MpegEncContext * s,
00206 int *mx_ptr, int *my_ptr, int dmin,
00207 int src_index, int ref_index,
00208 int size, int h)
00209 {
00210 MotionEstContext * const c= &s->me;
00211 const int mx = *mx_ptr;
00212 const int my = *my_ptr;
00213 const int penalty_factor= c->sub_penalty_factor;
00214 const unsigned map_generation = c->map_generation;
00215 const int subpel_quality= c->avctx->me_subpel_quality;
00216 uint32_t *map= c->map;
00217 me_cmp_func cmpf, chroma_cmpf;
00218 me_cmp_func cmp_sub, chroma_cmp_sub;
00219
00220 LOAD_COMMON
00221 int flags= c->sub_flags;
00222
00223 cmpf= s->dsp.me_cmp[size];
00224 chroma_cmpf= s->dsp.me_cmp[size+1];
00225
00226
00227 cmp_sub= s->dsp.me_sub_cmp[size];
00228 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
00229
00230 if(c->skip){
00231 *mx_ptr = 0;
00232 *my_ptr = 0;
00233 return dmin;
00234 }
00235
00236 if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
00237 dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
00238 if(mx || my || size>0)
00239 dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
00240 }
00241
00242 if (mx > xmin && mx < xmax &&
00243 my > ymin && my < ymax) {
00244 int bx=4*mx, by=4*my;
00245 int d= dmin;
00246 int i, nx, ny;
00247 const int index= (my<<ME_MAP_SHIFT) + mx;
00248 const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
00249 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
00250 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
00251 const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
00252 const int c= score_map[(index )&(ME_MAP_SIZE-1)];
00253 int best[8];
00254 int best_pos[8][2];
00255
00256 memset(best, 64, sizeof(int)*8);
00257 if(s->me.dia_size>=2){
00258 const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
00259 const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
00260 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
00261 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
00262
00263 for(ny= -3; ny <= 3; ny++){
00264 for(nx= -3; nx <= 3; nx++){
00265
00266 const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
00267 const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
00268 const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
00269 int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;
00270 int i;
00271
00272 if((nx&3)==0 && (ny&3)==0) continue;
00273
00274 score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
00275
00276
00277
00278
00279 for(i=0; i<8; i++){
00280 if(score < best[i]){
00281 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
00282 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
00283 best[i]= score;
00284 best_pos[i][0]= nx + 4*mx;
00285 best_pos[i][1]= ny + 4*my;
00286 break;
00287 }
00288 }
00289 }
00290 }
00291 }else{
00292 int tl;
00293
00294 const int cx = 4*(r - l);
00295 const int cx2= r + l - 2*c;
00296 const int cy = 4*(b - t);
00297 const int cy2= b + t - 2*c;
00298 int cxy;
00299
00300 if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){
00301 tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
00302 }else{
00303 tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
00304 }
00305
00306 cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
00307
00308 av_assert2(16*cx2 + 4*cx + 32*c == 32*r);
00309 av_assert2(16*cx2 - 4*cx + 32*c == 32*l);
00310 av_assert2(16*cy2 + 4*cy + 32*c == 32*b);
00311 av_assert2(16*cy2 - 4*cy + 32*c == 32*t);
00312 av_assert2(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
00313
00314 for(ny= -3; ny <= 3; ny++){
00315 for(nx= -3; nx <= 3; nx++){
00316
00317 int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c;
00318 int i;
00319
00320 if((nx&3)==0 && (ny&3)==0) continue;
00321
00322 score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
00323
00324
00325
00326 for(i=0; i<8; i++){
00327 if(score < best[i]){
00328 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
00329 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
00330 best[i]= score;
00331 best_pos[i][0]= nx + 4*mx;
00332 best_pos[i][1]= ny + 4*my;
00333 break;
00334 }
00335 }
00336 }
00337 }
00338 }
00339 for(i=0; i<subpel_quality; i++){
00340 nx= best_pos[i][0];
00341 ny= best_pos[i][1];
00342 CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
00343 }
00344
00345 av_assert2(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
00346
00347 *mx_ptr = bx;
00348 *my_ptr = by;
00349 }else{
00350 *mx_ptr =4*mx;
00351 *my_ptr =4*my;
00352 }
00353
00354 return dmin;
00355 }
00356
00357
00358 #define CHECK_MV(x,y)\
00359 {\
00360 const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
00361 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
00362 av_assert2((x) >= xmin);\
00363 av_assert2((x) <= xmax);\
00364 av_assert2((y) >= ymin);\
00365 av_assert2((y) <= ymax);\
00366 if(map[index]!=key){\
00367 d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00368 map[index]= key;\
00369 score_map[index]= d;\
00370 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
00371 COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
00372 }\
00373 }
00374
00375 #define CHECK_CLIPPED_MV(ax,ay)\
00376 {\
00377 const int Lx= ax;\
00378 const int Ly= ay;\
00379 const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
00380 const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
00381 CHECK_MV(Lx2, Ly2)\
00382 }
00383
00384 #define CHECK_MV_DIR(x,y,new_dir)\
00385 {\
00386 const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
00387 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
00388 if(map[index]!=key){\
00389 d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00390 map[index]= key;\
00391 score_map[index]= d;\
00392 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
00393 if(d<dmin){\
00394 best[0]=x;\
00395 best[1]=y;\
00396 dmin=d;\
00397 next_dir= new_dir;\
00398 }\
00399 }\
00400 }
00401
00402 #define check(x,y,S,v)\
00403 if( (x)<(xmin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
00404 if( (x)>(xmax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
00405 if( (y)<(ymin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
00406 if( (y)>(ymax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
00407
00408 #define LOAD_COMMON2\
00409 uint32_t *map= c->map;\
00410 const int qpel= flags&FLAG_QPEL;\
00411 const int shift= 1+qpel;\
00412
00413 static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
00414 int src_index, int ref_index, int const penalty_factor,
00415 int size, int h, int flags)
00416 {
00417 MotionEstContext * const c= &s->me;
00418 me_cmp_func cmpf, chroma_cmpf;
00419 int next_dir=-1;
00420 LOAD_COMMON
00421 LOAD_COMMON2
00422 unsigned map_generation = c->map_generation;
00423
00424 cmpf= s->dsp.me_cmp[size];
00425 chroma_cmpf= s->dsp.me_cmp[size+1];
00426
00427 {
00428 const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
00429 const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
00430 if(map[index]!=key){
00431 score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
00432 map[index]= key;
00433 }
00434 }
00435
00436 for(;;){
00437 int d;
00438 const int dir= next_dir;
00439 const int x= best[0];
00440 const int y= best[1];
00441 next_dir=-1;
00442
00443 if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
00444 if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
00445 if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
00446 if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
00447
00448 if(next_dir==-1){
00449 return dmin;
00450 }
00451 }
00452 }
00453
00454 static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
00455 int src_index, int ref_index, int const penalty_factor,
00456 int size, int h, int flags)
00457 {
00458 MotionEstContext * const c= &s->me;
00459 me_cmp_func cmpf, chroma_cmpf;
00460 int dia_size;
00461 LOAD_COMMON
00462 LOAD_COMMON2
00463 unsigned map_generation = c->map_generation;
00464
00465 cmpf= s->dsp.me_cmp[size];
00466 chroma_cmpf= s->dsp.me_cmp[size+1];
00467
00468 for(dia_size=1; dia_size<=4; dia_size++){
00469 int dir;
00470 const int x= best[0];
00471 const int y= best[1];
00472
00473 if(dia_size&(dia_size-1)) continue;
00474
00475 if( x + dia_size > xmax
00476 || x - dia_size < xmin
00477 || y + dia_size > ymax
00478 || y - dia_size < ymin)
00479 continue;
00480
00481 for(dir= 0; dir<dia_size; dir+=2){
00482 int d;
00483
00484 CHECK_MV(x + dir , y + dia_size - dir);
00485 CHECK_MV(x + dia_size - dir, y - dir );
00486 CHECK_MV(x - dir , y - dia_size + dir);
00487 CHECK_MV(x - dia_size + dir, y + dir );
00488 }
00489
00490 if(x!=best[0] || y!=best[1])
00491 dia_size=0;
00492 }
00493 return dmin;
00494 }
00495
00496 static int hex_search(MpegEncContext * s, int *best, int dmin,
00497 int src_index, int ref_index, int const penalty_factor,
00498 int size, int h, int flags, int dia_size)
00499 {
00500 MotionEstContext * const c= &s->me;
00501 me_cmp_func cmpf, chroma_cmpf;
00502 LOAD_COMMON
00503 LOAD_COMMON2
00504 unsigned map_generation = c->map_generation;
00505 int x,y,d;
00506 const int dec= dia_size & (dia_size-1);
00507
00508 cmpf= s->dsp.me_cmp[size];
00509 chroma_cmpf= s->dsp.me_cmp[size+1];
00510
00511 for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
00512 do{
00513 x= best[0];
00514 y= best[1];
00515
00516 CHECK_CLIPPED_MV(x -dia_size , y);
00517 CHECK_CLIPPED_MV(x+ dia_size , y);
00518 CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
00519 CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
00520 if(dia_size>1){
00521 CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
00522 CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
00523 }
00524 }while(best[0] != x || best[1] != y);
00525 }
00526
00527 return dmin;
00528 }
00529
00530 static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
00531 int src_index, int ref_index, int const penalty_factor,
00532 int size, int h, int flags)
00533 {
00534 MotionEstContext * const c= &s->me;
00535 me_cmp_func cmpf, chroma_cmpf;
00536 LOAD_COMMON
00537 LOAD_COMMON2
00538 unsigned map_generation = c->map_generation;
00539 int x,y,i,d;
00540 int dia_size= c->dia_size&0xFF;
00541 const int dec= dia_size & (dia_size-1);
00542 static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
00543 { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
00544
00545 cmpf= s->dsp.me_cmp[size];
00546 chroma_cmpf= s->dsp.me_cmp[size+1];
00547
00548 for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
00549 do{
00550 x= best[0];
00551 y= best[1];
00552 for(i=0; i<8; i++){
00553 CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
00554 }
00555 }while(best[0] != x || best[1] != y);
00556 }
00557
00558 x= best[0];
00559 y= best[1];
00560 CHECK_CLIPPED_MV(x+1, y);
00561 CHECK_CLIPPED_MV(x, y+1);
00562 CHECK_CLIPPED_MV(x-1, y);
00563 CHECK_CLIPPED_MV(x, y-1);
00564
00565 return dmin;
00566 }
00567
00568 static int umh_search(MpegEncContext * s, int *best, int dmin,
00569 int src_index, int ref_index, int const penalty_factor,
00570 int size, int h, int flags)
00571 {
00572 MotionEstContext * const c= &s->me;
00573 me_cmp_func cmpf, chroma_cmpf;
00574 LOAD_COMMON
00575 LOAD_COMMON2
00576 unsigned map_generation = c->map_generation;
00577 int x,y,x2,y2, i, j, d;
00578 const int dia_size= c->dia_size&0xFE;
00579 static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
00580 { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
00581 {-2, 3}, { 0, 4}, { 2, 3},
00582 {-2,-3}, { 0,-4}, { 2,-3},};
00583
00584 cmpf= s->dsp.me_cmp[size];
00585 chroma_cmpf= s->dsp.me_cmp[size+1];
00586
00587 x= best[0];
00588 y= best[1];
00589 for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
00590 CHECK_MV(x2, y);
00591 }
00592 for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
00593 CHECK_MV(x, y2);
00594 }
00595
00596 x= best[0];
00597 y= best[1];
00598 for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
00599 for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
00600 CHECK_MV(x2, y2);
00601 }
00602 }
00603
00604
00605
00606 for(j=1; j<=dia_size/4; j++){
00607 for(i=0; i<16; i++){
00608 CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
00609 }
00610 }
00611
00612 return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
00613 }
00614
00615 static int full_search(MpegEncContext * s, int *best, int dmin,
00616 int src_index, int ref_index, int const penalty_factor,
00617 int size, int h, int flags)
00618 {
00619 MotionEstContext * const c= &s->me;
00620 me_cmp_func cmpf, chroma_cmpf;
00621 LOAD_COMMON
00622 LOAD_COMMON2
00623 unsigned map_generation = c->map_generation;
00624 int x,y, d;
00625 const int dia_size= c->dia_size&0xFF;
00626
00627 cmpf= s->dsp.me_cmp[size];
00628 chroma_cmpf= s->dsp.me_cmp[size+1];
00629
00630 for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){
00631 for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){
00632 CHECK_MV(x, y);
00633 }
00634 }
00635
00636 x= best[0];
00637 y= best[1];
00638 d= dmin;
00639 CHECK_CLIPPED_MV(x , y);
00640 CHECK_CLIPPED_MV(x+1, y);
00641 CHECK_CLIPPED_MV(x, y+1);
00642 CHECK_CLIPPED_MV(x-1, y);
00643 CHECK_CLIPPED_MV(x, y-1);
00644 best[0]= x;
00645 best[1]= y;
00646
00647 return d;
00648 }
00649
00650 #define SAB_CHECK_MV(ax,ay)\
00651 {\
00652 const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
00653 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
00654 if(map[index]!=key){\
00655 d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00656 map[index]= key;\
00657 score_map[index]= d;\
00658 d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
00659 if(d < minima[minima_count-1].height){\
00660 int j=0;\
00661 \
00662 while(d >= minima[j].height) j++;\
00663 \
00664 memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
00665 \
00666 minima[j].checked= 0;\
00667 minima[j].height= d;\
00668 minima[j].x= ax;\
00669 minima[j].y= ay;\
00670 \
00671 i=-1;\
00672 continue;\
00673 }\
00674 }\
00675 }
00676
00677 #define MAX_SAB_SIZE ME_MAP_SIZE
00678 static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
00679 int src_index, int ref_index, int const penalty_factor,
00680 int size, int h, int flags)
00681 {
00682 MotionEstContext * const c= &s->me;
00683 me_cmp_func cmpf, chroma_cmpf;
00684 Minima minima[MAX_SAB_SIZE];
00685 const int minima_count= FFABS(c->dia_size);
00686 int i, j;
00687 LOAD_COMMON
00688 LOAD_COMMON2
00689 unsigned map_generation = c->map_generation;
00690
00691 av_assert1(minima_count <= MAX_SAB_SIZE);
00692
00693 cmpf= s->dsp.me_cmp[size];
00694 chroma_cmpf= s->dsp.me_cmp[size+1];
00695
00696
00697
00698
00699 for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_SIZE; i++){
00700 uint32_t key= map[i];
00701
00702 key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
00703
00704 if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
00705
00706 minima[j].height= score_map[i];
00707 minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
00708 minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
00709 minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
00710 minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
00711
00712
00713 if( minima[j].x > xmax || minima[j].x < xmin
00714 || minima[j].y > ymax || minima[j].y < ymin)
00715 continue;
00716
00717 minima[j].checked=0;
00718 if(minima[j].x || minima[j].y)
00719 minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
00720
00721 j++;
00722 }
00723
00724 qsort(minima, j, sizeof(Minima), minima_cmp);
00725
00726 for(; j<minima_count; j++){
00727 minima[j].height=256*256*256*64;
00728 minima[j].checked=0;
00729 minima[j].x= minima[j].y=0;
00730 }
00731
00732 for(i=0; i<minima_count; i++){
00733 const int x= minima[i].x;
00734 const int y= minima[i].y;
00735 int d;
00736
00737 if(minima[i].checked) continue;
00738
00739 if( x >= xmax || x <= xmin
00740 || y >= ymax || y <= ymin)
00741 continue;
00742
00743 SAB_CHECK_MV(x-1, y)
00744 SAB_CHECK_MV(x+1, y)
00745 SAB_CHECK_MV(x , y-1)
00746 SAB_CHECK_MV(x , y+1)
00747
00748 minima[i].checked= 1;
00749 }
00750
00751 best[0]= minima[0].x;
00752 best[1]= minima[0].y;
00753 dmin= minima[0].height;
00754
00755 if( best[0] < xmax && best[0] > xmin
00756 && best[1] < ymax && best[1] > ymin){
00757 int d;
00758
00759 CHECK_MV(best[0]-1, best[1])
00760 CHECK_MV(best[0]+1, best[1])
00761 CHECK_MV(best[0], best[1]-1)
00762 CHECK_MV(best[0], best[1]+1)
00763 }
00764 return dmin;
00765 }
00766
00767 static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
00768 int src_index, int ref_index, int const penalty_factor,
00769 int size, int h, int flags)
00770 {
00771 MotionEstContext * const c= &s->me;
00772 me_cmp_func cmpf, chroma_cmpf;
00773 int dia_size;
00774 LOAD_COMMON
00775 LOAD_COMMON2
00776 unsigned map_generation = c->map_generation;
00777
00778 cmpf= s->dsp.me_cmp[size];
00779 chroma_cmpf= s->dsp.me_cmp[size+1];
00780
00781 for(dia_size=1; dia_size<=c->dia_size; dia_size++){
00782 int dir, start, end;
00783 const int x= best[0];
00784 const int y= best[1];
00785
00786 start= FFMAX(0, y + dia_size - ymax);
00787 end = FFMIN(dia_size, xmax - x + 1);
00788 for(dir= start; dir<end; dir++){
00789 int d;
00790
00791
00792 CHECK_MV(x + dir , y + dia_size - dir);
00793 }
00794
00795 start= FFMAX(0, x + dia_size - xmax);
00796 end = FFMIN(dia_size, y - ymin + 1);
00797 for(dir= start; dir<end; dir++){
00798 int d;
00799
00800
00801 CHECK_MV(x + dia_size - dir, y - dir );
00802 }
00803
00804 start= FFMAX(0, -y + dia_size + ymin );
00805 end = FFMIN(dia_size, x - xmin + 1);
00806 for(dir= start; dir<end; dir++){
00807 int d;
00808
00809
00810 CHECK_MV(x - dir , y - dia_size + dir);
00811 }
00812
00813 start= FFMAX(0, -x + dia_size + xmin );
00814 end = FFMIN(dia_size, ymax - y + 1);
00815 for(dir= start; dir<end; dir++){
00816 int d;
00817
00818
00819 CHECK_MV(x - dia_size + dir, y + dir );
00820 }
00821
00822 if(x!=best[0] || y!=best[1])
00823 dia_size=0;
00824 }
00825 return dmin;
00826 }
00827
00828 static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
00829 int src_index, int ref_index, int const penalty_factor,
00830 int size, int h, int flags){
00831 MotionEstContext * const c= &s->me;
00832 if(c->dia_size==-1)
00833 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00834 else if(c->dia_size<-1)
00835 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00836 else if(c->dia_size<2)
00837 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00838 else if(c->dia_size>1024)
00839 return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00840 else if(c->dia_size>768)
00841 return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00842 else if(c->dia_size>512)
00843 return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);
00844 else if(c->dia_size>256)
00845 return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00846 else
00847 return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00848 }
00849
00856 static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
00857 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
00858 int ref_mv_scale, int flags, int size, int h)
00859 {
00860 MotionEstContext * const c= &s->me;
00861 int best[2]={0, 0};
00865 int d;
00866 int dmin;
00868 unsigned map_generation;
00869 int penalty_factor;
00870 const int ref_mv_stride= s->mb_stride;
00871 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride;
00872 me_cmp_func cmpf, chroma_cmpf;
00873
00874 LOAD_COMMON
00875 LOAD_COMMON2
00876
00877 if(c->pre_pass){
00878 penalty_factor= c->pre_penalty_factor;
00879 cmpf= s->dsp.me_pre_cmp[size];
00880 chroma_cmpf= s->dsp.me_pre_cmp[size+1];
00881 }else{
00882 penalty_factor= c->penalty_factor;
00883 cmpf= s->dsp.me_cmp[size];
00884 chroma_cmpf= s->dsp.me_cmp[size+1];
00885 }
00886
00887 map_generation= update_map_generation(c);
00888
00889 av_assert2(cmpf);
00890 dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
00891 map[0]= map_generation;
00892 score_map[0]= dmin;
00893
00894
00895 if((s->pict_type == AV_PICTURE_TYPE_B && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)
00896 dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;
00897
00898
00899 if (s->first_slice_line) {
00900 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
00901 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
00902 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
00903 }else{
00904 if(dmin<((h*h*s->avctx->mv0_threshold)>>8)
00905 && ( P_LEFT[0] |P_LEFT[1]
00906 |P_TOP[0] |P_TOP[1]
00907 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
00908 *mx_ptr= 0;
00909 *my_ptr= 0;
00910 c->skip=1;
00911 return dmin;
00912 }
00913 CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)
00914 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)
00915 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)
00916 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )
00917 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )
00918 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
00919 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
00920 CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
00921 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
00922 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
00923 }
00924 if(dmin>h*h*4){
00925 if(c->pre_pass){
00926 CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
00927 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
00928 if(!s->first_slice_line)
00929 CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
00930 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
00931 }else{
00932 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
00933 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
00934 if(s->mb_y+1<s->end_mb_y)
00935 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
00936 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
00937 }
00938 }
00939
00940 if(c->avctx->last_predictor_count){
00941 const int count= c->avctx->last_predictor_count;
00942 const int xstart= FFMAX(0, s->mb_x - count);
00943 const int ystart= FFMAX(0, s->mb_y - count);
00944 const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
00945 const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
00946 int mb_y;
00947
00948 for(mb_y=ystart; mb_y<yend; mb_y++){
00949 int mb_x;
00950 for(mb_x=xstart; mb_x<xend; mb_x++){
00951 const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
00952 int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
00953 int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
00954
00955 if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
00956 CHECK_MV(mx,my)
00957 }
00958 }
00959 }
00960
00961
00962 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00963
00964
00965 *mx_ptr= best[0];
00966 *my_ptr= best[1];
00967
00968 return dmin;
00969 }
00970
00971
00972 int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr,
00973 int P[10][2], int src_index, int ref_index,
00974 int16_t (*last_mv)[2], int ref_mv_scale,
00975 int size, int h)
00976 {
00977 MotionEstContext * const c= &s->me;
00978
00979 if(c->flags==0 && h==16 && size==0){
00980 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
00981
00982
00983 }else{
00984 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
00985 }
00986 }
00987
00988 static int epzs_motion_search4(MpegEncContext * s,
00989 int *mx_ptr, int *my_ptr, int P[10][2],
00990 int src_index, int ref_index, int16_t (*last_mv)[2],
00991 int ref_mv_scale)
00992 {
00993 MotionEstContext * const c= &s->me;
00994 int best[2]={0, 0};
00995 int d, dmin;
00996 unsigned map_generation;
00997 const int penalty_factor= c->penalty_factor;
00998 const int size=1;
00999 const int h=8;
01000 const int ref_mv_stride= s->mb_stride;
01001 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
01002 me_cmp_func cmpf, chroma_cmpf;
01003 LOAD_COMMON
01004 int flags= c->flags;
01005 LOAD_COMMON2
01006
01007 cmpf= s->dsp.me_cmp[size];
01008 chroma_cmpf= s->dsp.me_cmp[size+1];
01009
01010 map_generation= update_map_generation(c);
01011
01012 dmin = 1000000;
01013
01014
01015 if (s->first_slice_line) {
01016 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01017 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01018 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01019 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01020 }else{
01021 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01022
01023 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
01024 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01025 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
01026 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
01027 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01028 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01029 }
01030 if(dmin>64*4){
01031 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
01032 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
01033 if(s->mb_y+1<s->end_mb_y)
01034 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
01035 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
01036 }
01037
01038 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
01039
01040 *mx_ptr= best[0];
01041 *my_ptr= best[1];
01042
01043 return dmin;
01044 }
01045
01046
01047 static int epzs_motion_search2(MpegEncContext * s,
01048 int *mx_ptr, int *my_ptr, int P[10][2],
01049 int src_index, int ref_index, int16_t (*last_mv)[2],
01050 int ref_mv_scale)
01051 {
01052 MotionEstContext * const c= &s->me;
01053 int best[2]={0, 0};
01054 int d, dmin;
01055 unsigned map_generation;
01056 const int penalty_factor= c->penalty_factor;
01057 const int size=0;
01058 const int h=8;
01059 const int ref_mv_stride= s->mb_stride;
01060 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
01061 me_cmp_func cmpf, chroma_cmpf;
01062 LOAD_COMMON
01063 int flags= c->flags;
01064 LOAD_COMMON2
01065
01066 cmpf= s->dsp.me_cmp[size];
01067 chroma_cmpf= s->dsp.me_cmp[size+1];
01068
01069 map_generation= update_map_generation(c);
01070
01071 dmin = 1000000;
01072
01073
01074 if (s->first_slice_line) {
01075 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01076 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01077 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01078 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01079 }else{
01080 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01081
01082 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
01083 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01084 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
01085 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
01086 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01087 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01088 }
01089 if(dmin>64*4){
01090 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
01091 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
01092 if(s->mb_y+1<s->end_mb_y)
01093 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
01094 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
01095 }
01096
01097 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
01098
01099 *mx_ptr= best[0];
01100 *my_ptr= best[1];
01101
01102 return dmin;
01103 }