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

📄 sesenc.cpp

📁 《Visual C++小波变换技术与工程实践》靳济芳编著的光盘程序。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************

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

	Marc Mongenet (Marc.Mongenet@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)

    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
    Massimo Ravasi (Massimo.Ravasi@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)

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:

	sesEnc.cpp

Abstract:

	Encoder for one video session.

Revision History:
	Sept. 30, 1997: Error resilient tools added by Toshiba
	Nov.  27, 1997: Spatial Scalable tools added, and modified for Spatial Scalable
						by Takefumi Nagumo(nagumo@av.crl.sony.co.jp) SONY
	Dec 11, 1997:	Interlaced tools added by NextLevel Systems (GI)
						(B.Eifrig, beifrig@nlvl.com, X.Chen, xchen@nlvl.com)
	Jun 17, 1998:	add Complexity Estimation syntax support
					Marc Mongenet (Marc.Mongenet@epfl) - EPFL
    Feb.16, 1999:   add Quarter Sample 
                    Mathias Wien (wien@ient.rwth-aachen.de) 
    Feb.24, 1999:   GMC added by Yoshinori Suzuki (Hitachi, Ltd.) 
	May  9, 1999:	tm5 rate control by DemoGraFX, duhoff@mediaone.net (added by mwi)
	Aug.24, 1999:   NEWPRED added by Hideaki Kimata (NTT) 
	Sep.06	1999 : RRV added by Eishi Morimatsu (Fujitsu Laboratories Ltd.) 
	Nov.11  1999 : Fixed Complexity Estimation syntax support, version 2 (Massimo Ravasi, EPFL)
	Feb.12  2000 : Bugfix of OBSS by Takefumi Nagumo (Sony)

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

#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "fstream.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 "sesenc.hpp"

#include "tps_enhcbuf.hpp" // added by Sharp (98/2/12)
#include "vopses.hpp"
#include "vopseenc.hpp"
#include "enhcbufenc.hpp" // added by Sharp (98/2/12)

// NEWPRED
#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_

#ifdef __PC_COMPILER_					//OS specific stuff
#define SUB_CMPFILE "%s\\%2.2d\\%s.cmp"
#define SUB_TRCFILE "%s\\%2.2d\\%s.trc"
#define SUB_YUVFILE	"%s\\%2.2d\\%s.yuv"
#define SUB_SEGFILE	"%s\\%2.2d\\%s.seg"
#define SUB_AUXFILE "%s\\%2.2d\\%s.%d.aux"
#define ENHN_SUB_CMPFILE "%s\\%2.2d\\%s_e.cmp"
#define ENHN_SUB_TRCFILE "%s\\%2.2d\\%s_e.trc"
#define ENHN_SUB_YUVFILE "%s\\%2.2d\\%s_e.yuv"
#define ENHN_SUB_SEGFILE "%s\\%2.2d\\%s_e.seg"
#define SUB_VDLFILE "%s\\%2.2d\\%s.spt"	//for sprite i/o
#define SUB_PNTFILE "%s\\%2.2d\\%s.pnt"	//for sprite i/o
#define ROOT_YUVFILE "%s\\%s.yuv"
#define ROOT_SEGFILE "%s\\%s.seg"
#define ROOT_AUXFILE "%s\\%s.%d.aux"
#define IOS_BINARY ios::binary
//#define IOS_BINARY 0
#define MKDIR "mkdir %s\\%2.2d"
#else
#define SUB_CMPFILE "%s/%2.2d/%s.cmp"
#define SUB_TRCFILE "%s/%2.2d/%s.trc"
#define SUB_YUVFILE	"%s/%2.2d/%s.yuv"
#define SUB_SEGFILE	"%s/%2.2d/%s.seg"
#define SUB_AUXFILE "%s/%2.2d/%s.%d.aux"
#define ENHN_SUB_CMPFILE "%s/%2.2d/%s_e.cmp"
#define ENHN_SUB_TRCFILE "%s/%2.2d/%s_e.trc"
#define ENHN_SUB_YUVFILE "%s/%2.2d/%s_e.yuv"
#define ENHN_SUB_SEGFILE "%s/%2.2d/%s_e.seg"
#define SUB_VDLFILE "%s/%2.2d/%s.vdl"	//for sprite i/o
#define SUB_PNTFILE "%s/%2.2d/%s.pnt"	//for sprite i/o
#define ROOT_YUVFILE "%s/%s.yuv"
#define ROOT_SEGFILE "%s/%s.seg"
#define ROOT_AUXFILE "%s/%s.%d.aux"
#define IOS_BINARY ios::bin
#define MKDIR "mkdir %s/%2.2d"
#endif

#define BASE_LAYER 0
#define ENHN_LAYER 1

#define _FOR_GSSP_

Bool fileExistence (const Char* pchFile) 
{
	Bool ret = 1;
	FILE* pf = fopen (pchFile, "r");
	if (pf == NULL)
		ret = 0;
	else
		fclose (pf);
	return ret;
}

Void CSessionEncoder::createReconDir (UInt idx) const
{
	Char pchTmp [100];
	sprintf (pchTmp, SUB_YUVFILE, m_pchReconYUVDir, idx, m_pchPrefix);
	FILE* pf = fopen (pchTmp, "wb");
	if (pf == NULL) {
		sprintf (pchTmp, MKDIR, m_pchReconYUVDir, idx);
		system (pchTmp);																	
	}
	else
		fclose (pf);
}

Void CSessionEncoder::createCmpDir (UInt idx) const
{
	Char pchTmp [100];
	sprintf (pchTmp, SUB_CMPFILE, m_pchOutStrFiles, idx, m_pchPrefix);
	FILE* pf = fopen (pchTmp, "wb");
	if (pf == NULL) {
		sprintf (pchTmp, MKDIR, m_pchOutStrFiles, idx);
		system (pchTmp);																	
	}
	else
		fclose (pf);
}

CSessionEncoder::~CSessionEncoder ()
{
	delete [] m_rgvolmd [BASE_LAYER];
	delete [] m_rgvolmd [ENHN_LAYER];
	delete [] m_rgvopmd [BASE_LAYER];
	delete [] m_rgvopmd [ENHN_LAYER];

	// sprite 
	for (Int iVO = 0; iVO < m_iNumVO; iVO++) {
		delete [] m_ppstSrc [iVO];
		for (Int ifr = 0; ifr < m_iNumFrame; ifr++)
			delete [] m_pppstDst [iVO] [ifr];
		delete [] m_pppstDst [iVO];
	}
	delete [] m_ppstSrc;
	delete [] m_pppstDst;
}


CSessionEncoder::CSessionEncoder (SessionEncoderArgList *pArgs)
 :	m_iFirstFrame (pArgs->iFirstFrm), m_iLastFrame (pArgs->iLastFrm),
	m_iFirstVO (pArgs->iFirstVO), m_iLastVO (pArgs->iLastVO),
	m_rgbSpatialScalability (pArgs->rgbSpatialScalability),
	m_rguiRateControl (pArgs->rguiRateControl), 
	m_rguiBudget (pArgs->rguiBudget),
	m_pchPrefix (pArgs->pchPrefix), m_pchBmpFiles (pArgs->pchBmpFiles),
	m_pchReconYUVDir (pArgs->pchOutBmpFiles), m_rgfChrType (pArgs->rgfChrType),
	m_pchOutStrFiles (pArgs->pchOutStrFiles),
	m_rguiSpriteUsage (pArgs->rguiSpriteUsage), m_rguiWarpingAccuracy (pArgs->rguiWarpingAccuracy), 
	m_rgNumOfPnts (pArgs->rgNumOfPnts), m_pchSptDir (pArgs->pchSptDir), 
	m_pchSptPntDir (pArgs->pchSptPntDir),
	m_rgiTemporalScalabilityType (pArgs->rgiTemporalScalabilityType)
{
	// data preparation
	m_iNumFrame = m_iLastFrame - m_iFirstFrame + 1;
	assert (m_iNumFrame > 0);
	m_rctOrg = CRct (0, 0, pArgs->uiFrmWidth, pArgs->uiFrmHeight);
	if( pArgs->uiFrameWidth_SS !=0 && pArgs->uiFrameHeight_SS!=0)
		m_rctOrgSpatialEnhn = CRct(0, 0, pArgs->uiFrameWidth_SS, pArgs->uiFrameHeight_SS);
	assert (pArgs->uiFrmWidth <= 8192 && pArgs->uiFrmHeight <= 8192); //2^13 maximum size
	m_iNumVO = m_iLastVO - m_iFirstVO + 1;
	assert (m_iNumVO > 0);
	m_rgvolmd [BASE_LAYER] = new VOLMode [m_iNumVO];
	m_rgvolmd [ENHN_LAYER] = new VOLMode [m_iNumVO];
	m_rgvopmd [BASE_LAYER] = new VOPMode [m_iNumVO];
	m_rgvopmd [ENHN_LAYER] = new VOPMode [m_iNumVO];
	Int iVO;
	for (iVO = 0; iVO < m_iNumVO; iVO++) {
		// set VOL and VOP mode values
		for (Int iLayer = BASE_LAYER; iLayer <= m_rgbSpatialScalability [iVO] * ENHN_LAYER; iLayer++)	{
// GMC
			m_rgvolmd [iLayer][iVO].uiVerID	= pArgs->rguiVerID [iVO];  // version id
// ~GMC
			// NBIT
			m_rgvolmd [iLayer][iVO].bNot8Bit 		= pArgs->bNot8Bit;
			m_rgvolmd [iLayer][iVO].uiQuantPrecision 	= pArgs->uiQuantPrecision;
			m_rgvolmd [iLayer][iVO].nBits 			= pArgs->nBits;

			m_rgvolmd [iLayer][iVO].volType			= (VOLtype) iLayer;
			m_rgvolmd [iLayer][iVO].fAUsage			= pArgs->rgfAlphaUsage [iVO];
// MAC 
			if (m_rgvolmd [iLayer][iVO].fAUsage==EIGHT_BIT) {
				m_rgvolmd [iLayer][iVO].iAlphaShapeExtension = pArgs->rgiAlphaShapeExtension [iVO];
				m_rgvolmd [iLayer][iVO].iAuxCompCount = CVideoObject::getAuxCompCount(pArgs->rgiAlphaShapeExtension [iVO]);
			} else
				m_rgvolmd [iLayer][iVO].iAuxCompCount = 0;
// ~MAC
			m_rgvolmd [iLayer][iVO].bShapeOnly		= pArgs->rgbShapeOnly [iVO];
			m_rgvolmd [iLayer][iVO].iBinaryAlphaTH	= pArgs->rgiBinaryAlphaTH [iVO] * 16;  //magic no. from the vm
			m_rgvolmd [iLayer][iVO].iBinaryAlphaRR	= (pArgs->rgiBinaryAlphaRR [iVO]<0) ? -1 : 
				(pArgs->rgiBinaryAlphaRR [iVO] +1)*(pArgs->rgiNumOfBbetweenPVOP [iVO] +1)*pArgs->rgiTemporalRate [iVO];  // Binary shape refresh rate: Added for error resilient mode by Toshiba(1997-11-14): Modified (1998-1-16)
			m_rgvolmd [iLayer][iVO].bNoCrChange		= pArgs->rgbNoCrChange [iVO];
			m_rgvolmd [iLayer][iVO].bOriginalForME	= pArgs->rgbOriginalForME [iLayer][iVO];
			m_rgvolmd [iLayer][iVO].bAdvPredDisable = pArgs->rgbAdvPredDisable [iLayer][iVO];
			m_rgvolmd [iLayer][iVO].bQuarterSample  = pArgs->rgbQuarterSample [iLayer][iVO]; // QuarterSample mwi 
// NEWPRED
			m_rgvolmd [iLayer][iVO].bNewpredEnable = pArgs->rgbNewpredEnable [iLayer][iVO]; 
			m_rgvolmd [iLayer][iVO].bNewpredSegmentType = pArgs->rgbNewpredSegmentType [iLayer][iVO]; 
			m_rgvolmd [iLayer][iVO].cNewpredRefName = pArgs->rgcNewpredRefName [iLayer][iVO]; 
			m_rgvolmd [iLayer][iVO].cNewpredSlicePoint = pArgs->rgcNewpredSlicePoint [iLayer][iVO]; 
// ~NEWPRED

			// START: Complexity Estimation syntax support - Marc Mongenet (EPFL) - 17 Jun 1998
			m_rgvolmd [iLayer][iVO].bComplexityEstimationDisable = pArgs->rgbComplexityEstimationDisable [iLayer][iVO];
			// START: Complexity Estimation syntax support - Update version 2 - Massimo Ravasi (EPFL) - 11 Nov 1999
			//m_rgvolmd [iLayer][iVO].bVersion2ComplexityEstimationDisable = pArgs->rgbComplexityEstimationDisable [iLayer][iVO] || (pArgs->rguiVerID [iVO]==1);
			// see last lines of current "Complexity Estimation syntax support" section
			// END: Complexity Estimation syntax support - Update version 2

			m_rgvolmd [iLayer][iVO].iEstimationMethod = (Int)pArgs->rguiEstimationMethod [iLayer][iVO];
			m_rgvolmd [iLayer][iVO].bOpaque = pArgs->rgbOpaque [iLayer][iVO];
			m_rgvolmd [iLayer][iVO].bTransparent = pArgs->rgbTransparent [iLayer][iVO];

⌨️ 快捷键说明

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