📄 mcdec.c
字号:
/*************************************************************************This software module was originally developed by Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation (date: July, 1997)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-4 Video conforming products. This copyright notice must be included in all copies or derivative works. Copyright (c) 1996, 1997.Module Name: mcdec.cAbstract: motion compensation for decoderRevision History: Dec 20, 1997: Interlaced tools added by NextLevel Systems (GI) B. Eifrig (beifrig@nlvl.com) X. Chen (xchen@nlvl.com) Feb.16, 1999: add Quarter Sample Mathias Wien (wien@ient.rwth-aachen.de) *************************************************************************/#include <stdio.h>#include <math.h>#include <stdlib.h>#include "typeapi.h"#include "mode.h"#include "codehead.h"#include "entropy/bitstrm.h"#include "entropy/huffman.h"#include "global.h"#include "vopses.h"#include "vopsedec.h"#include "mae_pass_thru.h"const Int rgiBlkOffsetX [] = {0, BLOCK_SIZE, 0, BLOCK_SIZE};const Int rgiBlkOffsetY [] = {0, 0, BLOCK_SIZE, BLOCK_SIZE};const Int rgiBlkOffsetPixel [] = {0, OFFSET_BLK1, OFFSET_BLK2, OFFSET_BLK3};Void motionCompAndAddErrorMB_BVOP (CMotionVector* pmvForward, CMotionVector* pmvBackward, CMBMode* pmbmd, Int iMBX, Int iMBY, CoordI x, CoordI y, CRct *prctMVLimitForward,CRct *prctMVLimitBackward){ int MVX, MVY; Int iBlk;#ifdef ENABLE_INTERLACING// INTERLACE // new chnages if (m_vopmd.bInterlace) // Should not depend on .bInterlace; this code should work the progressive case. Original code retained due to possible differences in direct mode { switch (pmbmd->m_mbType) { case FORWARD: g_MAEWrapper->Set_MAEMB_mbmode(MBM_FORWARD,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); if (pmbmd->m_bFieldMV) g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else { if (pmbmd->m_bhas4MVForward) g_MAEWrapper->Set_MAEMB_mbtype(MBT_8x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x16,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); } motionCompOneBVOPReference(FORWARD, pmbmd, pmvForward);// HV For Travis // Revert back the Stride value before writing // the Final data into the current Y, U & V pointers if (nFlipToRef == FLIP_TO_REF) { m_iFrameWidthY -= EXPANDY_REF_FRAMEx2; m_iFrameWidthUV -= EXPANDUV_REF_FRAMEx2; }// ~HV For Travis break; case BACKWARD: g_MAEWrapper->Set_MAEMB_mbmode(MBM_BACKWARD,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); if (pmbmd->m_bFieldMV) g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else { if (pmbmd->m_bhas4MVBackward) g_MAEWrapper->Set_MAEMB_mbtype(MBT_8x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x16,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); } motionCompOneBVOPReference(BACKWARD,pmbmd, pmvBackward); // HV For Travis // Revert back the Stride value before writing // the Final data into the current Y, U & V pointers if (nFlipToRef == FLIP_TO_REF) { m_iFrameWidthY -= EXPANDY_REF_FRAMEx2; m_iFrameWidthUV -= EXPANDUV_REF_FRAMEx2; }// ~HV For Travis break; case DIRECT: Int iOffset; if(m_volmd.fAUsage != RECTANGLE) iOffset = (min (max (0, iMBX), m_iNumMBXRef - 1) + min (max (0, iMBY), m_iNumMBYRef - 1) * m_iNumMBXRef) * PVOP_MV_PER_REF_PER_MB; else iOffset=PVOP_MV_PER_REF_PER_MB*(iMBX + iMBY*m_iNumMBX); g_MAEWrapper->Set_MAEMB_mbmode(MBM_BIDIRECTIONAL,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); if (pmbmd->m_bFieldMV) g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else { if (pmbmd->m_bhas4MVForward) g_MAEWrapper->Set_MAEMB_mbtype(MBT_8x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x16,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); } motionCompDirectMode(x, y, pmbmd, &m_rgmvRef[iOffset], prctMVLimitForward, prctMVLimitBackward, 0); // HV For Travis // Revert back the Stride value before writing // the Final data into the current Y, U & V pointers if (nFlipToRef == FLIP_TO_REF) { m_iFrameWidthY -= EXPANDY_REF_FRAMEx2; m_iFrameWidthUV -= EXPANDUV_REF_FRAMEx2; }// ~HV For Travis break; case INTERPOLATE: g_MAEWrapper->Set_MAEMB_mbmode(MBM_BIDIRECTIONAL,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); if (pmbmd->m_bFieldMV) g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else { if (pmbmd->m_bhas4MVForward) g_MAEWrapper->Set_MAEMB_mbtype(MBT_8x8,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); else g_MAEWrapper->Set_MAEMB_mbtype(MBT_16x16,"CVideoObjectDecoder::motionCompAndAddErrorMB_BVOP", __LINE__, __FILE__); } motionCompOneBVOPReference(FORWARD, pmbmd, pmvForward); motionCompOneBVOPReference(BACKWARD,pmbmd, pmvBackward);// HV For Travis // Revert back the Stride value before writing // the Final data into the current Y, U & V pointers if (nFlipToRef == FLIP_TO_REF) { m_iFrameWidthY -= EXPANDY_REF_FRAMEx2; m_iFrameWidthUV -= EXPANDUV_REF_FRAMEx2; }// ~HV For Travis break; } return; }#endif // ~INTERLACE // Reset mbmode to begin with g_pHeader2->mbmode = MBM_INTRA; if (pmbmd->m_mbType == DIRECT || pmbmd->m_mbType == INTERPOLATE) { if (pmbmd->m_bhas4MVForward != TRUE && pmbmd->m_mbType != DIRECT) { g_pHeader2->mbmode = MBMODE_FWD_ALL_420; g_pHeader3->mbtype = MBT_16x16; // Get the half-pel values MVX = TRUEMVHALFPEL_X(pmvForward); MVY = TRUEMVHALFPEL_Y(pmvForward); // Use hpel (4 MVs each 32-bit) g_pMV[0] = g_pMV[1] = g_pMV[2] = g_pMV[3] = ((MVX << 16) | (MVY & 0x0000FFFF)); } else { const CMotionVector* pmv8 = pmvForward; for (iBlk = 0; iBlk < 4; iBlk++) { pmv8++; g_pHeader2->mbmode = MBMODE_FWD_ALL_420; g_pHeader3->mbtype = MBT_8x8; // Get the half-pel values MVX = TRUEMVHALFPEL_X(pmv8); MVY = TRUEMVHALFPEL_Y(pmv8); // Use hpel g_pMV[iBlk] = ((MVX << 16) | (MVY & 0x0000FFFF)); } } CoordI xRefUVForward, yRefUVForward; mvLookupUVWithShape (pmbmd, pmvForward, &xRefUVForward, &yRefUVForward); // For Chroma MVs, update here only if we are handling // the MBM_BIDIRECTIONAL case. For the regular // case, it gets filled within motionCompUV()#ifdef EXTRA_MV_CLIPPING CoordI xRefUV, yRefUV, iTmpX, iTmpY; iTmpX = x + xRefUVForward; iTmpY = y + yRefUVForward; LIMITMVRANGETOEXTENDEDBBFULLPEL (&iTmpX,&iTmpY,prctMVLimitForward, MB_SIZE); xRefUV = iTmpX - x; yRefUV = iTmpY - y; // U & V Motion Vectors are already in Half-Pel // units. So, lets just pass it down (16x16 FWD/BWD/BID) // ******************************************** g_pMV[g_UVMVId++] = ((xRefUV << 16) | (yRefUV & 0x0000FFFF));#else // U & V Motion Vectors are already in Half-Pel // units. So, lets just pass it down (16x16 FWD/BWD/BID) // ******************************************** g_pMV[g_UVMVId++] = ((xRefUVForward << 16) | (yRefUVForward & 0x0000FFFF));#endif //if (pmbmd->m_bhas4MVBackward != TRUE) if (pmbmd->m_bhas4MVBackward != TRUE && pmbmd->m_mbType != DIRECT) { g_pHeader2->mbmode |= MBMODE_BWD_ALL_420; g_pHeader3->mbtype = MBT_16x16; // Get the half-pel values MVX = TRUEMVHALFPEL_X(pmvBackward); MVY = TRUEMVHALFPEL_Y(pmvBackward); // Use hpel. If we are doing bi-directional, then retain the first 2 values if (g_pHeader2->mbmode == MBMODE_BID_ALL_420) g_pMV[2] = g_pMV[3] = (MVX << 16) | (MVY & 0x0000FFFF); else g_pMV[0] = g_pMV[1] = g_pMV[2] = g_pMV[3] = ((MVX << 16) | (MVY & 0x0000FFFF)); } else { const CMotionVector* pmv8 = pmvBackward; for (iBlk = 0; iBlk < 4; iBlk++) { pmv8++; g_pHeader2->mbmode |= MBMODE_BWD_ALL_420; g_pHeader3->mbtype = MBT_8x8; // Get the half-pel values MVX = TRUEMVHALFPEL_X(pmv8); MVY = TRUEMVHALFPEL_Y(pmv8); // Use hpel. If we are doing bi-directional, then retain the first 2 values if (g_pHeader2->mbmode == MBMODE_BID_ALL_420) g_pMV[iBlk+4] = ((MVX << 16) | (MVY & 0x0000FFFF)); else g_pMV[iBlk] = ((MVX << 16) | (MVY & 0x0000FFFF)); } } CoordI xRefUVBackward, yRefUVBackward; mvLookupUVWithShape (pmbmd, pmvBackward, &xRefUVBackward, &yRefUVBackward); // For Chroma MVs, update here only if we are handling // the MBM_BIDIRECTIONAL case. For the regular // case, it gets filled within motionCompUV()#ifdef EXTRA_MV_CLIPPING
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -