📄 estimation_pvop.c
字号:
if (x != 0) { pmv[3].x = EVEN(pmv[1].x); pmv[3].y = EVEN(pmv[1].y); }/* pmv[3] is left neighbour */
else pmv[3].x = pmv[3].y = 0;
if (y != 0) { pmv[4].x = EVEN(pmv[2].x); pmv[4].y = EVEN(pmv[2].y); }/* [4] top neighbour */
else pmv[4].x = pmv[4].y = 0;
/* [1] median prediction */
pmv[1].x = EVEN(pmv[0].x); pmv[1].y = EVEN(pmv[0].y);
pmv[0].x = pmv[0].y = 0; /* [0] is zero; not used in the loop (checked before) but needed here for make_mask */
pmv[2].x = EVEN(prevMB->mvs[0].x); /* [2] is last frame */
pmv[2].y = EVEN(prevMB->mvs[0].y);
if ((x < iWcount-1) && (y < iHcount-1)) {
pmv[6].x = EVEN((prevMB+1+iWcount)->mvs[0].x); /* [6] right-down neighbour in last frame */
pmv[6].y = EVEN((prevMB+1+iWcount)->mvs[0].y);
} else pmv[6].x = pmv[6].y = 0;
}
static void
Search8(SearchData * const OldData,
const int x, const int y,
const uint32_t MotionFlags,
const MBParam * const pParam,
MACROBLOCK * const pMB,
const MACROBLOCK * const pMBs,
const int block,
SearchData * const Data)
{
int i = 0;
VECTOR vbest_q; int32_t sbest_q;
*Data->iMinSAD = *(OldData->iMinSAD + 1 + block);
*Data->currentMV = *(OldData->currentMV + 1 + block);
*Data->currentQMV = *(OldData->currentQMV + 1 + block);
if(Data->qpel) {
Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2, y/2, block);
if (block != 0) i = d_mv_bits( Data->currentQMV->x, Data->currentQMV->y,
Data->predMV, Data->iFcode, 0);
} else {
Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2, y/2, block);
if (block != 0) i = d_mv_bits( Data->currentMV->x, Data->currentMV->y,
Data->predMV, Data->iFcode, 0);
}
*(Data->iMinSAD) += (Data->lambda8 * i);
if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) {
vbest_q = Data->currentQMV[0];
sbest_q = Data->iMinSAD[0];
Data->RefP[0] = OldData->RefP[0] + 8 * ((block&1) + Data->iEdgedWidth*(block>>1));
Data->RefP[1] = OldData->RefP[1] + 8 * ((block&1) + Data->iEdgedWidth*(block>>1));
Data->RefP[2] = OldData->RefP[2] + 8 * ((block&1) + Data->iEdgedWidth*(block>>1));
Data->RefP[3] = OldData->RefP[3] + 8 * ((block&1) + Data->iEdgedWidth*(block>>1));
Data->Cur = OldData->Cur + 8 * ((block&1) + Data->iEdgedWidth*(block>>1));
Data->qpel_precision = 0;
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3,
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1);
if (MotionFlags & XVID_ME_EXTSEARCH8 && (!(MotionFlags & XVID_ME_EXTSEARCH_RD))) {
MainSearchFunc *MainSearchPtr;
if (MotionFlags & XVID_ME_USESQUARES8) MainSearchPtr = xvid_me_SquareSearch;
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND8) MainSearchPtr = xvid_me_AdvDiamondSearch;
else MainSearchPtr = xvid_me_DiamondSearch;
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidate8);
}
if(!Data->qpel) {
/* halfpel mode */
if (MotionFlags & XVID_ME_HALFPELREFINE8)
/* perform halfpel refine of current best vector */
xvid_me_SubpelRefine(Data->currentMV[0], Data, CheckCandidate8, 0);
} else {
/* qpel mode */
Data->currentQMV->x = 2*Data->currentMV->x;
Data->currentQMV->y = 2*Data->currentMV->y;
if(MotionFlags & XVID_ME_FASTREFINE8) {
/* fast */
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3,
pParam->width, pParam->height, Data->iFcode, 2);
FullRefine_Fast(Data, CheckCandidate8, 0);
} else if(MotionFlags & XVID_ME_QUARTERPELREFINE8) {
/* full */
if (MotionFlags & XVID_ME_HALFPELREFINE8) {
xvid_me_SubpelRefine(Data->currentMV[0], Data, CheckCandidate8, 0); /* hpel part */
Data->currentQMV->x = 2*Data->currentMV->x;
Data->currentQMV->y = 2*Data->currentMV->y;
}
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 3,
pParam->width, pParam->height, Data->iFcode, 2);
Data->qpel_precision = 1;
xvid_me_SubpelRefine(Data->currentQMV[0], Data, CheckCandidate8, 0); /* qpel part */
}
}
if (sbest_q <= Data->iMinSAD[0]) /* we have not found a better match */
Data->currentQMV[0] = vbest_q;
}
if(Data->qpel) {
pMB->pmvs[block].x = Data->currentQMV->x - Data->predMV.x;
pMB->pmvs[block].y = Data->currentQMV->y - Data->predMV.y;
pMB->qmvs[block] = *Data->currentQMV;
} else {
pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x;
pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;
}
*(OldData->iMinSAD + 1 + block) = *Data->iMinSAD;
*(OldData->currentMV + 1 + block) = *Data->currentMV;
*(OldData->currentQMV + 1 + block) = *Data->currentQMV;
pMB->mvs[block] = *Data->currentMV;
pMB->sad8[block] = 4 * *Data->iMinSAD;
}
static void
SearchP(const IMAGE * const pRef,
const uint8_t * const pRefH,
const uint8_t * const pRefV,
const uint8_t * const pRefHV,
const IMAGE * const pCur,
const int x,
const int y,
const uint32_t MotionFlags,
const uint32_t VopFlags,
SearchData * const Data,
const MBParam * const pParam,
const MACROBLOCK * const pMBs,
const MACROBLOCK * const prevMBs,
MACROBLOCK * const pMB)
{
int i, threshA;
VECTOR pmv[7];
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0);
CheckFunc * CheckCandidate;
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1);
get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, pmv, Data->temp);
Data->chromaX = Data->chromaY = 0; /* chroma-sad cache */
Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16;
Data->CurV = pCur->v + (x + y * (Data->iEdgedWidth/2)) * 8;
Data->CurU = pCur->u + (x + y * (Data->iEdgedWidth/2)) * 8;
Data->RefP[0] = pRef->y + (x + Data->iEdgedWidth*y) * 16;
Data->RefP[2] = pRefH + (x + Data->iEdgedWidth*y) * 16;
Data->RefP[1] = pRefV + (x + Data->iEdgedWidth*y) * 16;
Data->RefP[3] = pRefHV + (x + Data->iEdgedWidth*y) * 16;
Data->RefP[4] = pRef->u + (x + y * (Data->iEdgedWidth/2)) * 8;
Data->RefP[5] = pRef->v + (x + y * (Data->iEdgedWidth/2)) * 8;
Data->lambda16 = xvid_me_lambda_vec16[pMB->quant];
Data->lambda8 = xvid_me_lambda_vec8[pMB->quant];
Data->qpel_precision = 0;
Data->dir = 0;
memset(Data->currentMV, 0, 5*sizeof(VECTOR));
if (Data->qpel) Data->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0);
else Data->predMV = pmv[0];
i = d_mv_bits(0, 0, Data->predMV, Data->iFcode, 0);
Data->iMinSAD[0] = pMB->sad16 + (Data->lambda16 * i);
Data->iMinSAD[1] = pMB->sad8[0] + (Data->lambda8 * i);
Data->iMinSAD[2] = pMB->sad8[1];
Data->iMinSAD[3] = pMB->sad8[2];
Data->iMinSAD[4] = pMB->sad8[3];
if ((!(VopFlags & XVID_VOP_MODEDECISION_RD)) && (x | y)) {
threshA = Data->temp[0]; /* that's where we keep this SAD atm */
if (threshA < 512) threshA = 512;
else if (threshA > 1024) threshA = 1024;
} else
threshA = 512;
PreparePredictionsP(pmv, x, y, pParam->mb_width, pParam->mb_height,
prevMBs + x + y * pParam->mb_width);
if (inter4v) CheckCandidate = CheckCandidate16;
else CheckCandidate = CheckCandidate16no4v; /* for extra speed */
/* main loop. checking all predictions (but first, which is 0,0 and has been checked in MotionEstimation())*/
for (i = 1; i < 7; i++)
if (!vector_repeats(pmv, i)) {
CheckCandidate(pmv[i].x, pmv[i].y, Data, i);
if (Data->iMinSAD[0] <= threshA) { i++; break; }
}
if ((Data->iMinSAD[0] <= threshA) ||
(MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) &&
(Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16)))
inter4v = 0;
else {
MainSearchFunc * MainSearchPtr;
int mask = make_mask(pmv, i, Data->dir); /* all vectors pmv[0..i-1] have been checked */
if (MotionFlags & XVID_ME_USESQUARES16) MainSearchPtr = xvid_me_SquareSearch;
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = xvid_me_AdvDiamondSearch;
else MainSearchPtr = xvid_me_DiamondSearch;
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate);
/* extended search, diamond starting in 0,0 and in prediction.
note that this search is/might be done in halfpel positions,
which makes it more different than the diamond above */
if (MotionFlags & XVID_ME_EXTSEARCH16) {
int32_t bSAD;
VECTOR startMV = Data->predMV, backupMV = Data->currentMV[0];
if (Data->qpel) {
startMV.x /= 2;
startMV.y /= 2;
}
if (!(MVequal(startMV, backupMV))) {
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
CheckCandidate(startMV.x, startMV.y, Data, 255);
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate);
if (bSAD < Data->iMinSAD[0]) {
Data->currentMV[0] = backupMV;
Data->iMinSAD[0] = bSAD;
}
}
backupMV = Data->currentMV[0];
startMV.x = startMV.y = 1;
if (!(MVequal(startMV, backupMV))) {
bSAD = Data->iMinSAD[0]; Data->iMinSAD[0] = MV_MAX_ERROR;
CheckCandidate(startMV.x, startMV.y, Data, 255);
xvid_me_DiamondSearch(startMV.x, startMV.y, Data, 255, CheckCandidate);
if (bSAD < Data->iMinSAD[0]) {
Data->currentMV[0] = backupMV;
Data->iMinSAD[0] = bSAD;
}
}
}
}
if(!Data->qpel) {
/* halfpel mode */
if (MotionFlags & XVID_ME_HALFPELREFINE16)
xvid_me_SubpelRefine(Data->currentMV[0], Data, CheckCandidate, 0);
} else {
/* qpel mode */
for(i = 0; i < 5; i++) {
Data->currentQMV[i].x = 2 * Data->currentMV[i].x; /* initialize qpel vectors */
Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
}
if(MotionFlags & XVID_ME_FASTREFINE16 && MotionFlags & XVID_ME_QUARTERPELREFINE16) {
/* fast */
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
pParam->width, pParam->height, Data->iFcode, 2);
FullRefine_Fast(Data, CheckCandidate, 0);
} else {
if(MotionFlags & (XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE16_RD)) {
/* full */
if (MotionFlags & XVID_ME_HALFPELREFINE16) {
xvid_me_SubpelRefine(Data->currentMV[0], Data, CheckCandidate, 0); /* hpel part */
for(i = 0; i < 5; i++) {
Data->currentQMV[i].x = 2 * Data->currentMV[i].x;
Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
}
}
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4,
pParam->width, pParam->height, Data->iFcode, 2);
Data->qpel_precision = 1;
if(MotionFlags & XVID_ME_QUARTERPELREFINE16)
xvid_me_SubpelRefine(Data->currentQMV[0], Data, CheckCandidate, 0); /* qpel part */
}
}
}
if (Data->iMinSAD[0] < (int32_t)pMB->quant * 30 * ((MotionFlags & XVID_ME_FASTREFINE16) ? 8 : 1))
inter4v = 0;
if (inter4v) {
SearchData Data8;
memcpy(&Data8, Data, sizeof(SearchData)); /* quick copy of common data */
Search8(Data, 2*x, 2*y, MotionFlags, pParam, pMB, pMBs, 0, &Data8);
Search8(Data, 2*x + 1, 2*y, MotionFlags, pParam, pMB, pMBs, 1, &Data8);
Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8);
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8);
if ((Data->chroma) && (!(VopFlags & XVID_VOP_MODEDECISION_RD))) {
/* chroma is only used for comparison to INTER. if the comparison will be done in RD domain, it will not be used */
int sumx = 0, sumy = 0;
if (Data->qpel)
for (i = 1; i < 5; i++) {
sumx += Data->currentQMV[i].x/2;
sumy += Data->currentQMV[i].y/2;
}
else
for (i = 1; i < 5; i++) {
sumx += Data->currentMV[i].x;
sumy += Data->currentMV[i].y;
}
Data->iMinSAD[1] += xvid_me_ChromaSAD((sumx >> 3) + roundtab_76[sumx & 0xf],
(sumy >> 3) + roundtab_76[sumy & 0xf], Data);
}
} else Data->iMinSAD[1] = 4096*256;
}
static int
InitialSkipDecisionP(int sad00,
const MBParam * pParam,
const FRAMEINFO * current,
MACROBLOCK * pMB,
const MACROBLOCK * prevMB,
int x, int y,
const SearchData * Data,
const IMAGE * const pGMC,
const IMAGE * const pCurrent,
const IMAGE * const pRef,
const uint32_t MotionFlags)
{
const unsigned int iEdgedWidth = pParam->edged_width;
int skip_thresh = INITIAL_SKIP_THRESH * \
(current->vop_flags & XVID_VOP_MODEDECISION_RD ? 2:1);
int stat_thresh = 0;
/* initial skip decision */
if (current->coding_type != S_VOP) { /* no fast SKIP for S(GMC)-VOPs */
if (pMB->dquant == 0 && sad00 < pMB->quant * skip_thresh)
if (Data->chroma || xvid_me_SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant)) {
ZeroMacroblockP(pMB, sad00);
pMB->mode = MODE_NOT_CODED;
return 1;
}
}
if(MotionFlags & XVID_ME_DETECT_STATIC_MOTION) {
VECTOR *cmpMV;
VECTOR staticMV = { 0, 0 };
const MACROBLOCK * pMBs = current->mbs;
if (current->coding_type == S_VOP)
cmpMV = &pMB->amv;
else
cmpMV = &staticMV;
if(x > 0 && y > 0 && x < pParam->mb_width) {
if(MVequal((&pMBs[(x-1) + y * pParam->mb_width])->mvs[0], *cmpMV) &&
MVequal((&pMBs[x + (y-1) * pParam->mb_width])->mvs[0], *cmpMV) &&
MVequal((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mvs[0], *cmpMV) &&
MVequal(prevMB->mvs[0], *cmpMV)) {
stat_thresh = MAX((&pMBs[(x-1) + y * pParam->mb_width])->sad16,
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16,
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16,
prevMB->sad16)));
} else {
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16,
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16,
MIN((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16,
prevMB->sad16)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -