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

📄 vopses.cpp

📁 visual c++小波技术和工程实践随书光盘
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************

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
	(date: March, 1996)
and edited by
        Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Center
and also edited by
    Mathias Wien (wien@ient.rwth-aachen.de) RWTH Aachen / Robert BOSCH GmbH
and also edited by
	Yoshinori Suzuki (Hitachi, Ltd.)
and also edited by
	Hideaki Kimata (NTT)

and also edited by
    Fujitsu Laboratories Ltd. (contact: Eishi Morimatsu)

and also edited by 
	Takefumi Nagumo (nagumo@av.crl.sony.co.jp) Sony Corporation
    Sehoon Son (shson@unitel.co.kr) Samsung AIT

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:

	vopSes.cpp

Abstract:

	Base class for the encoder for one VOP session.

Revision History:
	December 20, 1997:	Interlaced tools added by NextLevel Systems (GI)
                        X.Chen (xchen@nlvl.com), B. Eifrig (beifrig@nlvl.com)
        May. 9   1998:  add boundary by Hyundai Electronics 
                                  Cheol-Soo Park (cspark@super5.hyundai.co.kr) 
        May. 9   1998:  add field based unrestricted MC padding by Hyundai Electronics 
                                  Cheol-Soo Park (cspark@super5.hyundai.co.kr) 
        Feb. 16  1999:  add Quarter Sample 
                        Mathias Wien (wien@ient.rwth-aachen.de) 
        Feb. 23  1999:  GMC added by Yoshinori Suzuki (Hitachi, Ltd.)
		Aug.24, 1999 : NEWPRED added by Hideaki Kimata (NTT) 
		Sep.06	1999 : RRV added by Eishi Morimatsu (Fujitsu Laboratories Ltd.) 
		Feb.12	2000 : Bug fix of OBSS by Takefumi Nagumo (SONY)

*************************************************************************/

#include <stdio.h>

#include "typeapi.h"
#include "basic.hpp"
#include "header.h"
#include "codehead.h"
#include "mode.hpp"
#include "dct.hpp"
#include "cae.h"
#include "vopses.hpp"

// NEWPRED
#include "global.hpp"
#include "newpred.hpp"
// ~NEWPRED

#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

#define new DEBUG_NEW				   
#endif // __MFC_

CVideoObject::~CVideoObject ()
{
	delete m_pvopcCurrQ;
	delete m_pvopcRefQ0;
	delete m_pvopcRefQ1;       // modified by Shu 12/12/97
							   // wchen: unmodified 12/16/97

	delete m_pvopcCurrMB;
	delete m_pvopcPredMB;
	delete m_pvopiErrorMB;
	delete [] m_rgmbmd;
	delete [] m_rgmv;
	delete [] m_rgmvBY;
    delete [] m_rgmvRef;
	delete m_pidct;

	Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 6+m_volmd.iAuxCompCount*4 : 6;
	Int iBlk;
	for (iBlk = 0; iBlk < nBlk; iBlk++)
		delete [] m_rgpiCoefQ [iBlk];
	delete [] m_rgpiCoefQ;
//	delete m_pvopfCurrFilteredQ;
//	delete m_pdrtmdRef1;

	delete [] m_rgiQPpred;

	// HHI Schueuer: sadct
	if (m_rgiCurrMBCoeffWidth) {
		for (int i=Y_BLOCK1; i<=U_BLOCK; i++) 
			delete [] m_rgiCurrMBCoeffWidth[i];
		delete [] m_rgiCurrMBCoeffWidth;
	}	
	// end HHI


	if (m_volmd.fAUsage == RECTANGLE) {
		Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 6+m_volmd.iAuxCompCount*4 : 6;
		delete [] m_rgblkmCurrMB;
        if (m_rgpmbmAbove != NULL)
		    for (Int iMB = 0; iMB < m_iNumMBX; iMB++)	{
			    for (iBlk = 0; iBlk < nBlk; iBlk++)	{
				    delete [] (m_rgpmbmAbove [iMB]->rgblkm) [iBlk];
				    delete [] (m_rgpmbmCurr  [iMB]->rgblkm) [iBlk];
			    }
			    delete [] m_rgpmbmAbove [iMB]->rgblkm;
			    delete m_rgpmbmAbove [iMB];
			    delete [] m_rgpmbmCurr [iMB]->rgblkm;
			    delete m_rgpmbmCurr [iMB];
		    }
		delete [] m_rgpmbmAbove;
		delete [] m_rgpmbmCurr;
	}

	// sprite
	if (m_uiSprite == 1 || m_uiSprite == 2) { // GMC
		delete [] m_rgstSrcQ;
		delete [] m_rgstDstQ;
		if (m_sptMode == BASIC_SPRITE)
			delete m_pvopcSptQ;
	}
	delete m_pbEmptyRowArray;

/* NBIT: change
	m_rgiClipTab -= 400;
*/
	m_rgiClipTab -= m_iOffset;
	delete [] m_rgiClipTab;
	m_rgiClipTab = NULL;

	// shape
//OBSS_SAIT_991015
	if(m_rgshpmd!=NULL)
		delete m_rgshpmd;
	if(m_rgBaseshpmd!=NULL && m_volmd.volType == BASE_LAYER )
		delete m_rgBaseshpmd;								
//~OBSS_SAIT_991015

	delete m_puciPredBAB;
	delete m_parcodec;
	delete [] m_ppxlcCurrMBBYDown4;
	delete [] m_ppxlcCurrMBBYDown2;
	delete [] m_ppxlcReconCurrBAB;
	delete [] m_ppxlcPredBABDown2;
	delete [] m_ppxlcPredBABDown4;

// MAC
  delete [] m_ppxlcPredMBA;
  delete [] m_ppxliErrorMBA;
  delete [] m_ppxlcPredMBBackA;
  delete [] m_ppxlcCurrMBA;
}

CVideoObject::CVideoObject () :
	m_t (0), m_iBCount (0), m_tPastRef(0), m_tFutureRef(0),
	m_bCodedFutureRef(TRUE),
	m_rgmbmd (NULL), m_rgmv (NULL), m_rgmvBackward (NULL), m_rgmvBY (NULL),
	m_rgmbmdRef (NULL), m_rgmvRef (NULL),
	m_tModuloBaseDecd (0), m_tModuloBaseDisp (0),
	m_pvopcCurrQ (NULL), 
	m_pvopcRefQ0 (NULL), m_pvopcRefQ1 (NULL), 
	m_puciPredBAB (NULL), m_ppxlcReconCurrBAB (NULL), m_parcodec (NULL),
	m_ppxlcCurrMBBYDown4 (NULL),
	m_ppxlcCurrMBBYDown2 (NULL),
	m_ppxlcPredBABDown4 (NULL),
	m_ppxlcPredBABDown2 (NULL),
	m_pvopcSptQ (NULL), m_uiSprite (0), m_rgstSrcQ (NULL), m_rgstDstQ (NULL),
	m_iOffsetForPadY (0), m_iOffsetForPadUV (0),
	m_rgshpmd(NULL),
	// HHI Schueuer: sadct
	m_rgiCurrMBCoeffWidth(NULL)
	// end HHI
//OBSS_SAIT_991015
	, m_rgmvBaseBY(NULL),    
	m_rgBaseshpmd(NULL)	
//~OBSS_SAIT_991015
{
	m_pbEmptyRowArray = new Bool [MB_SIZE];

/* NBIT: replaced by setClipTab() function
	m_rgiClipTab = new U8 [1024];
	m_rgiClipTab += 400;
	Int i;
	for (i = -400; i < 624; i++)
		m_rgiClipTab [i] = (i < 0) ? 0 : (i > 255) ? 255 : i;
*/

// RRV insertion
	m_iRRVScale	= 1;	// default 

// ~RRV
}

// NBIT: added function
Void CVideoObject::setClipTab()
{
	Int TabSize = 1<<(m_volmd.nBits+2);
	Int maxVal = (1<<m_volmd.nBits)-1;
	m_iOffset = TabSize/2;
	m_rgiClipTab = new PixelC [TabSize];
	m_rgiClipTab += m_iOffset;
	Int i;
	for (i = -m_iOffset; i < m_iOffset; i++)
		m_rgiClipTab [i] = (i < 0) ? 0 : (i > maxVal) ? maxVal : i;
}

Void CVideoObject::allocateVOLMembers (Int iSessionWidth, Int iSessionHeight)
{
// RRV insertion
  Int iAuxComp;
  Int	iScaleMB	= (m_volmd.breduced_resolution_vop_enable) ? (2) : (1);
// ~RRV

// RRV modification
	m_pvopcCurrMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, (MB_SIZE *iScaleMB), (MB_SIZE *iScaleMB)),
                                   m_volmd.iAuxCompCount );
//	m_pvopcCurrMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
// ~RRV
	m_ppxlcCurrMBY = (PixelC*) m_pvopcCurrMB->pixelsY ();
	m_ppxlcCurrMBU = (PixelC*) m_pvopcCurrMB->pixelsU ();
	m_ppxlcCurrMBV = (PixelC*) m_pvopcCurrMB->pixelsV ();
	m_ppxlcCurrMBBY = (PixelC*) m_pvopcCurrMB->pixelsBY ();
	m_ppxlcCurrMBBUV = (PixelC*) m_pvopcCurrMB->pixelsBUV ();
  m_ppxlcCurrMBA = new PixelC* [m_volmd.iAuxCompCount];
  for(iAuxComp=0;iAuxComp<m_volmd.iAuxCompCount;iAuxComp++) { // MAC (SB) 26-Nov-99
    m_ppxlcCurrMBA[iAuxComp] = (PixelC*) m_pvopcCurrMB->pixelsA (iAuxComp);
  }
// RRV modification
	m_pvopcPredMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, (MB_SIZE *iScaleMB), (MB_SIZE *iScaleMB)),
                                   m_volmd.iAuxCompCount );
//	m_pvopcPredMB = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
// ~RRV

	m_ppxlcPredMBY = (PixelC*) m_pvopcPredMB->pixelsY ();
	m_ppxlcPredMBU = (PixelC*) m_pvopcPredMB->pixelsU ();
	m_ppxlcPredMBV = (PixelC*) m_pvopcPredMB->pixelsV ();
  m_ppxlcPredMBA = new PixelC* [m_volmd.iAuxCompCount];
  for(iAuxComp=0;iAuxComp<m_volmd.iAuxCompCount;iAuxComp++) { // MAC (SB) 26-Nov-99
  	m_ppxlcPredMBA[iAuxComp] = (PixelC*) m_pvopcPredMB->pixelsA (iAuxComp);
  }
	
	// B-VOP MB buffer data
// RRV modification
	m_pvopcPredMBBack = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, (MB_SIZE *iScaleMB), (MB_SIZE *iScaleMB)),
                                       m_volmd.iAuxCompCount);
//	m_pvopcPredMBBack = new CVOPU8YUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
// ~RRV
	m_ppxlcPredMBBackY = (PixelC*) m_pvopcPredMBBack->pixelsY ();
	m_ppxlcPredMBBackU = (PixelC*) m_pvopcPredMBBack->pixelsU ();
	m_ppxlcPredMBBackV = (PixelC*) m_pvopcPredMBBack->pixelsV ();
  m_ppxlcPredMBBackA = new PixelC* [m_volmd.iAuxCompCount];
  for(iAuxComp=0;iAuxComp<m_volmd.iAuxCompCount;iAuxComp++) { // MAC (SB) 26-Nov-99
    m_ppxlcPredMBBackA[iAuxComp] = (PixelC*) m_pvopcPredMBBack->pixelsA (iAuxComp);
  }

// RRV modification
	m_pvopiErrorMB = new CVOPIntYUVBA (m_volmd.fAUsage, m_volmd.iAuxCompCount, CRct (0, 0, (MB_SIZE *iScaleMB), (MB_SIZE *iScaleMB)));
//	m_pvopiErrorMB = new CVOPIntYUVBA (m_volmd.fAUsage, CRct (0, 0, MB_SIZE, MB_SIZE));
// ~RRV
	m_ppxliErrorMBY = (PixelI*) m_pvopiErrorMB->getPlane (Y_PLANE)->pixels ();
	m_ppxliErrorMBU = (PixelI*) m_pvopiErrorMB->getPlane (U_PLANE)->pixels ();
	m_ppxliErrorMBV = (PixelI*) m_pvopiErrorMB->getPlane (V_PLANE)->pixels ();
  m_ppxliErrorMBA = new PixelI* [m_volmd.iAuxCompCount];
  for(iAuxComp=0;iAuxComp<m_volmd.iAuxCompCount;iAuxComp++) { // MAC (SB) 26-Nov-99
	  m_ppxliErrorMBA[iAuxComp] = (PixelI*) m_pvopiErrorMB->getPlaneA ( iAuxComp)->pixels ();
  }

	if (m_uiSprite == 0 || m_uiSprite == 2) // GMC
		m_pvopcCurrQ = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
	else //for sprite m_rctRefFrameY is for whole sprite, m_rctOrg is the display window 
// dshu: begin of modification
	//	m_pvopcCurrQ = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctDisplayWindow);
	{
		CRct rctCurrQ = CRct (
			-EXPANDY_REF_FRAME, -EXPANDY_REF_FRAME, 
			EXPANDY_REF_FRAME + m_rctDisplayWindow.width, EXPANDY_REF_FRAME + m_rctDisplayWindow.height()
		);

		m_pvopcCurrQ = new CVOPU8YUVBA (m_volmd.fAUsage, rctCurrQ, m_volmd.iAuxCompCount);
	}
// dshu: end of modification

    assert (m_pvopcCurrQ != NULL);
	m_pvopcRefQ0 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
	assert (m_pvopcRefQ0 != NULL);
	m_pvopcRefQ1 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
	assert (m_pvopcRefQ1 != NULL);

	m_iFrameWidthY = m_pvopcRefQ0->whereY ().width;
	m_iFrameWidthUV = m_pvopcRefQ0->whereUV ().width;
	m_iFrameWidthYxMBSize = MB_SIZE * m_pvopcRefQ0->whereY ().width; 
	m_iFrameWidthYxBlkSize = BLOCK_SIZE * m_pvopcRefQ0->whereY ().width; 
	m_iFrameWidthUVxBlkSize = BLOCK_SIZE * m_pvopcRefQ0->whereUV ().width;

	// MB data	
	Int nBlk = (m_volmd.fAUsage == EIGHT_BIT) ? 6+m_volmd.iAuxCompCount*4 : 6;
	m_rgpiCoefQ = new Int* [nBlk];
	m_rgiQPpred = new Int [nBlk];
	Int iBlk;
	for (iBlk = 0; iBlk < nBlk; iBlk++)
		m_rgpiCoefQ [iBlk] = new Int [BLOCK_SQUARE_SIZE];
/* NBIT: change
	m_pidct = new CInvBlockDCT;
*/
	// m_pidct = new CInvBlockDCT(m_volmd.nBits);
	// HHI Schueuer: sadct
	if (m_volmd.fAUsage != RECTANGLE && (!m_volmd.bSadctDisable)) {
    	int i, j;
		m_pidct = new CInvSADCT(m_volmd.nBits);
		// m_pidct = new CInvBlockDCT(m_volmd.nBits); // 20-11
        m_rgiCurrMBCoeffWidth = new Int*[11];
        for (i=0; i<11; i++) 
        	m_rgiCurrMBCoeffWidth[i] = 0;
        
		for (i=Y_BLOCK1; i<=U_BLOCK; i++) 
			m_rgiCurrMBCoeffWidth[i] = new Int[BLOCK_SIZE];
        // shape of U and V is the same, no need to duplicate the data    
        m_rgiCurrMBCoeffWidth[V_BLOCK] = m_rgiCurrMBCoeffWidth[U_BLOCK];
        // the 8bit alpha blocks use the same shape information as the luminance blocks
        for (j=Y_BLOCK1,i=A_BLOCK1; i<=A_BLOCK4; i++,j++) {
        	m_rgiCurrMBCoeffWidth[i] = m_rgiCurrMBCoeffWidth[j];
        }    
	}
	else
		m_pidct = new CInvBlockDCT(m_volmd.nBits);
	// end HHI

	// motion vectors and MBMode
	Int iNumMBX = iSessionWidth / MB_SIZE; 
	if (iSessionWidth  % MB_SIZE != 0)				//round up
		iNumMBX++;
	Int iNumMBY = iSessionHeight / MB_SIZE;
	if (iSessionHeight % MB_SIZE != 0)				//deal with frational MB
		iNumMBY++;
	Int iNumMB = m_iSessNumMB = iNumMBX * iNumMBY;

	m_rgmbmd = new CMBMode [iNumMB];
  if (m_volmd.iAuxCompCount>0) {
    for(Int k=0; k<iNumMB; k++)
      m_rgmbmd[k]=CMBMode(m_volmd.iAuxCompCount);
  }
	m_rgmv = new CMotionVector [max(PVOP_MV_PER_REF_PER_MB, 2*BVOP_MV_PER_REF_PER_MB) * iNumMB];
	m_rgmvBackward = m_rgmv + BVOP_MV_PER_REF_PER_MB * m_iSessNumMB;
	m_rgmvRef = new CMotionVector [max(PVOP_MV_PER_REF_PER_MB, 2*BVOP_MV_PER_REF_PER_MB) * iNumMB];
	m_rgmvBY = new CMotionVector [iNumMB]; // for shape
	m_rgmbmdRef = new CMBMode [iNumMB];
  if (m_volmd.iAuxCompCount>0) {
    for(Int k=0; k<iNumMB; k++)
      m_rgmbmdRef[k]=CMBMode(m_volmd.iAuxCompCount);
  }

//OBSS_SAIT_991015
	m_rgmvBaseBY = new CMotionVector [iNumMB]; // for shape  
	if (m_volmd.volType == ENHN_LAYER && !(m_volmd.bSpatialScalability && m_volmd.iHierarchyType==0))
		m_rgshpmd = new ShapeMode [iNumMB];
//~OBSS_SAIT_991015
	
	// shape data
	if (m_volmd.fAUsage != RECTANGLE) {
		m_puciPredBAB = new CU8Image (CRct (0, 0, MC_BAB_SIZE, MC_BAB_SIZE));
		m_ppxlcReconCurrBAB = new PixelC [BAB_SIZE * BAB_SIZE];
		m_parcodec = new ArCodec;

⌨️ 快捷键说明

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