📄 mv.cpp
字号:
/**************************************************************************
This software module was originally developed by
Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
Simon Winder (swinder@microsoft.com), Microsoft Corporation
(date: June, 1997)
and edited by
Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Center
and also edited by
Yoshihiro Kikuchi (TOSHIBA CORPORATION)
Takeshi Nagai (TOSHIBA CORPORATION)
Toshiaki Watanabe (TOSHIBA CORPORATION)
Noboru Yamaguchi (TOSHIBA CORPORATION)
and also edited by
Yoshinori Suzuki (Hitachi, Ltd.)
and also edited by
Fujitsu Laboratories Ltd. (contact: Eishi Morimatsu)
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2).
This software module is an implementation of a part of one or more MPEG-4 Video tools
as specified by the MPEG-4 Video.
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video.
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents.
The original developer of this software module and his/her company,
the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation.
Copyright is not released for non MPEG-4 Video conforming products.
Microsoft retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1996, 1997.
Revision History:
Nov. 14, 1997: Added/Modified for error resilient mode by Toshiba
December 20, 1997: Interlaced tools added by NextLevel Systems (GI)
X. Chen (xchen@nlvl.com), B. Eifrig (beifrig@nlvl.com)
Feb.16 1999 : add Quarter Sample
Mathias Wien (wien@ient.rwth-aachen.de)
Sep.06 1999 : RRV added by Eishi Morimatsu (Fujitsu Laboratories Ltd.)
**************************************************************************/
#include <stdio.h>
#include "typeapi.h"
#include "global.hpp"
#include "codehead.h"
#include "mode.hpp"
#include "vopses.hpp"
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
inline Int medianof3 (Int a0, Int a1, Int a2)
{
if (a0 > a1) {
if (a1 > a2)
return a1;
else if (a0 > a2)
return a2;
else
return a0;
}
else if (a0 > a2)
return a0;
else if (a1 > a2)
return a2;
else
return a1;
}
Void CVideoObject::find16x16MVpred (CVector& vecPred, const CMotionVector* pmv, Bool bLeftBndry, Bool bRightBndry, Bool bTopBndry) const
{
CVector vctCandMV0, vctCandMV1, vctCandMV2;
if (bLeftBndry)
vctCandMV0.set (0, 0);
else
vctCandMV0 = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0]) -> trueMVHalfPel ();
if (bTopBndry) {
vecPred = vctCandMV0;
return;
}
else {
vctCandMV1 = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [1] [1]) -> trueMVHalfPel ();
if (bRightBndry)
vctCandMV2.set (0, 0);
else
vctCandMV2 = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2]) -> trueMVHalfPel ();
}
vecPred.x = medianof3 (vctCandMV0.x, vctCandMV1.x, vctCandMV2.x);
vecPred.y = medianof3 (vctCandMV0.y, vctCandMV1.y, vctCandMV2.y);
}
Void CVideoObject::find8x8MVpredAtBoundary (CVector& vecPred, const CMotionVector* pmv, Bool bLeftBndry, Bool bRightBndry, Bool bTopBndry, Int blknCurr) const
{
CVector vctCandMV0, vctCandMV1, vctCandMV2;
switch (blknCurr){
case Y_BLOCK1:
if (bLeftBndry)
vctCandMV0.set (0, 0);
else
vctCandMV0 = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
if (bTopBndry){
vecPred = vctCandMV0;
return;
}
else{
vctCandMV1 = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [blknCurr] [1])->trueMVHalfPel ();
if (bRightBndry)
vctCandMV2.set (0, 0);
else
vctCandMV2 = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2])->trueMVHalfPel ();
}
break;
case Y_BLOCK2:
vctCandMV0 = (pmv + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
if (bTopBndry) {
vecPred = vctCandMV0;
return;
}
else{
vctCandMV1 = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
if (bRightBndry)
vctCandMV2.set (0, 0);
else
vctCandMV2 = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
}
break;
case Y_BLOCK3:
if (bLeftBndry)
vctCandMV0.set (0,0);
else
vctCandMV0 = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
vctCandMV1 = (pmv + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
vctCandMV2 = (pmv + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
break;
case Y_BLOCK4:
vctCandMV0 = (pmv + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
vctCandMV1 = (pmv + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
vctCandMV2 = (pmv + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
break;
}
vecPred.x = medianof3 (vctCandMV0.x, vctCandMV1.x, vctCandMV2.x);
vecPred.y = medianof3 (vctCandMV0.y, vctCandMV1.y, vctCandMV2.y);
}
Void CVideoObject::find8x8MVpredInterior (CVector& vecPred, const CMotionVector* pmv, Int blknCurr) const
{
CVector vctCandMV0, vctCandMV1, vctCandMV2;
switch (blknCurr){
case Y_BLOCK1:
vctCandMV0 = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
vctCandMV1 = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
vctCandMV2 = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
break;
case Y_BLOCK2:
vctCandMV0 = (pmv + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
vctCandMV1 = (pmv - m_iNumOfTotalMVPerRow + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
vctCandMV2 = (pmv - m_iNumOfTotalMVPerRow + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
break;
case Y_BLOCK3:
vctCandMV0 = (pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
vctCandMV1 = (pmv + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
vctCandMV2 = (pmv + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
break;
case Y_BLOCK4:
vctCandMV0 = (pmv + gIndexOfCandBlk [blknCurr] [0]) -> trueMVHalfPel ();
vctCandMV1 = (pmv + gIndexOfCandBlk [blknCurr] [1]) -> trueMVHalfPel ();
vctCandMV2 = (pmv + gIndexOfCandBlk [blknCurr] [2]) -> trueMVHalfPel ();
break;
}
vecPred.x = medianof3 (vctCandMV0.x, vctCandMV1.x, vctCandMV2.x);
vecPred.y = medianof3 (vctCandMV0.y, vctCandMV1.y, vctCandMV2.y);
}
Void CVideoObject::mvLookupUV (const CMBMode* pmbmd, const CMotionVector* pmv,
CoordI& xRefUV, CoordI& yRefUV, CoordI& xRefUV1,CoordI& yRefUV1)
{
Int dx = 0, dy = 0;
if (m_volmd.bQuarterSample) {
if (pmbmd -> m_bhas4MVForward) {
pmv++;
for (UInt k = 1; k <= 4; k++){
dx += pmv->iMVX;
dy += pmv->iMVY;
pmv++;
}
xRefUV = sign (dx) * (grgiMvRound16 [abs (dx) % 16] + (abs (dx) / 16) * 2);
yRefUV = sign (dy) * (grgiMvRound16 [abs (dy) % 16] + (abs (dy) / 16) * 2);
}
// INTERLACE
else if (pmbmd -> m_bFieldMV) {
if(pmbmd->m_bForwardTop) {
dx = pmv [6].iMVX;
dy = pmv [6].iMVY;
}
else {
dx = pmv [5].iMVX;
dy = pmv [5].iMVY;
}
xRefUV = ((dx & 3) ? ((dx >> 1) | 1) : (dx>>1));
yRefUV = ((dy & 6) ? ((dy >> 1) | 2) : (dy>>1));
if(pmbmd->m_bForwardBottom) {
dx = pmv [8].iMVX;
dy = pmv [8].iMVY;
}
else {
dx = pmv [7].iMVX;
dy = pmv [7].iMVY;
}
xRefUV1 = ((dx & 3) ? ((dx >> 1) | 1) : (dx>>1));
yRefUV1 = ((dy & 6) ? ((dy >> 1) | 2) : (dy>>1));
}
// ~INTERLACE
else {
dx = pmv->iMVX;
dy = pmv->iMVY;
xRefUV = sign (dx) * (grgiMvRound4 [abs (dx) % 4] + (abs (dx) / 4) * 2);
yRefUV = sign (dy) * (grgiMvRound4 [abs (dy) % 4] + (abs (dy) / 4) * 2);
}
}
else {
if (pmbmd -> m_bhas4MVForward) {
pmv++;
// RRV modification
if(m_vopmd.RRVmode.iRRVOnOff == 1)
{
for (UInt k = 1; k <= 4; k++)
{
dx += pmv->m_vctTrueHalfPel_x2.x;
dy += pmv->m_vctTrueHalfPel_x2.y;
pmv++;
}
}
else{
for (UInt k = 1; k <= 4; k++)
{
dx += pmv->m_vctTrueHalfPel.x;
dy += pmv->m_vctTrueHalfPel.y;
pmv++;
}
// for (UInt k = 1; k <= 4; k++){
// dx += pmv->m_vctTrueHalfPel.x;
// dy += pmv->m_vctTrueHalfPel.y;
// pmv++;
// ~RRV
}
xRefUV = sign (dx) * (grgiMvRound16 [abs (dx) % 16] + (abs (dx) / 16) * 2);
yRefUV = sign (dy) * (grgiMvRound16 [abs (dy) % 16] + (abs (dy) / 16) * 2);
}
// INTERLACE
else if (pmbmd -> m_bFieldMV) {
if(pmbmd->m_bForwardTop) {
dx = pmv [6].m_vctTrueHalfPel.x;
dy = pmv [6].m_vctTrueHalfPel.y;
}
else {
dx = pmv [5].m_vctTrueHalfPel.x;
dy = pmv [5].m_vctTrueHalfPel.y;
}
xRefUV = ((dx & 3) ? ((dx >> 1) | 1) : (dx>>1));
yRefUV = ((dy & 6) ? ((dy >> 1) | 2) : (dy>>1));
if(pmbmd->m_bForwardBottom) {
dx = pmv [8].m_vctTrueHalfPel.x;
dy = pmv [8].m_vctTrueHalfPel.y;
}
else {
dx = pmv [7].m_vctTrueHalfPel.x;
dy = pmv [7].m_vctTrueHalfPel.y;
}
xRefUV1 = ((dx & 3) ? ((dx >> 1) | 1) : (dx>>1));
yRefUV1 = ((dy & 6) ? ((dy >> 1) | 2) : (dy>>1));
}
// ~INTERLACE
else {
// RRV modification
if(m_vopmd.RRVmode.iRRVOnOff == 1){
dx = pmv->m_vctTrueHalfPel_x2.x;
dy = pmv->m_vctTrueHalfPel_x2.y;
}
else{
dx = pmv->m_vctTrueHalfPel.x;
dy = pmv->m_vctTrueHalfPel.y;
}
// dx = pmv->m_vctTrueHalfPel.x;
// dy = pmv->m_vctTrueHalfPel.y;
// ~RRV
xRefUV = sign (dx) * (grgiMvRound4 [abs (dx) % 4] + (abs (dx) / 4) * 2);
yRefUV = sign (dy) * (grgiMvRound4 [abs (dy) % 4] + (abs (dy) / 4) * 2);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -