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

📄 tps_bfshape.cpp

📁 网络MPEG4IP流媒体开发源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************This software module was originally developed by 	Hiroyuki Katata (katata@imgsl.mkhar.sharp.co.jp), Sharp Corporation	Norio Ito (norio@imgsl.mkhar.sharp.co.jp), Sharp Corporation	Shuichi Watanabe (watanabe@imgsl.mkhar.sharp.co.jp), Sharp Corporation	(date: August, 1997)in the course of development of the MPEG-4 Video (ISO/IEC 14496-2). Thissoftware module is an implementation of a part of one or more MPEG-4 Videotools as specified by the MPEG-4 Video. ISO/IEC gives users of the MPEG-4Video free license to this software module or modifications thereof for usein hardware or software products claiming conformance to the MPEG-4Video. Those intending to use this software module in hardware or softwareproducts are advised that its use may infringe existing patents. Theoriginal developer of this software module and his/her company, thesubsequent editors and their companies, and ISO/IEC have no liability foruse of this software module or modifications thereof in animplementation. Copyright is not released for non MPEG-4 Video conformingproducts. Sharp retains full right to use the code for his/her ownpurpose, assign or donate the code to a third party and to inhibit thirdparties from using the code for non <MPEG standard> conformingproducts. This copyright notice must be included in all copies or derivativeworks.Copyright (c) 1997.Module Name:	tps_bfshape.cppAbstract:	set volmd, vopmd for backward/forward shape coding	 (for Object based Temporal Scalability)Revision History:*************************************************************************/#include "typeapi.h"#include "entropy/entropy.hpp"#include "entropy/huffman.hpp"#include "entropy/bitstrm.hpp"#include "global.hpp"#include "mode.hpp"#include "codehead.h"#include "cae.h"#include "vopses.hpp"#include "encoder/vopseenc.hpp"#include "tps_enhcbuf.hpp"#ifdef __MFC_#ifdef _DEBUG#undef THIS_FILEstatic char BASED_CODE THIS_FILE[] = __FILE__;#endif#define new DEBUG_NEW				   #endif // __MFC_Int QMatrix [BLOCK_SQUARE_SIZE] = {	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16,	16, 16, 16, 16, 16, 16, 16, 16};Void set_modes(VOLMode* volmd, VOPMode* vopmd) {    ///// set VOL modes	volmd->volType			= (VOLtype) BASE_LAYER; // should not be used.	volmd->fAUsage			= ONE_BIT;	volmd->bShapeOnly		= FALSE; // should be changed to TRUE after checked.//	volmd->iBinaryAlphaTH		= rgiBinaryAlphaTH [iVO] * 16;  //magic no. from the vm	volmd->bNoCrChange		= TRUE; // mb level binary alpha size conversion disable	volmd->bOriginalForME		= TRUE;	volmd->bAdvPredDisable		= TRUE;// Modified by Toshiba (98-04-07) //	volmd->bErrorResilientDisable 	= TRUE;// End Toshiba	volmd->fQuantizer		= Q_H263; // should not be used. H.263/MPEG quantizer.	volmd->bNoGrayQuantUpdate 	= FALSE; // should not be used.	volmd->bLoadIntraMatrix		= FALSE; // should not be used.	volmd->bLoadInterMatrix		= FALSE; // should not be used.	volmd->bLoadIntraMatrixAlpha  = FALSE; // should not be used.	volmd->bLoadInterMatrixAlpha  = FALSE; // should not be used.	volmd->bVPBitTh = -1; // added by Sharp (98/4/13)	memcpy (volmd->rgiIntraQuantizerMatrix, QMatrix, BLOCK_SQUARE_SIZE * sizeof (Int));//	memcpy (volmd->rgiInterQuantizerMatrix,		rgppiInterQuantizerMatrix [iLayer][iVO], BLOCK_SQUARE_SIZE * sizeof (Int));//	memcpy (volmd->rgiIntraQuantizerMatrixAlpha,	rgppiIntraQuantizerMatrixAlpha [iLayer][iVO], BLOCK_SQUARE_SIZE * sizeof (Int));//	memcpy (volmd->rgiInterQuantizerMatrixAlpha,	rgppiInterQuantizerMatrixAlpha [iLayer][iVO], BLOCK_SQUARE_SIZE * sizeof (Int));	volmd->bDeblockFilterDisable	= FALSE; // should not be used.	volmd->fEntropyType		= huffman; // huffman VLC for texture ? ... may not be used //	volmd->iPeriodOfIVOP	= (rgiNumOfBbetweenPVOP [iVO] + 1) * (rgiNumOfPbetweenIVOP [iVO] + 1);	//in temporally sumsampled domain//	volmd->iPeriodOfPVOP	= rgiNumOfBbetweenPVOP [iVO] + 1;			//in temporally sumsampled domain//	volmd->iTemporalRate	= rgiTemporalRate [iVO];//	volmd->iClockRate		= SOURCE_FRAME_RATE / volmd->iTemporalRate;	//default to frame per second	volmd->bDumpMB			= FALSE; // should not be used.	volmd->bTrace			= FALSE; // if changed to TRUE, Trace files for backward/forward shape should be prepared like in getInputFiles() and CVideoObjectEncoderTPS().    ///// set VOP modes//	vopmd->iSearchRangeForward	= rguiSearchRange [iLayer][iVO];//	vopmd->iSearchRangeBackward	= rguiSearchRange [iLayer][iVO];// Q-step sizes	vopmd->intStepI			= 10; // set temporalily, should not be used after binary_shape_only mode will be integrated.//	vopmd->intStep			= rgiStep [iLayer][iVO];//	vopmd->intStepIAlpha		= rgiStepIAlpha [iLayer][iVO];//	vopmd->intStepAlpha		= rgiStepAlpha [iLayer][iVO];//	vopmd->intDBQuant		= rgiStepBCode [iLayer][iVO];	vopmd->iIntraDcSwitchThr        = 0; // threhold to code Intra DC as AC coefs. 0=never do that	vopmd->vopPredType      = IVOP;}Void write420_sep(Int num, char *name, PixelC* destY, PixelC* destU, PixelC* destV, Int width, Int height) // modified by Sharp (98/10/26){#ifdef __OUT_ONE_FRAME_  char file[100];#endif  FILE *fp;#ifndef __OUT_ONE_FRAME_  fp = fopen(name, "ab");#else  sprintf(file, "%s%d", name ,num);  fp = fopen(file, "wb");#endif  fwrite(destY, sizeof (PixelC), width*height, fp);  fwrite(destU, sizeof (PixelC), width*height/4, fp);  fwrite(destV, sizeof (PixelC), width*height/4, fp);  fclose(fp);}// begin: added by Sharp (98/10/26)Void write420_jnt(FILE *fp, PixelC* destY, PixelC* destU, PixelC* destV, Int width, Int height){  fwrite(destY, sizeof (PixelC), width*height, fp);  fwrite(destU, sizeof (PixelC), width*height/4, fp);  fwrite(destV, sizeof (PixelC), width*height/4, fp);}// end: added by Sharp (98/10/26)Void write_seg_test(Int num, char *name, PixelC* destY, Int width, Int height){  char file[100];  FILE *fp;  sprintf(file, "%s%d", name ,num);  fp = fopen(file, "a");  fwrite(destY, sizeof (PixelC), width*height, fp);  fclose(fp);}Void bg_comp_each(PixelC* f_curr, PixelC* f_prev, PixelC* f_next, PixelC* mask_curr, PixelC* mask_prev, PixelC* mask_next, Int curr_t, Int prev_t, Int next_t, Int width, Int height, Int CoreMode){  Int i;  PixelC* out_image    = new PixelC [width*height];  PixelC* mask_overlap = new PixelC [width*height];/* NBIT: change unsigned char to PixelC  Void pre_pad(unsigned char *mask, unsigned char *curr, int width, int height);*/  Void pre_pad(PixelC *mask, PixelC *curr, int width, int height);// begin: added by Sharp (98/3/24)	if ( CoreMode ){		for(i=0; i<width*height; i++)			if(mask_curr[i] == 0 )         // should be used after Type 1 is implemented 				f_curr[i] = f_prev[i];	}	else {// end: added by Sharp (98/3/24)  /* ----- put nearest frame ----- */  if( (abs(curr_t-prev_t) > abs(curr_t-next_t) ) && (abs(abs(curr_t-prev_t) - abs(curr_t-next_t) ) < 1 ))    for(i=0; i<width*height; i++)	out_image[i]=f_next[i];  else    for(i=0; i<width*height; i++)	 out_image[i]=f_prev[i];  /* ----- perform background composition ----- */  for(i=0; i<width*height; i++) {    if(mask_prev[i] > 0 && mask_next[i] == 0)	  /* ----- f_next is used ----- */	out_image[i]=f_next[i];    else if(mask_prev[i] == 0 && mask_next[i] > 0)/* ----- f_prev is used ----- */	out_image[i]=f_prev[i];    if(mask_prev[i] > 0 && mask_next[i] > 0)	  /* ----- overlapped area ----- */	mask_overlap[i]=0;    else	mask_overlap[i]=1;  }  pre_pad(mask_overlap, out_image, width, height); /* for padding */  /* ----- overlap current frame to back ground ----- */  for(i=0; i<width*height; i++)    if(mask_curr[i] == 0 )         // should be used after Type 1 is implemented       f_curr[i] = out_image[i];	} // added by Sharp (98/3/24)  delete out_image;  delete mask_overlap;}Void inv_convertYuv(const CVOPU8YUVBA* pvopcSrc, PixelC* destY, PixelC* destU, PixelC* destV, Int width, Int height){    CoordI x, y;    Int Fwidth   = pvopcSrc->whereY ().width;    Int FwidthUV = pvopcSrc->whereUV ().width;    Int nSkipYPixel = Fwidth  * EXPANDY_REF_FRAME  + EXPANDY_REF_FRAME;    Int nSkipUVPixel = FwidthUV * EXPANDUV_REF_FRAME + EXPANDUV_REF_FRAME;    PixelC* ppxlcY = (PixelC*)( (Int)(pvopcSrc->pixelsY ()) + nSkipYPixel );    PixelC* ppxlcU = (PixelC*)( (Int)(pvopcSrc->pixelsU ()) + nSkipUVPixel );    PixelC* ppxlcV = (PixelC*)( (Int)(pvopcSrc->pixelsV ()) + nSkipUVPixel );    PixelC* pdY = destY;    PixelC* pdU = destU;    PixelC* pdV = destV;    PixelC* psY;    PixelC* psU;    PixelC* psV;	  // convert    for (y = 0; y < height; y++) {      psY = ppxlcY;      for (x = 0; x < width; x++) {	*psY = *pdY;	pdY++;	psY++;      }      ppxlcY += Fwidth;    }    for (y = 0; y < height/2; y++) {      psU = ppxlcU;      for (x = 0; x < width/2; x++) {	*psU = *pdU;	pdU++;	psU++;      }      ppxlcU += FwidthUV;    }    for (y = 0; y < height/2; y++) {      psV = ppxlcV;      for (x = 0; x < width/2; x++) {	*psV = *pdV;	pdV++;	psV++;

⌨️ 快捷键说明

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