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

📄 vtcenc.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************//*   MPEG4 Visual Texture Coding (VTC) Mode Software                        *//*                                                                          *//*   This software was jointly developed by the following participants:     *//*                                                                          *//*   Single-quant,  multi-quant and flow control                            *//*   are provided by  Sarnoff Corporation                                   *//*     Iraj Sodagar   (iraj@sarnoff.com)                                    *//*     Hung-Ju Lee    (hjlee@sarnoff.com)                                   *//*     Paul Hatrack   (hatrack@sarnoff.com)                                 *//*     Shipeng Li     (shipeng@sarnoff.com)                                 *//*     Bing-Bing Chai (bchai@sarnoff.com)                                   *//*     B.S. Srinivas  (bsrinivas@sarnoff.com)                               *//*                                                                          *//*   Bi-level is provided by Texas Instruments                              *//*     Jie Liang      (liang@ti.com)                                        *//*                                                                          *//*   Shape Coding is provided by  OKI Electric Industry Co., Ltd.           *//*     Zhixiong Wu    (sgo@hlabs.oki.co.jp)                                 *//*     Yoshihiro Ueda (yueda@hlabs.oki.co.jp)                               *//*     Toshifumi Kanamaru (kanamaru@hlabs.oki.co.jp)                        *//*                                                                          *//*   OKI, Sharp, Sarnoff, TI and Microsoft contributed to bitstream         *//*   exchange and bug fixing.                                               *//*                                                                          *//*                                                                          *//* In the course of development of the MPEG-4 standard, this software       *//* module is an implementation of a part of one or more MPEG-4 tools as     *//* specified by the MPEG-4 standard.                                        *//*                                                                          *//* The copyright of this software belongs to ISO/IEC. ISO/IEC gives use     *//* of the MPEG-4 standard free license to use this  software module or      *//* modifications thereof for hardware or software products claiming         *//* conformance to the MPEG-4 standard.                                      *//*                                                                          *//* Those intending to use this software module in hardware or software      *//* products are advised that use may infringe existing  patents. The        *//* original developers of this software module and their companies, the     *//* subsequent editors and their companies, and ISO/IEC have no liability    *//* and ISO/IEC have no liability for use of this software module or         *//* modification thereof in an implementation.                               *//*                                                                          *//* Permission is granted to MPEG members to use, copy, modify,              *//* and distribute the software modules ( or portions thereof )              *//* for standardization activity within ISO/IEC JTC1/SC29/WG11.              *//*                                                                          *//* Copyright 1995, 1996, 1997, 1998 ISO/IEC                                 *//****************************************************************************//************************************************************//*     Sarnoff Very Low Bit Rate Still Image Coder          *//*     Copyright 1995, 1996, 1997, 1998 Sarnoff Corporation *//************************************************************/#include <stdlib.h>#include <stdio.h>#include <math.h>#include <assert.h>// begin: added by Sharp (99/2/16)#include <iostream.h>#include <sys/stat.h>// end: added by Sharp (99/2/16)#include "basic.hpp"#include "dataStruct.hpp"#include "startcode.hpp"#include "bitpack.hpp"#include "msg.hpp"#include "globals.hpp"#include "states.hpp" // hjlee 0901CVTCEncoder::CVTCEncoder(){	m_cImagePath = new Char[80];	m_cSegImagePath = new Char[80];	m_cOutBitsFile = new Char[80];	mzte_codec.m_cBitFile = new Char[80];}CVTCEncoder::~CVTCEncoder(){	delete m_cImagePath;	delete m_cSegImagePath;	delete m_cOutBitsFile;	delete mzte_codec.m_cBitFile;}//CVTCEncoder::CVTCEncoder(Void CVTCEncoder::init(		UInt uiVerID, // added by Sharp (99/11/18)		Char* cImagePath,	    UInt uiAlphaChannel,		Char* cSegImagePath,		UInt uiAlphaTh,		UInt uiChangeCRDisable,// FPDAM begin: deleted by Sharp//		UInt uiShapeScalable, //added by SL@Sarnoff (03/02/99)// FPDAM end: deleted by Sharp		UInt uiSTOConstAlpha, //added by SL@Sarnoff (03/03/99)		UInt uiSTOConstAlphaValue, //added by SL@Sarnoff (03/02/99)		Char* cOutBitsFile,		UInt uiColors,		UInt uiFrmWidth,		UInt uiFrmHeight,// begin: added by Sharp (99/2/16)    UInt uiTilingDisable,		UInt uiTilingJump,    UInt uiTileWidth,    UInt uiTileHeight,// end: added by Sharp (99/2/16)		UInt uiWvtType,		UInt uiWvtDownload,  // hjlee 0901		UInt uiWvtDecmpLev,		UInt uiWvtUniform, // hjlee 0901		Int* iWvtFilters,  // hjlee 0901		UInt uiQuantType,		UInt uiScanDirection,		Bool bStartCodeEnable,		UInt uiTargetSpatialLev,		UInt uiTargetSNRLev,		UInt uiTargetShapeLev, //added by SL@Sarnoff (03/02/99)		UInt uiFullSizeOut, //added by SL@Sarnoff (03/02/99)// begin: added by Sharp (99/2/16)    UInt uiTargetTileFrom,    UInt uiTargetTileTo,// end: added by Sharp (99/2/16)		UInt uiQdcY,		UInt uiQdcUV,		UInt uiSpatialLev ,		UInt defaultSpatialScale, // hjlee 0901		Int  lastWvtDecompInSpaLayer[MAXDECOMPLEV], // hjlee 0901		SNR_PARAM* Qinfo[],//Added by Sarnoff for error resilience, 3/5/99		Int uiErrResiDisable,   //bbc, 2/19/99		Int uiPacketThresh,  		Int uiSegmentThresh //End: Added by Sarnoff for error resilience, 3/5/99	){	// input/output	mzte_codec.m_visual_object_verid = uiVerID; // added by Sharp(99/11/18)	strcpy(m_cImagePath,cImagePath);	strcpy(m_cSegImagePath,cSegImagePath);	strcpy(m_cOutBitsFile,cOutBitsFile);	strcpy(mzte_codec.m_cBitFile,cOutBitsFile);		mzte_codec.m_iAlphaChannel = (int)uiAlphaChannel;	mzte_codec.m_iAlphaTh = (int)uiAlphaTh;	mzte_codec.m_iChangeCRDisable = (int)uiChangeCRDisable;	//begin: added by SL@Sarnoff (03/02/99)// FPDAM begin: modified by Sharp	mzte_codec.m_iShapeScalable = 1; // (int)uiShapeScalable;// FPDAM end: modified by Sharp	STO_const_alpha=mzte_codec.m_iSTOConstAlpha = (int)uiSTOConstAlpha;	STO_const_alpha_value=mzte_codec.m_iSTOConstAlphaValue = (int)uiSTOConstAlphaValue;	//end: added by SL@Sarnoff (03/02/99)	mzte_codec.m_iBitDepth = 8;	mzte_codec.m_iColorFormat = 0;	mzte_codec.m_iColors = (int)uiColors;	mzte_codec.m_iWidth = (int)uiFrmWidth;	mzte_codec.m_iHeight = (int)uiFrmHeight;	mzte_codec.m_iWvtType = (int)uiWvtType;	mzte_codec.m_iWvtDecmpLev = (int)uiWvtDecmpLev;	mzte_codec.m_iQuantType = (int)uiQuantType;	mzte_codec.m_iScanDirection = (int)uiScanDirection;	mzte_codec.m_bStartCodeEnable = bStartCodeEnable;	mzte_codec.m_iSpatialLev = (int)uiSpatialLev;	mzte_codec.m_iTargetSpatialLev = (int)uiTargetSpatialLev;	mzte_codec.m_iTargetSNRLev = (int)uiTargetSNRLev;// begin: added by SL@Sarnoff (03/02/99)	mzte_codec.m_iTargetShapeLev = (int) uiTargetShapeLev;	mzte_codec.m_iFullSizeOut = (int)uiFullSizeOut;// end: added by SL@Sarnoff (03/02/99)// begin: added by Sharp (99/2/16)  mzte_codec.m_tiling_disable = (int)uiTilingDisable;	mzte_codec.m_tiling_jump_table_enable = (int)uiTilingJump;  mzte_codec.m_tile_width = (int)uiTileWidth;  mzte_codec.m_tile_height = (int)uiTileHeight;  mzte_codec.m_target_tile_id_from = (int)uiTargetTileFrom;  mzte_codec.m_target_tile_id_to = (int)uiTargetTileTo;// end: added by Sharp (99/2/16)	mzte_codec.m_iWvtDownload = (int)uiWvtDownload; // hjlee 0901	mzte_codec.m_iWvtUniform = (int)uiWvtUniform;// hjlee 0901	mzte_codec.m_WvtFilters = (int *)iWvtFilters; // hjlee 0901	mzte_codec.m_defaultSpatialScale = (int)defaultSpatialScale; // hjlee 0901	if (uiQuantType == 2) {		if (uiSpatialLev != uiWvtDecmpLev) {		  /* read in usedefault */		  mzte_codec.m_defaultSpatialScale=(int)defaultSpatialScale;		  if (defaultSpatialScale==0) {			int spa_lev;			/* read in spatial layer info */			for (spa_lev=0; spa_lev<(int)uiSpatialLev-1; ++spa_lev)   			  mzte_codec.m_lastWvtDecompInSpaLayer[spa_lev][0]				= lastWvtDecompInSpaLayer[spa_lev];		  }		}	}	for (int i=0; i<(int)uiColors; i++)		mzte_codec.m_Qinfo[i] = Qinfo[i];	mzte_codec.m_iQDC[0] = (int)uiQdcY;	mzte_codec.m_iQDC[1] = mzte_codec.m_iQDC[2] = (int)uiQdcUV;/*	mzte_codec.m_iDCWidth = GetDCWidth();	mzte_codec.m_iDCHeight = GetDCHeight(); */ //deleted by SL 030499  	mzte_codec.m_iSingleBitFile = 1;//	mzte_codec.m_cBitFile = NULL;	mzte_codec.m_cBitFileAC = NULL;	// check parameter	if (mzte_codec.m_iQuantType==1 && mzte_codec.m_iScanDirection==0)		mzte_codec.m_bStartCodeEnable = 0;//Added by Sarnoff for error resilience, 3/5/99	//disable startcode in error resilience case	if((mzte_codec.m_usErrResiDisable=(UShort)uiErrResiDisable)==0)		mzte_codec.m_bStartCodeEnable=0;  	mzte_codec.m_usPacketThresh=(UShort)uiPacketThresh; 	mzte_codec.m_usSegmentThresh=(UShort)uiSegmentThresh;//End: Added by Sarnoff for error resilience, 3/5/99}/*******************************************************//*  Flush buffer and close file. Only and must be used *//*   by encoder to close bitstream file                *//*******************************************************/Void CVTCEncoder::flush_buffer_file(){  flush_bits();  flush_bytes();}Void CVTCEncoder::close_buffer_file(FILE *fp){  flush_buffer_file();  fclose(fp);}Void CVTCEncoder::texture_packet_header_Enc(FILTER **wvtfilter) // hjlee 0901 {  Int  texture_object_id=0;  //  Int  texture_object_layer_shape=mzte_codec.m_iAlphaChannel;  //  Int  wavelet_stuffing = 0x0f;//  Int  wavelet_upload;//  Int  wavelet_uniform;  // hjlee 0901//  long tile_table_position=0;  if(!mzte_codec.m_usErrResiDisable){		flush_bits(); // added by Sharp(99/3/29)		texture_object_id=1<<15; // error resilience		prev_TU_first = prev_TU_last = prev_TU_err = -1;		flush_bytes(); // to get alignment in buffer		emit_bits((UShort)1,2); // 1st bit dummy, 2nd bit HEC=1		packet_size=0;  }//End: Added by Sarnoff for error resilience, 3/5/99	header_Enc_Common( wvtfilter ,1);//Added by Sarnoff for error resilience, 3/5/99  if(!mzte_codec.m_usErrResiDisable) {	  emit_bits((UShort)mzte_codec.m_usSegmentThresh,16);	  emit_bits((UShort)MARKER_BIT, 1); // added for FDAM1 by Samsung AIT on 2000/02/03  }//End: Added by Sarnoff for error resilience, 3/5/99}Void CVTCEncoder::header_Enc_V1(FILTER **wvtfilter) // hjlee 0901{  Int  texture_object_id=0;  Int  texture_object_layer_shape=mzte_codec.m_iAlphaChannel;  Int  wavelet_stuffing = 0x0f;//  Int  wavelet_upload;  Int  wavelet_uniform;  // hjlee 0901  Int i; // hjlee 0901  /*------- Write header info to bitstream file -------*/  emit_bits((UShort)(STILL_TEXTURE_OBJECT_START_CODE>>16), 16);  emit_bits((UShort)STILL_TEXTURE_OBJECT_START_CODE, 16);  emit_bits((UShort)texture_object_id, 16);  emit_bits((UShort)MARKER_BIT, 1);  emit_bits((UShort)(mzte_codec.m_iWvtType==0?0:1), 1); // hjlee 0901  emit_bits((UShort)mzte_codec.m_iWvtDownload, 1); // hjlee 0901  emit_bits((UShort)mzte_codec.m_iWvtDecmpLev, 4); // hjlee 0901  emit_bits((UShort)mzte_codec.m_iScanDirection,1);  emit_bits((UShort)mzte_codec.m_bStartCodeEnable, 1);  emit_bits((UShort)texture_object_layer_shape, 2);  emit_bits((UShort)mzte_codec.m_iQuantType, 2);  /* hjlee 0901 */  if (mzte_codec.m_iQuantType==2) {    Int i;    emit_bits((UShort)mzte_codec.m_iSpatialLev, 4); 	    /* Calc number decomp layers for all spatial layers */    if (mzte_codec.m_iSpatialLev == 1)    {      mzte_codec.m_lastWvtDecompInSpaLayer[0][0]=mzte_codec.m_iWvtDecmpLev-1;    }    else if (mzte_codec.m_iSpatialLev != mzte_codec.m_iWvtDecmpLev)    {      emit_bits((UShort)mzte_codec.m_defaultSpatialScale, 1);      if (mzte_codec.m_defaultSpatialScale==0)      {  	     /* For the 1st spatial_scalability_levels-1 layers the luma componant	        of lastWvtDecompInSpaLayer should have been filled in from the 	        parameter file. */	     for (i=0; i<mzte_codec.m_iSpatialLev-1; ++i)	         emit_bits((UShort)mzte_codec.m_lastWvtDecompInSpaLayer[i][0], 4);	     mzte_codec.m_lastWvtDecompInSpaLayer[mzte_codec.m_iSpatialLev-1][0]	         =mzte_codec.m_iWvtDecmpLev-1;      }      else      {		Int sp0;		sp0=mzte_codec.m_iWvtDecmpLev-mzte_codec.m_iSpatialLev;		mzte_codec.m_lastWvtDecompInSpaLayer[0][0]=sp0;		  		for (i=1; i<mzte_codec.m_iSpatialLev; ++i)		  mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=sp0+i;      }    }    else    {      for (i=0; i<mzte_codec.m_iSpatialLev; ++i)		mzte_codec.m_lastWvtDecompInSpaLayer[i][0]=i;    }        /* Calculate for chroma (one less than luma) */    for (i=0; i<mzte_codec.m_iSpatialLev; ++i)      mzte_codec.m_lastWvtDecompInSpaLayer[i][1]		=mzte_codec.m_lastWvtDecompInSpaLayer[i][2]		=mzte_codec.m_lastWvtDecompInSpaLayer[i][0]-1;  }  if (mzte_codec.m_iWvtDownload == 1) {	// hjlee 0901    wavelet_uniform = (mzte_codec.m_iWvtUniform!=0)?1:0;    emit_bits((UShort)wavelet_uniform, 1);    if(wavelet_uniform) {      upload_wavelet_filters(wvtfilter[0]);    }    else {      for(i=0;i<mzte_codec.m_iWvtDecmpLev;i++) 	    upload_wavelet_filters(wvtfilter[i]);		}  }    emit_bits((UShort)wavelet_stuffing, 3);  if (texture_object_layer_shape == 0x00) {    emit_bits((UShort)mzte_codec.m_iRealWidth, 15);    emit_bits((UShort)MARKER_BIT, 1);    emit_bits((UShort)mzte_codec.m_iRealHeight, 15);    emit_bits((UShort)MARKER_BIT, 1);  }  else { /* Arbitrary shape info, SL */        emit_bits((UShort)mzte_codec.m_iOriginX, 15);  /*horizontal_ref */        emit_bits((UShort)MARKER_BIT, 1); /* marker_bit */       emit_bits((UShort)mzte_codec.m_iOriginY, 15); /*vertical_ref */        emit_bits((UShort)MARKER_BIT, 1);  /* marker_bit */        emit_bits((UShort)mzte_codec.m_iWidth, 15);  /* object_width */        emit_bits((UShort)MARKER_BIT, 1);   /* marker_bit */        emit_bits((UShort)mzte_codec.m_iHeight, 15);  /* object_height */        emit_bits((UShort)MARKER_BIT, 1);  /* marker_bit */    noteProgress("Merge Shape Bitstream ....");    // MergeShapeBitstream();  }}// begin: modified by Sharp (99/2/16)//Void CVTCEncoder::header_Enc(FILTER *wvtfilter)  // hjlee 0901long CVTCEncoder::header_Enc(FILTER **wvtfilter) // hjlee 0901 {  //  Int  texture_object_id=0;  //  Int  texture_object_layer_shape=mzte_codec.m_iAlphaChannel;  //  Int  wavelet_stuffing = 0x0f;//  Int  wavelet_upload;//  Int  wavelet_uniform;  // hjlee 0901  Int i; // hjlee 0901  long tile_table_position=0;  /*------- Write header info to bitstream file -------*/  emit_bits((UShort)(STILL_TEXTURE_OBJECT_START_CODE>>16), 16);  emit_bits((UShort)STILL_TEXTURE_OBJECT_START_CODE, 16);  emit_bits((UShort)mzte_codec.m_tiling_disable, 1); // added by Sharp (99/2/16)//Added by Sarnoff for error resilience, 3/5/99  emit_bits(mzte_codec.m_usErrResiDisable,1);  /* bbc, 2/18/99 *///  flush_bits(); // deleted by Sharp (99/3/29)// This part is moved to texture_packet_header_Enc, by Sharp (99/4/7)#if 0  if(!mzte_codec.m_usErrResiDisable){		flush_bits(); // added by Sharp(99/3/29)		texture_object_id=1<<15; // error resilience		prev_TU_first = prev_TU_last = prev_TU_err = -1;		flush_bytes(); // to get alignment in buffer		emit_bits((UShort)1,2); // 1st bit dummy, 2nd bit HEC=1		packet_size=0;  }//End: Added by Sarnoff for error resilience, 3/5/99#endif//	if ( mzte_codec.m_usErrResiDisable == 1) // added by Sharp (99/3/29) // @@@@@@		header_Enc_Common( wvtfilter );  if ( mzte_codec.m_tiling_disable == 0 ){    emit_bits((UShort)mzte_codec.m_tile_width, 15); // modified by Sharp (99/11/16)    emit_bits((UShort)1, 1);    emit_bits((UShort)mzte_codec.m_tile_height, 15); // modified by Sharp (99/11/16)    emit_bits((UShort)1, 1);		emit_bits((UShort)mzte_codec.m_iNumOfTile, 16);		emit_bits((UShort)1, 1);/*		mzte_codec.m_tiling_jump_table_enable = 1;*/    emit_bits((UShort)mzte_codec.m_tiling_jump_table_enable, 1);    mzte_codec.m_extension_type = 0;    used_bits = current_put_bits() % 8;/*		printf("used_bits = %d\n", used_bits);*/    flush_bytes();    tile_table_position = current_fp();		if ( mzte_codec.m_tiling_jump_table_enable == 1 )

⌨️ 快捷键说明

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