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

📄 sesenc.cpp

📁 《Visual C++小波变换技术与工程实践》靳济芳编著的光盘程序。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					for (Int iEFrame = iSearchFrame - iDT + iDT_enhn; iEFrame < iSearchFrame; iEFrame += iDT_enhn ) {

					updateRefForTPS( rgpvoenc[ENHN_LAYER], pBufP1, pBufP2, pBufB1, pBufB2, pBufE,
						0, iVOrelative, iEcount, iBFrame-iDT+iDT_enhn, iEFrame, 0 );

					iEcount++;
					encodeEnhanceVideoObject(bObjectExists, iEFrame, rgpvoenc[ENHN_LAYER]->m_vopmd.vopPredType, DUMP_CURR,
						iVO,iVOrelative,pfYuvSrc,pfSegSrc,rgpfReconYUV,rgpfReconSeg,
						pxlcObjColor,rgpvoenc[ENHN_LAYER],volmd, volmd_enhn, iSearchFrame - iDT + iDT_enhn, rgpostrm,
						*pBufP1, *pBufP2, *pBufB1, *pBufB2, *pBufE
						);
				}
				pBufB1->dispose();
				}
// end: added by Sharp (98/2/12)
				// move onwards
				iRefFrame = iSearchFrame;
			}
		}

		if(bCachedRefDump && (m_rguiSpriteUsage [iVOrelative] == 0 || m_rguiSpriteUsage [iVOrelative] == 2)) // GMC
		{
			// 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);
			
			bCachedRefDump = FALSE; // added by Sharp (98/11/11)
#endif
		}

// NEWPRED
		if (m_rgvolmd [BASE_LAYER][iVOrelative].bNewpredEnable) 
			delete g_pNewPredEnc;
// ~NEWPRED

		cout << "\nBASE VOL " << iVO << "\n";
		CStatistics sts = rgpvoenc [BASE_LAYER] -> statVOL ();
#ifdef __TRACE_AND_STATS_
		sts.print (TRUE); // dumping statistics
#endif // __TRACE_AND_STATS_
		delete rgpvoenc [BASE_LAYER];
		fclose (rgpfReconYUV [BASE_LAYER]);
		if (m_rgvolmd [BASE_LAYER] [iVOrelative].fAUsage != RECTANGLE)	{
			fclose (rgpfReconSeg [BASE_LAYER]);
		}
		if (volmd.fAUsage == EIGHT_BIT) {   // MAC (SB) 24-Nov-99
			for(Int iAuxComp=0; iAuxComp<volmd.iAuxCompCount; iAuxComp++) {
				if(volmd.iAlphaShapeExtension >= 0)
					fclose (ppfAuxSrc[iAuxComp]);
				fclose (rgpfReconAux[0][iAuxComp]);
				//fclose (rgpfReconAux[1][iAuxComp]); //not needed
			}
		}
		delete ppfAuxSrc;
		delete rgpfReconAux[0];
		delete rgpfReconAux[1];
		delete rgpostrm [BASE_LAYER];
		delete rgpostrmTrace [BASE_LAYER];

		if (m_rgbSpatialScalability [iVOrelative] == TRUE)	{
			cout << "\nEHNANCED VOL " << iVO << "\n";
			sts = rgpvoenc [ENHN_LAYER] -> statVOL ();
#ifdef __TRACE_AND_STATS_
			sts.print (TRUE); // dumping statistics
#endif // __TRACE_AND_STATS_
			delete rgpvoenc [ENHN_LAYER];
			fclose (rgpfReconYUV [ENHN_LAYER]);
			if (m_rgvolmd [BASE_LAYER] [iVOrelative].fAUsage != RECTANGLE)	{
				fclose (rgpfReconSeg [ENHN_LAYER]);
			}
			delete rgpostrm [ENHN_LAYER];
			delete rgpostrmTrace [ENHN_LAYER];
		}
	} // VO loop
}

Bool CSessionEncoder::loadDataSpriteCheck(UInt iVOrelative,UInt iFrame, FILE* pfYuvSrc, FILE* pfSegSrc, FILE** ppfAuxSrc, PixelC pxlcObjColor, CVOPU8YUVBA* pvopcDst, const VOLMode& volmd)
{
	Bool bObjectExists = TRUE;
	if(m_rguiSpriteUsage [iVOrelative] == 0 || m_rguiSpriteUsage [iVOrelative] == 2) // GMC
		bObjectExists = loadData (iFrame,pfYuvSrc,pfSegSrc,ppfAuxSrc,pxlcObjColor, pvopcDst, m_rctOrg, volmd);
	return bObjectExists;
}

//OBSS_SAIT_991015
Bool CSessionEncoder::loadDataSpriteCheck(UInt iVOrelative,UInt iFrame, FILE* pfYuvSrc, FILE* pfSegSrc, PixelC pxlcObjColor, CVOPU8YUVBA* pvopcDst, const VOLMode& volmd,const VOLMode& volmd_enhn)
{
	Bool bObjectExists = TRUE;
	if(m_rguiSpriteUsage [iVOrelative] == 0)
		bObjectExists = loadData (iFrame,pfYuvSrc,pfSegSrc, pxlcObjColor, pvopcDst, m_rctOrg, volmd, volmd_enhn);
	return bObjectExists;
}
//~OBSS_SAIT_991015

Void CSessionEncoder::encodeVideoObject(Bool bObjectExists,
										Bool bPrevObjectExists,
										Int iFrame,
										VOPpredType predType,
										Int iDumpMode,
										Int iVO,
										Int iVOrelative,
										Int iLayer,
										FILE* pfYuvSrc,
										FILE* pfSegSrc,
                    FILE** ppfAuxSrc,
										FILE* rgpfReconYUV[],
										FILE* rgpfReconSeg[],
                    FILE** rgpfReconAux[2],
										PixelC pxlcObjColor,
										CVideoObjectEncoder** rgpvoenc,
										const VOLMode& volmd,
										ofstream* rgpostrm[],
										const CVOPU8YUVBA* pvopcBaseQuant)
{
	CRct rctOrg;
	Bool BGComposition = FALSE;	//OBSS_SAIT_991015		//for OBSS partial enhancement mode
	if (m_rguiSpriteUsage [iVOrelative] == 0 || m_rguiSpriteUsage [iVOrelative] == 2) { // GMC
        rctOrg = m_rctOrg;
		if (iLayer == ENHN_LAYER) { 
			rctOrg = m_rctOrgSpatialEnhn;
			if((rgpvoenc [iLayer] -> skipTest((Time)iFrame,predType)))  // rate control
				return;
//OBSSFIX_MODE3
			if(iLayer == ENHN_LAYER && rgpvoenc[iLayer]->m_volmd.bSpatialScalability && rgpvoenc[iLayer]->m_volmd.iHierarchyType == 0)
				bObjectExists = loadData(iFrame, pfYuvSrc, pfSegSrc, ppfAuxSrc, pxlcObjColor, rgpvoenc [iLayer]->m_pvopcOrig, rctOrg, rgpvoenc[iLayer]->m_volmd);
			else
				bObjectExists = loadData(iFrame, pfYuvSrc, pfSegSrc, ppfAuxSrc, pxlcObjColor, rgpvoenc [iLayer]->m_pvopcOrig, rctOrg, volmd);
//			bObjectExists = loadData(iFrame, pfYuvSrc, pfSegSrc, ppfAuxSrc, pxlcObjColor, rgpvoenc [iLayer]->m_pvopcOrig, rctOrg, volmd);
//~OBSSFIX_MODE3
//OBSS_SAIT_991015
			if(volmd.bSpatialScalability) {
				rgpvoenc[ENHN_LAYER] -> m_rgBaseshpmd = rgpvoenc[BASE_LAYER] -> m_rgBaseshpmd;
				rgpvoenc[ENHN_LAYER] -> m_rgmvBaseBY = rgpvoenc[BASE_LAYER] -> m_rgmvBaseBY;
				rgpvoenc[ENHN_LAYER] -> m_iNumMBBaseXRef = rgpvoenc[BASE_LAYER] -> m_iNumMBX;
				rgpvoenc[ENHN_LAYER] -> m_iNumMBBaseYRef = rgpvoenc[BASE_LAYER] -> m_iNumMBY;
				rgpvoenc[ENHN_LAYER] -> m_rctBase = rgpvoenc[BASE_LAYER] -> m_rctBase;
				rgpvoenc[ENHN_LAYER] -> m_bCodedBaseRef = rgpvoenc[BASE_LAYER] -> m_bCodedFutureRef;	
			}
//~OBSS_SAIT_991015
		}
		rgpvoenc [iLayer] -> encode (bObjectExists, (Time) (iFrame - m_iFirstFrame), predType, pvopcBaseQuant);
//OBSS_SAIT_991015
		// for Spatial Scalability composition(OBSS partial enhancement mode)
//OBSSFIX_MODE3
		if(iLayer == ENHN_LAYER && rgpvoenc[ENHN_LAYER] -> m_volmd.iEnhnType == 1 ) {
//		if(iLayer == ENHN_LAYER && rgpvoenc[ENHN_LAYER] -> m_volmd.iEnhnTypeSpatial == 1 && rgpvoenc[ENHN_LAYER] -> m_volmd.iuseRefShape == 0) {
//~OBSSFIX_MODE3
			if (predType != BVOP)
				BGComposition = rgpvoenc[ENHN_LAYER] -> BackgroundComposition(rctOrg.width, rctOrg.height (),
					iFrame, rgpvoenc[ENHN_LAYER] ->m_pvopcRefQ0, m_pchReconYUVDir, iVO, m_pchPrefix,
					rgpfReconYUV[iLayer],rgpfReconSeg[iLayer]); 
			else 
				BGComposition = rgpvoenc[ENHN_LAYER] -> BackgroundComposition(rctOrg.width, rctOrg.height (),
					iFrame, rgpvoenc[ENHN_LAYER]->m_pvopcRefQ1, m_pchReconYUVDir, iVO, m_pchPrefix,
					rgpfReconYUV[iLayer],rgpfReconSeg[iLayer]); 
		}
//~OBSS_SAIT_991015
		if (iLayer == ENHN_LAYER)
			rgpvoenc [iLayer]-> swapSpatialScalabilityBVOP ();
	}
	else {
        rctOrg = m_rctFrame;
		CRct rctWarp = (m_rgNumOfPnts [iVO - m_iFirstVO] > 0)? 
                        findBoundBoxInAlpha (iFrame, iVO) : m_rctOrg;
		rgpvoenc [BASE_LAYER]->encodeSptTrajectory (iFrame, m_pppstDst [iVO - m_iFirstVO] [iFrame - m_iFirstFrame], rctWarp);
		bObjectExists = TRUE;
	}
	//dump the output

// begin: added by Sharp (99/1/28)
#ifndef __OUT_ONE_FRAME_
	if(iDumpMode==DUMP_CURR || m_rguiSpriteUsage [iVOrelative] == 1) // GMC
	{
//OBSS_SAIT_991015	//for OBSS partial enhancement mode
		if (bObjectExists) {
//OBSSFIX_MODE3
			if(!(iLayer == ENHN_LAYER && rgpvoenc[ENHN_LAYER] -> m_volmd.iEnhnType == 1 && BGComposition)) 
				dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpfReconAux [iLayer], iLayer, rgpvoenc[iLayer] ->pvopcReconCurr(), rctOrg, rgpvoenc[iLayer]->m_volmd, rgpvoenc[iLayer] ->m_vopmd.bInterlace);
//			if(!(iLayer == ENHN_LAYER && rgpvoenc[ENHN_LAYER] -> m_volmd.iEnhnTypeSpatial == 1 && rgpvoenc[ENHN_LAYER] -> m_volmd.iuseRefShape == 0 && BGComposition)) 
//				dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpfReconAux [iLayer], iLayer, rgpvoenc[iLayer] ->pvopcReconCurr(), rctOrg, volmd);
//~OBSSFIX_MODE3
		}
//~OBSS_SAIT_991015
		else
			dumpDataNonCoded(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer],
				rgpfReconAux [iLayer], iLayer, rctOrg, volmd);
	}
	else if(iDumpMode==DUMP_PREV){ // dump previous reference frame
		if ( bPrevObjectExists )
				dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpfReconAux [iLayer], iLayer, rgpvoenc[iLayer] ->pvopcRefQPrev(), rctOrg, volmd, rgpvoenc[iLayer] ->m_vopmd.bInterlace);
		else
				dumpDataNonCoded(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer],
					rgpfReconAux [iLayer], iLayer, rctOrg, volmd);
	}
#else
	if (bObjectExists) 
		dumpDataOneFrame (iFrame, iVO, rgpvoenc[iLayer] ->pvopcReconCurr(), volmd); // save one frame
	else
		dumpDataNonCoded(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer],
			rgpfReconAux [iLayer], iLayer, rctOrg, volmd);
#endif
// end: added by Sharp (99/1/28)

	rgpostrm [iLayer]->write (rgpvoenc [iLayer]->pOutStream ()->str (),
		rgpvoenc [iLayer]->pOutStream ()->pcount ());
}

Void CSessionEncoder::readPntFile (UInt iobj)
{
	Char pchtmp [100];
	sprintf (pchtmp, SUB_PNTFILE, m_pchSptPntDir, iobj, m_pchPrefix);
	FILE* pfPnt = fopen (pchtmp, "r");
	if(pfPnt==NULL)
		fatal_error("Can't open sprite point file");

	Int numPnt;
	Int iVOidx = iobj - m_iFirstVO;
	fscanf (pfPnt, "%d", &numPnt);
	assert (numPnt == m_rgNumOfPnts [iVOidx]);
	Int ifrF;
	Double dblX, dblY;
	for (Int ip = 0; ip < numPnt; ip++)
		fscanf (pfPnt, "%lf%lf", &m_ppstSrc [iVOidx] [ip].x, &m_ppstSrc [iVOidx] [ip].y); // not used
	while (fscanf (pfPnt, "%d", &ifrF) != EOF) {
		if ((ifrF >= m_iFirstFrame) && (ifrF <= m_iLastFrame)) {
			for (Int ip = 0; ip < numPnt; ip++)	{
				fscanf (pfPnt, "%lf %lf", &dblX, &dblY);
				Int iFrmIndex = ifrF - m_iFirstFrame;
				if (iFrmIndex % (m_rgvolmd [BASE_LAYER] [iVOidx].iTemporalRate) == 0)	{
					m_pppstDst [iVOidx] [iFrmIndex] [ip].x = dblX;
					m_pppstDst [iVOidx] [iFrmIndex] [ip].y = dblY;
				}
			}
		} else {
			for (Int ip = 0; ip < numPnt; ip++)	{
				fscanf (pfPnt, "%lf %lf", &dblX, &dblY);
			}
		}
	}
}

Void CSessionEncoder::loadSpt (UInt iobj, CVOPU8YUVBA* pvopcDst)
{
	Char pchSpt [100];
	sprintf (pchSpt, SUB_VDLFILE, m_pchSptDir, iobj, m_pchPrefix);

	FILE* pf = fopen (pchSpt, "rb");
	// read overhead
	Int c0 = getc (pf);
	Int c1 = getc (pf);
	Int c2 = getc (pf);
	assert (c0 == 'S' && (c1 == 'P' || c2 == 'T') );
	CRct rctSpt;
	Bool bAUsage;
	fread (&rctSpt.left, sizeof (CoordI), 1, pf);
	fread (&rctSpt.top, sizeof (CoordI), 1, pf);
	fread (&rctSpt.right, sizeof (CoordI), 1, pf);
	fread (&rctSpt.bottom, sizeof (CoordI), 1, pf);
	fread (&bAUsage, sizeof (Int), 1, pf);
#ifndef _FOR_GSSP_
	assert (bAUsage != EIGHT_BIT); // sprite with Alpha channel is not supported at this moment
#endif
	Int iYDataHeight = m_rctOrg.height ();
	Int iUVDataHeight = m_rctOrg.height () / 2;
	Int iYFrmWidth = pvopcDst->whereY ().width;
	Int iUvFrmWidth = pvopcDst->whereUV ().width;
	Int nSkipYPixel = iYFrmWidth * EXPANDY_REF_FRAME + EXPANDY_REF_FRAME;
	Int nSkipUvPixel = iUvFrmWidth * EXPANDUV_REF_FRAME + EXPANDUV_REF_FRAME;
	PixelC* ppxlcY = (PixelC*) pvopcDst->pixelsY () + nSkipYPixel;
	PixelC* ppxlcU = (PixelC*) pvopcDst->pixelsU () + nSkipUvPixel;
	PixelC* ppxlcV = (PixelC*) pvopcDst->pixelsV () + nSkipUvPixel;
	
	CoordI y;
	for (y = 0; y < iYDataHeight; y++) {
		Int size = (Int) fread (ppxlcY, sizeof (U8), m_rctOrg.width, pf);
		if (size == 0)
		{
			fprin

⌨️ 快捷键说明

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