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 \
00367 if(map[index]!=key){\
00368 d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00369 map[index]= key;\
00370 score_map[index]= d;\
00371 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
00372 \
00373 COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
00374 }\
00375 }
00376
00377 #define CHECK_CLIPPED_MV(ax,ay)\
00378 {\
00379 const int Lx= ax;\
00380 const int Ly= ay;\
00381 const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
00382 const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
00383 CHECK_MV(Lx2, Ly2)\
00384 }
00385
00386 #define CHECK_MV_DIR(x,y,new_dir)\
00387 {\
00388 const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
00389 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
00390 \
00391 if(map[index]!=key){\
00392 d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00393 map[index]= key;\
00394 score_map[index]= d;\
00395 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
00396 \
00397 if(d<dmin){\
00398 best[0]=x;\
00399 best[1]=y;\
00400 dmin=d;\
00401 next_dir= new_dir;\
00402 }\
00403 }\
00404 }
00405
00406 #define check(x,y,S,v)\
00407 if( (x)<(xmin<<(S)) ) printf("%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
00408 if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
00409 if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
00410 if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
00411
00412 #define LOAD_COMMON2\
00413 uint32_t *map= c->map;\
00414 const int qpel= flags&FLAG_QPEL;\
00415 const int shift= 1+qpel;\
00416
00417 static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
00418 int src_index, int ref_index, int const penalty_factor,
00419 int size, int h, int flags)
00420 {
00421 MotionEstContext * const c= &s->me;
00422 me_cmp_func cmpf, chroma_cmpf;
00423 int next_dir=-1;
00424 LOAD_COMMON
00425 LOAD_COMMON2
00426 unsigned map_generation = c->map_generation;
00427
00428 cmpf= s->dsp.me_cmp[size];
00429 chroma_cmpf= s->dsp.me_cmp[size+1];
00430
00431 {
00432 const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
00433 const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
00434 if(map[index]!=key){
00435 score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
00436 map[index]= key;
00437 }
00438 }
00439
00440 for(;;){
00441 int d;
00442 const int dir= next_dir;
00443 const int x= best[0];
00444 const int y= best[1];
00445 next_dir=-1;
00446
00447
00448 if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
00449 if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
00450 if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
00451 if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
00452
00453 if(next_dir==-1){
00454 return dmin;
00455 }
00456 }
00457 }
00458
00459 static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
00460 int src_index, int ref_index, int const penalty_factor,
00461 int size, int h, int flags)
00462 {
00463 MotionEstContext * const c= &s->me;
00464 me_cmp_func cmpf, chroma_cmpf;
00465 int dia_size;
00466 LOAD_COMMON
00467 LOAD_COMMON2
00468 unsigned map_generation = c->map_generation;
00469
00470 cmpf= s->dsp.me_cmp[size];
00471 chroma_cmpf= s->dsp.me_cmp[size+1];
00472
00473 for(dia_size=1; dia_size<=4; dia_size++){
00474 int dir;
00475 const int x= best[0];
00476 const int y= best[1];
00477
00478 if(dia_size&(dia_size-1)) continue;
00479
00480 if( x + dia_size > xmax
00481 || x - dia_size < xmin
00482 || y + dia_size > ymax
00483 || y - dia_size < ymin)
00484 continue;
00485
00486 for(dir= 0; dir<dia_size; dir+=2){
00487 int d;
00488
00489 CHECK_MV(x + dir , y + dia_size - dir);
00490 CHECK_MV(x + dia_size - dir, y - dir );
00491 CHECK_MV(x - dir , y - dia_size + dir);
00492 CHECK_MV(x - dia_size + dir, y + dir );
00493 }
00494
00495 if(x!=best[0] || y!=best[1])
00496 dia_size=0;
00497 }
00498 return dmin;
00499 }
00500
00501 static int hex_search(MpegEncContext * s, int *best, int dmin,
00502 int src_index, int ref_index, int const penalty_factor,
00503 int size, int h, int flags, int dia_size)
00504 {
00505 MotionEstContext * const c= &s->me;
00506 me_cmp_func cmpf, chroma_cmpf;
00507 LOAD_COMMON
00508 LOAD_COMMON2
00509 unsigned map_generation = c->map_generation;
00510 int x,y,d;
00511 const int dec= dia_size & (dia_size-1);
00512
00513 cmpf= s->dsp.me_cmp[size];
00514 chroma_cmpf= s->dsp.me_cmp[size+1];
00515
00516 for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
00517 do{
00518 x= best[0];
00519 y= best[1];
00520
00521 CHECK_CLIPPED_MV(x -dia_size , y);
00522 CHECK_CLIPPED_MV(x+ dia_size , y);
00523 CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
00524 CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
00525 if(dia_size>1){
00526 CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
00527 CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
00528 }
00529 }while(best[0] != x || best[1] != y);
00530 }
00531
00532 return dmin;
00533 }
00534
00535 static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
00536 int src_index, int ref_index, int const penalty_factor,
00537 int size, int h, int flags)
00538 {
00539 MotionEstContext * const c= &s->me;
00540 me_cmp_func cmpf, chroma_cmpf;
00541 LOAD_COMMON
00542 LOAD_COMMON2
00543 unsigned map_generation = c->map_generation;
00544 int x,y,i,d;
00545 int dia_size= c->dia_size&0xFF;
00546 const int dec= dia_size & (dia_size-1);
00547 static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
00548 { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
00549
00550 cmpf= s->dsp.me_cmp[size];
00551 chroma_cmpf= s->dsp.me_cmp[size+1];
00552
00553 for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
00554 do{
00555 x= best[0];
00556 y= best[1];
00557 for(i=0; i<8; i++){
00558 CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
00559 }
00560 }while(best[0] != x || best[1] != y);
00561 }
00562
00563 x= best[0];
00564 y= best[1];
00565 CHECK_CLIPPED_MV(x+1, y);
00566 CHECK_CLIPPED_MV(x, y+1);
00567 CHECK_CLIPPED_MV(x-1, y);
00568 CHECK_CLIPPED_MV(x, y-1);
00569
00570 return dmin;
00571 }
00572
00573 static int umh_search(MpegEncContext * s, int *best, int dmin,
00574 int src_index, int ref_index, int const penalty_factor,
00575 int size, int h, int flags)
00576 {
00577 MotionEstContext * const c= &s->me;
00578 me_cmp_func cmpf, chroma_cmpf;
00579 LOAD_COMMON
00580 LOAD_COMMON2
00581 unsigned map_generation = c->map_generation;
00582 int x,y,x2,y2, i, j, d;
00583 const int dia_size= c->dia_size&0xFE;
00584 static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
00585 { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
00586 {-2, 3}, { 0, 4}, { 2, 3},
00587 {-2,-3}, { 0,-4}, { 2,-3},};
00588
00589 cmpf= s->dsp.me_cmp[size];
00590 chroma_cmpf= s->dsp.me_cmp[size+1];
00591
00592 x= best[0];
00593 y= best[1];
00594 for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
00595 CHECK_MV(x2, y);
00596 }
00597 for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
00598 CHECK_MV(x, y2);
00599 }
00600
00601 x= best[0];
00602 y= best[1];
00603 for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
00604 for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
00605 CHECK_MV(x2, y2);
00606 }
00607 }
00608
00609
00610
00611 for(j=1; j<=dia_size/4; j++){
00612 for(i=0; i<16; i++){
00613 CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
00614 }
00615 }
00616
00617 return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
00618 }
00619
00620 static int full_search(MpegEncContext * s, int *best, int dmin,
00621 int src_index, int ref_index, int const penalty_factor,
00622 int size, int h, int flags)
00623 {
00624 MotionEstContext * const c= &s->me;
00625 me_cmp_func cmpf, chroma_cmpf;
00626 LOAD_COMMON
00627 LOAD_COMMON2
00628 unsigned map_generation = c->map_generation;
00629 int x,y, d;
00630 const int dia_size= c->dia_size&0xFF;
00631
00632 cmpf= s->dsp.me_cmp[size];
00633 chroma_cmpf= s->dsp.me_cmp[size+1];
00634
00635 for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){
00636 for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){
00637 CHECK_MV(x, y);
00638 }
00639 }
00640
00641 x= best[0];
00642 y= best[1];
00643 d= dmin;
00644 CHECK_CLIPPED_MV(x , y);
00645 CHECK_CLIPPED_MV(x+1, y);
00646 CHECK_CLIPPED_MV(x, y+1);
00647 CHECK_CLIPPED_MV(x-1, y);
00648 CHECK_CLIPPED_MV(x, y-1);
00649 best[0]= x;
00650 best[1]= y;
00651
00652 return d;
00653 }
00654
00655 #define SAB_CHECK_MV(ax,ay)\
00656 {\
00657 const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
00658 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
00659 \
00660 if(map[index]!=key){\
00661 d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
00662 map[index]= key;\
00663 score_map[index]= d;\
00664 d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
00665 \
00666 if(d < minima[minima_count-1].height){\
00667 int j=0;\
00668 \
00669 while(d >= minima[j].height) j++;\
00670 \
00671 memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
00672 \
00673 minima[j].checked= 0;\
00674 minima[j].height= d;\
00675 minima[j].x= ax;\
00676 minima[j].y= ay;\
00677 \
00678 i=-1;\
00679 continue;\
00680 }\
00681 }\
00682 }
00683
00684 #define MAX_SAB_SIZE ME_MAP_SIZE
00685 static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
00686 int src_index, int ref_index, int const penalty_factor,
00687 int size, int h, int flags)
00688 {
00689 MotionEstContext * const c= &s->me;
00690 me_cmp_func cmpf, chroma_cmpf;
00691 Minima minima[MAX_SAB_SIZE];
00692 const int minima_count= FFABS(c->dia_size);
00693 int i, j;
00694 LOAD_COMMON
00695 LOAD_COMMON2
00696 unsigned map_generation = c->map_generation;
00697
00698 cmpf= s->dsp.me_cmp[size];
00699 chroma_cmpf= s->dsp.me_cmp[size+1];
00700
00701
00702
00703
00704 for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_SIZE; i++){
00705 uint32_t key= map[i];
00706
00707 key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
00708
00709 if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
00710
00711 minima[j].height= score_map[i];
00712 minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
00713 minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
00714 minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
00715 minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
00716
00717
00718 if( minima[j].x > xmax || minima[j].x < xmin
00719 || minima[j].y > ymax || minima[j].y < ymin)
00720 continue;
00721
00722 minima[j].checked=0;
00723 if(minima[j].x || minima[j].y)
00724 minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
00725
00726 j++;
00727 }
00728
00729 qsort(minima, j, sizeof(Minima), minima_cmp);
00730
00731 for(; j<minima_count; j++){
00732 minima[j].height=256*256*256*64;
00733 minima[j].checked=0;
00734 minima[j].x= minima[j].y=0;
00735 }
00736
00737 for(i=0; i<minima_count; i++){
00738 const int x= minima[i].x;
00739 const int y= minima[i].y;
00740 int d;
00741
00742 if(minima[i].checked) continue;
00743
00744 if( x >= xmax || x <= xmin
00745 || y >= ymax || y <= ymin)
00746 continue;
00747
00748 SAB_CHECK_MV(x-1, y)
00749 SAB_CHECK_MV(x+1, y)
00750 SAB_CHECK_MV(x , y-1)
00751 SAB_CHECK_MV(x , y+1)
00752
00753 minima[i].checked= 1;
00754 }
00755
00756 best[0]= minima[0].x;
00757 best[1]= minima[0].y;
00758 dmin= minima[0].height;
00759
00760 if( best[0] < xmax && best[0] > xmin
00761 && best[1] < ymax && best[1] > ymin){
00762 int d;
00763
00764 CHECK_MV(best[0]-1, best[1])
00765 CHECK_MV(best[0]+1, best[1])
00766 CHECK_MV(best[0], best[1]-1)
00767 CHECK_MV(best[0], best[1]+1)
00768 }
00769 return dmin;
00770 }
00771
00772 static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
00773 int src_index, int ref_index, int const penalty_factor,
00774 int size, int h, int flags)
00775 {
00776 MotionEstContext * const c= &s->me;
00777 me_cmp_func cmpf, chroma_cmpf;
00778 int dia_size;
00779 LOAD_COMMON
00780 LOAD_COMMON2
00781 unsigned map_generation = c->map_generation;
00782
00783 cmpf= s->dsp.me_cmp[size];
00784 chroma_cmpf= s->dsp.me_cmp[size+1];
00785
00786 for(dia_size=1; dia_size<=c->dia_size; dia_size++){
00787 int dir, start, end;
00788 const int x= best[0];
00789 const int y= best[1];
00790
00791 start= FFMAX(0, y + dia_size - ymax);
00792 end = FFMIN(dia_size, xmax - x + 1);
00793 for(dir= start; dir<end; dir++){
00794 int d;
00795
00796
00797 CHECK_MV(x + dir , y + dia_size - dir);
00798 }
00799
00800 start= FFMAX(0, x + dia_size - xmax);
00801 end = FFMIN(dia_size, y - ymin + 1);
00802 for(dir= start; dir<end; dir++){
00803 int d;
00804
00805
00806 CHECK_MV(x + dia_size - dir, y - dir );
00807 }
00808
00809 start= FFMAX(0, -y + dia_size + ymin );
00810 end = FFMIN(dia_size, x - xmin + 1);
00811 for(dir= start; dir<end; dir++){
00812 int d;
00813
00814
00815 CHECK_MV(x - dir , y - dia_size + dir);
00816 }
00817
00818 start= FFMAX(0, -x + dia_size + xmin );
00819 end = FFMIN(dia_size, ymax - y + 1);
00820 for(dir= start; dir<end; dir++){
00821 int d;
00822
00823
00824 CHECK_MV(x - dia_size + dir, y + dir );
00825 }
00826
00827 if(x!=best[0] || y!=best[1])
00828 dia_size=0;
00829 }
00830 return dmin;
00831 }
00832
00833 static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
00834 int src_index, int ref_index, int const penalty_factor,
00835 int size, int h, int flags){
00836 MotionEstContext * const c= &s->me;
00837 if(c->dia_size==-1)
00838 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00839 else if(c->dia_size<-1)
00840 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00841 else if(c->dia_size<2)
00842 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00843 else if(c->dia_size>1024)
00844 return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00845 else if(c->dia_size>768)
00846 return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00847 else if(c->dia_size>512)
00848 return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);
00849 else if(c->dia_size>256)
00850 return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00851 else
00852 return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00853 }
00854
00861 static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
00862 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
00863 int ref_mv_scale, int flags, int size, int h)
00864 {
00865 MotionEstContext * const c= &s->me;
00866 int best[2]={0, 0};
00870 int d;
00871 int dmin;
00873 unsigned map_generation;
00874 int penalty_factor;
00875 const int ref_mv_stride= s->mb_stride;
00876 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride;
00877 me_cmp_func cmpf, chroma_cmpf;
00878
00879 LOAD_COMMON
00880 LOAD_COMMON2
00881
00882 if(c->pre_pass){
00883 penalty_factor= c->pre_penalty_factor;
00884 cmpf= s->dsp.me_pre_cmp[size];
00885 chroma_cmpf= s->dsp.me_pre_cmp[size+1];
00886 }else{
00887 penalty_factor= c->penalty_factor;
00888 cmpf= s->dsp.me_cmp[size];
00889 chroma_cmpf= s->dsp.me_cmp[size+1];
00890 }
00891
00892 map_generation= update_map_generation(c);
00893
00894 av_assert2(cmpf);
00895 dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
00896 map[0]= map_generation;
00897 score_map[0]= dmin;
00898
00899
00900 if((s->pict_type == AV_PICTURE_TYPE_B && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)
00901 dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;
00902
00903
00904 if (s->first_slice_line) {
00905 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
00906 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
00907 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
00908 }else{
00909 if(dmin<((h*h*s->avctx->mv0_threshold)>>8)
00910 && ( P_LEFT[0] |P_LEFT[1]
00911 |P_TOP[0] |P_TOP[1]
00912 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
00913 *mx_ptr= 0;
00914 *my_ptr= 0;
00915 c->skip=1;
00916 return dmin;
00917 }
00918 CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)
00919 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)
00920 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)
00921 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )
00922 CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )
00923 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
00924 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
00925 CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
00926 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
00927 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
00928 }
00929 if(dmin>h*h*4){
00930 if(c->pre_pass){
00931 CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
00932 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
00933 if(!s->first_slice_line)
00934 CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
00935 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
00936 }else{
00937 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
00938 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
00939 if(s->mb_y+1<s->end_mb_y)
00940 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
00941 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
00942 }
00943 }
00944
00945 if(c->avctx->last_predictor_count){
00946 const int count= c->avctx->last_predictor_count;
00947 const int xstart= FFMAX(0, s->mb_x - count);
00948 const int ystart= FFMAX(0, s->mb_y - count);
00949 const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
00950 const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
00951 int mb_y;
00952
00953 for(mb_y=ystart; mb_y<yend; mb_y++){
00954 int mb_x;
00955 for(mb_x=xstart; mb_x<xend; mb_x++){
00956 const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
00957 int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
00958 int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
00959
00960 if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
00961 CHECK_MV(mx,my)
00962 }
00963 }
00964 }
00965
00966
00967 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
00968
00969
00970 *mx_ptr= best[0];
00971 *my_ptr= best[1];
00972
00973
00974 return dmin;
00975 }
00976
00977
00978 int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr,
00979 int P[10][2], int src_index, int ref_index,
00980 int16_t (*last_mv)[2], int ref_mv_scale,
00981 int size, int h)
00982 {
00983 MotionEstContext * const c= &s->me;
00984
00985 if(c->flags==0 && h==16 && size==0){
00986 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
00987
00988
00989 }else{
00990 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
00991 }
00992 }
00993
00994 static int epzs_motion_search4(MpegEncContext * s,
00995 int *mx_ptr, int *my_ptr, int P[10][2],
00996 int src_index, int ref_index, int16_t (*last_mv)[2],
00997 int ref_mv_scale)
00998 {
00999 MotionEstContext * const c= &s->me;
01000 int best[2]={0, 0};
01001 int d, dmin;
01002 unsigned map_generation;
01003 const int penalty_factor= c->penalty_factor;
01004 const int size=1;
01005 const int h=8;
01006 const int ref_mv_stride= s->mb_stride;
01007 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
01008 me_cmp_func cmpf, chroma_cmpf;
01009 LOAD_COMMON
01010 int flags= c->flags;
01011 LOAD_COMMON2
01012
01013 cmpf= s->dsp.me_cmp[size];
01014 chroma_cmpf= s->dsp.me_cmp[size+1];
01015
01016 map_generation= update_map_generation(c);
01017
01018 dmin = 1000000;
01019
01020
01021 if (s->first_slice_line) {
01022 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01023 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01024 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01025 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01026 }else{
01027 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01028
01029 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
01030 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01031 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
01032 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
01033 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01034 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01035 }
01036 if(dmin>64*4){
01037 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
01038 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
01039 if(s->mb_y+1<s->end_mb_y)
01040 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
01041 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
01042 }
01043
01044 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
01045
01046 *mx_ptr= best[0];
01047 *my_ptr= best[1];
01048
01049
01050 return dmin;
01051 }
01052
01053
01054 static int epzs_motion_search2(MpegEncContext * s,
01055 int *mx_ptr, int *my_ptr, int P[10][2],
01056 int src_index, int ref_index, int16_t (*last_mv)[2],
01057 int ref_mv_scale)
01058 {
01059 MotionEstContext * const c= &s->me;
01060 int best[2]={0, 0};
01061 int d, dmin;
01062 unsigned map_generation;
01063 const int penalty_factor= c->penalty_factor;
01064 const int size=0;
01065 const int h=8;
01066 const int ref_mv_stride= s->mb_stride;
01067 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
01068 me_cmp_func cmpf, chroma_cmpf;
01069 LOAD_COMMON
01070 int flags= c->flags;
01071 LOAD_COMMON2
01072
01073 cmpf= s->dsp.me_cmp[size];
01074 chroma_cmpf= s->dsp.me_cmp[size+1];
01075
01076 map_generation= update_map_generation(c);
01077
01078 dmin = 1000000;
01079
01080
01081 if (s->first_slice_line) {
01082 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01083 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01084 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01085 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01086 }else{
01087 CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
01088
01089 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
01090 CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
01091 CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
01092 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
01093 CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
01094 (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
01095 }
01096 if(dmin>64*4){
01097 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
01098 (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
01099 if(s->mb_y+1<s->end_mb_y)
01100 CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
01101 (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
01102 }
01103
01104 dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
01105
01106 *mx_ptr= best[0];
01107 *my_ptr= best[1];
01108
01109
01110 return dmin;
01111 }