365 |
*Data->iMinSAD = MV_MAX_ERROR; |
*Data->iMinSAD = MV_MAX_ERROR; |
366 |
Data->iFcode = iFcode; |
Data->iFcode = iFcode; |
367 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
368 |
Data->chromaX = Data->chromaX = Data->chromaSAD = 256*4096; /* reset chroma-sad cache */ |
Data->chromaX = Data->chromaY = Data->chromaSAD = 256*4096; /* reset chroma-sad cache */ |
369 |
|
|
370 |
Data->RefP[0] = pRef->y + (x + Data->iEdgedWidth*y) * 16; |
Data->RefP[0] = pRef->y + (x + Data->iEdgedWidth*y) * 16; |
371 |
Data->RefP[2] = pRefH + (x + Data->iEdgedWidth*y) * 16; |
Data->RefP[2] = pRefH + (x + Data->iEdgedWidth*y) * 16; |
391 |
if (!vector_repeats(pmv, i) ) |
if (!vector_repeats(pmv, i) ) |
392 |
CheckCandidate16no4v(pmv[i].x, pmv[i].y, Data, i); |
CheckCandidate16no4v(pmv[i].x, pmv[i].y, Data, i); |
393 |
|
|
394 |
|
if (*Data->iMinSAD > 512) { |
395 |
|
unsigned int mask = make_mask(pmv, 7, Data->dir); |
396 |
|
|
397 |
|
MainSearchFunc *MainSearchPtr; |
398 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
399 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
400 |
else MainSearchPtr = xvid_me_DiamondSearch; |
else MainSearchPtr = xvid_me_DiamondSearch; |
401 |
|
|
|
if (*Data->iMinSAD > 512) { |
|
|
unsigned int mask = make_mask(pmv, 7, Data->dir); |
|
402 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v); |
403 |
} |
} |
404 |
|
|
448 |
const uint32_t x, const uint32_t y, |
const uint32_t x, const uint32_t y, |
449 |
const SearchData * const Data) |
const SearchData * const Data) |
450 |
{ |
{ |
451 |
|
int k; |
452 |
|
|
453 |
|
if (!Data->chroma) { |
454 |
int dx = 0, dy = 0, b_dx = 0, b_dy = 0; |
int dx = 0, dy = 0, b_dx = 0, b_dy = 0; |
455 |
int32_t sum; |
int32_t sum; |
|
int k; |
|
456 |
const uint32_t stride = Data->iEdgedWidth/2; |
const uint32_t stride = Data->iEdgedWidth/2; |
457 |
/* this is not full chroma compensation, only it's fullpel approximation. should work though */ |
/* this is not full chroma compensation, only it's fullpel approximation. should work though */ |
458 |
|
|
480 |
b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
481 |
stride); |
stride); |
482 |
|
|
483 |
if (sum < MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) { |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ |
484 |
|
} |
485 |
|
|
486 |
|
/* skip */ |
487 |
pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
488 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
489 |
pMB->qmvs[k] = pMB->mvs[k] = Data->directmvF[k]; |
pMB->qmvs[k] = pMB->mvs[k] = Data->directmvF[k]; |
490 |
pMB->b_qmvs[k] = pMB->b_mvs[k] = Data->directmvB[k]; |
pMB->b_qmvs[k] = pMB->b_mvs[k] = Data->directmvB[k]; |
491 |
} |
} |
492 |
} |
} |
|
} |
|
493 |
|
|
494 |
static uint32_t |
static uint32_t |
495 |
SearchDirect(const IMAGE * const f_Ref, |
SearchDirect(const IMAGE * const f_Ref, |
569 |
/* initial (fast) skip decision */ |
/* initial (fast) skip decision */ |
570 |
if (*Data->iMinSAD < (int)Data->iQuant * INITIAL_SKIP_THRESH * (Data->chroma?3:2)) { |
if (*Data->iMinSAD < (int)Data->iQuant * INITIAL_SKIP_THRESH * (Data->chroma?3:2)) { |
571 |
/* possible skip */ |
/* possible skip */ |
|
if (Data->chroma) { |
|
|
pMB->mode = MODE_DIRECT_NONE_MV; |
|
|
return *Data->iMinSAD; /* skip. */ |
|
|
} else { |
|
572 |
SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data); |
SkipDecisionB(pCur, f_Ref, b_Ref, pMB, x, y, Data); |
573 |
if (pMB->mode == MODE_DIRECT_NONE_MV) return *Data->iMinSAD; /* skip. */ |
if (pMB->mode == MODE_DIRECT_NONE_MV) return *Data->iMinSAD; /* skipped */ |
|
} |
|
574 |
} |
} |
575 |
|
|
576 |
*Data->iMinSAD += Data->lambda16; |
*Data->iMinSAD += Data->lambda16; |
577 |
skip_sad = *Data->iMinSAD; |
skip_sad = *Data->iMinSAD; |
578 |
|
|
|
/* |
|
|
* DIRECT MODE DELTA VECTOR SEARCH. |
|
|
* This has to be made more effective, but at the moment I'm happy it's running at all |
|
|
*/ |
|
|
|
|
579 |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch; |
580 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch; |
581 |
else MainSearchPtr = xvid_me_DiamondSearch; |
else MainSearchPtr = xvid_me_DiamondSearch; |
749 |
SubpelRefine_dir(Data, CheckCandidateInt, 2); |
SubpelRefine_dir(Data, CheckCandidateInt, 2); |
750 |
} |
} |
751 |
|
|
752 |
*Data->iMinSAD += (2+3) * Data->lambda16; /* two bits are needed to code interpolate mode. */ |
*Data->iMinSAD += 2 * Data->lambda16; /* two bits are needed to code interpolate mode. */ |
753 |
|
|
754 |
if (*Data->iMinSAD < *best_sad) { |
if (*Data->iMinSAD < *best_sad) { |
755 |
*best_sad = *Data->iMinSAD; |
*best_sad = *Data->iMinSAD; |
807 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
808 |
|
|
809 |
Data.iEdgedWidth = pParam->edged_width; |
Data.iEdgedWidth = pParam->edged_width; |
|
Data.lambda16 = xvid_me_lambda_vec16[MAX(frame->quant-2, 2)]; |
|
810 |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL ? 1 : 0; |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL ? 1 : 0; |
811 |
Data.rounding = 0; |
Data.rounding = 0; |
812 |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
831 |
continue; |
continue; |
832 |
} |
} |
833 |
|
|
834 |
|
Data.lambda16 = xvid_me_lambda_vec16[b_mb->quant]; |
835 |
|
|
836 |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
837 |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
838 |
Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8; |
880 |
&Data); |
&Data); |
881 |
|
|
882 |
/* final skip decision */ |
/* final skip decision */ |
883 |
if ( (skip_sad < Data.iQuant * MAX_SAD00_FOR_SKIP * 2) |
if ( (skip_sad < Data.iQuant * MAX_SAD00_FOR_SKIP * (Data.chroma ? 3:2) ) |
884 |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) |
885 |
|
|
886 |
SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data); |
SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data); |
887 |
|
|
888 |
switch (pMB->mode) { |
switch (pMB->mode) { |