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

📄 shape.cpp

📁 jpeg and mpeg 编解码技术源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			ppxlcDstTop1 [iPixel]  = *ppxlcSrcTop1;
			//src pixel never out of bound due to padding of Ref1
			ppxlcDstTop2 [iPixel]  = *ppxlcSrcTop2;
			//BY should be intialized as zero outside of VOP
		}
		else {
			ppxlcDstTop1 [iPixel]  = (PixelC) 0;
			ppxlcDstTop2 [iPixel]  = (PixelC) 0;
		}
		ppxlcSrcTop1++; 
		ppxlcSrcTop2++; 
	}
	for (iPixel = TOTAL_BAB_SIZE-BAB_BORDER; iPixel < TOTAL_BAB_SIZE; iPixel++)	{
		if (!m_bVPNoRightTop) {
			ppxlcDstTop1 [iPixel]  = *ppxlcSrcTop1;
			//src pixel never out of bound due to padding of Ref1
			ppxlcDstTop2 [iPixel]  = *ppxlcSrcTop2;
			//BY should be intialized as zero outside of VOP
		}
		else {
			ppxlcDstTop1 [iPixel]  = (PixelC) 0;
			ppxlcDstTop2 [iPixel]  = (PixelC) 0;
		}
		ppxlcSrcTop1++; 
		ppxlcSrcTop2++; 
	}
	ppxlcSrcLeft1 += BAB_BORDER*m_iFrameWidthY; 
	ppxlcSrcLeft2 += BAB_BORDER*m_iFrameWidthY; 
	ppxlcDstLeft += BAB_BORDER*TOTAL_BAB_SIZE;
	for (iPixel = BAB_BORDER; iPixel < TOTAL_BAB_SIZE; iPixel++)	{
		if (!m_bVPNoLeft) {
			*ppxlcDstLeft		= *ppxlcSrcLeft1;
			*(ppxlcDstLeft + 1)	= *ppxlcSrcLeft2;
		}
		else {
			*ppxlcDstLeft		= (PixelC) 0;
			*(ppxlcDstLeft + 1)	= (PixelC) 0;
		}
		ppxlcSrcLeft1 += m_iFrameWidthY; 
		ppxlcSrcLeft2 += m_iFrameWidthY; 
		ppxlcDstLeft += TOTAL_BAB_SIZE;				//last two values of left border will be over written after the loop
	}
	//repeat pad the left border (this will be done again in right bottom border; improve in the future)
	if (!m_bVPNoLeft) {
		Int iLastValidSrcLeft1 = *(ppxlcSrcLeft1 - (BAB_BORDER+1) * m_iFrameWidthY);
		Int iLastValidSrcLeft2 = *(ppxlcSrcLeft2 - (BAB_BORDER+1) * m_iFrameWidthY);
		for (iPixel = 0; iPixel < BAB_BORDER; iPixel++)	{
			ppxlcDstLeft -= TOTAL_BAB_SIZE;
			*ppxlcDstLeft       = iLastValidSrcLeft1;
			*(ppxlcDstLeft + 1) = iLastValidSrcLeft2;
		}
	}
// End Toshiba(1997-11-14)
}

Void CVideoObject::subsampleLeftTopBorderFromVOP (PixelC* ppxlcSrc, PixelC* ppxlcDst)
{
	PixelC* ppxlcSrcTop1 = ppxlcSrc - BAB_BORDER  * m_iFrameWidthY - BAB_BORDER;
	PixelC* ppxlcSrcTop2 = ppxlcSrcTop1 + m_iFrameWidthY;
	PixelC* ppxlcSrcLft1 = ppxlcSrcTop1;
	PixelC* ppxlcSrcLft2 = ppxlcSrcLft1 + 1;
	PixelC* ppxlcDstTop1 = ppxlcDst;
	PixelC* ppxlcDstTop2 = ppxlcDst + m_iWidthCurrBAB;
	PixelC* ppxlcDstLft1 = ppxlcDst;
	PixelC* ppxlcDstLft2 = ppxlcDst + 1;
	Int iThresh = (m_iInverseCR == 2) ? 0 : opaqueValue;
	CoordI iPixel, iPixelSub, iSampleInterval;
	//	Modified for error resilient mode by Toshiba(1997-11-14)
	for (iPixelSub = BAB_BORDER, iSampleInterval = BAB_BORDER; 
		iPixelSub < m_iWidthCurrBAB - BAB_BORDER; 
		iPixelSub++, iSampleInterval += m_iInverseCR) {					//get each subsample
		Int iTempSumTop1 = 0, iTempSumTop2 = 0; 
		Int iTempSumLft1 = 0, iTempSumLft2 = 0;
		for (iPixel = 0; iPixel < m_iInverseCR; iPixel++)	{
			iTempSumTop1 += ppxlcSrcTop1 [iSampleInterval + iPixel];
			iTempSumTop2 += ppxlcSrcTop2 [iSampleInterval + iPixel];
			iTempSumLft1 += ppxlcSrcLft1 [(iSampleInterval + iPixel) * m_iFrameWidthY];
			iTempSumLft2 += ppxlcSrcLft2 [(iSampleInterval + iPixel) * m_iFrameWidthY];
		}
		if (!m_bVPNoTop) {
			ppxlcDstTop1 [iPixelSub] = (iTempSumTop1 > iThresh) ? opaqueValue : transpValue;
			ppxlcDstTop2 [iPixelSub] = (iTempSumTop2 > iThresh) ? opaqueValue : transpValue;
		}
		else {
			ppxlcDstTop1 [iPixelSub] = 0;
			ppxlcDstTop2 [iPixelSub] = 0;
		}
		if (!m_bVPNoLeft) {
			ppxlcDstLft1 [iPixelSub * m_iWidthCurrBAB] = (iTempSumLft1 > iThresh) ? opaqueValue : transpValue;
			ppxlcDstLft2 [iPixelSub * m_iWidthCurrBAB] = (iTempSumLft2 > iThresh) ? opaqueValue : transpValue;
		}
		else {
			ppxlcDstLft1 [iPixelSub * m_iWidthCurrBAB] = 0;
			ppxlcDstLft2 [iPixelSub * m_iWidthCurrBAB] = 0;
		}
	}
	//boundary conditions 0, 1, 18, 19 
	CoordI iBorder;
	for (iBorder = 0; iBorder < BAB_BORDER; iBorder++)	{
		if (!m_bVPNoLeftTop) {
			ppxlcDstTop1 [iBorder] = ppxlcSrcTop1 [iBorder];
			ppxlcDstTop2 [iBorder] = ppxlcSrcTop2 [iBorder];
		}
		else {
			ppxlcDstTop1 [iBorder] = 0;
			ppxlcDstTop2 [iBorder] = 0;
		}
		if (!m_bVPNoRightTop) {
			ppxlcDstTop1 [m_iWidthCurrBAB - 1 - iBorder] = ppxlcSrcTop1 [TOTAL_BAB_SIZE - 1 - iBorder];
			ppxlcDstTop2 [m_iWidthCurrBAB - 1 - iBorder] = ppxlcSrcTop2 [TOTAL_BAB_SIZE - 1 - iBorder];
		}
		else {
			ppxlcDstTop1 [m_iWidthCurrBAB - 1 - iBorder] = 0;
			ppxlcDstTop2 [m_iWidthCurrBAB - 1 - iBorder] = 0;
		}
	}
	// End Toshiba(1997-11-14)
	//repeat pad left-bottom corner
	ppxlcDstLft1 [(m_iWidthCurrBAB - 1) * m_iWidthCurrBAB] = 
		ppxlcDstLft1 [(m_iWidthCurrBAB - 2) * m_iWidthCurrBAB] =
		ppxlcDstLft1 [(m_iWidthCurrBAB - 3) * m_iWidthCurrBAB];	
	ppxlcDstLft2 [(m_iWidthCurrBAB - 1) * m_iWidthCurrBAB] =
		ppxlcDstLft2 [(m_iWidthCurrBAB - 2) * m_iWidthCurrBAB] =
		ppxlcDstLft2 [(m_iWidthCurrBAB - 3) * m_iWidthCurrBAB];
}

Void CVideoObject::makeRightBottomBorder (PixelC* ppxlcSrc, Int iWidth)
{
	Int i;
	PixelC* ppxlcDst = ppxlcSrc + BAB_BORDER * iWidth + iWidth - BAB_BORDER;		//make right border
	for (i = 0; i < iWidth - 2*BAB_BORDER; i++) {
		*ppxlcDst = *(ppxlcDst - 1);
		*(ppxlcDst + 1) = *ppxlcDst;
		ppxlcDst += iWidth;
	}
	ppxlcDst = ppxlcSrc + (iWidth - BAB_BORDER) * iWidth;							//make bottom border
	for (i = 0; i < iWidth; i++) {
		*ppxlcDst = *(ppxlcDst - iWidth);
		*(ppxlcDst + iWidth) = *ppxlcDst;
		ppxlcDst++;
	}
}

Int CVideoObject::contextIntra (const PixelC* ppxlcSrc)
{
	Int iContext = 0, i;
	static Int rgiNeighbourIndx [10];
	rgiNeighbourIndx [0] = -1;
	rgiNeighbourIndx [1] = -2;
	rgiNeighbourIndx [2] = -m_iWidthCurrBAB + 2;
	rgiNeighbourIndx [3] = -m_iWidthCurrBAB + 1;
	rgiNeighbourIndx [4] = -m_iWidthCurrBAB;
	rgiNeighbourIndx [5] = -m_iWidthCurrBAB - 1;
	rgiNeighbourIndx [6] = -m_iWidthCurrBAB - 2;
	rgiNeighbourIndx [7] = -2 * m_iWidthCurrBAB + 1;
	rgiNeighbourIndx [8] = -2 * m_iWidthCurrBAB;
	rgiNeighbourIndx [9] = -2 * m_iWidthCurrBAB - 1;
	for (i = 0; i < 10; i++)
		iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i;
	assert (iContext >= 0 && iContext < 1024);
	return iContext;
}

Int CVideoObject::contextIntraTranspose (const PixelC* ppxlcSrc)
{
	Int iContext = 0, i;
	static Int rgiNeighbourIndx [10];
	rgiNeighbourIndx [0] = -m_iWidthCurrBAB;
	rgiNeighbourIndx [1] = -2 * m_iWidthCurrBAB;
	rgiNeighbourIndx [2] = -1 + 2 * m_iWidthCurrBAB;
	rgiNeighbourIndx [3] = -1 + m_iWidthCurrBAB;
	rgiNeighbourIndx [4] = -1;
	rgiNeighbourIndx [5] = -m_iWidthCurrBAB - 1;
	rgiNeighbourIndx [6] = -1 - 2 * m_iWidthCurrBAB;
	rgiNeighbourIndx [7] = -2 + m_iWidthCurrBAB;
	rgiNeighbourIndx [8] = -2;
	rgiNeighbourIndx [9] = -2 - m_iWidthCurrBAB;
	for (i = 0; i < 10; i++)
		iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i;
	assert (iContext >= 0 && iContext < 1024);
	return iContext;
}

Int CVideoObject::contextInter (const PixelC* ppxlcSrc, const PixelC* ppxlcPred)
{
	Int i, iContext = 0;
	static Int rgiNeighbourIndx [9];
	Int iSizePredBAB = m_iWidthCurrBAB - 2*BAB_BORDER + 2*MC_BAB_BORDER;

	rgiNeighbourIndx [0] = -1;
	rgiNeighbourIndx [1] = -m_iWidthCurrBAB + 1;
	rgiNeighbourIndx [2] = -m_iWidthCurrBAB;
	rgiNeighbourIndx [3] = -m_iWidthCurrBAB - 1;
	rgiNeighbourIndx [4] = iSizePredBAB;
	rgiNeighbourIndx [5] = 1;
	rgiNeighbourIndx [6] = 0;
	rgiNeighbourIndx [7] = -1;
	rgiNeighbourIndx [8] = -iSizePredBAB;

	for (i = 0; i < 4; i++)	{
		iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i;
	}

	for (i = 4; i < 9; i++)	{
		iContext += (ppxlcPred [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i;
	}
	assert (iContext >= 0 && iContext < 1024);
	return iContext;
}

Int CVideoObject::contextInterTranspose (const PixelC* ppxlcSrc, const PixelC* ppxlcPred)
{
	Int i, iContext = 0;
	static Int rgiNeighbourIndx [9];
	Int iSizePredBAB = m_iWidthCurrBAB - 2*BAB_BORDER + 2*MC_BAB_BORDER;

	rgiNeighbourIndx [0] = -m_iWidthCurrBAB;
	rgiNeighbourIndx [1] = m_iWidthCurrBAB - 1;
	rgiNeighbourIndx [2] = -1;
	rgiNeighbourIndx [3] = -m_iWidthCurrBAB - 1;
	rgiNeighbourIndx [4] = 1;
	rgiNeighbourIndx [5] = iSizePredBAB;
	rgiNeighbourIndx [6] = 0;
	rgiNeighbourIndx [7] = -iSizePredBAB;
	rgiNeighbourIndx [8] = -1;	

	for (i = 0; i < 4; i++)
		iContext += (ppxlcSrc [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i;

	for (i = 4; i < 9; i++)
		iContext += (ppxlcPred [rgiNeighbourIndx [i]] == MPEG4_OPAQUE) << i;
	assert (iContext >= 0 && iContext < 1024);
	return iContext;
}

Void CVideoObject::copyReconShapeToMbAndRef (
	PixelC* ppxlcDstMB, 
	PixelC* ppxlcRefFrm, PixelC pxlcSrc
)
{
	pxlcmemset (ppxlcDstMB, pxlcSrc, MB_SQUARE_SIZE); // Modified by swinder
	for (Int i = 0; i < MB_SIZE; i++)	{
		pxlcmemset (ppxlcRefFrm, pxlcSrc, MB_SIZE);
		ppxlcRefFrm += m_iFrameWidthY;
	}
}

Void CVideoObject::copyReconShapeUVToRef (
	PixelC* ppxlcRefFrm, const PixelC* ppxlcSrc)
{
	for (Int i = 0; i < BLOCK_SIZE; i++)	{
		memcpy (ppxlcRefFrm, ppxlcSrc, BLOCK_SIZE*sizeof(PixelC));
		ppxlcRefFrm += m_iFrameWidthUV;
		ppxlcSrc += BLOCK_SIZE;
	}
}

Void CVideoObject::copyReconShapeToMbAndRef (
	PixelC* ppxlcDstMB, 
	PixelC* ppxlcRefFrm, 
	const PixelC* ppxlcSrc, Int iSrcWidth, Int iBorder
)
{
	Int iUnit = sizeof(PixelC); // NBIT: for memcpy
	ppxlcSrc += iSrcWidth * iBorder + iBorder;
	for (Int i = 0; i < MB_SIZE; i++)	{
		memcpy (ppxlcDstMB, ppxlcSrc, MB_SIZE*iUnit);
		memcpy (ppxlcRefFrm, ppxlcSrc, MB_SIZE*iUnit);
		ppxlcRefFrm += m_iFrameWidthY;
		ppxlcDstMB  += MB_SIZE;
		ppxlcSrc += iSrcWidth;
	}
}

CMotionVector CVideoObject::findShapeMVP (
	const CMotionVector* pmv, const CMotionVector* pmvBY, 
	const CMBMode* pmbmd,
	Int iMBX, Int iMBY
) const
{
	CMotionVector mvRet;
	// try shape vector first

	Bool bLeftBndry, bRightBndry, bTopBndry;
	Int iMBnum = VPMBnum(iMBX, iMBY);
	bLeftBndry = bVPNoLeft(iMBnum, iMBX);
	bTopBndry = bVPNoTop(iMBnum);
	bRightBndry = bVPNoRightTop(iMBnum, iMBX);

	mvRet = *(pmvBY - 1);	
//	Modified for error resilient mode by Toshiba(1997-11-14)
//	if ((iMBX > 0) && ((pmbmd - 1)->m_shpmd == INTER_CAE_MVDZ ||
	if (!bLeftBndry && ((pmbmd - 1)->m_shpmd == INTER_CAE_MVDZ ||
		(pmbmd - 1)->m_shpmd == INTER_CAE_MVDNZ ||
		(pmbmd - 1)->m_shpmd == MVDZ_NOUPDT ||
		(pmbmd - 1)->m_shpmd == MVDNZ_NOUPDT))
		return mvRet;
	if (iMBY > 0)   {
		mvRet = *(pmvBY - m_iNumMBX);
//	Modified for error resilient mode by Toshiba(1997-11-14)
//		if ((pmbmd - m_iNumMBX)->m_shpmd == INTER_CAE_MVDZ ||
		if (!bTopBndry && ((pmbmd - m_iNumMBX)->m_shpmd == INTER_CAE_MVDZ ||
			(pmbmd - m_iNumMBX)->m_shpmd == INTER_CAE_MVDNZ ||
			(pmbmd - m_iNumMBX)->m_shpmd == MVDZ_NOUPDT ||
			(pmbmd - m_iNumMBX)->m_shpmd == MVDNZ_NOUPDT
//	Modified for error resilient mode by Toshiba(1997-11-14)
//		)
		))
			return mvRet;			
		mvRet = *(pmvBY - m_iNumMBX + 1);
//	Modified for error resilient mode by Toshiba(1997-11-14)
//		if ((iMBX < m_iNumMBX - 1) && ((pmbmd - m_iNumMBX + 1)->m_shpmd == INTER_CAE_MVDZ ||
		if (!bRightBndry && ((pmbmd - m_iNumMBX + 1)->m_shpmd == INTER_CAE_MVDZ ||
			(pmbmd - m_iNumMBX + 1)->m_shpmd == INTER_CAE_MVDNZ ||
			(pmbmd - m_iNumMBX + 1)->m_shpmd == MVDZ_NOUPDT ||
			(pmbmd - m_iNumMBX + 1)->m_shpmd == MVDNZ_NOUPDT)
		)
			return mvRet;
	}

	// try texture vector then; truncate half pel
	if(m_volmd.bShapeOnly==FALSE && m_vopmd.vopPredType==PVOP)
	{
//	Modified for error resilient mode by Toshiba(1997-11-14)
//		if (iMBX != 0 && validBlock (pmbmd - 1, gIndexOfCandBlk [1] [0]))
		if (!bLeftBndry && validBlock (pmbmd, pmbmd - 1, gIndexOfCandBlk [1] [0]))
			return CMotionVector ((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0])->m_vctTrueHalfPel.x / 2,
								  (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0])->m_vctTrueHalfPel.y / 2);
		if (iMBY != 0)   {
//	Modified for error resilient mode by Toshiba(1997-11-14)
//			if (validBlock (pmbmd - m_iNumMBX, gIndexOfCandBlk [1] [1]))
			if (!bTopBndry && validBlock (pmbmd, pmbmd - m_iNumMBX, gIndexOfCandBlk [1] [1]))
				return CMotionVector ((pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [1] [1])->m_vctTrueHalfPel.x / 2,
									  (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [1] [1])->m_vctTrueHalfPel.y / 2);
//	Modified for error resilient mode by Toshiba(1997-11-14)
//			if (iMBX < m_iNumMBX - 1 && validBlock (pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [1] [2]))
			if (!bRightBndry && validBlock (pmbmd, pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [1] [2]))
				return CMotionVector ((pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2])->m_vctTrueHalfPel.x / 2,
									  (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2])->m_vctTrueHalfPel.y / 2);
		}
	}
	return CMotionVector ();																		
}

⌨️ 快捷键说明

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