⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vopmbdec.cpp

📁 jpeg and mpeg 编解码技术源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*************************************************************************

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
	Yoshihiro Kikuchi (TOSHIBA CORPORATION)
	Takeshi Nagai (TOSHIBA CORPORATION)
	Toshiaki Watanabe (TOSHIBA CORPORATION)
	Noboru Yamaguchi (TOSHIBA CORPORATION)

and also edited by
	David B. Shu (dbshu@hrl.com), Hughes Electronics/HRL Laboratories

and edited by
	Xuemin Chen (xchen@gi.com), General Instrument Corp.

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:

	vopmbDec.cpp

Abstract:

	Decoder for VOP composed of MB's

Revision History:

	Nov. 26 , 1997: modified for error resilient by Toshiba

	Nov. 30 , 1997: modified for Spatial Scalable by Takefumi Nagumo
						(nagumo@av.crl.sony.co.jp) SONY Corporation 
	Dec 20, 1997:	Interlaced tools added by GI
                        X. Chen (xchen@gi.com), B. Eifrig (beifrig@gi.com)
        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) 

*************************************************************************/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include "typeapi.h"
#include "mode.hpp"
#include "codehead.h"
#include "entropy/bitstrm.hpp"
#include "entropy/entropy.hpp"
#include "entropy/huffman.hpp"
#include "global.hpp"
#include "vopses.hpp"
#include "vopsedec.hpp"

#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW				   
#endif // __MFC_

Void CVideoObjectDecoder::decodeVOP ()	
{
	if (m_volmd.fAUsage != RECTANGLE) {
		//	Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
		if(m_volmd.bDataPartitioning && !m_volmd.bShapeOnly){
			if (m_vopmd.vopPredType == PVOP)
				decodePVOP_WithShape_DataPartitioning ();
			else if (m_vopmd.vopPredType == IVOP)
				decodeIVOP_WithShape_DataPartitioning ();
			else
				decodeBVOP_WithShape ();
		}
		else {
		//	End Toshiba(1998-1-16:DP+RVLC)
			if (m_vopmd.vopPredType == PVOP)
			{	// Sprite update piece contains no shape information which has been included in the object piece
				if (m_uiSprite == 1 && m_vopmd.SpriteXmitMode != STOP)
					decodePVOP ();
				else
					decodePVOP_WithShape ();
			}
			else if (m_vopmd.vopPredType == IVOP)
				decodeIVOP_WithShape ();
			else
				decodeBVOP_WithShape ();
		}
	}
	else {
		//	Modified for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
		if(m_volmd.bDataPartitioning){
			if (m_vopmd.vopPredType == PVOP)
				decodePVOP_DataPartitioning ();
			else if (m_vopmd.vopPredType == IVOP)
				decodeIVOP_DataPartitioning ();
			else
				decodeBVOP ();
		}
		else {
			if (m_vopmd.vopPredType == PVOP)
				decodePVOP ();
			else if (m_vopmd.vopPredType == IVOP)
				decodeIVOP ();
			else
				decodeBVOP ();
		}
		//	End Toshiba(1998-1-16:DP+RVLC)
	}
}

Void CVideoObjectDecoder::decodeIVOP_WithShape ()	
{
	//in case the IVOP is used as an ref for direct mode
	memset (m_rgmv, 0, m_iNumMB * PVOP_MV_PER_REF_PER_MB * sizeof (CMotionVector));

	Int iMBX, iMBY;
	CMBMode* pmbmd = m_rgmbmd;
	// Added for field based MC padding by Hyundai(1998-5-9)
        CMBMode* field_pmbmd = m_rgmbmd;
	// End of Hyundai(1998-5-9)

	PixelC* ppxlcRefY  = (PixelC*) m_pvopcRefQ1->pixelsY () + m_iStartInRefToCurrRctY;
	PixelC* ppxlcRefU  = (PixelC*) m_pvopcRefQ1->pixelsU () + m_iStartInRefToCurrRctUV;
	PixelC* ppxlcRefV  = (PixelC*) m_pvopcRefQ1->pixelsV () + m_iStartInRefToCurrRctUV;
	PixelC* ppxlcRefBY = (PixelC*) m_pvopcRefQ1->pixelsBY () + m_iStartInRefToCurrRctY;
	PixelC* ppxlcRefA  = (PixelC*) m_pvopcRefQ1->pixelsA () + m_iStartInRefToCurrRctY;
	PixelC* ppxlcRefBUV = (PixelC*) m_pvopcRefQ1->pixelsBUV () + m_iStartInRefToCurrRctUV;

	pmbmd->m_bFieldDCT=0;	// new changes by X. Chen

	Int iCurrentQP  = m_vopmd.intStepI;	
	Int iCurrentQPA = m_vopmd.intStepIAlpha;	
	//	Added for error resilient mode by Toshiba(1997-11-14)
	Int	iVideoPacketNumber = 0;
	m_iVPMBnum = 0;
	Bool bRestartDelayedQP = TRUE;

	//	End Toshiba(1997-11-14)
	for (iMBY = 0; iMBY < m_iNumMBY; iMBY++) {
		PixelC* ppxlcRefMBY  = ppxlcRefY;
		PixelC* ppxlcRefMBU  = ppxlcRefU;
		PixelC* ppxlcRefMBV  = ppxlcRefV;
		PixelC* ppxlcRefMBBY = ppxlcRefBY;
		PixelC* ppxlcRefMBBUV = ppxlcRefBUV;
		PixelC* ppxlcRefMBA  = ppxlcRefA;

		Bool  bSptMB_NOT_HOLE= TRUE;
// Begin: modified by Hughes	  4/9/98
//		if (m_uiSprite == 1 && m_vopmd.SpriteXmitMode != STOP) {
		if (m_uiSprite == 1 && m_sptMode != BASIC_SPRITE && m_vopmd.SpriteXmitMode != STOP) {
// end:  modified by Hughes	  4/9/98

			bSptMB_NOT_HOLE = SptPieceMB_NOT_HOLE(0, iMBY, pmbmd);		 
			RestoreMBmCurrRow (iMBY, m_rgpmbmCurr);  // restore current row pointed by *m_rgpmbmCurr
		}

		for (iMBX = 0; iMBX < m_iNumMBX; iMBX++) {
			m_bSptMB_NOT_HOLE	 = 	bSptMB_NOT_HOLE;	
			if (!m_bSptMB_NOT_HOLE ) // current Sprite macroblock is not a hole and should be decoded			
				goto END_OF_DECODING1;

			//	Added for error resilient mode by Toshiba(1997-11-14)
			if	(checkResyncMarker())	{
				decodeVideoPacketHeader(iCurrentQP);
				iVideoPacketNumber++;
				bRestartDelayedQP = TRUE;
			}
			pmbmd->m_iVideoPacketNumber = iVideoPacketNumber;
			//	End Toshiba(1997-11-14)
			decodeIntraShape (pmbmd, iMBX, iMBY, m_ppxlcCurrMBBY, ppxlcRefMBBY);
			downSampleBY (m_ppxlcCurrMBBY, m_ppxlcCurrMBBUV); // downsample original BY now for LPE padding (using original shape)
			/*BBM// Added for Boundary by Hyundai(1998-5-9)
                        if (m_vopmd.bInterlace) initMergedMode (pmbmd);
			// End of Hyundai(1998-5-9)*/
			if(m_volmd.bShapeOnly==FALSE)
			{
				pmbmd->m_bPadded=FALSE;
				if (pmbmd->m_rgTranspStatus [0] != ALL) {
					/*BBM// Added for Boundary by Hyundai(1998-5-9)
                    if (m_vopmd.bInterlace && pmbmd->m_rgTranspStatus [0] == PARTIAL)
                            isBoundaryMacroBlockMerged (pmbmd);
					// End of Hyundai(1998-5-9)*/
					decodeMBTextureHeadOfIVOP (pmbmd, iCurrentQP, bRestartDelayedQP);
					decodeTextureIntraMB (pmbmd, iMBX, iMBY, ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV);
// INTERLACE
			//new changes
				if ((pmbmd->m_rgTranspStatus [0] == NONE) && 
					(m_vopmd.bInterlace == TRUE) && (pmbmd->m_bFieldDCT == TRUE))
					fieldDCTtoFrameC(ppxlcRefMBY);
			//end of new changes
// ~INTERLACE
					if (m_volmd.fAUsage == EIGHT_BIT) {
						decodeMBAlphaHeadOfIVOP (pmbmd, iCurrentQP, iCurrentQPA, m_vopmd.intStepI, m_vopmd.intStepIAlpha);
						decodeAlphaIntraMB (pmbmd, iMBX, iMBY, ppxlcRefMBA);
					}
					/*BBM// Added for Boundary by Hyundai(1998-5-9)
                        if (m_vopmd.bInterlace && pmbmd->m_bMerged[0])
                                mergedMacroBlockSplit (pmbmd, ppxlcRefMBY, ppxlcRefMBA);
					// End of Hyundai(1998-5-9)*/
// Begin: modified by Hughes	  4/9/98
//				  if (m_uiSprite == 0) 	{  // added for sprite by dshu: [v071]	to delay the padding until ready for warping
				  if (m_uiSprite == 0 || m_sptMode == BASIC_SPRITE) 	{  //  delay the padding until ready for sprite warping
// end:  modified by Hughes	  4/9/98
					// MC padding
                                        // Added for field based MC padding by Hyundai(1998-5-9)
                                        if (!m_vopmd.bInterlace) {
						if (pmbmd -> m_rgTranspStatus [0] == PARTIAL)
							mcPadCurrMB (ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, ppxlcRefMBA);
						padNeighborTranspMBs (
							iMBX, iMBY,
							pmbmd,
							ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, ppxlcRefMBA
						);
					}
					// End of Hyundai(1998-5-9)
				  }   // added for sprite by dshu: [v071]
				}
				else {
// Begin: modified by Hughes	  4/9/98
//				  if (m_uiSprite == 0) 	  // added for sprite by dshu: [v071]	to delay the padding until ready for warping
				  if (m_uiSprite == 0 || m_sptMode == BASIC_SPRITE) //  delay the padding until ready for sprite warping
// end:  modified by Hughes	  4/9/98
					// Added for field based MC padding by Hyundai(1998-5-9)
					if (!m_vopmd.bInterlace) {
						padCurrAndTopTranspMBFromNeighbor (
							iMBX, iMBY,
							pmbmd,
							ppxlcRefMBY, ppxlcRefMBU, ppxlcRefMBV, ppxlcRefMBA
						);
					}
					// End of Hyundai(1998-5-9)
				}
			}

END_OF_DECODING1:
			ppxlcRefMBA += MB_SIZE;
			ppxlcRefMBBY += MB_SIZE;
			ppxlcRefMBBUV += BLOCK_SIZE;
			pmbmd++;
			ppxlcRefMBY += MB_SIZE;
			ppxlcRefMBU += BLOCK_SIZE;
			ppxlcRefMBV += BLOCK_SIZE;

// Begin: modified by Hughes	  4/9/98
//			if (m_uiSprite == 1 && m_vopmd.SpriteXmitMode != STOP)
			if (m_uiSprite == 1 && m_sptMode != BASIC_SPRITE && m_vopmd.SpriteXmitMode != STOP)
// end:  modified by Hughes	  4/9/98
				bSptMB_NOT_HOLE = SptPieceMB_NOT_HOLE(iMBX+1, iMBY, pmbmd);	 			
			else
				bSptMB_NOT_HOLE= TRUE;
		}
		MacroBlockMemory** ppmbmTemp = m_rgpmbmAbove;
		m_rgpmbmAbove = m_rgpmbmCurr;
				
// dshu: [v071] begin of modification	  1/18/98
// Begin: modified by Hughes	  4/9/98
// 		if  (m_uiSprite == 1)
 		if  (m_uiSprite == 1 && m_sptMode != BASIC_SPRITE)
// end:  modified by Hughes	  4/9/98
			SaveMBmCurrRow (iMBY, m_rgpmbmCurr);		 //	  save current row pointed by *m_rgpmbmCurr 
// dshu: [v071] end of modification

		m_rgpmbmCurr  = ppmbmTemp;
		ppxlcRefY += m_iFrameWidthYxMBSize;
		ppxlcRefU += m_iFrameWidthUVxBlkSize;
		ppxlcRefV += m_iFrameWidthUVxBlkSize;
		ppxlcRefBY += m_iFrameWidthYxMBSize;
		ppxlcRefA += m_iFrameWidthYxMBSize;
		ppxlcRefBUV += m_iFrameWidthUVxBlkSize;
	}
	// Added for field based MC padding by Hyundai(1998-5-9)
        if (m_vopmd.bInterlace && m_volmd.bShapeOnly == FALSE)
                fieldBasedMCPadding (field_pmbmd, m_pvopcRefQ1);
        // End of Hyundai(1998-5-9)

}

Void CVideoObjectDecoder::decodeIVOP ()	
{
	//in case the IVOP is used as an ref for direct mode
	memset (m_rgmv, 0, m_iNumMB * PVOP_MV_PER_REF_PER_MB * sizeof (CMotionVector));

	//Int macrotellertje=0;  // [FDS]


	Int iMBX, iMBY;
	Int iMBXstart, iMBXstop, iMBYstart, iMBYstop; // Added by KPN for short headers
	UInt uiNumberOfGobs; // Added by KPN
	UInt uiGobNumber; // Added by KPN
	CMBMode* pmbmd = m_rgmbmd;
	pmbmd->m_stepSize = m_vopmd.intStepI;
	PixelC* ppxlcRefY = (PixelC*) m_pvopcRefQ1->pixelsY () + m_iStartInRefToCurrRctY;
	PixelC* ppxlcRefU = (PixelC*) m_pvopcRefQ1->pixelsU () + m_iStartInRefToCurrRctUV;
	PixelC* ppxlcRefV = (PixelC*) m_pvopcRefQ1->pixelsV () + m_iStartInRefToCurrRctUV;
	pmbmd->m_bFieldDCT = 0;

	Int iCurrentQP  = m_vopmd.intStepI;		
	Int	iVideoPacketNumber = 0; 			//	added for error resilience mode by Toshiba
	m_iVPMBnum = 0;	//	Added for error resilient mode by Toshiba(1997-11-14)

	if (!short_video_header) { 
		uiNumberOfGobs = 1;
		iMBXstart=0; 
		iMBXstop= m_iNumMBX;
		iMBYstart=0;
		iMBYstop= m_iNumMBY;
	}
	else { // short_header
		uiNumberOfGobs = uiNumGobsInVop;
		iMBXstart=0; 
		iMBXstop= 0;
		iMBYstart=0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -