⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 estimation_pvop.c

📁 这是一个压缩解压包,用C语言进行编程的,里面有详细的源代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* intra decision */	if (iQuant > 10) InterBias += 60 * (iQuant - 10); /* to make high quants work */	if (y != 0)		if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80;	if (x != 0)		if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80;	if (Data->chroma) InterBias += 50; /* dev8(chroma) ??? <-- yes, we need dev8 (no big difference though) */	if (InterBias < sad) {		int32_t deviation = dev16(Data->Cur, Data->iEdgedWidth);		if (deviation < (sad - InterBias)) mode = MODE_INTRA;	}	pMB->cbp = 63;	pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;	if (mode == MODE_INTER && mcsel == 0) {		pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];		if(Data->qpel) {			pMB->qmvs[0] = pMB->qmvs[1]				= pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];			pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x;			pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y;		} else {			pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;			pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;		}	} else if (mode == MODE_INTER ) { /* but mcsel == 1 */		pMB->mcsel = 1;		if (Data->qpel) {			pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv;			pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2;			pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2;		} else			pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv;	} else		if (mode == MODE_INTER4V) ; /* anything here? */	else	/* INTRA, NOT_CODED */		ZeroMacroblockP(pMB, 0);	pMB->mode = mode;}static __inline voidPreparePredictionsP(VECTOR * const pmv, int x, int y, int iWcount,			int iHcount, const MACROBLOCK * const prevMB){	if ( (y != 0) && (x < (iWcount-1)) ) {		/* [5] top-right neighbour */		pmv[5].x = EVEN(pmv[3].x);		pmv[5].y = EVEN(pmv[3].y);	} else pmv[5].x = pmv[5].y = 0;	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 voidSearch8(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 voidSearchP(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;				}			}		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -