Mercurial > libavcodec.hg
comparison motion_est_template.c @ 2079:75aae96e6b54 libavcodec
fewer overflows
author | michael |
---|---|
date | Mon, 14 Jun 2004 16:18:04 +0000 |
parents | c200977cdf78 |
children | 07a663d46be2 |
comparison
equal
deleted
inserted
replaced
2078:3dabadc91d19 | 2079:75aae96e6b54 |
---|---|
321 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)]; | 321 const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)]; |
322 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)]; | 322 const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)]; |
323 | 323 |
324 for(ny= -3; ny <= 3; ny++){ | 324 for(ny= -3; ny <= 3; ny++){ |
325 for(nx= -3; nx <= 3; nx++){ | 325 for(nx= -3; nx <= 3; nx++){ |
326 const int t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t; | 326 //FIXME this could overflow (unlikely though) |
327 const int c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c; | 327 const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t; |
328 const int b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b; | 328 const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c; |
329 int score= ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2; | 329 const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b; |
330 int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10; | |
330 int i; | 331 int i; |
331 | 332 |
332 if((nx&3)==0 && (ny&3)==0) continue; | 333 if((nx&3)==0 && (ny&3)==0) continue; |
333 | 334 |
334 score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor; | 335 score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor; |
335 | 336 |
336 // if(nx&1) score-=1024*c->penalty_factor; | 337 // if(nx&1) score-=1024*c->penalty_factor; |
337 // if(ny&1) score-=1024*c->penalty_factor; | 338 // if(ny&1) score-=1024*c->penalty_factor; |
338 | 339 |
339 for(i=0; i<8; i++){ | 340 for(i=0; i<8; i++){ |
348 } | 349 } |
349 } | 350 } |
350 } | 351 } |
351 }else{ | 352 }else{ |
352 int tl; | 353 int tl; |
354 //FIXME this could overflow (unlikely though) | |
353 const int cx = 4*(r - l); | 355 const int cx = 4*(r - l); |
354 const int cx2= r + l - 2*c; | 356 const int cx2= r + l - 2*c; |
355 const int cy = 4*(b - t); | 357 const int cy = 4*(b - t); |
356 const int cy2= b + t - 2*c; | 358 const int cy2= b + t - 2*c; |
357 int cxy; | 359 int cxy; |
370 assert(16*cy2 - 4*cy + 32*c == 32*t); | 372 assert(16*cy2 - 4*cy + 32*c == 32*t); |
371 assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl); | 373 assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl); |
372 | 374 |
373 for(ny= -3; ny <= 3; ny++){ | 375 for(ny= -3; ny <= 3; ny++){ |
374 for(nx= -3; nx <= 3; nx++){ | 376 for(nx= -3; nx <= 3; nx++){ |
377 //FIXME this could overflow (unlikely though) | |
375 int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor | 378 int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor |
376 int i; | 379 int i; |
377 | 380 |
378 if((nx&3)==0 && (ny&3)==0) continue; | 381 if((nx&3)==0 && (ny&3)==0) continue; |
379 | 382 |