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

📄 sesenc.cpp

📁 jpeg and mpeg 编解码技术源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				}
// begin: added by Sharp (98/2/12)
				else if ( m_rgbSpatialScalability [iVOrelative] && bTemporalScalability ){  // loop for TPS enhancement layer
					rgpvoenc [ENHN_LAYER] -> m_iBCount = 0;
					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)
		{
			// last ref frame needs to be output
#ifndef __OUT_ONE_FRAME_
		if ( bCachedRefCoded )
				dumpData (rgpfReconYUV [BASE_LAYER], rgpfReconSeg [BASE_LAYER], rgpvoenc[BASE_LAYER] ->pvopcRefQLater(), m_rctOrg, volmd);
		else
				dumpNonCodedFrame(rgpfReconYUV [BASE_LAYER], rgpfReconSeg [BASE_LAYER], m_rctOrg, volmd.nBits);

// begin deleted by sony
//			if (m_rgbSpatialScalability [iVOrelative] && !bTemporalScalability)
//				dumpData (rgpfReconYUV [BASE_LAYER], rgpfReconSeg [BASE_LAYER], rgpvoenc[BASE_LAYER] ->pvopcRefQLater(), m_rctOrgSpatialEnhn, volmd);
// end deleted by sony
			bCachedRefDump = FALSE; // added by Sharp (98/11/11)
// begin: deleted by Sharp (98/11/11)
//#else
//				dumpDataOneFrame (iFrame, iVO, rgpvoenc[BASE_LAYER] ->pvopcRefQLater(), volmd); // save one frame
//				if (m_rgbSpatialScalability [iVOrelative] && !bTemporalScalability)
//					dumpDataOneFrame (iFrame, iVO, rgpvoenc[ENHN_LAYER] ->pvopcRefQLater(), volmd); // save one frame
// end: deleted by Sharp (98/11/11)
#endif
		}

		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]);
		}
		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];
		}
	}
}

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

Void CSessionEncoder::encodeVideoObject(Bool bObjectExists,
										Bool bPrevObjectExists,
										Int iFrame,
										VOPpredType predType,
										Int iDumpMode,
										Int iVO,
										Int iVOrelative,
										Int iLayer,
										FILE* pfYuvSrc,
										FILE* pfSegSrc,
										FILE* rgpfReconYUV[],
										FILE* rgpfReconSeg[],
										PixelC pxlcObjColor,
										CVideoObjectEncoder** rgpvoenc,
										const VOLMode& volmd,
										ofstream* rgpostrm[],
										const CVOPU8YUVBA* pvopcBaseQuant)
{
	CRct rctOrg;
	if (m_rguiSpriteUsage [iVOrelative] == 0) {
        rctOrg = m_rctOrg;
		if (iLayer == ENHN_LAYER) { 
			rctOrg = m_rctOrgSpatialEnhn;
			if((rgpvoenc [iLayer] -> skipTest((Time)iFrame,predType)))  // rate control
				return;
			bObjectExists = loadData(iFrame, pfYuvSrc, pfSegSrc, pxlcObjColor, rgpvoenc [iLayer]->m_pvopcOrig, rctOrg, volmd);
		}
		rgpvoenc [iLayer] -> encode (bObjectExists, (Time) (iFrame - m_iFirstFrame), predType, pvopcBaseQuant);
		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] != 0)
	{
		if (bObjectExists) 
				dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpvoenc[iLayer] ->pvopcReconCurr(), rctOrg, volmd);
		else
			dumpNonCodedFrame(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rctOrg, volmd.nBits);
	}
	else if(iDumpMode==DUMP_PREV){ // dump previous reference frame
		if ( bPrevObjectExists )
				dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpvoenc[iLayer] ->pvopcRefQPrev(), rctOrg, volmd);
		else
				dumpNonCodedFrame(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rctOrg, volmd.nBits);
	}
#else
	if (bObjectExists) 
		dumpDataOneFrame (iFrame, iVO, rgpvoenc[iLayer] ->pvopcReconCurr(), volmd); // save one frame
	else
		dumpNonCodedFrame(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rctOrg, volmd.nBits);
#endif
// end: added by Sharp (99/1/28)

// begin: deleted by Sharp (99/1/28)
/*
	if (bObjectExists)	{
// begin: modified by Sharp (98/11/11)
// begin: modification by Sharp (98/2/12)
#ifndef __OUT_ONE_FRAME_
		if(iDumpMode==DUMP_CURR || m_rguiSpriteUsage [iVOrelative] != 0)
		{
			// dump current reconstructed frame
			dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpvoenc[iLayer] ->pvopcReconCurr(), rctOrg, volmd);
		}
		else if(iDumpMode==DUMP_PREV) // dump previous reference frame
		{
			dumpData (rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rgpvoenc[iLayer] ->pvopcRefQPrev(), rctOrg, volmd);
		}
// end: modification by Sharp (98/2/12)
#else
			dumpDataOneFrame (iFrame, iVO, rgpvoenc[iLayer] ->pvopcReconCurr(), volmd); // save one frame
#endif
// end: modified by Sharp (98/11/11)
	}
#ifndef __OUT_ONE_FRAME_ // added by Sharp (98/11/11)
	else
		dumpNonCodedFrame(rgpfReconYUV [iLayer], rgpfReconSeg [iLayer], rctOrg, volmd.nBits);
#endif // added by Sharp (98/11/11)
*/
// end: deleted 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)
			fprintf (stderr, "Unexpected end of file\n");
		ppxlcY += iYFrmWidth;
	}

	for (y = 0; y < iUVDataHeight; y++) {
		Int size = (Int) fread (ppxlcU, sizeof (U8), m_rctOrg.width / 2, pf);
		if (size == 0)
			fprintf (stderr, "Unexpected end of file\n");
		ppxlcU += iUvFrmWidth;
	}

	for (y = 0; y < iUVDataHeight; y++) {
		Int size = (Int) fread (ppxlcV, sizeof (U8), m_rctOrg.width / 2, pf);
		if (size == 0)
			fprintf (stderr, "Unexpected end of file\n");
		ppxlcV += iUvFrmWidth;
	}

	PixelC* ppxlcBY = (PixelC*) pvopcDst->pixelsBY () + nSkipYPixel;
	//Int iObjectExist = 0;
	if ((bAUsage == ONE_BIT) && (pvopcDst -> fAUsage () == ONE_BIT)) { // load Alpha
		//binary
		for (CoordI y = 0; y < iYDataHeight; y++) {
			Int size = (Int) fread (ppxlcBY, sizeof (U8), m_rctOrg.width, pf);
			if (size == 0)
				fprintf (stderr, "Unexpected end of file\n");
			ppxlcBY += iYFrmWidth;
		}
		((CU8Image*) pvopcDst->getPlane (BUV_PLANE))->decimateBinaryShapeFrom (*(pvopcDst->getPlane (BY_PLANE)));
	}
#ifdef _FOR_GSSP_
	else if ((bAUsage == EIGHT_BIT) && (pvopcDst -> fAUsage () == EIGHT_BIT)) { // load Alpha
		//grayscale alpha
		PixelC* ppxlcA = (PixelC*) pvopcDst->pixelsA () + nSkipYPixel;
		for (CoordI y = 0; y < iYDataHeight; y++) {
			for (CoordI x = 0; x < m_rctOrg.width; x++) {
				PixelC pxlcCurr = getc (pf);
				ppxlcA [x]  = (pxlcCurr >= GRAY_ALPHA_THRESHOLD) ? pxlcCurr : transpValue;
				ppxlcBY [x] = (pxlcCurr >= GRAY_ALPHA_THRESHOLD) ? opaqueValue : transpValue;
			}
			ppxlcBY += iYFrmWidth;
			ppxlcA  += iYFrmWidth;
		}
		((CU8Image*) pvopcDst->getPlane (BUV_PLANE))->decimateBinaryShapeFrom (*(pvopcDst->getPlane (BY_PLANE)));
	}
#endif
}

Void CSessionEncoder::getInputFiles (FILE*& pfYuvSrc, FILE*& pfAlpSrc, FILE*& pfYuvSrcSpatialEnhn,
									 FILE* rgpfReconYUV [], FILE* rgpfReconSeg [], 
									 ofstream* rgpostrm [], ofstream* rgpostrmTrace [],
									 PixelC& pxlcObjColor, Int iobj, const VOLMode& volmd, const VOLMode& volmd_enhn)
{
	static Char pchYUV [100], pchSeg [100], pchCmp [100], pchTrace [100];

	//output files
	createCmpDir (iobj);
	sprintf (pchCmp, SUB_CMPFILE, m_pchOutStrFiles, iobj, m_pchPrefix);
	sprintf (pchTrace, SUB_TRCFILE, m_pchOutStrFiles, iobj, m_pchPrefix);
	rgpostrm [BASE_LAYER] = new ofstream (pchCmp, IOS_BINARY | ios::out);	
	rgpostrmTrace [BASE_LAYER] = NULL;
	if (volmd.bTrace)
		rgpostrmTrace [BASE_LAYER] = new ofstream (pchTrace);

	// prepare for the reconstructed files
	createReconDir (iobj); // create a directory for the reconstructed YUV in case it doesn't exist
	sprintf (pchYUV, SUB_YUVFILE, m_pchReconYUVDir, iobj, m_pchPrefix);
	sprintf (pchSeg, SUB_SEGFILE, m_pchReconYUVDir, iobj, m_pchPrefix);

⌨️ 快捷键说明

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