2 |
* |
* |
3 |
* Modifications: |
* Modifications: |
4 |
* |
* |
5 |
|
* 01.05.2002 updated MotionEstimationBVOP |
6 |
* 25.04.2002 partial prevMB conversion |
* 25.04.2002 partial prevMB conversion |
7 |
* 22.04.2002 remove some compile warning by chenm001 <chenm001@163.com> |
* 22.04.2002 remove some compile warning by chenm001 <chenm001@163.com> |
8 |
* 14.04.2002 added MotionEstimationBVOP() |
* 14.04.2002 added MotionEstimationBVOP() |
185 |
|
|
186 |
typedef MainSearch8Func* MainSearch8FuncPtr; |
typedef MainSearch8Func* MainSearch8FuncPtr; |
187 |
|
|
188 |
|
static int32_t lambda_vec16[32] = /* rounded values for lambda param for weight of motion bits as in modified H.26L */ |
189 |
|
{ 0 ,(int)(1.00235+0.5), (int)(1.15582+0.5), (int)(1.31976+0.5), (int)(1.49591+0.5), (int)(1.68601+0.5), |
190 |
|
(int)(1.89187+0.5), (int)(2.11542+0.5), (int)(2.35878+0.5), (int)(2.62429+0.5), (int)(2.91455+0.5), |
191 |
|
(int)(3.23253+0.5), (int)(3.58158+0.5), (int)(3.96555+0.5), (int)(4.38887+0.5), (int)(4.85673+0.5), |
192 |
|
(int)(5.37519+0.5), (int)(5.95144+0.5), (int)(6.59408+0.5), (int)(7.31349+0.5), (int)(8.12242+0.5), |
193 |
|
(int)(9.03669+0.5), (int)(10.0763+0.5), (int)(11.2669+0.5), (int)(12.6426+0.5), (int)(14.2493+0.5), |
194 |
|
(int)(16.1512+0.5), (int)(18.442+0.5), (int)(21.2656+0.5), (int)(24.8580+0.5), (int)(29.6436+0.5), |
195 |
|
(int)(36.4949+0.5) }; |
196 |
|
|
197 |
|
static int32_t *lambda_vec8 = lambda_vec16; /* same table for INTER and INTER4V for now*/ |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
// mv.length table |
// mv.length table |
202 |
static const uint32_t mvtab[33] = { |
static const uint32_t mvtab[33] = { |
203 |
1, 2, 3, 4, 6, 7, 7, 7, |
1, 2, 3, 4, 6, 7, 7, 7, |
233 |
} |
} |
234 |
|
|
235 |
|
|
236 |
static __inline uint32_t calc_delta_16(const int32_t dx, const int32_t dy, const uint32_t iFcode) |
static __inline uint32_t calc_delta_16(const int32_t dx, const int32_t dy, const uint32_t iFcode, const uint32_t iQuant) |
237 |
{ |
{ |
238 |
return NEIGH_TEND_16X16 * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode)); |
return NEIGH_TEND_16X16 * lambda_vec16[iQuant] * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode)); |
239 |
} |
} |
240 |
|
|
241 |
static __inline uint32_t calc_delta_8(const int32_t dx, const int32_t dy, const uint32_t iFcode) |
static __inline uint32_t calc_delta_8(const int32_t dx, const int32_t dy, const uint32_t iFcode, const uint32_t iQuant) |
242 |
|
|
243 |
{ |
{ |
244 |
return NEIGH_TEND_8X8 * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode)); |
return NEIGH_TEND_8X8 * lambda_vec8[iQuant] * (mv_bits(dx, iFcode) + mv_bits(dy, iFcode)); |
245 |
} |
} |
246 |
|
|
247 |
|
|
290 |
if (sadInit) |
if (sadInit) |
291 |
(*sadInit)(); |
(*sadInit)(); |
292 |
|
|
|
|
|
|
/* eventhough we have a seperate prevMBs, |
|
|
pmvfast/epsz does something "funny" with the previous frames data */ |
|
|
|
|
|
/* for (i = 0; i < iHcount; i++) |
|
|
for (j = 0; j < iWcount; j++) |
|
|
{ |
|
|
pMBs[j + i * iWcount].mvs[0] = prevMBs[j + i * iWcount].mvs[0]; |
|
|
pMBs[j + i * iWcount].mvs[1] = prevMBs[j + i * iWcount].mvs[1]; |
|
|
pMBs[j + i * iWcount].mvs[2] = prevMBs[j + i * iWcount].mvs[2]; |
|
|
pMBs[j + i * iWcount].mvs[3] = prevMBs[j + i * iWcount].mvs[3]; |
|
|
} |
|
|
*/ |
|
|
/*dprintf("*** BEFORE ***"); |
|
|
for (i = 0; i < iHcount; i++) |
|
|
for (j = 0; j < iWcount; j++) |
|
|
{ |
|
|
dprintf(" [%i,%i] mode=%i dquant=%i mvs=(%i %i %i %i) sad8=(%i %i %i %i) sad16=(%i)", j,i, |
|
|
pMBs[j + i * iWcount].mode, |
|
|
pMBs[j + i * iWcount].dquant, |
|
|
pMBs[j + i * iWcount].mvs[0], |
|
|
pMBs[j + i * iWcount].mvs[1], |
|
|
pMBs[j + i * iWcount].mvs[2], |
|
|
pMBs[j + i * iWcount].mvs[3], |
|
|
prevMBs[j + i * iWcount].sad8[0], |
|
|
prevMBs[j + i * iWcount].sad8[1], |
|
|
prevMBs[j + i * iWcount].sad8[2], |
|
|
prevMBs[j + i * iWcount].sad8[3], |
|
|
prevMBs[j + i * iWcount].sad16); |
|
|
} |
|
|
*/ |
|
|
|
|
293 |
// note: i==horizontal, j==vertical |
// note: i==horizontal, j==vertical |
294 |
for (i = 0; i < iHcount; i++) |
for (i = 0; i < iHcount; i++) |
295 |
for (j = 0; j < iWcount; j++) |
for (j = 0; j < iWcount; j++) |
364 |
pMB->mode = MODE_INTER; |
pMB->mode = MODE_INTER; |
365 |
pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x; |
pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x; |
366 |
pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y; |
pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y; |
367 |
|
pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16; |
368 |
pMB->pmvs[0].x = pmv16.x; |
pMB->pmvs[0].x = pmv16.x; |
369 |
pMB->pmvs[0].y = pmv16.y; |
pMB->pmvs[0].y = pmv16.y; |
370 |
} |
} |
371 |
else |
else |
372 |
|
{ |
373 |
pMB->mode = MODE_INTER4V; |
pMB->mode = MODE_INTER4V; |
374 |
|
pMB->sad8[0] *= 4; |
375 |
|
pMB->sad8[1] *= 4; |
376 |
|
pMB->sad8[2] *= 4; |
377 |
|
pMB->sad8[3] *= 4; |
378 |
|
} |
379 |
} |
} |
380 |
else |
else |
381 |
{ |
{ |
383 |
pMB->mode = MODE_INTER; |
pMB->mode = MODE_INTER; |
384 |
pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x; |
pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = mv16.x; |
385 |
pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y; |
pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = mv16.y; |
386 |
|
pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad16; |
387 |
|
|
388 |
pMB->pmvs[0].x = pmv16.x; |
pMB->pmvs[0].x = pmv16.x; |
389 |
pMB->pmvs[0].y = pmv16.y; |
pMB->pmvs[0].y = pmv16.y; |
390 |
} |
} |
391 |
} |
} |
392 |
|
|
|
/* dprintf("*** AFTER ***", pMBs[0].b_mvs[0].x); |
|
|
for (i = 0; i < iHcount; i++) |
|
|
for (j = 0; j < iWcount; j++) |
|
|
{ |
|
|
dprintf(" [%i,%i] mode=%i dquant=%i mvs=(%i %i %i %i) sad8=(%i %i %i %i) sad16=(%i)", j,i, |
|
|
pMBs[j + i * iWcount].mode, |
|
|
pMBs[j + i * iWcount].dquant, |
|
|
pMBs[j + i * iWcount].mvs[0], |
|
|
pMBs[j + i * iWcount].mvs[1], |
|
|
pMBs[j + i * iWcount].mvs[2], |
|
|
pMBs[j + i * iWcount].mvs[3], |
|
|
pMBs[j + i * iWcount].sad8[0], |
|
|
pMBs[j + i * iWcount].sad8[1], |
|
|
pMBs[j + i * iWcount].sad8[2], |
|
|
pMBs[j + i * iWcount].sad8[3], |
|
|
pMBs[j + i * iWcount].sad16); |
|
|
} |
|
|
*/ |
|
|
|
|
393 |
return 0; |
return 0; |
394 |
} |
} |
395 |
|
|
403 |
&& (0 <= max_dy) && (0 >= min_dy) ) \ |
&& (0 <= max_dy) && (0 >= min_dy) ) \ |
404 |
{ \ |
{ \ |
405 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, 0, 0 , iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, 0, 0 , iEdgedWidth), iEdgedWidth, MV_MAX_ERROR); \ |
406 |
iSAD += calc_delta_16(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_16(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode, iQuant);\ |
407 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
408 |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } } \ |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } } \ |
409 |
} |
} |
410 |
|
|
411 |
#define NOCHECK_MV16_CANDIDATE(X,Y) { \ |
#define NOCHECK_MV16_CANDIDATE(X,Y) { \ |
412 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
413 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
414 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
415 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
416 |
} |
} |
420 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
421 |
{ \ |
{ \ |
422 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
423 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
424 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
425 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
426 |
} |
} |
430 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
431 |
{ \ |
{ \ |
432 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
433 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
434 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
435 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
436 |
} |
} |
440 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
441 |
{ \ |
{ \ |
442 |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
iSAD = sad16( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 16, X, Y, iEdgedWidth),iEdgedWidth, iMinSAD); \ |
443 |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_16((X) - pmv[0].x, (Y) - pmv[0].y, (uint8_t)iFcode, iQuant);\ |
444 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
445 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
446 |
} |
} |
448 |
|
|
449 |
#define CHECK_MV8_ZERO {\ |
#define CHECK_MV8_ZERO {\ |
450 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, 0, 0 , iEdgedWidth), iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, 0, 0 , iEdgedWidth), iEdgedWidth); \ |
451 |
iSAD += calc_delta_8(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_8(-pmv[0].x, -pmv[0].y, (uint8_t)iFcode, iQuant);\ |
452 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
453 |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } \ |
{ iMinSAD=iSAD; currMV->x=0; currMV->y=0; } \ |
454 |
} |
} |
456 |
#define NOCHECK_MV8_CANDIDATE(X,Y) \ |
#define NOCHECK_MV8_CANDIDATE(X,Y) \ |
457 |
{ \ |
{ \ |
458 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
459 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
460 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
461 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } \ |
462 |
} |
} |
466 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
467 |
{ \ |
{ \ |
468 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
469 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
470 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
471 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); } } \ |
472 |
} |
} |
476 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
477 |
{ \ |
{ \ |
478 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
479 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
480 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
481 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); } } \ |
482 |
} |
} |
486 |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
&& ((Y) <= max_dy) && ((Y) >= min_dy) ) \ |
487 |
{ \ |
{ \ |
488 |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
iSAD = sad8( cur, get_ref(pRef, pRefH, pRefV, pRefHV, x, y, 8, (X), (Y), iEdgedWidth),iEdgedWidth); \ |
489 |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode) * iQuant;\ |
iSAD += calc_delta_8((X)-pmv[0].x, (Y)-pmv[0].y, (uint8_t)iFcode, iQuant);\ |
490 |
if (iSAD < iMinSAD) \ |
if (iSAD < iMinSAD) \ |
491 |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
{ iMinSAD=iSAD; currMV->x=(X); currMV->y=(Y); iDirection=(D); iFound=0; } } \ |
492 |
} |
} |
958 |
iMinSAD = sad16( cur, |
iMinSAD = sad16( cur, |
959 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth), |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth), |
960 |
iEdgedWidth, MV_MAX_ERROR); |
iEdgedWidth, MV_MAX_ERROR); |
961 |
iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode) * iQuant; |
iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode, iQuant); |
962 |
|
|
963 |
if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) ) |
if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) ) |
964 |
{ |
{ |
1013 |
} |
} |
1014 |
} |
} |
1015 |
|
|
1016 |
if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) && (iSAD <= iQuant * 96) ) |
if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) /* && (iMinSAD <= iQuant * 96)*/ ) |
1017 |
iMinSAD -= MV16_00_BIAS; |
iMinSAD -= MV16_00_BIAS; |
1018 |
|
|
1019 |
|
|
1312 |
iMinSAD = sad8( cur, |
iMinSAD = sad8( cur, |
1313 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth), |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth), |
1314 |
iEdgedWidth); |
iEdgedWidth); |
1315 |
iMinSAD += calc_delta_8(currMV->x - pmv[0].x, currMV->y - pmv[0].y, (uint8_t)iFcode) * iQuant; |
iMinSAD += calc_delta_8(currMV->x - pmv[0].x, currMV->y - pmv[0].y, (uint8_t)iFcode, iQuant); |
1316 |
|
|
1317 |
if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock])) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) ) |
if ( (iMinSAD < 256/4 ) || ( (MVequal(*currMV,prevMB->mvs[iSubBlock])) && ((uint32_t)iMinSAD < prevMB->sad8[iSubBlock]) ) ) |
1318 |
{ |
{ |
1369 |
} |
} |
1370 |
} |
} |
1371 |
|
|
1372 |
if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) && (iSAD <= iQuant * 96) ) |
if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) /* && (iMinSAD <= iQuant * 96) */ ) |
1373 |
iMinSAD -= MV8_00_BIAS; |
iMinSAD -= MV8_00_BIAS; |
1374 |
|
|
1375 |
|
|
1507 |
MainSearch16FuncPtr EPZSMainSearchPtr; |
MainSearch16FuncPtr EPZSMainSearchPtr; |
1508 |
|
|
1509 |
if (oldMBs == NULL) |
if (oldMBs == NULL) |
1510 |
{ oldMBs = (MACROBLOCK*) calloc(1,iWcount*iHcount*sizeof(MACROBLOCK)); |
{ oldMBs = (MACROBLOCK*) calloc(iWcount*iHcount,sizeof(MACROBLOCK)); |
1511 |
// fprintf(stderr,"allocated %d bytes for oldMBs\n",iWcount*iHcount*sizeof(MACROBLOCK)); |
// fprintf(stderr,"allocated %d bytes for oldMBs\n",iWcount*iHcount*sizeof(MACROBLOCK)); |
1512 |
} |
} |
1513 |
oldMB = oldMBs + x + y * iWcount; |
oldMB = oldMBs + x + y * iWcount; |
1555 |
iMinSAD = sad16( cur, |
iMinSAD = sad16( cur, |
1556 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth), |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 16, currMV, iEdgedWidth), |
1557 |
iEdgedWidth, MV_MAX_ERROR); |
iEdgedWidth, MV_MAX_ERROR); |
1558 |
iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode) * iQuant; |
iMinSAD += calc_delta_16(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode, iQuant); |
1559 |
|
|
1560 |
// thresh1 is fixed to 256 |
// thresh1 is fixed to 256 |
1561 |
if ( (iMinSAD < 256 ) || ( (MVequal(*currMV,pMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) ) |
if ( (iMinSAD < 256 ) || ( (MVequal(*currMV, prevMB->mvs[0])) && ((uint32_t)iMinSAD < prevMB->sad16) ) ) |
1562 |
{ |
{ |
1563 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
1564 |
goto EPZS16_Terminate_without_Refine; |
goto EPZS16_Terminate_without_Refine; |
1569 |
/************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/ |
/************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/ |
1570 |
|
|
1571 |
// previous frame MV |
// previous frame MV |
1572 |
CHECK_MV16_CANDIDATE(pMB->mvs[0].x,pMB->mvs[0].y); |
CHECK_MV16_CANDIDATE(prevMB->mvs[0].x,prevMB->mvs[0].y); |
1573 |
|
|
1574 |
// set threshhold based on Min of Prediction and SAD of collocated block |
// set threshhold based on Min of Prediction and SAD of collocated block |
1575 |
// CHECK_MV16 always uses iSAD for the SAD of last vector to check, so now iSAD is what we want |
// CHECK_MV16 always uses iSAD for the SAD of last vector to check, so now iSAD is what we want |
1625 |
*/ |
*/ |
1626 |
|
|
1627 |
if ( (iMinSAD <= thresh2) |
if ( (iMinSAD <= thresh2) |
1628 |
|| ( MVequal(*currMV,pMB->mvs[0]) && ((uint32_t)iMinSAD <= prevMB->sad16) ) ) |
|| ( MVequal(*currMV,prevMB->mvs[0]) && ((uint32_t)iMinSAD <= prevMB->sad16) ) ) |
1629 |
{ |
{ |
1630 |
if (MotionFlags & PMV_QUICKSTOP16) |
if (MotionFlags & PMV_QUICKSTOP16) |
1631 |
goto EPZS16_Terminate_without_Refine; |
goto EPZS16_Terminate_without_Refine; |
1635 |
|
|
1636 |
/***** predictor SET C: acceleration MV (new!), neighbours in prev. frame(new!) ****/ |
/***** predictor SET C: acceleration MV (new!), neighbours in prev. frame(new!) ****/ |
1637 |
|
|
1638 |
backupMV = pMB->mvs[0]; // last MV |
backupMV = prevMB->mvs[0]; // collocated MV |
1639 |
backupMV.x += (pMB->mvs[0].x - oldMB->mvs[0].x ); // acceleration X |
backupMV.x += (prevMB->mvs[0].x - oldMB->mvs[0].x ); // acceleration X |
1640 |
backupMV.y += (pMB->mvs[0].y - oldMB->mvs[0].y ); // acceleration Y |
backupMV.y += (prevMB->mvs[0].y - oldMB->mvs[0].y ); // acceleration Y |
1641 |
|
|
1642 |
CHECK_MV16_CANDIDATE(backupMV.x,backupMV.y); |
CHECK_MV16_CANDIDATE(backupMV.x,backupMV.y); |
1643 |
|
|
1644 |
// left neighbour |
// left neighbour |
1645 |
if (x != 0) |
if (x != 0) |
1646 |
CHECK_MV16_CANDIDATE((oldMB-1)->mvs[0].x,oldMB->mvs[0].y); |
CHECK_MV16_CANDIDATE((prevMB-1)->mvs[0].x,(prevMB-1)->mvs[0].y); |
1647 |
|
|
1648 |
// top neighbour |
// top neighbour |
1649 |
if (y != 0) |
if (y != 0) |
1650 |
CHECK_MV16_CANDIDATE((oldMB-iWcount)->mvs[0].x,oldMB->mvs[0].y); |
CHECK_MV16_CANDIDATE((prevMB-iWcount)->mvs[0].x,(prevMB-iWcount)->mvs[0].y); |
1651 |
|
|
1652 |
// right neighbour, if allowed (this value is not written yet, so take it from pMB->mvs |
// right neighbour, if allowed (this value is not written yet, so take it from pMB->mvs |
1653 |
|
|
1654 |
if ((uint32_t)x != iWcount-1) |
if ((uint32_t)x != iWcount-1) |
1655 |
CHECK_MV16_CANDIDATE((pMB+1)->mvs[0].x,oldMB->mvs[0].y); |
CHECK_MV16_CANDIDATE((prevMB+1)->mvs[0].x,(prevMB+1)->mvs[0].y); |
1656 |
|
|
1657 |
// bottom neighbour, dito |
// bottom neighbour, dito |
1658 |
if ((uint32_t)y != iHcount-1) |
if ((uint32_t)y != iHcount-1) |
1659 |
CHECK_MV16_CANDIDATE((pMB+iWcount)->mvs[0].x,oldMB->mvs[0].y); |
CHECK_MV16_CANDIDATE((prevMB+iWcount)->mvs[0].x,(prevMB+iWcount)->mvs[0].y); |
1660 |
|
|
1661 |
/* Terminate if MinSAD <= T_3 (here T_3 = T_2) */ |
/* Terminate if MinSAD <= T_3 (here T_3 = T_2) */ |
1662 |
if (iMinSAD <= thresh2) |
if (iMinSAD <= thresh2) |
1713 |
iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur, |
iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur, |
1714 |
x, y, |
x, y, |
1715 |
0, 0, iMinSAD, &newMV, |
0, 0, iMinSAD, &newMV, |
1716 |
pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth, /*iDiamondSize*/ 2, iFcode, iQuant, 0); |
pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth, 2, iFcode, iQuant, 0); |
1717 |
|
|
1718 |
if (iSAD < iMinSAD) |
if (iSAD < iMinSAD) |
1719 |
{ |
{ |
1734 |
|
|
1735 |
EPZS16_Terminate_without_Refine: |
EPZS16_Terminate_without_Refine: |
1736 |
|
|
1737 |
*oldMB = *pMB; |
*oldMB = *prevMB; |
1738 |
|
|
1739 |
currPMV->x = currMV->x - pmv[0].x; |
currPMV->x = currMV->x - pmv[0].x; |
1740 |
currPMV->y = currMV->y - pmv[0].y; |
currPMV->y = currMV->y - pmv[0].y; |
1759 |
VECTOR * const currMV, |
VECTOR * const currMV, |
1760 |
VECTOR * const currPMV) |
VECTOR * const currPMV) |
1761 |
{ |
{ |
1762 |
|
/* Please not that EPZS might not be a good choice for 8x8-block motion search ! */ |
1763 |
|
|
1764 |
const uint32_t iWcount = pParam->mb_width; |
const uint32_t iWcount = pParam->mb_width; |
1765 |
const int32_t iWidth = pParam->width; |
const int32_t iWidth = pParam->width; |
1766 |
const int32_t iHeight = pParam->height; |
const int32_t iHeight = pParam->height; |
1838 |
iMinSAD = sad8( cur, |
iMinSAD = sad8( cur, |
1839 |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth), |
get_ref_mv(pRef, pRefH, pRefV, pRefHV, x, y, 8, currMV, iEdgedWidth), |
1840 |
iEdgedWidth); |
iEdgedWidth); |
1841 |
iMinSAD += calc_delta_8(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode) * iQuant; |
iMinSAD += calc_delta_8(currMV->x-pmv[0].x, currMV->y-pmv[0].y, (uint8_t)iFcode, iQuant); |
1842 |
|
|
1843 |
|
|
1844 |
// thresh1 is fixed to 256 |
// thresh1 is fixed to 256 |
1852 |
|
|
1853 |
/************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/ |
/************** This is predictor SET B: (0,0), prev.frame MV, neighbours **************/ |
1854 |
|
|
|
// previous frame MV |
|
|
CHECK_MV8_CANDIDATE(pMB->mvs[0].x,pMB->mvs[0].y); |
|
1855 |
|
|
1856 |
// MV=(0,0) is often a good choice |
// MV=(0,0) is often a good choice |
|
|
|
1857 |
CHECK_MV8_ZERO; |
CHECK_MV8_ZERO; |
1858 |
|
|
1859 |
|
// previous frame MV |
1860 |
|
CHECK_MV8_CANDIDATE(prevMB->mvs[iSubBlock].x,prevMB->mvs[iSubBlock].y); |
1861 |
|
|
1862 |
|
// left neighbour, if allowed |
1863 |
|
if (psad[1] != MV_MAX_ERROR) |
1864 |
|
{ |
1865 |
|
if (!(MotionFlags & PMV_HALFPEL8 )) |
1866 |
|
{ pmv[1].x = EVEN(pmv[1].x); |
1867 |
|
pmv[1].y = EVEN(pmv[1].y); |
1868 |
|
} |
1869 |
|
CHECK_MV8_CANDIDATE(pmv[1].x,pmv[1].y); |
1870 |
|
} |
1871 |
|
|
1872 |
|
// top neighbour, if allowed |
1873 |
|
if (psad[2] != MV_MAX_ERROR) |
1874 |
|
{ |
1875 |
|
if (!(MotionFlags & PMV_HALFPEL8 )) |
1876 |
|
{ pmv[2].x = EVEN(pmv[2].x); |
1877 |
|
pmv[2].y = EVEN(pmv[2].y); |
1878 |
|
} |
1879 |
|
CHECK_MV8_CANDIDATE(pmv[2].x,pmv[2].y); |
1880 |
|
|
1881 |
|
// top right neighbour, if allowed |
1882 |
|
if (psad[3] != MV_MAX_ERROR) |
1883 |
|
{ |
1884 |
|
if (!(MotionFlags & PMV_HALFPEL8 )) |
1885 |
|
{ pmv[3].x = EVEN(pmv[3].x); |
1886 |
|
pmv[3].y = EVEN(pmv[3].y); |
1887 |
|
} |
1888 |
|
CHECK_MV8_CANDIDATE(pmv[3].x,pmv[3].y); |
1889 |
|
} |
1890 |
|
} |
1891 |
|
|
1892 |
|
/* // this bias is zero anyway, at the moment! |
1893 |
|
|
1894 |
|
if ( (MVzero(*currMV)) && (!MVzero(pmv[0])) ) // && (iMinSAD <= iQuant * 96) |
1895 |
|
iMinSAD -= MV8_00_BIAS; |
1896 |
|
|
1897 |
|
*/ |
1898 |
|
|
1899 |
/* Terminate if MinSAD <= T_2 |
/* Terminate if MinSAD <= T_2 |
1900 |
Terminate if MV[t] == MV[t-1] and MinSAD[t] <= MinSAD[t-1] |
Terminate if MV[t] == MV[t-1] and MinSAD[t] <= MinSAD[t-1] |
1901 |
*/ |
*/ |
1908 |
goto EPZS8_Terminate_with_Refine; |
goto EPZS8_Terminate_with_Refine; |
1909 |
} |
} |
1910 |
|
|
1911 |
/************ (if Diamond Search) **************/ |
/************ (Diamond Search) **************/ |
1912 |
|
|
1913 |
backupMV = *currMV; /* save best prediction, actually only for EXTSEARCH */ |
backupMV = *currMV; /* save best prediction, actually only for EXTSEARCH */ |
1914 |
|
|
1915 |
if (!(MotionFlags & PMV_HALFPELDIAMOND8)) |
if (!(MotionFlags & PMV_HALFPELDIAMOND8)) |
1916 |
iDiamondSize *= 2; |
iDiamondSize *= 2; |
1917 |
|
|
1918 |
/* default: use best prediction as starting point for one call of PMVfast_MainSearch */ |
/* default: use best prediction as starting point for one call of EPZS_MainSearch */ |
1919 |
|
|
1920 |
|
/* // there is no EPZS^2 for inter4v at the moment |
1921 |
|
|
1922 |
|
if (MotionFlags & PMV_USESQUARES8) |
1923 |
|
EPZSMainSearchPtr = Square8_MainSearch; |
1924 |
|
else |
1925 |
|
*/ |
1926 |
|
|
|
// if (MotionFlags & PMV_USESQUARES8) |
|
|
// EPZSMainSearchPtr = Square8_MainSearch; |
|
|
// else |
|
1927 |
EPZSMainSearchPtr = Diamond8_MainSearch; |
EPZSMainSearchPtr = Diamond8_MainSearch; |
1928 |
|
|
1929 |
iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur, |
iSAD = (*EPZSMainSearchPtr)(pRef, pRefH, pRefV, pRefHV, cur, |
1930 |
x, y, |
x, y, |
1931 |
currMV->x, currMV->y, iMinSAD, &newMV, |
currMV->x, currMV->y, iMinSAD, &newMV, |
1932 |
pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
pmv, min_dx, max_dx, min_dy, max_dy, iEdgedWidth, |
1933 |
iDiamondSize, iFcode, iQuant, 00); |
iDiamondSize, iFcode, iQuant, 0); |
1934 |
|
|
1935 |
|
|
1936 |
if (iSAD < iMinSAD) |
if (iSAD < iMinSAD) |
1997 |
// TODO: need to incorporate prediction here (eg. sad += calc_delta_16) |
// TODO: need to incorporate prediction here (eg. sad += calc_delta_16) |
1998 |
***************************************************************/ |
***************************************************************/ |
1999 |
|
|
2000 |
/* |
|
2001 |
void MotionEstimationBVOP( |
void MotionEstimationBVOP( |
2002 |
MBParam * const pParam, |
MBParam * const pParam, |
2003 |
FRAMEINFO * const frame, |
FRAMEINFO * const frame, |
2019 |
const uint32_t mb_height = pParam->mb_height; |
const uint32_t mb_height = pParam->mb_height; |
2020 |
const int32_t edged_width = pParam->edged_width; |
const int32_t edged_width = pParam->edged_width; |
2021 |
|
|
2022 |
int32_t i,j; |
uint32_t i,j; |
2023 |
|
|
2024 |
int32_t f_sad16; |
int32_t f_sad16; |
2025 |
int32_t b_sad16; |
int32_t b_sad16; |
2043 |
&& b_mb->mvs[0].x == 0 |
&& b_mb->mvs[0].x == 0 |
2044 |
&& b_mb->mvs[0].y == 0) |
&& b_mb->mvs[0].y == 0) |
2045 |
{ |
{ |
2046 |
mb->mode = MB_IGNORE; |
mb->mode = MODE_NOT_CODED; |
2047 |
mb->mvs[0].x = 0; |
mb->mvs[0].x = 0; |
2048 |
mb->mvs[0].y = 0; |
mb->mvs[0].y = 0; |
2049 |
mb->b_mvs[0].x = 0; |
mb->b_mvs[0].x = 0; |
2058 |
i, j, |
i, j, |
2059 |
frame->motion_flags, frame->quant, frame->fcode, |
frame->motion_flags, frame->quant, frame->fcode, |
2060 |
pParam, |
pParam, |
2061 |
f_mbs, |
f_mbs, f_mbs /* todo */, |
2062 |
&mb->mvs[0], &pmv_dontcare); // ignore pmv |
&mb->mvs[0], &pmv_dontcare); // ignore pmv |
2063 |
|
|
2064 |
// backward search |
// backward search |
2067 |
i, j, |
i, j, |
2068 |
frame->motion_flags, frame->quant, frame->bcode, |
frame->motion_flags, frame->quant, frame->bcode, |
2069 |
pParam, |
pParam, |
2070 |
b_mbs, |
b_mbs, b_mbs, /* todo */ |
2071 |
&mb->b_mvs[0], &pmv_dontcare); // ignore pmv |
&mb->b_mvs[0], &pmv_dontcare); // ignore pmv |
2072 |
|
|
2073 |
// interpolate search (simple, but effective) |
// interpolate search (simple, but effective) |
2087 |
if (f_sad16 < b_sad16) |
if (f_sad16 < b_sad16) |
2088 |
{ |
{ |
2089 |
best_sad = f_sad16; |
best_sad = f_sad16; |
2090 |
mb->mode = MB_FORWARD; |
mb->mode = MODE_FORWARD; |
2091 |
} |
} |
2092 |
else |
else |
2093 |
{ |
{ |
2094 |
best_sad = b_sad16; |
best_sad = b_sad16; |
2095 |
mb->mode = MB_BACKWARD; |
mb->mode = MODE_BACKWARD; |
2096 |
} |
} |
2097 |
|
|
2098 |
if (i_sad16 < best_sad) |
if (i_sad16 < best_sad) |
2099 |
{ |
{ |
2100 |
best_sad = i_sad16; |
best_sad = i_sad16; |
2101 |
mb->mode = MB_INTERPOLATE; |
mb->mode = MODE_INTERPOLATE; |
2102 |
} |
} |
2103 |
|
|
2104 |
if (d_sad16 < best_sad) |
if (d_sad16 < best_sad) |
2105 |
{ |
{ |
2106 |
best_sad = d_sad16; |
best_sad = d_sad16; |
2107 |
mb->mode = MB_DIRECT; |
mb->mode = MODE_DIRECT; |
2108 |
} |
} |
2109 |
|
|
2110 |
} |
} |
2111 |
} |
} |
2112 |
} |
} |
|
|
|
|
*/ |
|