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

📄 vopseenc.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
	Simon Winder (swinder@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)

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

	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:

	vopSeEnc.hpp

Abstract:

	Encoder for one VO.

Revision History:
	Sept. 30, 1997: Error resilient tools added by Toshiba
	Dec.  11, 1997:	Interlaced tools added by NextLevel Systems
					X. Chen, xchen@nlvl.com B. Eifrig, beifrig@nlvl.com
	Jun.  16, 1998: add Complexity Estimation syntax support
					Marc Mongenet (Marc.Mongenet@epfl.ch) - EPFL
	Jan.  28, 1999: Rounding control parameters added by Hitachi, Ltd.
    Feb.  16, 1999: add Quarter Sample 
                    Mathias Wien (wien@ient.rwth-aachen.de) 
	Feb.  24, 1999: GMC added by 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 : Fixed OBSS Bug by Takefumi Nagumo (Sony)

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

#include <stdio.h>
#include <fstream.h>
#include <math.h>
#include <stdlib.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 "dct.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)
#include "cae.h" // Added for error resilient mode by Toshiba(1997-11-14)

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

// RRV
#include "rrv.hpp"
// ~RRV

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

#define new DEBUG_NEW				   
#endif // __MFC_

CVideoObjectEncoder::~CVideoObjectEncoder ()
{
	delete m_pvopcOrig;
	delete m_pvopcRefOrig1;
	delete m_pvopcRefOrig0;

	delete m_puciRefQZoom0;
	delete m_puciRefQZoom1;
	delete m_pfdct;
	delete [] m_rgdSNR;

	// bitstream stuff
	delete [] m_pchBitsBuffer; 
	delete m_pbitstrmOut;
	delete m_pentrencSet;
	delete [] m_pchShapeBitsBuffer;
	delete m_pbitstrmShape;

//	Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
	delete [] *m_pchShapeBitsBuffer_DP;
	delete [] *m_pbitstrmShape_DP;
	delete m_pchShapeBitsBuffer_DP;
	delete m_pbitstrmShape_DP;
//	End Toshiba(1998-1-16)

	// shape
	delete [] m_rgiSubBlkIndx16x16;
	delete [] m_rgiSSubBlkIndx16x16;
	delete [] m_rgiSubBlkIndx18x18;
	delete [] m_rgiSubBlkIndx20x20;
	delete [] m_rgiPxlIndx12x12;
	delete [] m_rgiPxlIndx8x8;

	// B-VOP MB buffer
	delete m_puciDirectPredMB;
	delete m_puciInterpPredMB;
	delete m_piiDirectErrorMB; 
	delete m_piiInterpErrorMB; 
}

CVideoObjectEncoder::CVideoObjectEncoder (
	UInt uiVOId, 
	VOLMode& volmd, 
	VOPMode& vopmd, 
	UInt nFirstFrame,
	UInt nLastFrame,
	Int iSessionWidth,
	Int iSessionHeight,
	UInt uiRateControl,
	UInt uiBudget,
	ostream* pstrmTrace, // trace outstream
	UInt uiSprite, // for sprite usage // GMC
	UInt uiWarpingAccuracy, // for sprite warping
	Int iNumOfPnts, // for sprite warping
	CSiteD** rgstDest, // for sprite warping destination
	SptMode SpriteMode,					// sprite reconstruction mode
	CRct rctFrame,						// sprite warping source
    CRct rctSpt,     	// rct sprite
	Int iMVFileUsage,
	Char* pchMVFileName
) :
	CVideoObject (),
	m_nFirstFrame (nFirstFrame), m_nLastFrame (nLastFrame), 
	m_iBufferSize (uiBudget), m_uiRateControl (uiRateControl),
	m_pvopcOrig (NULL),
	m_rgiSubBlkIndx16x16 (NULL),
	m_rgiSSubBlkIndx16x16 (NULL),
	m_rgiSubBlkIndx18x18 (NULL),
	m_rgiSubBlkIndx20x20 (NULL),
	m_rgiPxlIndx12x12 (NULL),
	m_rgiPxlIndx8x8 (NULL),
	m_pscanSelector (0), // HHI Schueuer
  m_statsVOL(volmd.iAuxCompCount),
  m_statsVOP(volmd.iAuxCompCount),
  m_statsMB (volmd.iAuxCompCount)
{
	m_ivolWidth = iSessionWidth;
	m_ivolHeight = iSessionHeight;		
		
	// sprite stuff
	if (iNumOfPnts >= 0) {
		m_uiSprite = uiSprite; // GMC
		m_uiWarpingAccuracy = uiWarpingAccuracy;
		m_iNumOfPnts = iNumOfPnts;
		m_rgstSrcQ = new CSiteD [m_iNumOfPnts];
		m_rgstDstQ = new CSiteD [m_iNumOfPnts];
// GMC
	    if(m_uiSprite == 1)
	    {
// ~GMC
		m_rctSpt = rctSpt;
		//#ifdef __LOW_LATENCY_SPRITE_
		m_pprgstDest = rgstDest;
		m_sptMode = SpriteMode ;
		m_rctOrg = 	rctFrame;
		m_rctDisplayWindow = m_rctOrg;	//only used for sprite, will be combined with Org later
// GMC
	    }
// ~GMC
	}
	else 
		m_uiSprite = 0;

	m_pchBitsBuffer = new Char [iSessionWidth * iSessionHeight * 2];	//we think this is enof for 4:2:0; if crushes, increase the buffer
	m_pbitstrmOut = new COutBitStream (m_pchBitsBuffer, 0, pstrmTrace);
	m_pentrencSet = new CEntropyEncoderSet (*m_pbitstrmOut);

	// shape cache
	m_pchShapeBitsBuffer = new Char [MB_SIZE * MB_SIZE * 2]; // same as above
	m_pbitstrmShape = new COutBitStream (m_pchShapeBitsBuffer, 0, pstrmTrace);
	m_pbitstrmShapeMBOut = m_pbitstrmOut; // initially the output stream (only changes for inter)

	m_uiVOId = uiVOId;
	m_volmd = volmd;

	// NBIT: set right clip table
	setClipTab();

	Int iClockRate = m_volmd.iClockRate-1;
	assert (iClockRate < 65536);
	if(iClockRate>0)
	{
		for (m_iNumBitsTimeIncr = 1; m_iNumBitsTimeIncr < NUMBITS_TIME_RESOLUTION; m_iNumBitsTimeIncr++)	{	
			if (iClockRate == 1)			
				break;
			iClockRate = (iClockRate >> 1);
		}
	}
	else
		m_iNumBitsTimeIncr = 0;

	m_vopmd = vopmd;
//	decideMVInfo ();                // MV search radius now varys with GOP
// GMC
	if(m_uiSprite == 1){
	    m_vopmd.iRoundingControlEncSwitch = 0;
	    m_vopmd.iRoundingControl = 0;
	}else{
// ~GMC
	    m_vopmd.iRoundingControlEncSwitch = m_volmd.iInitialRoundingType;
	    if(!m_volmd.bRoundingControlDisable)
		m_vopmd.iRoundingControlEncSwitch ^= 0x00000001;
	    m_vopmd.iRoundingControl = m_vopmd.iRoundingControlEncSwitch;
// GMC
	}
// ~GMC
//OBSS_SAIT_991015
	Int iSessionWidthRound=0;
	Int iSessionHeightRound=0;
	//if(!(m_volmd.bSpatialScalability && m_volmd.iHierarchyType==0)) {
	if(!(m_volmd.bSpatialScalability && m_volmd.iHierarchyType==0 && m_volmd.fAUsage == ONE_BIT)) {    //OBSSFIX_V2-8_after
		Int iMod = iSessionWidth % MB_SIZE; 
		iSessionWidthRound = (iMod > 0) ? iSessionWidth + MB_SIZE - iMod : iSessionWidth;
		iMod = iSessionHeight % MB_SIZE;
		iSessionHeightRound = (iMod > 0) ? iSessionHeight + MB_SIZE - iMod : iSessionHeight;
	}
	else {
		iSessionWidthRound = iSessionWidth;
		iSessionHeightRound = iSessionHeight;
	}
/*
	Int iMod = iSessionWidth % MB_SIZE;
	Int iSessionWidthRound = (iMod > 0) ? iSessionWidth + MB_SIZE - iMod : iSessionWidth;
	iMod = iSessionHeight % MB_SIZE;
	Int iSessionHeightRound = (iMod > 0) ? iSessionHeight + MB_SIZE - iMod : iSessionHeight;
	*/
//~OBSS_SAIT_991015

//	Added for data partitioning mode By Toshiba(1998-1-16:DP+RVLC)
	Int iMB;
	Int iMBN = (iSessionWidthRound/MB_SIZE)*(iSessionHeightRound/MB_SIZE);
	m_pchShapeBitsBuffer_DP = new Char* [iMBN];
	m_pbitstrmShape_DP = new COutBitStream* [iMBN];
	for (iMB = 0; iMB < iMBN; iMB++) {
		m_pchShapeBitsBuffer_DP[iMB] = new Char [MB_SIZE * MB_SIZE * 2]; // same as above
		m_pbitstrmShape_DP[iMB] = new COutBitStream (m_pchShapeBitsBuffer_DP[iMB], 0, pstrmTrace);
	}
// End Toshiba(1998-1-16:DP+RVLC)
	m_rctRefFrameY = CRct (
		-EXPANDY_REF_FRAME, -EXPANDY_REF_FRAME, 
		EXPANDY_REF_FRAME + iSessionWidthRound, EXPANDY_REF_FRAME + iSessionHeightRound
	);
	m_rctRefFrameUV = m_rctRefFrameY.downSampleBy2 ();
	m_pvopcOrig = new CVOPU8YUVBA( m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
  m_pvopcRefOrig0 = new CVOPU8YUVBA( m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
	m_pvopcRefOrig1 = new CVOPU8YUVBA (m_volmd.fAUsage, m_rctRefFrameY, m_volmd.iAuxCompCount);
	allocateVOLMembers (iSessionWidthRound, iSessionHeightRound);

    //#ifdef __LOW_LATENCY_SPRITE_
	// identify initial sprite piece
	if ((m_uiSprite == 1) && (m_sptMode != BASIC_SPRITE) ){
		initialSpritePiece (iSessionWidthRound, iSessionHeightRound);
	}

    CRct rctFrameZoom = m_rctRefFrameY.upSampleBy2 ();
	m_puciRefQZoom0 = new CU8Image (rctFrameZoom);

	m_puciRefQZoom1 = new CU8Image (rctFrameZoom);

	// HHI Schueuer: sadct
	if (m_volmd.fAUsage != RECTANGLE && (!m_volmd.bSadctDisable)) {
		m_pfdct = new CFwdSADCT(volmd.nBits);
		m_pscanSelector = new CScanSelectorForSADCT(m_rgiCurrMBCoeffWidth);
	}
	else {
		m_pfdct = new CFwdBlockDCT(volmd.nBits);
		m_pscanSelector = new CScanSelector;
	}
	// end HHI
	// m_pfdct = new CFwdBlockDCT(volmd.nBits);

	// B-VOP MB buffer
	m_puciDirectPredMB = new CU8Image (CRct (0, 0, MB_SIZE, MB_SIZE));
	m_puciInterpPredMB = new CU8Image (CRct (0, 0, MB_SIZE, MB_SIZE));
	m_ppxlcDirectPredMBY = (PixelC*) m_puciDirectPredMB->pixels (); 
	m_ppxlcInterpPredMBY = (PixelC*) m_puciInterpPredMB->pixels (); 

⌨️ 快捷键说明

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