📄 mcenc.cpp
字号:
/*************************************************************************This software module was originally developed by Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation Bruce Lin (blin@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 Centerin 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.Module Name: mcenc.cppAbstract: Motion compensation routines for encoder.Revision History: Dec 20, 1997: Interlaced tools added by NextLevel Systems*************************************************************************/#include <stdio.h>#include <math.h>#include <stdlib.h>#include <iostream.h>#include "typeapi.h"#include "codehead.h"#include "global.hpp"#include "entropy/bitstrm.hpp"#include "entropy/entropy.hpp"#include "entropy/huffman.hpp"#include "mode.hpp"#include "vopses.hpp"#include "vopseenc.hpp"#ifdef __MFC_#ifdef _DEBUG#undef THIS_FILEstatic char BASED_CODE THIS_FILE[] = __FILE__;#endif#define new DEBUG_NEW #endif // __MFC_#define OFFSET_BLK1 8#define OFFSET_BLK2 128#define OFFSET_BLK3 136Void CVideoObjectEncoder::motionCompMBYEnc ( const CMotionVector* pmv, const CMBMode* pmbmd, Int imbX, Int imbY, CoordI x, CoordI y, CRct *prctMVLimit){ if (!m_volmd.bAdvPredDisable /* && pmbmd -> m_bhas4MVForward */ && !pmbmd->m_bFieldMV) { motionCompOverLapEncY ( pmv, pmbmd, (imbX == 0), (imbX == m_iNumMBX - 1), (imbY == 0), x, y, prctMVLimit ); } else { if (!pmbmd -> m_bhas4MVForward && !pmbmd -> m_bFieldMV) motionCompEncY ( m_pvopcRefQ0->pixelsY (), m_puciRefQZoom0->pixels (), m_ppxlcPredMBY, MB_SIZE, pmv, x, y, prctMVLimit );// INTERLACE else if (pmbmd -> m_bFieldMV) { const CMotionVector* pmvTop = pmv + 5 + pmbmd->m_bForwardTop; motionCompYField(m_ppxlcPredMBY, m_pvopcRefQ0->pixelsY () + pmbmd->m_bForwardTop * m_iFrameWidthY, 2*x + pmvTop->m_vctTrueHalfPel.x, 2*y + pmvTop->m_vctTrueHalfPel.y); const CMotionVector* pmvBottom = pmv + 7 + pmbmd->m_bForwardBottom; motionCompYField(m_ppxlcPredMBY + MB_SIZE, m_pvopcRefQ0->pixelsY () + pmbmd->m_bForwardBottom * m_iFrameWidthY, 2*x + pmvBottom->m_vctTrueHalfPel.x, 2*y + pmvBottom->m_vctTrueHalfPel.y); }// ~INTERLACE else { const CMotionVector* pmv8 = pmv; pmv8++; CoordI blkX = x + BLOCK_SIZE; CoordI blkY = y + BLOCK_SIZE; motionCompEncY ( m_pvopcRefQ0->pixelsY (), m_puciRefQZoom0->pixels (), m_ppxlcPredMBY, BLOCK_SIZE, pmv8, x, y, prctMVLimit ); pmv8++; motionCompEncY ( m_pvopcRefQ0->pixelsY (), m_puciRefQZoom0->pixels (), m_ppxlcPredMBY + OFFSET_BLK1, BLOCK_SIZE, pmv8, blkX, y, prctMVLimit ); pmv8++; motionCompEncY ( m_pvopcRefQ0->pixelsY (), m_puciRefQZoom0->pixels (), m_ppxlcPredMBY + OFFSET_BLK2, BLOCK_SIZE, pmv8, x, blkY, prctMVLimit ); pmv8++; motionCompEncY ( m_pvopcRefQ0->pixelsY (), m_puciRefQZoom0->pixels (), m_ppxlcPredMBY + OFFSET_BLK3, BLOCK_SIZE, pmv8, blkX, blkY, prctMVLimit ); } } if(m_volmd.fAUsage == EIGHT_BIT) motionCompMBAEnc ( pmv, pmbmd, m_ppxlcPredMBA, m_pvopcRefQ0, x, y, m_vopmd.iRoundingControl, prctMVLimit, 0 );}Void CVideoObjectEncoder::motionCompMBAEnc ( const CMotionVector* pmv, const CMBMode* pmbmd, PixelC *ppxlcPredMBA, CVOPU8YUVBA* pvopcRefQ, CoordI x, CoordI y, Int iRoundingControl, CRct *prctMVLimit, Int direction //12.22.98){ if (!pmbmd -> m_bhas4MVForward && !pmbmd -> m_bFieldMV) //12.22.98 motionComp ( ppxlcPredMBA, pvopcRefQ->pixelsA (), MB_SIZE, x * 2 + pmv->trueMVHalfPel ().x, y * 2 + pmv->trueMVHalfPel ().y , iRoundingControl, prctMVLimit );// INTERLACE 12.22.98 else if (pmbmd -> m_bFieldMV) { Int itmpref1,itmpref2; itmpref1=pmbmd->m_bForwardTop; itmpref2=pmbmd->m_bForwardBottom; if(m_vopmd.vopPredType==BVOP&&direction) { itmpref1=pmbmd->m_bBackwardTop; itmpref2=pmbmd->m_bBackwardBottom; } const CMotionVector* pmvTop,*pmvBottom; if(m_vopmd.vopPredType==BVOP) pmvTop = pmv + 1 + itmpref1; else pmvTop = pmv + 5 + itmpref1; motionCompYField(ppxlcPredMBA, pvopcRefQ->pixelsA () + itmpref1 * m_iFrameWidthY, 2*x + pmvTop->trueMVHalfPel ().x, 2*y + pmvTop->trueMVHalfPel ().y); if(m_vopmd.vopPredType==BVOP) pmvBottom = pmv + 3 + itmpref2; else pmvBottom = pmv + 7 + itmpref2; motionCompYField(ppxlcPredMBA + MB_SIZE, pvopcRefQ->pixelsA () + itmpref2 * m_iFrameWidthY, 2*x + pmvBottom->trueMVHalfPel ().x, 2*y + pmvBottom->trueMVHalfPel ().y); }// ~INTERLACE 12.22.98 else { const CMotionVector* pmv8 = pmv; pmv8++; CoordI blkX = x + BLOCK_SIZE; CoordI blkY = y + BLOCK_SIZE; motionComp ( ppxlcPredMBA, pvopcRefQ->pixelsA (), BLOCK_SIZE, x * 2 + pmv8->trueMVHalfPel ().x, y * 2 + pmv8->trueMVHalfPel ().y, iRoundingControl, prctMVLimit ); pmv8++; motionComp ( ppxlcPredMBA + OFFSET_BLK1, pvopcRefQ->pixelsA (), BLOCK_SIZE, blkX * 2 + pmv8->trueMVHalfPel ().x, y * 2 + pmv8->trueMVHalfPel ().y, iRoundingControl, prctMVLimit ); pmv8++; motionComp ( ppxlcPredMBA + OFFSET_BLK2, pvopcRefQ->pixelsA (), BLOCK_SIZE, x * 2 + pmv8->trueMVHalfPel ().x, blkY * 2 + pmv8->trueMVHalfPel ().y, iRoundingControl, prctMVLimit ); pmv8++; motionComp ( ppxlcPredMBA + OFFSET_BLK3, pvopcRefQ->pixelsA (), BLOCK_SIZE, blkX * 2 + pmv8->trueMVHalfPel ().x, blkY * 2 + pmv8->trueMVHalfPel ().y, iRoundingControl, prctMVLimit ); }}Void CVideoObjectEncoder::motionCompEncY ( const PixelC* ppxlcRef, const PixelC* ppxlcRefZoom, PixelC* ppxlcPred, Int iSize, // either MB or BLOCK size const CMotionVector* pmv, // motion vector CoordI x, CoordI y, // current coordinate system CRct *prctMVLimit){ Int iUnit = sizeof(PixelC); // NBIT: for memcpy CoordI ix, iy; Bool bXSubPxl, bYSubPxl; CoordI xHalf = 2*x + pmv->m_vctTrueHalfPel.x; CoordI yHalf = 2*y + pmv->m_vctTrueHalfPel.y;// CoordI xHalf = 2*(x + pmv->iMVX) + pmv->iHalfX;// CoordI yHalf = 2*(y + pmv->iMVY) + pmv->iHalfY; limitMVRangeToExtendedBBHalfPel(xHalf,yHalf,prctMVLimit,iSize); bXSubPxl = (xHalf&1); bYSubPxl = (yHalf&1); if (!bYSubPxl && !bXSubPxl) { const PixelC* ppxlcRefMB = ppxlcRef + m_rctRefFrameY.offset (xHalf>>1, yHalf>>1); for (iy = 0; iy < iSize; iy++) { memcpy (ppxlcPred, ppxlcRefMB, iSize*iUnit); ppxlcRefMB += m_iFrameWidthY; ppxlcPred += MB_SIZE; } } else { const PixelC* ppxlcPrevZoomY = ppxlcRefZoom + m_puciRefQZoom0->where ().offset (xHalf, yHalf); for (iy = 0; iy < iSize; iy++) { for (ix = 0; ix < iSize; ix++) ppxlcPred [ix] = ppxlcPrevZoomY [2 * ix]; ppxlcPrevZoomY += m_iFrameWidthZoomY * 2; ppxlcPred += MB_SIZE; } }}Void CVideoObjectEncoder::motionCompOverLapEncY ( const CMotionVector* pmv, // motion vector const CMBMode* pmbmd, // macroblk mode Bool bLeftBndry, Bool bRightBndry, Bool bTopBndry, CoordI x, // current coordinate system CoordI y, // current coordinate system CRct *prctMVLimit){ // Overlap Motion Comp use motion vector of current blk and motion vectors of neighboring blks. const CMotionVector *pmvC, *pmvT = NULL, *pmvB = NULL, *pmvR = NULL, *pmvL = NULL; // MVs of Cur, Top, Bot, Right and Left Blocks. const CMotionVector *pmvCurrMb, *pmvTopMb, *pmvRightMb, *pmvLeftMb; // MVs of Cur, Top, Right and Left MacroBlocks. const CMBMode *pmbmdTopMb, *pmbmdRightMb, *pmbmdLeftMb; // MVs of Cur, Top, Right and Left MacroBlocks. Bool bIntraT, bIntraR, bIntraL; // flags of 4MV for Cur, Top, Right and Left MacroBlocks. pmvTopMb = NULL; // compile warning pmvRightMb = NULL; pmvLeftMb = NULL; pmbmdTopMb = NULL; pmbmdRightMb = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -