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

📄 mv.cpp

📁 visual c++小波技术和工程实践随书光盘
💻 CPP
📖 第 1 页 / 共 2 页
字号:
Void CVideoObject::mvLookupUVWithShape (const CMBMode* pmbmd, const CMotionVector* pmv,
                                        CoordI& xRefUV, CoordI& yRefUV)
{
  Int* rgiMvRound;
  Int dx = 0, dy = 0;
  UInt uiDivisor = 0; //2 = Y->UV resolution change; another -> full pel
  if (pmbmd -> m_bhas4MVForward || pmbmd -> m_mbType == DIRECT)	{ //for QuarterPel. mwi
    if (m_volmd.bQuarterSample) {
      for (UInt i = Y_BLOCK1; i <= Y_BLOCK4; i++)	{
        pmv++;
        if (pmbmd->m_rgTranspStatus [i] != ALL)	{
          dx += pmv->iMVX;
          dy += pmv->iMVY;
          uiDivisor += 4; }
      }
    }
    else {
      for (UInt i = Y_BLOCK1; i <= Y_BLOCK4; i++)	{
        pmv++;
        if (pmbmd->m_rgTranspStatus [i] != ALL)	{
          dx += pmv->m_vctTrueHalfPel.x;
          dy += pmv->m_vctTrueHalfPel.y;
          uiDivisor += 4;
        }
      }
    }
      
    switch (uiDivisor)	{
    case 4:
      rgiMvRound = grgiMvRound4;
      break;
    case 8:
      rgiMvRound = grgiMvRound8;
      break;
    case 12:
      rgiMvRound = grgiMvRound12;
      break;
    case 16:
      rgiMvRound = grgiMvRound16;
      break;
    }
    xRefUV = sign (dx) * (rgiMvRound [abs (dx) % uiDivisor] + (abs (dx) / uiDivisor) * 2);
    yRefUV = sign (dy) * (rgiMvRound [abs (dy) % uiDivisor] + (abs (dy) / uiDivisor) * 2);
  }
  else {
    if (m_volmd.bQuarterSample) {
      dx = pmv->iMVX;
      dy = pmv->iMVY;
    }
    else {
      dx = pmv->m_vctTrueHalfPel.x;
      dy = pmv->m_vctTrueHalfPel.y;
    }
    xRefUV = sign (dx) * (grgiMvRound4  [abs (dx) % 4] + (abs (dx) / 4) * 2);
    yRefUV = sign (dy) * (grgiMvRound4  [abs (dy) % 4] + (abs (dy) / 4) * 2);
  }
}

Void CVideoObject::findMVpredGeneric (CVector& vecPred, 
									  const CMotionVector* pmv, 
									  const CMBMode* pmbmd, 
									  Int iBlk, 
									  Int iXMB, Int iYMB) const
{
	static Bool rgbInBound [3];
	rgbInBound [0] = FALSE;
	rgbInBound [1] = FALSE;
	rgbInBound [2] = FALSE;
	Int nInBound = 0;
	CVector vctCandMV [3];
	UInt i;
	for (i = 0; i < 3; i++)	{
		vctCandMV [i].x = 0;
		vctCandMV [i].y = 0;
	}

	Bool bLeftBndry, bRightBndry, bTopBndry;
	Int iMBnum = VPMBnum(iXMB, iYMB);
	bLeftBndry = bVPNoLeft(iMBnum, iXMB);
	bTopBndry = bVPNoTop(iMBnum);
	bRightBndry = bVPNoRightTop(iMBnum, iXMB);

	if (pmbmd->m_bhas4MVForward == TRUE)	{		//how about backward??
		switch (iBlk){
		case Y_BLOCK1:
//	Modified for error resilient mode by Toshiba(1997-11-14)
//			if (iXMB != 0 && validBlock (pmbmd - 1, gIndexOfCandBlk [iBlk] [0]))	{
			if (!bLeftBndry && validBlock (pmbmd, pmbmd - 1, gIndexOfCandBlk [iBlk] [0]))	{
				vctCandMV [0] = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [iBlk] [0]) -> trueMVHalfPel ();
				rgbInBound [0] = TRUE;
				nInBound++;
			}
			if (iYMB != 0)	{
//	Modified for error resilient mode by Toshiba(1997-11-14)
//				if (validBlock (pmbmd - m_iNumMBX, gIndexOfCandBlk [iBlk] [1]))	{
				if (!bTopBndry && validBlock (pmbmd, pmbmd - m_iNumMBX, gIndexOfCandBlk [iBlk] [1]))	{
					vctCandMV [1] = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [iBlk] [1])->trueMVHalfPel ();
					rgbInBound [1] = TRUE;
					nInBound++;
				}
//	Modified for error resilient mode by Toshiba(1997-11-14)
//				if (iXMB < m_iNumMBX - 1 && validBlock (pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [iBlk] [2]))	{
				if (!bRightBndry && validBlock (pmbmd, pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [iBlk] [2]))	{
					vctCandMV [2] = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [iBlk] [2])->trueMVHalfPel ();
					rgbInBound [2] = TRUE;
					nInBound++;
				}
			}
			break;
		case Y_BLOCK2:
			if (validBlock (pmbmd, pmbmd, gIndexOfCandBlk [iBlk] [0]))	{
				vctCandMV [0] = (pmv +  gIndexOfCandBlk [iBlk] [0]) -> trueMVHalfPel ();
				rgbInBound [0] = TRUE;
				nInBound++;
			}
			if (iYMB != 0)	{
//	Modified for error resilient mode by Toshiba(1997-11-14)
//				if (validBlock (pmbmd - m_iNumMBX, gIndexOfCandBlk [iBlk] [1]))	{
				if (!bTopBndry && validBlock (pmbmd, pmbmd - m_iNumMBX, gIndexOfCandBlk [iBlk] [1]))	{
					vctCandMV [1] = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [iBlk] [1]) -> trueMVHalfPel ();
					rgbInBound [1] = TRUE;
					nInBound++;
				}
//	Modified for error resilient mode by Toshiba(1997-11-14)
//				if (iXMB < m_iNumMBX - 1 && validBlock (pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [iBlk] [2]))	{
				if (!bRightBndry && validBlock (pmbmd, pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [iBlk] [2]))	{
					vctCandMV [2] = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [iBlk] [2]) -> trueMVHalfPel ();
					rgbInBound [2] = TRUE;
					nInBound++;
				}
			}
			break;
		case Y_BLOCK3:
//	Modified for error resilient mode by Toshiba(1997-11-14)
//			if (iXMB != 0 && validBlock (pmbmd - 1, gIndexOfCandBlk [iBlk] [0]))	{
			if (!bLeftBndry && validBlock (pmbmd, pmbmd - 1, gIndexOfCandBlk [iBlk] [0]))	{
				vctCandMV [0] = (pmv - PVOP_MV_PER_REF_PER_MB +  gIndexOfCandBlk [iBlk] [0]) -> trueMVHalfPel ();
				rgbInBound [0] = TRUE;
				nInBound++;
			}
			if (validBlock (pmbmd, pmbmd, gIndexOfCandBlk [iBlk] [1]))	{
				vctCandMV [1] = (pmv + gIndexOfCandBlk [iBlk] [1]) -> trueMVHalfPel ();
				rgbInBound [1] = TRUE;
				nInBound++;
			}
			if (validBlock (pmbmd, pmbmd, gIndexOfCandBlk [iBlk] [2]))	{
				vctCandMV [2] = (pmv + gIndexOfCandBlk [iBlk] [2]) -> trueMVHalfPel ();
				rgbInBound [2] = TRUE;
				nInBound++;
			}
			break;
		case Y_BLOCK4:
			if (validBlock (pmbmd, pmbmd, gIndexOfCandBlk [iBlk] [0]))	{
				vctCandMV [0] = (pmv + gIndexOfCandBlk [iBlk] [0]) -> trueMVHalfPel ();
				rgbInBound [0] = TRUE;
				nInBound++;
			}
			if (validBlock (pmbmd, pmbmd, gIndexOfCandBlk [iBlk] [1]))	{
				vctCandMV [1] = (pmv + gIndexOfCandBlk [iBlk] [1]) -> trueMVHalfPel ();
				rgbInBound [1] = TRUE;
				nInBound++;
			}
			if (validBlock (pmbmd, pmbmd, gIndexOfCandBlk [iBlk] [2]))	{
				vctCandMV [2] = (pmv + gIndexOfCandBlk [iBlk] [2]) -> trueMVHalfPel ();
				rgbInBound [2] = TRUE;
				nInBound++;
			}
			break;
		}
	}
	else {
//	Modified for error resilient mode by Toshiba(1997-11-14)
//		if (iXMB != 0 && validBlock (pmbmd - 1, gIndexOfCandBlk [1] [0]))	{
		if (!bLeftBndry && validBlock (pmbmd, pmbmd - 1, gIndexOfCandBlk [1] [0]))	{
			vctCandMV [0] = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0]) -> trueMVHalfPel ();
			rgbInBound [0] = TRUE;
			nInBound++;
		}
		if (iYMB != 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]))	{
				vctCandMV [1] = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [1] [1]) -> trueMVHalfPel ();
				rgbInBound [1] = TRUE;
				nInBound++;
			}
//	Modified for error resilient mode by Toshiba(1997-11-14)
//			if (iXMB < m_iNumMBX - 1 && validBlock (pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [1] [2]))	{
			if (!bRightBndry && validBlock (pmbmd, pmbmd - m_iNumMBX + 1, gIndexOfCandBlk [1] [2]))	{
				vctCandMV [2] = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2]) -> trueMVHalfPel ();
				rgbInBound [2] = TRUE;
				nInBound++;
			}
		}
	}

	if (nInBound == 1)	{
		for (UInt i = 0; i < 3; i++)	{
			if (rgbInBound [i] == TRUE)	{
				vecPred = vctCandMV [i];
				return;
			}
		}
	}

	vecPred.x = medianof3 (vctCandMV [0].x, vctCandMV [1].x, vctCandMV [2].x);
	vecPred.y = medianof3 (vctCandMV [0].y, vctCandMV [1].y, vctCandMV [2].y);
}

Bool CVideoObject::validBlock (const CMBMode* pmbmdCurr, const CMBMode* pmbmd, Int blkn) const
{
	// block tests with mv padding
	if (pmbmd->m_rgTranspStatus [0] == ALL)		
		return FALSE;
	else if(pmbmd != pmbmdCurr)
		return TRUE;
	else {
		if(pmbmd->m_rgTranspStatus [blkn] == ALL)
			return FALSE;
		else
			return TRUE;
	}
}

Void CVideoObject::findMVpredictorOfBVOP (CVector& vctPred, const CMotionVector* pmv, const CMBMode* pmbmd, Int iMBX) const  		    //for B-VOP only
{
	vctPred.x = vctPred.y = 0;		//intialize to 0
	MBType mbtypCurr = pmbmd->m_mbType;
	for (Int iMBXCandidate = iMBX - 1; iMBXCandidate >= 0; iMBXCandidate--)	{		//scan backward MBs
		pmbmd--;
		pmv -= 5;
		if (pmbmd->m_bSkip)
			return;
		else if (pmbmd->m_mbType == mbtypCurr && pmbmd->m_rgTranspStatus [0] != ALL)	{
			vctPred = pmv->m_vctTrueHalfPel;
			return;
		}
	}
	return;							//reach the start of the row; reset
}

Void CVideoObject::backwardMVFromForwardMV (								//compute back mv from forward mv and ref mv for direct mode
					CMotionVector& mvBackward, const CMotionVector& mvForward,
					const CMotionVector& mvRef,	CVector vctDirectDeltaMV)
{
	assert (mvForward.iMVX != NOT_MV && mvForward.iMVY != NOT_MV);	//mv is valid
	CVector vctBackward;
	Int iFullInterval = m_tFutureRef - m_tPastRef;
	if (vctDirectDeltaMV.x == 0)
		vctBackward.x = (m_t - m_tFutureRef) * mvRef.m_vctTrueHalfPel.x / iFullInterval;
	else 
		vctBackward.x = mvForward.m_vctTrueHalfPel.x - mvRef.m_vctTrueHalfPel.x;

	if (vctDirectDeltaMV.y == 0)
		vctBackward.y = (m_t - m_tFutureRef) * mvRef.m_vctTrueHalfPel.y / iFullInterval;
	else 
		vctBackward.y = mvForward.m_vctTrueHalfPel.y - mvRef.m_vctTrueHalfPel.y;
	mvBackward = CMotionVector (vctBackward);
}


CVector CVideoObject::averageOfRefMV (const CMotionVector* pmvRef, const CMBMode* pmbmdRef)	
{
	assert(pmvRef!=NULL);
	CVector vctRef (0, 0);
	Int i;
	if (pmbmdRef -> m_bhas4MVForward)	{						//average
		Int iDivisor = 0;
		for (i = Y_BLOCK1; i <= Y_BLOCK4; i++)	{
			pmvRef++;
			if (pmbmdRef->m_rgTranspStatus [i] != ALL)	{
				assert (pmvRef->iMVX != NOT_MV);
				vctRef.x += pmvRef->m_vctTrueHalfPel.x;
				vctRef.y += pmvRef->m_vctTrueHalfPel.y;
				iDivisor += 1;
			}
		}
		vctRef.x = (Int) rounded((Float) vctRef.x / iDivisor);
		vctRef.y = (Int) rounded((Float) vctRef.y / iDivisor);
	}
	else {
		vctRef = pmvRef->m_vctTrueHalfPel;
		assert (pmvRef->iMVX != NOT_MV);
	}
	return vctRef;
}

Void CVideoObject::padMotionVectors (const CMBMode* pmbmd,CMotionVector *pmv)
{
	if(pmbmd->m_rgTranspStatus[0]==ALL)
		return;

	if(pmbmd->m_rgTranspStatus[1]==ALL)
	{
		pmv[1]=(pmbmd->m_rgTranspStatus[2]!=ALL)?pmv[2]:
			((pmbmd->m_rgTranspStatus[3]!=ALL)?pmv[3]:pmv[4]);
	}
	if(pmbmd->m_rgTranspStatus[2]==ALL)
	{
		pmv[2]=(pmbmd->m_rgTranspStatus[1]!=ALL)?pmv[1]:
			((pmbmd->m_rgTranspStatus[4]!=ALL)?pmv[4]:pmv[3]);
	}
	if(pmbmd->m_rgTranspStatus[3]==ALL)
	{
		pmv[3]=(pmbmd->m_rgTranspStatus[4]!=ALL)?pmv[4]:
			((pmbmd->m_rgTranspStatus[1]!=ALL)?pmv[1]:pmv[2]);
	}
	if(pmbmd->m_rgTranspStatus[4]==ALL)
	{
		pmv[4]=(pmbmd->m_rgTranspStatus[3]!=ALL)?pmv[3]:
			((pmbmd->m_rgTranspStatus[2]!=ALL)?pmv[2]:pmv[1]);
	}
}

⌨️ 快捷键说明

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