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

📄 motest.cpp

📁 网络MPEG4IP流媒体开发源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//end of new changes//end of INTERLACEDInt CVideoObjectEncoder::blkmatch16 (	CMotionVector* pmv, 	CoordI iXRef, CoordI iYRef,	CoordI iXCurr, CoordI iYCurr,	Int iMinSAD,	const PixelC* ppxlcRefMBY,	const CU8Image* puciRefQZoomY,	Int iSearchRange){	Int mbDiff; // start with big	Int iXDest = iXRef, iYDest = iYRef;	CoordI x = iXRef, y = iYRef, ix, iy;	Int uiPosInLoop, iLoop;	if (m_iMVFileUsage != 1) {	    // Spiral Search for the rest	    for (iLoop = 1; iLoop <= iSearchRange; iLoop++) {		    x++;		    y++;		    ppxlcRefMBY += m_iFrameWidthY + 1;		    for (uiPosInLoop = 0; uiPosInLoop < (iLoop << 3); uiPosInLoop++) { // inside each spiral loop 				if (				    x >= m_rctRefVOPY0.left && y >= m_rctRefVOPY0.top && 				    x <= m_rctRefVOPY0.right - MB_SIZE && y <= m_rctRefVOPY0.bottom - MB_SIZE			    ) {				    const PixelC* ppxlcTmpC = m_ppxlcCurrMBY;				    const PixelC* ppxlcRefMB = ppxlcRefMBY;				    mbDiff = 0;				    for (iy = 0; iy < MB_SIZE; iy++) {					    for (ix = 0; ix < MB_SIZE; ix++)						    mbDiff += abs (ppxlcTmpC [ix] - ppxlcRefMB [ix]);					    if (mbDiff >= iMinSAD)						    goto NEXT_POSITION; // skip the current position					    ppxlcRefMB += m_iFrameWidthY;					    ppxlcTmpC += MB_SIZE;				    }				    iMinSAD = mbDiff;				    iXDest = x;				    iYDest = y;			    }NEXT_POSITION:				    if (uiPosInLoop < (iLoop << 1)) {				    ppxlcRefMBY--;				    x--;			    }			    else if (uiPosInLoop < (iLoop << 2)) {				    ppxlcRefMBY -= m_iFrameWidthY;				    y--;			    }			    else if (uiPosInLoop < (iLoop * 6)) {				    ppxlcRefMBY++;					  				    x++;			    }			    else {				    ppxlcRefMBY += m_iFrameWidthY;				    y++;			    }		    }	    }	    *pmv = CMotionVector (iXDest - iXCurr, iYDest - iYCurr);	} else {		iXDest = iXRef + pmv->iMVX;		iYDest = iYRef + pmv->iMVY;	}/* NBIT: change to a bigger number	iMinSAD = 256*256;		// Reset iMinSAD because reference VOP changed from original to reconstructed (Bob Eifrig)*/	iMinSAD = 4096*256;/* NBIT: change	Int iFavorZero = pmv->isZero() ? -FAVORZERO : 0;*/	Int iFavorZero = pmv->isZero() ? FAVORZERO : 0;	Int nBits = m_volmd.nBits;	if (nBits > 8) {		iFavorZero <<= (nBits-8);	} else if (nBits < 8) {		iFavorZero >>= (8-nBits);	}	iFavorZero = -iFavorZero;	// half pel search	I8 destHalfX = 0, destHalfY = 0;	Int lowX = (iXDest == m_rctRefVOPY0.left) ? 0 : -1;	Int lowY = (iYDest == m_rctRefVOPY0.top) ? 0 : -1;	Int highX = (iXDest == m_rctRefVOPY0.right - MB_SIZE + 1) ? 0 : 1;	Int highY = (iYDest == m_rctRefVOPY0.bottom - MB_SIZE + 1) ? 0 : 1;	const PixelC* ppxlcRefZoom = puciRefQZoomY->pixels ((iXDest << 1) + lowX, (iYDest << 1) + lowY);	for (Int incY = lowY; incY <= highY; incY++) {		for (Int incX = lowX; incX <= highX; incX++) {			const PixelC* ppxlcRefZoomMB = ppxlcRefZoom;			const PixelC* ppxlcTmpC = m_ppxlcCurrMBY;			mbDiff = (incX || incY) ? 0 : iFavorZero;			for (iy = 0; iy < MB_SIZE; iy++) {				for (ix = 0; ix < MB_SIZE; ix++)					mbDiff += abs (ppxlcTmpC [ix] - ppxlcRefZoomMB [2 * ix]);				if (mbDiff > iMinSAD)			// Try to find shortest MV in case of equal SADs					goto NEXT_HALF_POSITION;				ppxlcRefZoomMB += m_iFrameWidthZoomY * 2;				ppxlcTmpC += MB_SIZE;			}			if ((iMinSAD > mbDiff) ||				((abs(pmv->m_vctTrueHalfPel.x + destHalfX) + abs(pmv->m_vctTrueHalfPel.y + destHalfY)) >				 (abs(pmv->m_vctTrueHalfPel.x + incX)      + abs(pmv->m_vctTrueHalfPel.y + incY)))) {				iMinSAD = mbDiff;				destHalfX = incX;				destHalfY = incY;			}NEXT_HALF_POSITION:			ppxlcRefZoom++;		}		ppxlcRefZoom += m_iFrameWidthZoomY - (highX - lowX + 1);	}	pmv -> iHalfX = destHalfX;	pmv -> iHalfY = destHalfY;	return iMinSAD;}Int CVideoObjectEncoder::blkmatch16WithShape (	CMotionVector* pmv, 	CoordI iXRef, CoordI iYRef,	CoordI iXCurr, CoordI iYCurr,	Int iMinSAD,	const PixelC* ppxlcRefMBY,	const CU8Image* puciRefQZoom,    const CMBMode *pmbmd,	Int iSearchRange,	Int iDirection){	Int mbDiff; // start with big	Int iXDest = iXRef, iYDest = iYRef;	CoordI x = iXRef, y = iYRef, ix, iy;	Int uiPosInLoop, iLoop;	CRct CTmp=(iDirection) ? m_rctRefVOPY1:m_rctRefVOPY0;	// Spiral Search for the rest	if (m_iMVFileUsage != 1) {	    for (iLoop = 1; iLoop <= iSearchRange; iLoop++) {		    x++;		    y++;		    ppxlcRefMBY += m_iFrameWidthY + 1;		    for (uiPosInLoop = 0; uiPosInLoop < (iLoop << 3); uiPosInLoop++) { // inside each spiral loop 				if (				    x >= CTmp.left && y >= CTmp.top && 				    x <= CTmp.right - MB_SIZE && y <= CTmp.bottom - MB_SIZE			    ) {				    const PixelC* ppxlcTmpC = m_ppxlcCurrMBY;				    const PixelC* ppxlcTmpCBY = m_ppxlcCurrMBBY;				    const PixelC* ppxlcRefMB = ppxlcRefMBY;				    mbDiff = 0;				    for (iy = 0; iy < MB_SIZE; iy++) {					    for (ix = 0; ix < MB_SIZE; ix++) {						    if (ppxlcTmpCBY [ix] != transpValue)							    mbDiff += abs (ppxlcTmpC [ix] - ppxlcRefMB [ix]);					    }					    if (mbDiff >= iMinSAD)						    goto NEXT_POSITION; // skip the current position					    ppxlcRefMB += m_iFrameWidthY;					    ppxlcTmpC += MB_SIZE;					    ppxlcTmpCBY += MB_SIZE;				    }				    iMinSAD = mbDiff;				    iXDest = x;				    iYDest = y;			    }NEXT_POSITION:				    if (uiPosInLoop < (iLoop << 1)) {				    ppxlcRefMBY--;				    x--;			    }			    else if (uiPosInLoop < (iLoop << 2)) {				    ppxlcRefMBY -= m_iFrameWidthY;				    y--;			    }			    else if (uiPosInLoop < (iLoop * 6)) {				    ppxlcRefMBY++;					  				    x++;			    }			    else {				    ppxlcRefMBY += m_iFrameWidthY;				    y++;			    }		    }	    }	    *pmv = CMotionVector (iXDest - iXCurr, iYDest - iYCurr);	} 	else {		iXDest = iXRef + pmv->iMVX;		iYDest = iYRef + pmv->iMVY;	}	// check for case when zero MV due to MB outside the extended BB.	if(iXDest==iXCurr && iYDest==iYCurr		&& (iXDest < CTmp.left || iYDest < CTmp.top	// 12.22.98 changes			|| iXDest > CTmp.right - MB_SIZE		// 12.22.98 changes			|| iYDest > CTmp.bottom - MB_SIZE))		// 12.22.98 changes	{		pmv -> iHalfX = 0;		pmv -> iHalfY = 0;		return iMinSAD;  	}/* NBIT: change to a bigger number	iMinSAD = 256*256;		// Reset iMinSAD because reference VOP may change from original to reconstructed (Bob Eifrig)*/	iMinSAD = 4096*256;	Int iFavorZero = pmv->isZero() ? -(pmbmd -> m_rgNumNonTranspPixels [0] >> 1) - 1 : 0;		// half pel search	I8 destHalfX = 0, destHalfY = 0;	Int lowY, highY, lowX, highX;	lowX = (iXDest == CTmp.left) ? 0 : -1;	// 12.22.98 changes	lowY = (iYDest == CTmp.top) ? 0 : -1;	// 12.22.98 changes	highX = (iXDest == CTmp.right - MB_SIZE + 1) ? 0 : 1;	// 12.22.98 changes	highY = (iYDest == CTmp.bottom - MB_SIZE + 1) ? 0 : 1;	// 12.22.98 changes	const PixelC* ppxlcRefZoom = puciRefQZoom->pixels ((iXDest << 1) + lowX, (iYDest << 1) + lowY);	for (Int incY = lowY; incY <= highY; incY++) {		for (Int incX = lowX; incX <= highX; incX++) {			const PixelC* ppxlcRefZoomMB = ppxlcRefZoom;			const PixelC* ppxlcTmpC = m_ppxlcCurrMBY;			const PixelC* ppxlcTmpCBY = m_ppxlcCurrMBBY;			mbDiff = (incX || incY) ? 0 : iFavorZero;			for (iy = 0; iy < MB_SIZE; iy++) {				for (ix = 0; ix < MB_SIZE; ix++) {					if (ppxlcTmpCBY [ix] != transpValue) 						mbDiff += abs (ppxlcTmpC [ix] - ppxlcRefZoomMB [2 * ix]);				}				if (mbDiff > iMinSAD)			// Try to find shortest MV in case of equal SADs					goto NEXT_HALF_POSITION;				ppxlcRefZoomMB += m_iFrameWidthZoomY * 2;				ppxlcTmpC += MB_SIZE;				ppxlcTmpCBY += MB_SIZE;			}			if ((iMinSAD > mbDiff) ||				((abs(pmv->m_vctTrueHalfPel.x + destHalfX) + abs(pmv->m_vctTrueHalfPel.y + destHalfY)) >				 (abs(pmv->m_vctTrueHalfPel.x + incX)      + abs(pmv->m_vctTrueHalfPel.y + incY)))) {				iMinSAD = mbDiff;				destHalfX = incX;				destHalfY = incY;			}NEXT_HALF_POSITION:			ppxlcRefZoom++;		}		ppxlcRefZoom += m_iFrameWidthZoomY - (highX - lowX + 1);	}	pmv -> iHalfX = destHalfX;	pmv -> iHalfY = destHalfY;	return iMinSAD;}Int CVideoObjectEncoder::blockmatch8 (	const PixelC* ppxlcCodedBlkY, 	CMotionVector* pmv8, 	CoordI iXBlk, CoordI iYBlk,	const CMotionVector* pmvPred,	Int iSearchRange){	Int mbDiff,iMinSAD; // start with big	CoordI ix,iy,iXDest,iYDest;	if (m_iMVFileUsage != 1) {	    CoordI x = iXBlk + pmvPred->iMVX, y = iYBlk + pmvPred->iMVY; // , ix, iy;	    CoordI left = -1 * min (abs (pmvPred->iMVX + iSearchRange), ADD_DISP);	    CoordI top = -1 * min (abs (pmvPred->iMVY + iSearchRange), ADD_DISP);	    CoordI right = min (abs (pmvPred->iMVX - iSearchRange), ADD_DISP);	    CoordI bottom = min (abs (pmvPred->iMVY - iSearchRange), ADD_DISP);	    //CoordI iOrigX = x, iOrigY = y;	    // CoordI 	    iXDest = x, iYDest = y;	    Int uiPosInLoop, iLoop;	    const PixelC* ppxlcRefBlk = (m_volmd.bOriginalForME ? m_pvopcRefOrig0 : m_pvopcRefQ0)->getPlane (Y_PLANE)->pixels (x, y);	    iMinSAD = sad8x8At0 (ppxlcCodedBlkY, ppxlcRefBlk);	    // Spiral Search for the rest	    Int iix = 0, iiy = 0;	    for (iLoop = 1; iLoop <= ADD_DISP; iLoop++) {		    x++;		    y++;		    iix++; iiy++;		    ppxlcRefBlk += m_iFrameWidthY + 1;		    for (uiPosInLoop = 0; uiPosInLoop < (iLoop << 3); uiPosInLoop++) { // inside each spiral loop 				if (				    iix >= left && iix <= right &&				    iiy >= top && iiy <= bottom &&				    x >= m_rctRefVOPY0.left && y >= m_rctRefVOPY0.top && 				    x <= m_rctRefVOPY0.right - MB_SIZE && y <= m_rctRefVOPY0.bottom - MB_SIZE			    ) {				    const PixelC* ppxlcTmpC = ppxlcCodedBlkY;				    const PixelC* ppxlcRefMB = ppxlcRefBlk;				    mbDiff = 0;				    for (iy = 0; iy < BLOCK_SIZE; iy++) {					    for (ix = 0; ix < BLOCK_SIZE; ix++)						    mbDiff += abs (ppxlcTmpC [ix] - ppxlcRefMB [ix]);					    if (mbDiff > iMinSAD)						    goto NEXT_POSITION; // skip the current position					    ppxlcRefMB += m_iFrameWidthY;					    ppxlcTmpC += MB_SIZE;				    }				    iMinSAD = mbDiff;				    iXDest = x;				    iYDest = y;			    }NEXT_POSITION:				    if (uiPosInLoop < (iLoop << 1)) {				    ppxlcRefBlk--;				    x--;				    iix--;			    }			    else if (uiPosInLoop < (iLoop << 2)) {				    ppxlcRefBlk -= m_iFrameWidthY;				    y--;				    iiy--;			    }			    else if (uiPosInLoop < (iLoop * 6)) {				    ppxlcRefBlk++;					  				    x++;				    iix++;			    }			    else {				    ppxlcRefBlk += m_iFrameWidthY;				    y++;				    iiy++;			    }		    }	    }	    *pmv8 = CMotionVector (iXDest - iXBlk, iYDest - iYBlk);	} 	else {		iXDest = iXBlk + pmv8->iMVX;		iYDest = iYBlk + pmv8->iMVY;	}/* NBIT: change to a bigger number	iMinSAD = 256*256;		// Reset iMinSAD because reference VOP changed from original to reconstructed (Bob Eifrig)*/	iMinSAD = 4096*256;			// half pel search	I8 destHalfX = 0, destHalfY = 0;	Int lowY, highY, lowX, highX;	lowX = (iXDest == m_rctRefVOPY0.left) ? 0 : -1;	lowY = (iYDest == m_rctRefVOPY0.top) ? 0 : -1;	highX = (iXDest == m_rctRefVOPY0.right - MB_SIZE + 1) ? 0 : 1;	highY = (iYDest == m_rctRefVOPY0.bottom - MB_SIZE + 1) ? 0 : 1;	const PixelC* ppxlcRefZoom = m_puciRefQZoom0->pixels ((iXDest << 1) + lowX, (iYDest << 1) + lowY);	for (Int incY = lowY; incY <= highY; incY++) {		for (Int incX = lowX; incX <= highX; incX++) {			// no longer skipp (0,0) due to using original as interger pel reference			//if (!(incX == 0 && incY == 0)) {				const PixelC* ppxlcRefZoomBlk = ppxlcRefZoom;				const PixelC* ppxlcTmpC = ppxlcCodedBlkY;				mbDiff = 0;				for (iy = 0; iy < BLOCK_SIZE; iy++) {					for (ix = 0; ix < BLOCK_SIZE; ix++)						mbDiff += abs (ppxlcTmpC [ix] - ppxlcRefZoomBlk [2 * ix]);					if (mbDiff > iMinSAD)						goto NEXT_HALF_POSITION;					ppxlcRefZoomBlk += m_iFrameWidthZoomY * 2;					ppxlcTmpC += MB_SIZE;				}				if ((iMinSAD > mbDiff) ||					((abs(pmv8->m_vctTrueHalfPel.x + destHalfX) + abs(pmv8->m_vctTrueHalfPel.y + destHalfY)) >					 (abs(pmv8->m_vctTrueHalfPel.x + incX)      + abs(pmv8->m_vctTrueHalfPel.y + incY)))) {					iMinSAD = mbDiff;					destHalfX = incX;					destHalfY = incY;				}NEXT_HALF_POSITION:			ppxlcRefZoom++;		}		ppxlcRefZoom += m_iFrameWidthZoomY - (highX - lowX + 1);	}	pmv8 -> iHalfX = destHalfX;	pmv8 -> iHal

⌨️ 快捷键说明

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