📄 sys_mode.cpp
字号:
/*************************************************************************This software module was originally developed by Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation Bruce Lin (blin@microsoft.com), Microsoft Corporation Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation Simon Winder (swinder@microsoft.com), Microsoft Corporation (date: March, 1996)and edited by Yoshinori Suzuki (Hitachi, Ltd.) Sehoon Son (shson@unitel.co.kr) Samsung AITin 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: mode.hAbstract: basic coding modes for VOP and MBRevision History: Dec. 12, 1997: Interlaced tools added by NextLevel Systems May. 9 1998: add boundary by Hyundai Electronics Cheol-Soo Park (cspark@super5.hyundai.co.kr) May. 9 1998: add field based MC padding by Hyundai Electronics Cheol-Soo Park (cspark@super5.hyundai.co.kr) Feb. 23 1999: GMC added by Yoshinori Suzuki (Hitachi, Ltd.) May 9, 1999: tm5 rate control by DemoGraFX, duhoff@mediaone.net*************************************************************************/#include <string.h>#include <iostream>#include <math.h>#include "typeapi.h"#include "mode.hpp"#include "warp.hpp"#ifdef __MFC_#ifdef _DEBUG#undef THIS_FILEstatic char BASED_CODE THIS_FILE[] = __FILE__;#endif#define new DEBUG_NEW #endif // __MFC_// only works for 4:2:0#define MAX_NUM_MV 4//UInt uiNumBlks = 10; // variable with MAC//#define uiNumBlks 10CMBMode::~CMBMode (){ delete [] m_rgbCodedBlockPattern; delete [] m_rgfltMinErrors;// MAC (SB) 26-Nov-99 delete [] m_pCODAlpha; delete [] m_pbACPredictionAlpha; delete [] m_preddir;//~MAC}CMBMode::CMBMode (Int iAuxCompCount) : m_iAuxCompCount(iAuxCompCount){ UInt i; m_uiNumBlks = 6+iAuxCompCount*4; for (i = 0; i < 11; i++) { m_rgTranspStatus [i] = NONE; m_rgNumNonTranspPixels [i] = 0; } /*BBM// Added for Boundary by Hyundai(1998-5-9) for (i = 0; i < uiNumBlks + 1; i++) m_rgTranspStatusBBM[i] = NONE; memset (m_bMerged, FALSE, 7 * sizeof(Bool)); // End of Hyundai(1998-5-9)*/ // Added for field based MC padding by Hyundai(1998-5-9) for (i = 0; i < 5; i++) m_rgFieldTranspStatus [i] = ALL; memset (m_rgbFieldPadded, 0, 5 * sizeof(Bool)); // End of Hyundai(1998-5-9) m_rgbCodedBlockPattern = new Bool [m_uiNumBlks]; memset (m_rgbCodedBlockPattern, FALSE, m_uiNumBlks * sizeof (Bool)); m_rgfltMinErrors = new Float [m_uiNumBlks]; memset (m_rgfltMinErrors, 0, m_uiNumBlks * sizeof (Float)); m_preddir = new IntraPredDirection [m_uiNumBlks]; m_bPadded = FALSE; m_bSkip = FALSE;// GMC m_bMCSEL = FALSE;// ~GMC m_dctMd = INTRA; m_shpmd = UNKNOWN; m_shpssmd = UNDEFINED; //OBSS_SAIT_991015 m_mbType = FORWARD; m_intStepDelta = 0; m_bhas4MVForward = FALSE; m_bhas4MVBackward = FALSE; m_bFieldMV = FALSE; m_bForwardTop = FALSE; m_bForwardBottom = FALSE; m_bBackwardTop = FALSE; m_bBackwardBottom = FALSE; m_bFieldDCT = FALSE; m_bPerspectiveForward = FALSE; m_bPerspectiveBackward = FALSE; m_stepSize = 0; m_bACPrediction = FALSE; m_bInterShapeCoding = FALSE; m_bColocatedMBSkip = FALSE;// GMC m_bColocatedMBMCSEL = FALSE;// ~GMC m_iVideoPacketNumber = 0; m_vctDirectDeltaMV = CVector (0, 0); m_pCODAlpha = new CODAlpha [m_iAuxCompCount]; // MAC (SB) 26-Nov-99 m_pbACPredictionAlpha = new Bool [m_iAuxCompCount];}CMBMode::CMBMode (const CMBMode& md) : m_iAuxCompCount(md.m_iAuxCompCount), m_uiNumBlks(md.m_uiNumBlks){ memcpy (m_rgTranspStatus, md.m_rgTranspStatus, (11) * sizeof (TransparentStatus)); memcpy (m_rgNumNonTranspPixels, md.m_rgNumNonTranspPixels, (11) * sizeof (UInt)); m_preddir = new IntraPredDirection [m_uiNumBlks]; memcpy (m_preddir,md.m_preddir,m_uiNumBlks * sizeof(IntraPredDirection)); /*BBM// Added for Boundary by Hyundai(1998-5-9) memcpy (m_rgTranspStatusBBM, md.m_rgTranspStatusBBM, (uiNumBlks + 1) * sizeof (TransparentStatus)); memcpy (m_bMerged, md.m_bMerged, 7 * sizeof (Bool)); // End of Hyundai(1998-5-9)*/ // Added for field based MC padding by Hyundai(1998-5-9) memcpy (m_rgFieldTranspStatus, md.m_rgFieldTranspStatus, 5 * sizeof (TransparentStatus)); memcpy (m_rgbFieldPadded, md.m_rgbFieldPadded, 5 * sizeof (Bool)); // End of Hyundai(1998-5-9) m_bPadded = md.m_bPadded; m_bSkip = md.m_bSkip;// GMC m_bMCSEL = md.m_bMCSEL;// ~GMC m_mbType = md.m_mbType; m_dctMd = md.m_dctMd; m_shpmd = md.m_shpmd ; m_shpssmd = md.m_shpssmd ; //OBSS_SAIT_991015 m_intStepDelta = md.m_intStepDelta; m_bhas4MVForward = md.m_bhas4MVForward; m_bhas4MVBackward = md.m_bhas4MVBackward; m_bPerspectiveForward = md.m_bPerspectiveForward; m_bPerspectiveBackward = md.m_bPerspectiveBackward; m_stepSize = md.m_stepSize; m_bACPrediction = md.m_bACPrediction; m_bInterShapeCoding = md.m_bInterShapeCoding; m_bCodeDcAsAc = md.m_bCodeDcAsAc; m_bColocatedMBSkip = md.m_bColocatedMBSkip;// GMC m_bColocatedMBMCSEL = md.m_bColocatedMBMCSEL;// ~GMC m_iVideoPacketNumber = md.m_iVideoPacketNumber; m_rgbCodedBlockPattern = new Bool [m_uiNumBlks]; memcpy (m_rgbCodedBlockPattern, md.m_rgbCodedBlockPattern, m_uiNumBlks * sizeof (Bool)); m_rgfltMinErrors = new Float [m_uiNumBlks]; memcpy (m_rgfltMinErrors, md.m_rgfltMinErrors, m_uiNumBlks * sizeof (Float));// MAC m_stepSizeAlpha = md.m_stepSizeAlpha; m_bCodeDcAsAcAlpha = md.m_bCodeDcAsAcAlpha; m_pbACPredictionAlpha = new Bool [m_iAuxCompCount]; m_pCODAlpha = new CODAlpha [m_iAuxCompCount]; for(Int iAuxComp=0;iAuxComp<m_iAuxCompCount;iAuxComp++) { m_pCODAlpha[iAuxComp] = md.m_pCODAlpha[iAuxComp]; m_pbACPredictionAlpha[iAuxComp] = md.m_pbACPredictionAlpha[iAuxComp]; }//~MAC}Void CMBMode::operator = (const CMBMode& md){// assert( m_uiNumBlks==md.m_uiNumBlks ); if (m_uiNumBlks!=md.m_uiNumBlks) { delete [] m_rgbCodedBlockPattern; delete [] m_rgfltMinErrors; delete [] m_preddir; m_uiNumBlks = 6+md.m_iAuxCompCount*4; m_rgbCodedBlockPattern = new Bool [m_uiNumBlks]; m_rgfltMinErrors = new Float [m_uiNumBlks]; m_preddir = new IntraPredDirection [m_uiNumBlks]; } memcpy (m_rgTranspStatus, md.m_rgTranspStatus, (11) * sizeof (TransparentStatus)); memcpy (m_rgNumNonTranspPixels, md.m_rgNumNonTranspPixels, (11) * sizeof (UInt)); memcpy (m_preddir,md.m_preddir,m_uiNumBlks * sizeof(IntraPredDirection)); /*BBM// Added for Boundary by Hyundai(1998-5-9) memcpy (m_rgTranspStatusBBM, md.m_rgTranspStatusBBM, (uiNumBlks + 1) * sizeof (TransparentStatus)); memcpy (m_bMerged, md.m_bMerged, 7 * sizeof (Bool)); // End of Hyundai(1998-5-9)*/ // Added for field based MC padding by Hyundai(1998-5-9) memcpy (m_rgFieldTranspStatus, md.m_rgFieldTranspStatus, 5 * sizeof (TransparentStatus)); memcpy (m_rgbFieldPadded, md.m_rgbFieldPadded, 5 * sizeof (Bool)); // End of Hyundai(1998-5-9) m_bPadded = md.m_bPadded; m_bSkip = md.m_bSkip;// GMC m_bMCSEL = md.m_bMCSEL;// ~GMC m_mbType = md.m_mbType; m_dctMd = md.m_dctMd; m_shpmd = md.m_shpmd ; m_intStepDelta = md.m_intStepDelta; m_bhas4MVForward = md.m_bhas4MVForward; m_bhas4MVBackward = md.m_bhas4MVBackward; m_bPerspectiveForward = md.m_bPerspectiveForward; m_bPerspectiveBackward = md.m_bPerspectiveBackward; m_stepSize = md.m_stepSize; m_bACPrediction = md.m_bACPrediction; m_bInterShapeCoding = md.m_bInterShapeCoding; m_bCodeDcAsAc = md.m_bCodeDcAsAc; m_bColocatedMBSkip = md.m_bColocatedMBSkip;// GMC m_bColocatedMBMCSEL = md.m_bColocatedMBMCSEL;// ~GMC m_iVideoPacketNumber = md.m_iVideoPacketNumber; memcpy (m_rgbCodedBlockPattern, md.m_rgbCodedBlockPattern, m_uiNumBlks * sizeof (Bool)); memcpy (m_rgfltMinErrors, md.m_rgfltMinErrors, m_uiNumBlks * sizeof (Float));// MAC m_stepSizeAlpha = md.m_stepSizeAlpha; m_bCodeDcAsAcAlpha = md.m_bCodeDcAsAcAlpha; if (m_iAuxCompCount!=md.m_iAuxCompCount) { delete [] m_pCODAlpha; delete [] m_pbACPredictionAlpha; m_iAuxCompCount = md.m_iAuxCompCount; m_pCODAlpha = new CODAlpha [m_iAuxCompCount]; m_pbACPredictionAlpha = new Bool [m_iAuxCompCount]; } for(Int iAuxComp=0;iAuxComp<m_iAuxCompCount;iAuxComp++) { m_pCODAlpha[iAuxComp] = md.m_pCODAlpha[iAuxComp]; m_pbACPredictionAlpha[iAuxComp] = md.m_pbACPredictionAlpha[iAuxComp]; }//~MAC}Void CMBMode::setCodedBlockPattern (const Bool* rgbblockNum){ for (UInt i = 0; i < m_uiNumBlks; i++) m_rgbCodedBlockPattern[i] = rgbblockNum [i];}Void CMBMode::setMinError (const Float* pfltminError){ for (UInt i = 0; i < m_uiNumBlks; i++) m_rgfltMinErrors[i] = pfltminError [i];}CDirectModeData::~CDirectModeData (){ destroyMem ();}CDirectModeData::CDirectModeData (){ m_ppmbmd = NULL; m_prgmv = NULL;}Bool CDirectModeData::inBound (UInt iMbIdx) const{ if (iMbIdx >= m_uiNumMB) return FALSE; else return TRUE;}Bool CDirectModeData::inBound (UInt idX, UInt idY) const{ if (idX >= m_uiNumMBX || idY >= m_uiNumMBY || idX * idY >= m_uiNumMB) return FALSE; else return TRUE;}Void CDirectModeData::reassign (UInt numMBX, UInt numMBY, Int iAuxCompCount){ destroyMem (); m_uiNumMBX = numMBX; m_uiNumMBY = numMBY; m_uiNumMB = m_uiNumMBX * m_uiNumMBY; m_ppmbmd = new CMBMode* [m_uiNumMB]; m_prgmv = new CMotionVector* [m_uiNumMB]; for (UInt i = 0; i < m_uiNumMB; i++) { m_ppmbmd [i] = new CMBMode(iAuxCompCount); m_prgmv [i] = new CMotionVector [5]; }}Void CDirectModeData::assign (UInt imb, const CMBMode& mbmd, const CMotionVector* rgmv){ assert (inBound (imb)); *(m_ppmbmd [imb]) = mbmd; memcpy (m_prgmv [imb], rgmv, 5 * sizeof (CMotionVector));}Void CDirectModeData::destroyMem (){ if (m_ppmbmd != NULL) { for (UInt i = 0; i < m_uiNumMB; i++) delete m_ppmbmd [i]; delete [] m_ppmbmd; } if (m_prgmv != NULL) { for (UInt i = 0; i < m_uiNumMB; i++) delete [] m_prgmv [i]; delete [] m_prgmv; }}CStatistics::CStatistics ( Int iAuxCompCount) : m_iAuxCompCount(iAuxCompCount){ assert( iAuxCompCount>=0 ); dSNRA = new double [iAuxCompCount]; reset ();}CStatistics::~CStatistics(){ delete [] dSNRA;} Void CStatistics::print (Bool bVOPPrint){#if 0 (Void) total (); if (bVOPPrint) cout << "\t" << "VOP overhead:" << "\t\t" << nBitsHead << "\n"; cout << "\t" << "Y:" << "\t\t\t" << nBitsY << "\n"; cout << "\t" << "Cr:" << "\t\t\t" << nBitsCr << "\n"; cout << "\t" << "Cb:" << "\t\t\t" << nBitsCb << "\n"; cout << "\t" << "A:" << "\t\t\t" << nBitsA << "\n";// cout << "\t" << "1st Shape Code:" << "\t\t" << nBits1stShpCode << "\n"; cout << "\t" << "CBPY:" << "\t\t\t" << nBitsCBPY << "\n"; cout << "\t" << "MCBPC:" << "\t\t\t" << nBitsMCBPC << "\n";// GMC cout << "\t" << "MCSEL:" << "\t\t\t" << nBitsMCSEL << "\n";// ~GMC cout << "\t" << "DQUANT:" << "\t\t\t" << nBitsDQUANT << "\n"; cout << "\t" << "nBitsMODB:" << "\t\t" << nBitsMODB << "\n"; cout << "\t" << "nBitsCBPB:" << "\t\t" << nBitsCBPB << "\n"; cout << "\t" << "nBitsMBTYPE:" << "\t\t" << nBitsMBTYPE << "\n"; cout << "\t" << "nBitsIntraPred:" << "\t\t" << nBitsIntraPred << "\n"; cout << "\t" << "nBitsNoDCT:" << "\t\t" << nBitsNoDCT << "\n"; cout << "\t" << "nBitsCODA:" << "\t\t" << nBitsCODA << "\n"; cout << "\t" << "nBitsCBPA:" << "\t\t" << nBitsCBPA << "\n"; cout << "\t" << "nBitsMODBA:" << "\t\t" << nBitsMODBA << "\n"; cout << "\t" << "nBitsCBPBA:" << "\t\t" << nBitsCBPBA << "\n"; cout << "\t" << "nBitsInterlace:" << "\t\t" << nBitsInterlace << "\n"; cout << "\t" << "nBitsSTUFFING:" << "\t\t" << nBitsStuffing << "\n"; cout << "\t" << "# of Skipped MB:" << "\t" << nSkipMB << "\n";// GMC cout << "\t" << "# of GMC MB:" << "\t\t" << nMCSELMB << "\n";// ~GMC cout << "\t" << "# of Inter MB:" << "\t\t" << nInterMB << "\n"; cout << "\t" << "# of Inter4V MB:" << "\t" << nInter4VMB << "\n"; cout << "\t" << "# of Intra MB:" << "\t\t" << nIntraMB << "\n"; cout << "\t" << "# of Direct MB:" << "\t\t" << nDirectMB << "\n"; cout << "\t" << "# of Forward MB:" << "\t" << nForwardMB << "\n"; cout << "\t" << "# of Backward MB:" << "\t" << nBackwardMB << "\n"; cout << "\t" << "# of Interpolate MB:" << "\t" << nInterpolateMB << "\n"; cout << "\t" << "# of Field Fwd MB:" << "\t" << nFieldForwardMB << "\n"; cout << "\t" << "# of Field Back MB:" << "\t" << nFieldBackwardMB << "\n"; cout << "\t" << "# of Field Ave MB:" << "\t" << nFieldInterpolateMB << "\n"; cout << "\t" << "# of Field Direct MB:" << "\t" << nFieldDirectMB << "\n"; cout << "\t" << "# of Field DCT MBs:" << "\t" << nFieldDCTMB << "\n"; cout << "\t" << "Motion:" << "\t\t\t" << nBitsMV << "\n"; cout << "\t" << "Texture:" << "\t\t" << nBitsTexture << "\n";// if (bVOPPrint) cout << "\t" << "Shape:" << "\t\t\t" << nBitsShape << "\n"; cout << "\t" << "Total:" << "\t\t\t" << nBitsTotal << "\n"; cout << "\t" << "SNR Y:" << "\t\t\t" << dSNRY / nVOPs << " dB\n"; cout << "\t" << "SNR U:" << "\t\t\t" << dSNRU / nVOPs << " dB\n"; cout << "\t" << "SNR V:" << "\t\t\t" << dSNRV / nVOPs << " dB\n"; for(Int iAuxComp=0;iAuxComp<m_iAuxCompCount;iAuxComp++) // MAC (SB) 26-Nov-99 cout << "\t" << "SNR A[" << iAuxComp << "]:" << "\t\t" << dSNRA[iAuxComp] / nVOPs << " dB\n"; cout << "\n\t" << "average Qp:" << "\t\t" << (Double)nQp / nQMB << "\n\n"; cout.flush ();#endif}Void CStatistics::operator += (const CStatistics& statSrc){ nBitsHead += statSrc.nBitsHead; nBitsY += statSrc.nBitsY; nBitsCr += statSrc.nBitsCr; nBitsCb += statSrc.nBitsCb; nBitsA += statSrc.nBitsA;// nBits1stShpCode += statSrc.nBits1stShpCode; nBitsCOD += statSrc.nBitsCOD; nBitsCBPY += statSrc.nBitsCBPY; nBitsMCBPC += statSrc.nBitsMCBPC;// GMC nBitsMCSEL += statSrc.nBitsMCSEL;// ~GMC nBitsDQUANT += statSrc.nBitsDQUANT; nBitsMODB += statSrc.nBitsMODB; nBitsCBPB += statSrc.nBitsCBPB; nBitsMBTYPE += statSrc.nBitsMBTYPE; nBitsIntraPred += statSrc.nBitsIntraPred; nBitsNoDCT += statSrc.nBitsNoDCT; nBitsCODA += statSrc.nBitsCODA; nBitsCBPA += statSrc.nBitsCBPA; nBitsMODBA += statSrc.nBitsMODBA; nBitsCBPBA += statSrc.nBitsCBPBA; nBitsStuffing += statSrc.nBitsStuffing; nSkipMB += statSrc.nSkipMB;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -