📄 mc.cpp
字号:
pmvR = pmvRightMb + 3;
break;
default:
assert (FALSE);
}
// Compute the top left corner's x,y coordinates of current block.
UInt dxc = (((i - 1) & 1) << 3);
UInt dyc = (((i - 1) & 2) << 2);
UInt nxcY = (x + dxc) << 1;
UInt nycY = (y + dyc) << 1;
// Compute the corresponding positions on Ref frm, using 5 MVs.
CoordI xRefC = nxcY + pmvC->m_vctTrueHalfPel.x, yRefC = nycY + pmvC->m_vctTrueHalfPel.y;
CoordI xRefT = nxcY + pmvT->m_vctTrueHalfPel.x, yRefT = nycY + pmvT->m_vctTrueHalfPel.y;
CoordI xRefB = nxcY + pmvB->m_vctTrueHalfPel.x, yRefB = nycY + pmvB->m_vctTrueHalfPel.y;
CoordI xRefR = nxcY + pmvR->m_vctTrueHalfPel.x, yRefR = nycY + pmvR->m_vctTrueHalfPel.y;
CoordI xRefL = nxcY + pmvL->m_vctTrueHalfPel.x, yRefL = nycY + pmvL->m_vctTrueHalfPel.y;
// UInt nxcY = x + dxc;
// UInt nycY = y + dyc;
// // Compute the corresponding positions on Ref frm, using 5 MVs.
// CoordI xRefC = ((nxcY + pmvC -> iMVX) << 1) + pmvC -> iHalfX, yRefC = ((nycY + pmvC -> iMVY) << 1) + pmvC -> iHalfY;
// CoordI xRefT = ((nxcY + pmvT -> iMVX) << 1) + pmvT -> iHalfX, yRefT = ((nycY + pmvT -> iMVY) << 1) + pmvT -> iHalfY;
// CoordI xRefB = ((nxcY + pmvB -> iMVX) << 1) + pmvB -> iHalfX, yRefB = ((nycY + pmvB -> iMVY) << 1) + pmvB -> iHalfY;
// CoordI xRefR = ((nxcY + pmvR -> iMVX) << 1) + pmvR -> iHalfX, yRefR = ((nycY + pmvR -> iMVY) << 1) + pmvR -> iHalfY;
// CoordI xRefL = ((nxcY + pmvL -> iMVX) << 1) + pmvL -> iHalfX, yRefL = ((nycY + pmvL -> iMVY) << 1) + pmvL -> iHalfY;
limitMVRangeToExtendedBBHalfPel (xRefC,yRefC,prctMVLimit,BLOCK_SIZE);
limitMVRangeToExtendedBBHalfPel (xRefT,yRefT,prctMVLimit,BLOCK_SIZE);
limitMVRangeToExtendedBBHalfPel (xRefB,yRefB,prctMVLimit,BLOCK_SIZE);
limitMVRangeToExtendedBBHalfPel (xRefR,yRefR,prctMVLimit,BLOCK_SIZE);
limitMVRangeToExtendedBBHalfPel (xRefL,yRefL,prctMVLimit,BLOCK_SIZE);
Bool bXSubPxlC = (xRefC & 1), bYSubPxlC = (yRefC & 1),
bXSubPxlT = (xRefT & 1), bYSubPxlT = (yRefT & 1),
bXSubPxlB = (xRefB & 1), bYSubPxlB = (yRefB & 1),
bXSubPxlR = (xRefR & 1), bYSubPxlR = (yRefR & 1),
bXSubPxlL = (xRefL & 1), bYSubPxlL = (yRefL & 1);
// 5 starting pos. in Zoomed Ref. Frames
const PixelC* ppxliPrevYC = ppxlcRefLeftTop + ((yRefC >> 1) + EXPANDY_REF_FRAME) * m_iFrameWidthY + (xRefC >> 1) + EXPANDY_REF_FRAME;
const PixelC* ppxliPrevYT = ppxlcRefLeftTop + ((yRefT >> 1) + EXPANDY_REF_FRAME) * m_iFrameWidthY + (xRefT >> 1) + EXPANDY_REF_FRAME;
const PixelC* ppxliPrevYB = ppxlcRefLeftTop + ((yRefB >> 1) + EXPANDY_REF_FRAME) * m_iFrameWidthY + (xRefB >> 1) + EXPANDY_REF_FRAME;
const PixelC* ppxliPrevYR = ppxlcRefLeftTop + ((yRefR >> 1) + EXPANDY_REF_FRAME) * m_iFrameWidthY + (xRefR >> 1) + EXPANDY_REF_FRAME;
const PixelC* ppxliPrevYL = ppxlcRefLeftTop + ((yRefL >> 1) + EXPANDY_REF_FRAME) * m_iFrameWidthY + (xRefL >> 1) + EXPANDY_REF_FRAME;
UInt *pWghtC, *pWghtT, *pWghtB, *pWghtR, *pWghtL;
pWghtC = (UInt*) gWghtC;
pWghtT = (UInt*) gWghtT;
pWghtB = (UInt*) gWghtB + 32;
pWghtR = (UInt*) gWghtR;
pWghtL = (UInt*) gWghtL;
UInt* uiOvrlpPredY = gOvrlpPredY;
if (bXSubPxlC && bYSubPxlC)
bilnrMCVH (uiOvrlpPredY, ppxliPrevYC, pWghtC, 0, 8, 0, 8, FALSE);
else if (bXSubPxlC && !bYSubPxlC)
bilnrMCH (uiOvrlpPredY, ppxliPrevYC, pWghtC, 0, 8, 0, 8, FALSE);
else if (!bXSubPxlC && bYSubPxlC)
bilnrMCV (uiOvrlpPredY, ppxliPrevYC, pWghtC, 0, 8, 0, 8, FALSE);
else // (!bXSubPxlC && !bYSubPxlC)
bilnrMC (uiOvrlpPredY, ppxliPrevYC, pWghtC, 0, 8, 0, 8, FALSE);
if (bXSubPxlT && bYSubPxlT)
bilnrMCVH (uiOvrlpPredY, ppxliPrevYT, pWghtT, 0, 8, 0, 4, TRUE);
else if (bXSubPxlT && !bYSubPxlT)
bilnrMCH (uiOvrlpPredY, ppxliPrevYT, pWghtT, 0, 8, 0, 4, TRUE);
else if (!bXSubPxlT && bYSubPxlT)
bilnrMCV (uiOvrlpPredY, ppxliPrevYT, pWghtT, 0, 8, 0, 4, TRUE);
else // (!bXSubPxlT && !bYSubPxlT)
bilnrMC (uiOvrlpPredY, ppxliPrevYT, pWghtT, 0, 8, 0, 4, TRUE);
if (bXSubPxlB && bYSubPxlB)
bilnrMCVH (&uiOvrlpPredY [32], ppxliPrevYB + (m_iFrameWidthY << 2), pWghtB, 0, 8, 4, 8, TRUE);
else if (bXSubPxlB && !bYSubPxlB)
bilnrMCH (&uiOvrlpPredY [32], ppxliPrevYB + (m_iFrameWidthY << 2), pWghtB, 0, 8, 4, 8, TRUE);
else if (!bXSubPxlB && bYSubPxlB)
bilnrMCV (&uiOvrlpPredY [32], ppxliPrevYB + (m_iFrameWidthY << 2), pWghtB, 0, 8, 4, 8, TRUE);
else // (!bXSubPxlB && !bYSubPxlB)
bilnrMC (&uiOvrlpPredY [32], ppxliPrevYB + (m_iFrameWidthY << 2), pWghtB, 0, 8, 4, 8, TRUE);
if (bXSubPxlR && bYSubPxlR)
bilnrMCVH (uiOvrlpPredY, ppxliPrevYR, pWghtR, 4, 8, 0, 8, TRUE);
else if (bXSubPxlR && !bYSubPxlR)
bilnrMCH (uiOvrlpPredY, ppxliPrevYR, pWghtR, 4, 8, 0, 8, TRUE);
else if (!bXSubPxlR && bYSubPxlR)
bilnrMCV (uiOvrlpPredY, ppxliPrevYR, pWghtR, 4, 8, 0, 8, TRUE);
else // (!bXSubPxlR && !bYSubPxlR)
bilnrMC (uiOvrlpPredY, ppxliPrevYR, pWghtR, 4, 8, 0, 8, TRUE);
if (bXSubPxlL && bYSubPxlL)
bilnrMCVH (uiOvrlpPredY, ppxliPrevYL, pWghtL, 0, 4, 0, 8, TRUE);
else if (bXSubPxlL && !bYSubPxlL)
bilnrMCH (uiOvrlpPredY, ppxliPrevYL, pWghtL, 0, 4, 0, 8, TRUE);
else if (!bXSubPxlL && bYSubPxlL)
bilnrMCV (uiOvrlpPredY, ppxliPrevYL, pWghtL, 0, 4, 0, 8, TRUE);
else // (!bXSubPxlL && !bYSubPxlL)
bilnrMC (uiOvrlpPredY, ppxliPrevYL, pWghtL, 0, 4, 0, 8, TRUE);
PixelC* ppxliPredY = ppxlcPredMB + dxc + dyc * MB_SIZE; // Starting of Pred. Frame
for (UInt iy = 0; iy < BLOCK_SIZE; iy++){
for (UInt ix = 0; ix < BLOCK_SIZE; ix++)
*ppxliPredY++= (*uiOvrlpPredY++ + 4) >> 3;
ppxliPredY += BLOCK_SIZE;
}
}
}
Void CVideoObject::bilnrMCVH (UInt* PredY, const PixelC* ppxliPrevYC, UInt* pMWght, UInt xlow, UInt xhigh, UInt ylow, UInt yhigh, Bool bAdd)
{
const PixelC* ppxliPrevYCBot = ppxliPrevYC + m_iFrameWidthY;
if (bAdd)
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
// PredY [ix] += ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + ppxliPrevYCBot [ix] + ppxliPrevYCBot[ix+1] + 2) >> 2) * pMWght [ix];
PredY [ix] += ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + ppxliPrevYCBot [ix] + ppxliPrevYCBot[ix+1] + 2 - m_vopmd.iRoundingControl) >> 2) * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
ppxliPrevYCBot += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
else
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
// PredY [ix] = ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + ppxliPrevYCBot [ix] + ppxliPrevYCBot[ix+1] + 2) >> 2) * pMWght [ix];
PredY [ix] = ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + ppxliPrevYCBot [ix] + ppxliPrevYCBot[ix+1] + 2 - m_vopmd.iRoundingControl) >> 2) * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
ppxliPrevYCBot += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
}
Void CVideoObject::bilnrMCV (UInt* PredY, const PixelC* ppxliPrevYC, UInt* pMWght, UInt xlow, UInt xhigh, UInt ylow, UInt yhigh, Bool bAdd)
{
const PixelC* ppxliPrevYCBot = ppxliPrevYC + m_iFrameWidthY;
if (bAdd)
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
// PredY [ix] += ((UInt) (ppxliPrevYC [ix] + ppxliPrevYCBot [ix] + 1) >> 1) * pMWght [ix];
PredY [ix] += ((UInt) (ppxliPrevYC [ix] + ppxliPrevYCBot [ix] + 1 - m_vopmd.iRoundingControl) >> 1) * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
ppxliPrevYCBot += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
else
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
// PredY [ix] = ((UInt) (ppxliPrevYC [ix] + ppxliPrevYCBot [ix] + 1) >> 1) * pMWght [ix];
PredY [ix] = ((UInt) (ppxliPrevYC [ix] + ppxliPrevYCBot [ix] + 1 - m_vopmd.iRoundingControl) >> 1) * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
ppxliPrevYCBot += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
}
Void CVideoObject::bilnrMCH (UInt* PredY, const PixelC* ppxliPrevYC, UInt* pMWght, UInt xlow, UInt xhigh, UInt ylow, UInt yhigh, Bool bAdd)
{
//PixelC* ppxliPrevYCBot = ppxliPrevYC + m_iFrameWidthY;
if (bAdd)
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
// PredY [ix] += ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + 1) >> 1) * pMWght [ix];
PredY [ix] += ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + 1 - m_vopmd.iRoundingControl) >> 1) * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
else
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
// PredY [ix] = ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + 1) >> 1) * pMWght [ix];
PredY [ix] = ((UInt) (ppxliPrevYC [ix] + ppxliPrevYC [ix + 1] + 1 - m_vopmd.iRoundingControl) >> 1) * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
}
Void CVideoObject::bilnrMC (UInt* PredY, const PixelC* ppxliPrevYC, UInt* pMWght, UInt xlow, UInt xhigh, UInt ylow, UInt yhigh, Bool bAdd)
{
//PixelC* ppxliPrevYCBot = ppxliPrevYC + m_iFrameWidthY;
if (bAdd)
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
PredY [ix] += (UInt) ppxliPrevYC [ix] * pMWght[ix];
ppxliPrevYC += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
else
for (UInt iy = ylow; iy < yhigh; iy++) {
for (UInt ix = xlow; ix < xhigh; ix++)
PredY [ix] = (UInt) ppxliPrevYC [ix] * pMWght [ix];
ppxliPrevYC += m_iFrameWidthY;
PredY += BLOCK_SIZE;
pMWght += BLOCK_SIZE;
}
}
Void CVideoObject::motionCompBY (
PixelC* ppxlcPred, // can be either Y or A
const PixelC* ppxlcRefLeftTop,
CoordI iXRef, CoordI iYRef // x + mvX in full pel unit
)
{
CoordI iY;
const PixelC* ppxlcRef = ppxlcRefLeftTop +
(iYRef + EXPANDY_REF_FRAME) * m_iFrameWidthY + iXRef + EXPANDY_REF_FRAME;
// bugfix: use the proper bounding rect (!), 981028 mwi
Int iLeftBound;
Int iRightBound;
Int iTopBound;
Int iBottomBound;
if (m_vopmd.vopPredType == BVOP && m_vopmd.fShapeBPredDir == B_BACKWARD) {
iLeftBound = max(0,m_rctRefVOPY1.left - iXRef);
iRightBound = max(0,m_rctRefVOPY1.right - iXRef);
iTopBound = max(0,m_rctRefVOPY1.top - iYRef);
iBottomBound = max(0,m_rctRefVOPY1.bottom - iYRef);
}
else {
iLeftBound = max(0,m_rctRefVOPY0.left - iXRef);
iRightBound = max(0,m_rctRefVOPY0.right - iXRef);
iTopBound = max(0,m_rctRefVOPY0.top - iYRef);
iBottomBound = max(0,m_rctRefVOPY0.bottom - iYRef);
}
// ~bugfix: use the proper bounding rect
iLeftBound = min(MC_BAB_SIZE,iLeftBound);
iRightBound = min(MC_BAB_SIZE,iRightBound);
iTopBound = min(MC_BAB_SIZE,iTopBound);
iBottomBound = min(MC_BAB_SIZE,iBottomBound);
Int iHeightMax = iBottomBound-iTopBound;
Int iWidthMax = iRightBound-iLeftBound;
if (iHeightMax == MC_BAB_SIZE && iWidthMax == MC_BAB_SIZE) {
for (iY = 0; iY < MC_BAB_SIZE; iY++) {
memcpy (ppxlcPred, ppxlcRef, MC_BAB_SIZE*sizeof(PixelC));
ppxlcRef += m_iFrameWidthY;
ppxlcPred += MC_BAB_SIZE;
}
} else if(iWidthMax == 0 || iHeightMax==0)
for (iY = 0; iY < MC_BAB_SIZE; iY++) {
memset (ppxlcPred, 0, MC_BAB_SIZE*sizeof(PixelC));
ppxlcPred += MC_BAB_SIZE;
}
else {
for (iY = 0; iY < MC_BAB_SIZE; iY++) {
if(iY<iTopBound || iY>=iBottomBound)
memset (ppxlcPred, 0, MC_BAB_SIZE*sizeof(PixelC)); // clear row
else
{
if(iLeftBound>0)
memset (ppxlcPred, 0, iLeftBound*sizeof(PixelC)); // clear left hand span
if(iRightBound<MC_BAB_SIZE)
memset (ppxlcPred+iRightBound, 0, (MC_BAB_SIZE-iRightBound)*sizeof(PixelC)); // right span
memcpy (ppxlcPred+iLeftBound, ppxlcRef+iLeftBound, iWidthMax*sizeof(PixelC)); // copy middle region
}
ppxlcRef += m_iFrameWidthY;
ppxlcPred += MC_BAB_SIZE;
}
}
}
Void CVideoObject::copyFromRefToCurrQ (
const CVOPU8YUVBA* pvopcRef, // reference VOP
CoordI x, CoordI y,
PixelC* ppxlcCurrQMBY, PixelC* ppxlcCurrQMBU, PixelC* ppxlcCurrQMBV,
CRct *prctMVLimit
)
{
// needs limiting to reference area bounding box
limitMVRangeToExtendedBBFullPel(x,y,prctMVLimit,MB_SIZE);
Int iOffsetY = (y + EXPANDY_REF_FRAME) * m_iFrameWidthY + x + EXPANDY_REF_FRAME;
Int iOffsetUV = (y / 2 + EXPANDUV_REF_FRAME) * m_iFrameWidthUV + x / 2 + EXPANDUV_REF_FRAME;
const PixelC* ppxlcRefMBY = pvopcRef->pixelsY () + iOffsetY;
const PixelC* ppxlcRefMBU = pvopcRef->pixelsU () + iOffsetUV;
const PixelC* ppxlcRefMBV = pvopcRef->pixelsV () + iOffsetUV;
CoordI iY;
for (iY = 0; iY < BLOCK_SIZE; iY++) {
memcpy (ppxlcCurrQMBY, ppxlcRefMBY, MB_SIZE*sizeof(PixelC));
memcpy (ppxlcCurrQMBU, ppxlcRefMBU, BLOCK_SIZE*sizeof(PixelC));
memcpy (ppxlcCurrQMBV, ppxlcRefMBV, BLOCK_SIZE*sizeof(PixelC));
ppxlcCurrQMBY += m_iFrameWidthY; ppxlcRefMBY += m_iFrameWidthY;
ppxlcCurrQMBU += m_iFrameWidthUV; ppxlcRefMBU += m_iFrameWidthUV;
ppxlcCurrQMBV += m_iFrameWidthUV; ppxlcRefMBV += m_iFrameWidthUV;
memcpy (ppxlcCurrQMBY, ppxlcRefMBY, MB_SIZE*sizeof(PixelC));
ppxlcCurrQMBY += m_iFrameWidthY; ppxlcRefMBY += m_iFrameWidthY;
}
}
Void CVideoObject::copyFromRefToCurrQ_WithShape (
const CVOPU8YUVBA* pvopcRef, // reference VOP
CoordI x, CoordI y,
PixelC* ppxlcCurrQMBY, PixelC* ppxlcCurrQMBU, PixelC* ppxlcCurrQMBV, PixelC* ppxlcCurrQMBBY
)
{
Int iOffsetY = (y + EXPANDY_REF_FRAME) * m_iFrameWidthY + x + EXPANDY_REF_FRAME;
Int iOffsetUV = (y / 2 + EXPANDUV_REF_FRAME) * m_iFrameWidthUV + x / 2 + EXPANDUV_REF_FRAME;
const PixelC* ppxlcRefMBY = pvopcRef->pixelsY () + iOffsetY;
const PixelC* ppxlcRefMBBY = pvopcRef->pixelsBY () + iOffsetY;
const PixelC* ppxlcRefMBU = pvopcRef->pixelsU () + iOffsetUV;
const PixelC* ppxlcRefMBV = pvopcRef->pixelsV () + iOffsetUV;
CoordI iY;
for (iY = 0; iY < BLOCK_SIZE; iY++) {
memcpy (ppxlcCurrQMBY, ppxlcRefMBY, MB_SIZE*sizeof(PixelC));
memcpy (ppxlcCurrQMBBY, ppxlcRefMBBY, MB_SIZE*sizeof(PixelC));
memcpy (ppxlcCurrQMBU, ppxlcRefMBU, BLOCK_SIZE*sizeof(PixelC));
memcpy (ppxlcCurrQMBV, ppxlcRefMBV, BLOCK_SIZE*sizeof(PixelC));
ppxlcCurrQMBY += m_iFrameWidthY; ppxlcRefMBY += m_iFrameWidthY;
ppxlcCurrQMBBY += m_iFrameWidthY; ppxlcRefMBBY += m_iFrameWidthY;
ppxlcCurrQMBU += m_iFrameWidthUV; ppxlcRefMBU += m_iFrameWidthUV;
ppxlcCurrQMBV += m_iFrameWidthUV; ppxlcRefMBV += m_iFrameWidthUV;
memcpy (ppxlcCurrQMBY, ppxlcRefMBY, MB_SIZE*sizeof(PixelC));
ppxlcCurrQMBY += m_iFrameWidthY; ppxlcRefMBY += m_iFrameWidthY;
memcpy (ppxlcCurrQMBBY, ppxlcRefMBBY, MB_SIZE*sizeof(PixelC));
ppxlcCurrQMBBY += m_iFrameWidthY; ppxlcRefMBBY += m_iFrameWidthY;
}
}
Void CVideoObject::copyAlphaFromRefToCurrQ (
const CVOPU8YUVBA* pvopcRef, // reference VOP
CoordI x, CoordI y,
PixelC* ppxlcCurrQMBA,
CRct *prctMVLimit
)
{
// needs limiting to reference area bounding box
limitMVRangeToExtendedBBFullPel(x,y,prctMVLimit,MB_SIZE);
Int iOffsetY = (y + EXPANDY_REF_FRAME) * m_iFrameWidthY + x + EXPANDY_REF_FRAME;
const PixelC* ppxlcRefMBA = pvopcRef->pixelsA () + iOffsetY;
CoordI iY;
for (iY = 0; iY < MB_SIZE; iY++) {
memcpy (ppxlcCurrQMBA, ppxlcRefMBA, MB_SIZE*sizeof(PixelC));
ppxlcCurrQMBA += m_iFrameWidthY;
ppxlcRefMBA += m_iFrameWidthY;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -