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

📄 sesenc.cpp

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

		volmd_backShape = new VOLMode;
		volmd_forwShape = new VOLMode;
		vopmd_backShape = new VOPMode;
		vopmd_forwShape = new VOPMode;
		set_modes(volmd_backShape, vopmd_backShape);
		set_modes(volmd_forwShape, vopmd_forwShape);
	}
// end: added by Sharp (98/2/12)
	FILE** ppfAuxSrc = NULL;
	FILE** rgpfReconAux[2];
	rgpfReconAux[0] = rgpfReconAux[1] = NULL;


	for (iVO = m_iFirstVO; iVO <= (Int) m_iLastVO; iVO++, iVOrelative++) {
		ofstream* rgpostrm [2];
		ofstream* rgpostrmTrace [2];
		PixelC pxlcObjColor;
		VOLMode volmd = m_rgvolmd [BASE_LAYER] [iVOrelative];
		VOLMode volmd_enhn = m_rgvolmd [ENHN_LAYER] [iVOrelative]; // added by Sharp (98/2/10)
		ppfAuxSrc = new FILE* [volmd.iAuxCompCount];
		rgpfReconAux[0] = new FILE* [volmd.iAuxCompCount];
		rgpfReconAux[1] = new FILE* [volmd.iAuxCompCount]; // actually never used

		getInputFiles (	pfYuvSrc, pfSegSrc, ppfAuxSrc, pfYuvSrcSpatialEnhn,
						pfSegSrcSpatialEnhn,//OBSS_SAIT_991015
						rgpfReconYUV, rgpfReconSeg, rgpfReconAux,
						rgpostrm, rgpostrmTrace, pxlcObjColor, iVO, volmd, volmd_enhn); // modified by Sharp(98/2/10)
		CRct rctOrg;
		CVideoObjectEncoder* rgpvoenc [2];
		if (m_rguiSpriteUsage [iVOrelative] == 1) {
			// change m_rctOrg to sprite size
			rctOrg = m_rctOrg;
			m_rctFrame = m_rctOrg;
			m_rctOrg = findSptRct (iVO);
		}

// NEWPRED
		if (m_rgvolmd [BASE_LAYER][iVOrelative].bNewpredEnable) 
			g_pNewPredEnc = new CNewPredEncoder();
// ~NEWPRED

		initVOEncoder (rgpvoenc, iVO, rgpostrmTrace);
		rgpostrm [BASE_LAYER]->write (rgpvoenc [BASE_LAYER]->pOutStream ()->str (),			//VO and VOL header
									  rgpvoenc [BASE_LAYER]->pOutStream ()->pcount ());

		if(m_rgbSpatialScalability[iVOrelative]){
			rgpostrm[ENHN_LAYER]->write(rgpvoenc [ENHN_LAYER]->pOutStream () ->str(),
										rgpvoenc [ENHN_LAYER]->pOutStream () ->pcount ());
		}
	// begin: added by Sharp (98/2/12)
		// for back/forward shape
		if ( bTemporalScalability ){
		  initVObfShape (rgpvoenc[ENHN_LAYER]->rgpbfShape, iVO, *volmd_backShape, *vopmd_backShape, *volmd_forwShape, *vopmd_forwShape);
		  // copy pointers
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[0]->m_pchBitsBuffer = rgpvoenc[ENHN_LAYER]->m_pchBitsBuffer;
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[0]->m_pbitstrmOut   = rgpvoenc[ENHN_LAYER]->m_pbitstrmOut;
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[0]->m_pentrencSet   = rgpvoenc[ENHN_LAYER]->m_pentrencSet;

		  rgpvoenc[ENHN_LAYER]->rgpbfShape[0]->m_pchShapeBitsBuffer = rgpvoenc[ENHN_LAYER]->m_pchShapeBitsBuffer;	// Oct 8
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[0]->m_pbitstrmShape      = rgpvoenc[ENHN_LAYER]->m_pbitstrmShape;		//
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[0]->m_pbitstrmShapeMBOut = rgpvoenc[ENHN_LAYER]->m_pbitstrmShapeMBOut;	//

		  rgpvoenc[ENHN_LAYER]->rgpbfShape[1]->m_pchBitsBuffer = rgpvoenc[ENHN_LAYER]->m_pchBitsBuffer;
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[1]->m_pbitstrmOut   = rgpvoenc[ENHN_LAYER]->m_pbitstrmOut;
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[1]->m_pentrencSet   = rgpvoenc[ENHN_LAYER]->m_pentrencSet;

		  rgpvoenc[ENHN_LAYER]->rgpbfShape[1]->m_pchShapeBitsBuffer = rgpvoenc[ENHN_LAYER]->m_pchShapeBitsBuffer;	// Oct 8
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[1]->m_pbitstrmShape	    = rgpvoenc[ENHN_LAYER]->m_pbitstrmShape;		//
		  rgpvoenc[ENHN_LAYER]->rgpbfShape[1]->m_pbitstrmShapeMBOut = rgpvoenc[ENHN_LAYER]->m_pbitstrmShapeMBOut;	//
		}
	// end: added by Sharp (98/2/12)
		if (m_rguiSpriteUsage [iVO - m_iFirstVO] == 1) {
			// load sprite data into m_pvopcOrig
			loadSpt (iVO, rgpvoenc [BASE_LAYER] -> m_pvopcOrig);
			// encode the initial sprite
			if (m_SptMode == BASIC_SPRITE) 
				rgpvoenc [BASE_LAYER] -> encode (TRUE, -1, IVOP);
			else
				rgpvoenc [BASE_LAYER] -> encodeInitSprite (rctOrg);

			if (m_rgNumOfPnts [iVOrelative] > 0) {
				// change m_pvopcRefQ1 to m_pvopcSptQ for warping
				rgpvoenc [BASE_LAYER] -> swapRefQ1toSpt ();
				// restore m_pvopcCurrQ size to the normal one
				m_rctOrg = rctOrg;
				rgpvoenc [BASE_LAYER] -> changeSizeofCurrQ (rctOrg);
			}
			rgpostrm [BASE_LAYER]->write (rgpvoenc [BASE_LAYER]->pOutStream ()->str (), //write sprite unit
										  rgpvoenc [BASE_LAYER]->pOutStream ()->pcount ());
		}
		assert (!m_rctOrg.empty ());

		if (rgpvoenc [BASE_LAYER]->m_uiRateControl>=RC_TM5) {
			assert (!m_rgbSpatialScalability [iVOrelative]);
			assert (!bTemporalScalability);
			assert (volmd.iTemporalRate==1);
#ifndef __TRACE_AND_STATS_
			cerr << "Compile flag __TRACE_AND_STATS_ required for stats for TM5 rate control." << endl;
			exit(1);
#endif // __TRACE_AND_STATS_
			char pchQname[100];
			pchQname[0] = 0;
			//if( m_bRGBfiles ) {
			//	if( m_pchOutStrFiles && m_pchOutStrFiles[0]) sprintf (pchQname, m_pchOutStrFiles, "q", iVO);
			//} else {
				if( m_pchOutStrFiles && m_pchOutStrFiles[0]) {
					sprintf (pchQname, SUB_CMPFILE, m_pchOutStrFiles, iVO, m_pchPrefix);
				}
			//}
			rgpvoenc [BASE_LAYER]->m_tm5rc.tm5rc_init_seq ( pchQname,
				rgpvoenc [BASE_LAYER]->m_uiRateControl,
				m_rgvolmd [BASE_LAYER] [iVOrelative].fAUsage,
				m_rctOrg.width,
				m_rctOrg.height(),
				(UInt)((m_rguiBudget [BASE_LAYER] [iVOrelative] * m_rgvolmd [BASE_LAYER][iVOrelative].dFrameHz)
				 / (m_iLastFrame - m_iFirstFrame + 1)),
				m_rgvolmd [BASE_LAYER][iVOrelative].dFrameHz
			);
		}

		// algorithm for generation of IPB sequences with arbitrary shape
		 //   (transparency allows for possible skipped frames) 
		 //   P prediction across skips is not allowed 

#define DUMP_CURR	0
#define DUMP_PREV	1
#define DUMP_NONE	2

		Int iRefFrame;
		Int iDT = volmd.iTemporalRate;
		Int iDT_enhn = volmd_enhn.iTemporalRate; // added by Sharp (98/2/12)
		Int iRefInterval = volmd.iBbetweenP + 1;
		Int iPCount;
		Bool bObjectExists;
		const CVOPU8YUVBA* pvopcBaseQuant = NULL;
		Int iEcount = 0; // added by Sharp (98/2/12)
		Bool bCachedRefDump = FALSE;
		Bool bCachedRefCoded = TRUE;
		Bool bPrevObjectExists = FALSE; // added by Sharp (99/1/27)
		m_rgpvopcPrevDisp[BASE_LAYER] = NULL; // previously displayed vop pointers
		m_rgpvopcPrevDisp[ENHN_LAYER] = NULL;

		for(iRefFrame = m_iFirstFrame; iRefFrame <= m_iLastFrame; iRefFrame += iDT)
		{
			// encode initial I frame or non-coded sequence
			if(rgpvoenc [BASE_LAYER] -> skipTest(iRefFrame,IVOP)) // rate control
				continue;

			//encode GOV header added by SONY 980212
			// moved down slightly by swinder 980219
			//CAUTION:I don't know how GOV header is encoded in sprite mode
			// re-done by swinder 980511
			// gov header is output every n output frames, where n is iGOVperiod
			if (volmd.iGOVperiod != 0 
				&& ((iRefFrame-m_iFirstFrame) % (volmd.iGOVperiod * volmd.iTemporalRate)) == 0)
			{
				rgpvoenc [BASE_LAYER] -> codeGOVHead (iRefFrame - m_iFirstFrame);
				rgpostrm [BASE_LAYER]->write (rgpvoenc [BASE_LAYER]->pOutStream ()->str (),
					rgpvoenc [BASE_LAYER]->pOutStream ()->pcount ());
			}
			//980211

			// first dump any cached frames, otherwise a non coded frame will be out of order
			if(bCachedRefDump && (m_rguiSpriteUsage [iVOrelative] == 0 || m_rguiSpriteUsage [iVOrelative] == 2)) // GMC
			{
				bCachedRefDump = FALSE;
				// last ref frame needs to be output
#ifndef __OUT_ONE_FRAME_

				if ( bCachedRefCoded )
					dumpData (rgpfReconYUV [BASE_LAYER], rgpfReconSeg [BASE_LAYER], 
                    rgpfReconAux [BASE_LAYER], BASE_LAYER,
                    rgpvoenc[BASE_LAYER] ->pvopcRefQLater(), m_rctOrg, volmd,
                    rgpvoenc[BASE_LAYER] ->m_vopmd.bInterlace);
				else
					dumpDataNonCoded(rgpfReconYUV [BASE_LAYER], rgpfReconSeg [BASE_LAYER], 
						rgpfReconAux [BASE_LAYER], BASE_LAYER, m_rctOrg, volmd);

				if (m_rgbSpatialScalability [iVOrelative] && !bTemporalScalability)
					dumpData (rgpfReconYUV [ENHN_LAYER], rgpfReconSeg [ENHN_LAYER],
                    rgpfReconAux [ENHN_LAYER], ENHN_LAYER,
                    rgpvoenc[ENHN_LAYER] ->pvopcRefQLater(), m_rctOrgSpatialEnhn, volmd, 0);
#endif
			}

			int iGOPperiod = (volmd.iPbetweenI + 1) * (volmd.iBbetweenP + 1);
			if (rgpvoenc [BASE_LAYER]->m_uiRateControl >= RC_TM5 && iGOPperiod != 0 
				&& ((iRefFrame-m_iFirstFrame) % (iGOPperiod * volmd.iTemporalRate)) == 0)
			{
				Int nppic, npic = (m_iLastFrame - iRefFrame + 1) / volmd.iTemporalRate;
				if (iRefFrame == m_iFirstFrame) {
					if (npic > (iGOPperiod - volmd.iBbetweenP))
						npic = iGOPperiod - volmd.iBbetweenP;
				} else {
					npic += volmd.iBbetweenP;
					if (npic > iGOPperiod)
						npic = iGOPperiod;
				}
				nppic = (npic + volmd.iBbetweenP) / (volmd.iBbetweenP + 1) - 1;
				rgpvoenc [BASE_LAYER] -> m_tm5rc.tm5rc_init_GOP(nppic, npic - nppic - 1); //  np, nb remain
			}

			// encode non-coded frames or initial IVOPs
			// we always dump these out
//OBSS_SAIT_991015
			if(m_rgbSpatialScalability [iVOrelative] && !bTemporalScalability && (volmd.fAUsage == ONE_BIT))
				bObjectExists = loadDataSpriteCheck (iVOrelative,iRefFrame, pfYuvSrc, pfSegSrcSpatialEnhn, pxlcObjColor, rgpvoenc [BASE_LAYER]->m_pvopcOrig, volmd, volmd_enhn);
			else
//~OBSS_SAIT_991015
			bObjectExists = loadDataSpriteCheck (iVOrelative,iRefFrame, pfYuvSrc, pfSegSrc, ppfAuxSrc, pxlcObjColor, rgpvoenc [BASE_LAYER]->m_pvopcOrig, volmd);
			encodeVideoObject(bObjectExists, bObjectExists, iRefFrame, IVOP, DUMP_CURR,
							  iVO, iVOrelative, BASE_LAYER, 
							  pfYuvSrc,pfSegSrc,ppfAuxSrc,
                rgpfReconYUV,rgpfReconSeg,rgpfReconAux,
							  pxlcObjColor, rgpvoenc, volmd, rgpostrm);

			if (m_rgbSpatialScalability [iVOrelative] && !bTemporalScalability ) { // modified by Sharp (98/2/12)
				pvopcBaseQuant = rgpvoenc [BASE_LAYER]->pvopcReconCurr ();
//OBSS_SAIT_991015
				encodeVideoObject (bObjectExists, bObjectExists, iRefFrame, PVOP, DUMP_CURR,
								   iVO, iVOrelative, ENHN_LAYER,
								   pfYuvSrcSpatialEnhn, pfSegSrcSpatialEnhn, /*NULL*/ppfAuxSrc,		//OBSSFIX_MAC
                   rgpfReconYUV, rgpfReconSeg, /*NULL*/rgpfReconAux,
								   pxlcObjColor, rgpvoenc, volmd, rgpostrm,
								   pvopcBaseQuant);
//~OBSS_SAIT_991015
			}
// begin: added by Sharp (98/2/12)
				else if (m_rgbSpatialScalability [iVOrelative] && bTemporalScalability)
					pBufP2->getBuf( rgpvoenc[BASE_LAYER] );
// end: added by Sharp (98/2/12)

			// go to next frame if this was not coded or we are just coding sprites
			if(!bObjectExists)
				continue; 

			// we dumped first frame so rest must be delayed by one for re-order
			iPCount = volmd.iPbetweenI;			
			Int iWaitInterval = 0;

			while (TRUE) {
				// search for next reference frame
				Int iSearchFrame;
				for(iSearchFrame = iRefFrame + iDT * iRefInterval + iWaitInterval;
						iSearchFrame > iRefFrame; iSearchFrame -= iDT)
					if(iSearchFrame <= m_iLastFrame)
					{
//OBSS_SAIT_991015
						if(m_rgbSpatialScalability [iVOrelative] && !bTemporalScalability && (volmd.fAUsage == ONE_BIT))
							bObjectExists = loadDataSpriteCheck(iVOrelative,iSearchFrame, pfYuvSrc, pfSegSrcSpatialEnhn, pxlcObjColor, rgpvoenc [BASE_LAYER]->m_pvopcOrig, volmd,volmd_enhn);
						else
//~OBSS_SAIT_991015
						bObjectExists = loadDataSpriteCheck(iVOrelative,iSearchFrame, pfYuvSrc, pfSegSrc, ppfAuxSrc, pxlcObjColor, rgpvoenc [BASE_LAYER]->m_pvopcOrig, volmd);
						break;  // found a suitable reference frame
						// may not be coded
					}

				if(iSearchFrame==iRefFrame)
					break;

				if (rgpvoenc [BASE_LAYER] -> skipTest(iSearchFrame,iPCount ? PVOP : IVOP)) // rate control
				{
					// too early! need to wait a frame
					iWaitInterval += iDT;
					continue;
				}
				iWaitInterval = 0;
				CVOPU8YUVBA* pvopcBasePVOPQuant;

// begin: added by Sharp (98/2/12)
				if ( bTemporalScalability )
					if ( pBufP2 -> m_bCodedFutureRef == 1 ) // added by Sharp (99/1/28)
					pBufP1->copyBuf ( *pBufP2 );
// end: added by Sharp (98/2/12)
				// encode the next reference frame
				Bool bCachedRefDumpSaveForSpatialScalability = bCachedRefDump;
				if(iPCount==0)
				{
					//added to encode GOV header by SONY 980212
					// moved to here by swinder 980219
					//CAUTION:I don't know how GOV header is encoded in sprite mode - SONY
					// update by swinder 980511
					if (volmd.iGOVperiod != 0 
						&& ((iSearchFrame-m_iFirstFrame) % (volmd.iGOVperiod * volmd.iTemporalRate)) == 0)
					{
//modified by SONY (98/03/30)

⌨️ 快捷键说明

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