📄 mbheaddec.cpp
字号:
/*************************************************************************This software module was originally developed by Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation Simon Winder (swinder@microsoft.com), Microsoft Corporation (date: July, 1997)and edited by Yoshihiro Kikuchi (TOSHIBA CORPORATION) Takeshi Nagai (TOSHIBA CORPORATION) Toshiaki Watanabe (TOSHIBA CORPORATION) Noboru Yamaguchi (TOSHIBA CORPORATION)and also edited by Dick van Smirren (D.vanSmirren@research.kpn.com), KPN Research Cor Quist (C.P.Quist@research.kpn.com), KPN Research (date: July, 1998)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.Module Name: MBHeadDec.cppAbstract: MacroBlock overhead decoderRevision History: This software module was edited by Hiroyuki Katata (katata@imgsl.mkhar.sharp.co.jp), Sharp Corporation Norio Ito (norio@imgsl.mkhar.sharp.co.jp), Sharp Corporation Shuichi Watanabe (watanabe@imgsl.mkhar.sharp.co.jp), Sharp Corporation (date: October, 1997) for object based temporal scalability. Dec 20, 1997: Interlaced tools added by NextLevel Systems (GI) X. Chen (xchen@nlvl.com), B. Eifrig (beifrig@nlvl.com)*************************************************************************/#include "typeapi.h"#include "codehead.h"#include "mode.hpp"#include "global.hpp"#include "entropy/bitstrm.hpp"#include "entropy/entropy.hpp"#include "entropy/huffman.hpp"#include "vopses.hpp"#include "vopsedec.hpp"#ifdef __MFC_#ifdef _DEBUG#undef THIS_FILEstatic char BASED_CODE THIS_FILE[] = __FILE__;#endif#define new DEBUG_NEW #endif // __MFC_Void CVideoObjectDecoder::decodeMBTextureHeadOfIVOP (CMBMode* pmbmd, Int& iCurrentQP, Bool &bUseNewQPForVlcThr){ assert (pmbmd->m_rgTranspStatus [0] != ALL); Int iBlk = 0, cNonTrnspBlk = 0; for (iBlk = (Int) Y_BLOCK1; iBlk <= (Int) Y_BLOCK4; iBlk++) { if (pmbmd->m_rgTranspStatus [iBlk] != ALL) cNonTrnspBlk++; } Int iCBPC = 0; Int iCBPY = 0; //fprintf(stderr,"[%x]",m_pbitstrmIn->peekBits(32)); Int iMCBPC = m_pentrdecSet->m_pentrdecMCBPCintra->decodeSymbol (); //iMCBPC &= 7 //fprintf(stderr,"MCBPC = %d\n",iMCBPC); assert (iMCBPC >= 0 && iMCBPC <= 7); pmbmd->m_dctMd = INTRA; pmbmd->m_bSkip = FALSE; //reset for direct mode if (iMCBPC > 3) pmbmd->m_dctMd = INTRAQ; iCBPC = iMCBPC % 4;// pmbmd->m_bACPrediction = m_pbitstrmIn->getBits (1); if (!short_video_header) { pmbmd->m_bACPrediction = m_pbitstrmIn->getBits(1); } switch (cNonTrnspBlk) { case 1: iCBPY = m_pentrdecSet->m_pentrdecCBPY1->decodeSymbol (); break; case 2: iCBPY = m_pentrdecSet->m_pentrdecCBPY2->decodeSymbol (); break; case 3: iCBPY = m_pentrdecSet->m_pentrdecCBPY3->decodeSymbol (); break; case 4: iCBPY = m_pentrdecSet->m_pentrdecCBPY->decodeSymbol (); break; default: assert (FALSE); } //fprintf(stderr,"CBPY=%d\n",iCBPY); setCBPYandC (pmbmd, iCBPC, iCBPY, cNonTrnspBlk); pmbmd->m_stepSize = iCurrentQP; pmbmd->m_stepSizeDelayed = iCurrentQP; if (pmbmd->m_dctMd == INTRAQ) { Int iDQUANT = m_pbitstrmIn->getBits (2); switch (iDQUANT) { case 0: pmbmd->m_intStepDelta = -1; break; case 1: pmbmd->m_intStepDelta = -2; break; case 2: pmbmd->m_intStepDelta = 1; break; case 3: pmbmd->m_intStepDelta = 2; break; default: assert (FALSE); } pmbmd->m_stepSize += pmbmd->m_intStepDelta; if(bUseNewQPForVlcThr) pmbmd->m_stepSizeDelayed = pmbmd->m_stepSize; Int iQuantMax = (1<<m_volmd.uiQuantPrecision) - 1; checkrange (pmbmd->m_stepSize, 1, iQuantMax); iCurrentQP = pmbmd->m_stepSize; } // gets set to true at start of vop / packet header bUseNewQPForVlcThr = FALSE; // set to false once we decoded a macroblock pmbmd->m_bSkip = FALSE; pmbmd->m_bFieldMV = 0; if (m_vopmd.bInterlace) pmbmd->m_bFieldDCT = m_pbitstrmIn->getBits (1); // get dct_type}Void CVideoObjectDecoder::decodeMBAlphaHeadOfIVOP (CMBMode* pmbmd, Int iCurrQP, Int iCurrQPA, Int iVopQP, Int iVopQPA){ // update alpha quantiser if(!m_volmd.bNoGrayQuantUpdate) { iCurrQPA = (iCurrQP * iVopQPA) / iVopQP; if(iCurrQPA<1) iCurrQPA = 1; } pmbmd->m_stepSizeAlpha = iCurrQPA; assert (pmbmd->m_rgTranspStatus [0] != ALL); // coded Int iCODA = m_pbitstrmIn->getBits (1); pmbmd->m_CODAlpha = iCODA ? ALPHA_ALL255 : ALPHA_CODED; if(iCODA) return; // intra prediction for ac pmbmd->m_bACPredictionAlpha = m_pbitstrmIn->getBits (1); // decode CBPA Int iBlk = 0, cNonTrnspBlk = 0; for (iBlk = (Int) Y_BLOCK1; iBlk <= (Int) Y_BLOCK4; iBlk++) { if (pmbmd->m_rgTranspStatus [iBlk] != ALL) cNonTrnspBlk++; } Int iCBPA = 0; switch (cNonTrnspBlk) { case 1: iCBPA = 1 - m_pentrdecSet->m_pentrdecCBPY1->decodeSymbol (); break; case 2: iCBPA = 3 - m_pentrdecSet->m_pentrdecCBPY2->decodeSymbol (); break; case 3: iCBPA = 7 - m_pentrdecSet->m_pentrdecCBPY3->decodeSymbol (); break; case 4: iCBPA = 15 - m_pentrdecSet->m_pentrdecCBPY->decodeSymbol (); break; default: assert (FALSE); } Int iBitPos = 1; for (iBlk = A_BLOCK1; iBlk <= A_BLOCK4; iBlk++) { if (pmbmd->m_rgTranspStatus [iBlk - 6] != ALL) { pmbmd->setCodedBlockPattern ( (BlockNum) iBlk, (iCBPA >> (cNonTrnspBlk - iBitPos)) & 1 ); iBitPos++; } else pmbmd->setCodedBlockPattern ((BlockNum) iBlk, 0); }}// InterVoid CVideoObjectDecoder::decodeMBTextureHeadOfPVOP (CMBMode* pmbmd, Int& iCurrentQP, Bool &bUseNewQPForVlcThr){ assert (pmbmd->m_rgTranspStatus [0] != ALL); Int iBlk = 0, cNonTrnspBlk = 0; for (iBlk = (Int) Y_BLOCK1; iBlk <= (Int) Y_BLOCK4; iBlk++) { if (pmbmd->m_rgTranspStatus [iBlk] != ALL) cNonTrnspBlk++; } Int iCBPC = 0; Int iCBPY = 0; pmbmd->m_bSkip = m_pbitstrmIn->getBits (1); if (!pmbmd->m_bSkip) { Int iMCBPC = m_pentrdecSet->m_pentrdecMCBPCinter->decodeSymbol (); assert (iMCBPC >= 0 && iMCBPC <= 20); Int iMBtype = iMCBPC / 4; //per H.263's MBtype pmbmd -> m_bFieldMV = FALSE; switch (iMBtype) { case 0: pmbmd->m_dctMd = INTER; pmbmd -> m_bhas4MVForward = FALSE; break; case 1: pmbmd->m_dctMd = INTERQ; pmbmd -> m_bhas4MVForward = FALSE; break; case 2: pmbmd -> m_dctMd = INTER; pmbmd -> m_bhas4MVForward = TRUE; break; case 3: pmbmd->m_dctMd = INTRA; break; case 4: pmbmd->m_dctMd = INTRAQ; break; default: assert (FALSE); } iCBPC = iMCBPC % 4; if (pmbmd->m_dctMd == INTRA || pmbmd->m_dctMd == INTRAQ) { // pmbmd->m_bACPrediction = m_pbitstrmIn->getBits (1); if (!short_video_header) { pmbmd->m_bACPrediction = m_pbitstrmIn->getBits (1); } switch (cNonTrnspBlk) { case 1: iCBPY = m_pentrdecSet->m_pentrdecCBPY1->decodeSymbol (); break; case 2: iCBPY = m_pentrdecSet->m_pentrdecCBPY2->decodeSymbol (); break; case 3: iCBPY = m_pentrdecSet->m_pentrdecCBPY3->decodeSymbol (); break; case 4: iCBPY = m_pentrdecSet->m_pentrdecCBPY->decodeSymbol (); break; default: assert (FALSE); } } else { switch (cNonTrnspBlk) { case 1: iCBPY = 1 - m_pentrdecSet->m_pentrdecCBPY1->decodeSymbol (); break; case 2: iCBPY = 3 - m_pentrdecSet->m_pentrdecCBPY2->decodeSymbol (); break; case 3: iCBPY = 7 - m_pentrdecSet->m_pentrdecCBPY3->decodeSymbol (); break; case 4: iCBPY = 15 - m_pentrdecSet->m_pentrdecCBPY->decodeSymbol (); break; default: assert (FALSE); } } assert (iCBPY >= 0 && iCBPY <= 15);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -