📄 mv.c
字号:
/**************************************************************************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 Centerand 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. Module Name: mv.cAbstract: Motion Vector computation (Luma & Chroma) 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.h"#include "codehead.h"#include "mode.h"#ifdef UNDER_CE#include "bitstrm.h"#include "huffman.h"#else#include "entropy/bitstrm.h"#include "entropy/huffman.h"#endif#include "vopses.h"#include "vopsedec.h"#define MP4V_VPMBNUM(iRet, iMBX, iMBY) (iRet = (iMBY * g_pVO->m_iNumMBX + iMBX))#define MP4V_BVPNOLEFT(bRet, iMBnum, iMBX) (bRet = (iMBnum <= g_pVO->m_iVPMBnum || iMBX == 0))#define MP4V_BVPNORIGHTTOP(bRet, iMBnum, iMBX) (bRet = (iMBnum - g_pVO->m_iNumMBX + 1 < g_pVO->m_iVPMBnum || iMBX == g_pVO->m_iNumMBX - 1))#define MP4V_BVPNOTOP(bRet, iMBnum) (bRet = (iMBnum - g_pVO->m_iNumMBX < g_pVO->m_iVPMBnum))#define MP4V_ABS(x) ((x < 0) ? -x : x)#define MP4V_MEDIANOF3(Ret, a0, a1, a2)\\ (a0 > a1) ? ((a1 > a2) ? (Ret = a1) : ((a0 > a2) ? (Ret = a2) : (Ret = a0))) : \ ((a0 > a2) ? (Ret = a0) : ((a1 > a2) ? (Ret = a2) : (Ret = a1)))Void find16x16MVpred (CVector *vecPred, CMotionVector* pmv, Bool bLeftBndry, Bool bRightBndry, Bool bTopBndry){ CVector vctCandMV0, vctCandMV1, vctCandMV2; if (bLeftBndry) RESET_VECT (vctCandMV0); else vctCandMV0 = TRUEMVHALFPEL((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [0])); if (bTopBndry) { *vecPred = vctCandMV0; return; } else { vctCandMV1 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + gIndexOfCandBlk [1] [1])); if (bRightBndry) RESET_VECT (vctCandMV2); else vctCandMV2 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [1] [2])); } MP4V_MEDIANOF3 ((vecPred->x), (vctCandMV0.x), (vctCandMV1.x), (vctCandMV2.x)); MP4V_MEDIANOF3 ((vecPred->y), (vctCandMV0.y), (vctCandMV1.y), (vctCandMV2.y));}Void find8x8MVpredAtBoundary (CVector *vecPred, CMotionVector* pmv, Bool bLeftBndry, Bool bRightBndry, Bool bTopBndry, Int blknCurr){ CVector vctCandMV0, vctCandMV1, vctCandMV2; switch (blknCurr){ case Y_BLOCK1: if (bLeftBndry) RESET_VECT (vctCandMV0); else vctCandMV0 = TRUEMVHALFPEL((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0])); if (bTopBndry){ *vecPred = vctCandMV0; return; } else{ vctCandMV1 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + gIndexOfCandBlk [blknCurr] [1])); if (bRightBndry) RESET_VECT (vctCandMV2); else vctCandMV2 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2])); } break; case Y_BLOCK2: vctCandMV0 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [0])); if (bTopBndry) { *vecPred = vctCandMV0; return; } else{ vctCandMV1 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + gIndexOfCandBlk [blknCurr] [1])); if (bRightBndry) RESET_VECT (vctCandMV2); else vctCandMV2 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2])); } break; case Y_BLOCK3: if (bLeftBndry) RESET_VECT (vctCandMV0); else vctCandMV0 = TRUEMVHALFPEL((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0])); vctCandMV1 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [1])); vctCandMV2 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [2])); break; case Y_BLOCK4: vctCandMV0 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [0])); vctCandMV1 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [1])); vctCandMV2 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [2])); break; } MP4V_MEDIANOF3 ((vecPred->x), (vctCandMV0.x), (vctCandMV1.x), (vctCandMV2.x)); MP4V_MEDIANOF3 ((vecPred->y), (vctCandMV0.y), (vctCandMV1.y), (vctCandMV2.y));}Void find8x8MVpredInterior (CVector *vecPred, CMotionVector* pmv, Int blknCurr){ CVector vctCandMV0, vctCandMV1, vctCandMV2; switch (blknCurr) { case Y_BLOCK1: vctCandMV0 = TRUEMVHALFPEL((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0])); vctCandMV1 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + gIndexOfCandBlk [blknCurr] [1])); vctCandMV2 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2])); break; case Y_BLOCK2: vctCandMV0 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [0])); vctCandMV1 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + gIndexOfCandBlk [blknCurr] [1])); vctCandMV2 = TRUEMVHALFPEL((pmv - (g_pVO->m_iNumOfTotalMVPerRow) + PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [2])); break; case Y_BLOCK3: vctCandMV0 = TRUEMVHALFPEL((pmv - PVOP_MV_PER_REF_PER_MB + gIndexOfCandBlk [blknCurr] [0])); vctCandMV1 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [1])); vctCandMV2 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [2])); break; case Y_BLOCK4: vctCandMV0 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [0])); vctCandMV1 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [1])); vctCandMV2 = TRUEMVHALFPEL((pmv + gIndexOfCandBlk [blknCurr] [2])); break; } MP4V_MEDIANOF3 ((vecPred->x), (vctCandMV0.x), (vctCandMV1.x), (vctCandMV2.x)); MP4V_MEDIANOF3 ((vecPred->y), (vctCandMV0.y), (vctCandMV1.y), (vctCandMV2.y));}Void mvLookupUV (CMBMode* pmbmd, CMotionVector* pmv, CoordI *xRefUV, CoordI *yRefUV){ Int dx = 0, dy = 0, k; if (g_pVOL->bQuarterSample) { if (pmbmd -> m_bhas4MVForward) { pmv++; for (k = 0; k < 4; k++){ dx += pmv->iMVX; dy += pmv->iMVY; pmv++; } *xRefUV = sign (dx) * (grgiMvRound16 [MP4V_ABS (dx) % 16] + (MP4V_ABS (dx) / 16) * 2); *yRefUV = sign (dy) * (grgiMvRound16 [MP4V_ABS (dy) % 16] + (MP4V_ABS (dy) / 16) * 2); }#ifdef ENABLE_INTERLACING // 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#endif else { dx = pmv->iMVX; dy = pmv->iMVY; *xRefUV = sign (dx) * (grgiMvRound4 [MP4V_ABS (dx) % 4] + (MP4V_ABS (dx) / 4) * 2); *yRefUV = sign (dy) * (grgiMvRound4 [MP4V_ABS (dy) % 4] + (MP4V_ABS (dy) / 4) * 2); } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -