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

📄 dvp_process.c

📁  离散余弦变换对图象信号有近似最优的去相关能力, 但多维的变换公式一直没有给出. 为此深入研究了 三维离散余弦变换, 提出了任意尺寸的三维函数f (x , y , z ) 的正交离散余弦变换公式,
💻 C
字号:

/*
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//   Copyright (C) 2006-2008  Beijing,  pengzhen (pengzhenxp@yahoo.com.cn)   //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
*/


#include "dvp_demo.h"

static Dvp_Functions m_Dvp_Functions = 0 ;

static dvp_ctx  m_dvp_ctx  = {0} ; 
static avi_context m_write_avi = {0} ; 

static FILE *m_fp_in_v    = 0 ;
static FILE *m_file_out_v = 0 ;
#ifdef __OUT_RAW__
static FILE *m_file_out_raw_v = 0 ;
#endif //__OUT_RAW__


void Get_Dvp_Functions0( int function_id )
{

	switch( function_id )
	{

	/* Image Process ( wavelets <2D, 3D, 4D> ) */

	default : 
	case DVP_FId_Wavelets_Analysis_2D : 
		m_Dvp_Functions = (Dvp_Functions)dvp_wavelets_analysis_2d ; break ;
	case DVP_FId_Wavelets_Analysis_3D :
		m_Dvp_Functions = (Dvp_Functions)dvp_wavelets_analysis_3d ; break ;
	case DVP_FId_Wavelets_Analysis_4D : 
		m_Dvp_Functions = (Dvp_Functions)dvp_wavelets_analysis_4d ; break ;
	 
	case DVP_FId_Wavelets_Synthesis_2D : 
		m_Dvp_Functions = (Dvp_Functions)dvp_wavelets_synthesis_2d ; break ;
	case DVP_FId_Wavelets_Synthesis_3D : 
		m_Dvp_Functions = (Dvp_Functions)dvp_wavelets_synthesis_3d ; break ;
	case DVP_FId_Wavelets_Synthesis_4D : 
		m_Dvp_Functions = (Dvp_Functions)dvp_wavelets_synthesis_4d ; break ;

	/* Image Process */

	case DVP_FId_Detect_Edge :  
		m_Dvp_Functions = (Dvp_Functions)dvp_detect_edge ; break ;
	case DVP_FId_Detect_Object : 
		m_Dvp_Functions = (Dvp_Functions)dvp_detect_object ; break ;
	case DVP_FId_Detect_Background : 
		m_Dvp_Functions = (Dvp_Functions)dvp_detect_background ; break ;	
	case DVP_FId_Trace_Edge :
		m_Dvp_Functions = (Dvp_Functions)dvp_trace_edge ; break ;
	case DVP_FId_Trace_Object :
		m_Dvp_Functions = (Dvp_Functions)dvp_trace_object ; break ;
	case DVP_FId_Trace_Background : 	
		m_Dvp_Functions = (Dvp_Functions)dvp_trace_background ; break ;

	case DVP_FId_Denoise : 
		m_Dvp_Functions = (Dvp_Functions)dvp_denoise ; break ;
	case DVP_FId_Enhance : 
		m_Dvp_Functions = (Dvp_Functions)dvp_enhance ; break ;
	//case DVP_FId_MotionEstimate :  
	//	m_Dvp_Functions = (Dvp_Functions)dvp_motion_estimate ; break ;
	//case DVP_FId_Recognise : 
	//	m_Dvp_Functions = (Dvp_Functions)dvp_recognise ; break ;


	/* Image Compression */

	case DVP_FId_H265P_V0_Compression : 
		m_dvp_ctx.codec = (FOURCC_ZPV0) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_encode_frame (&m_dvp_ctx) ; 
		break ;
	case DVP_FId_H265P_V6_Compression :  
		m_dvp_ctx.codec = (FOURCC_ZPV6) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_encode_frame (&m_dvp_ctx) ; 
		break ;
	case DVP_FId_H265P_V8_Compression :  
		m_dvp_ctx.codec = (FOURCC_ZPV8) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_encode_frame (&m_dvp_ctx) ; 
		break ;
	case DVP_FId_H265P_V9_Compression : 
		m_dvp_ctx.codec = (FOURCC_ZPV9) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_encode_frame (&m_dvp_ctx) ; 
		break ;
		

	/* Image Decompression */

	case DVP_FId_H265P_V0_Decompression : 
		m_dvp_ctx.codec = (FOURCC_ZPV0) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_decode_frame (&m_dvp_ctx) ; 
		break ;
	case DVP_FId_H265P_V6_Decompression :  
		m_dvp_ctx.codec = (FOURCC_ZPV6) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_decode_frame (&m_dvp_ctx) ; 
		break ;
	case DVP_FId_H265P_V8_Decompression :  
		m_dvp_ctx.codec = (FOURCC_ZPV8) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_decode_frame (&m_dvp_ctx) ; 
		break ;
	case DVP_FId_H265P_V9_Decompression : 
		m_dvp_ctx.codec = (FOURCC_ZPV9) ;
		m_Dvp_Functions = (Dvp_Functions)dvp_decode_frame (&m_dvp_ctx) ; 
		break ;

	}

}

static void Get_Dvp_Functions( int function_id )
{

	Get_Dvp_Functions0( function_id ) ;

	switch( function_id )
	{

	/* Image Process ( wavelets <2D, 3D, 4D> ) */

	default : 
	case DVP_FId_Wavelets_Analysis_2D : 
	case DVP_FId_Wavelets_Analysis_3D :
	case DVP_FId_Wavelets_Analysis_4D : 
		printf( "\n wavelets analysis \n" );
		break ;
	case DVP_FId_Wavelets_Synthesis_2D : 
	case DVP_FId_Wavelets_Synthesis_3D : 
	case DVP_FId_Wavelets_Synthesis_4D :  
		printf( "\n wavelets synthesis \n" );
		break ;	
	
	/* Image Process */

	case DVP_FId_Detect_Edge : 
		printf( "\n digital image detect edge \n" ); 
		break ;	
	case DVP_FId_Detect_Object : 	
		printf( "\n digital image detect object \n" );
		break ;
	case DVP_FId_Detect_Background : 	
		printf( "\n digital image detect background \n" );
		break ;
	case DVP_FId_Trace_Edge : 
		printf( "\n digital image trace edge \n" ); 
		break ;	
	case DVP_FId_Trace_Object : 	
		printf( "\n digital image trace object \n" );
		break ;
	case DVP_FId_Trace_Background : 	
		printf( "\n digital image trace background \n" );
		break ;
		
	case DVP_FId_Denoise : 
		printf( "\n digital image denoise \n" );
		break ;
	case DVP_FId_Enhance : 
		printf( "\n digital image enhance \n" );
		break ;
	//case DVP_FId_MotionEstimate :  
	//	printf( "\n digital image correlate \n" );
	//	break ;
	case DVP_FId_Recognise :  
		printf( "\n digital image recognise \n" );
		break ;


	/* Image Compression */

	case DVP_FId_H265P_V0_Compression :  
		printf( "\n digital image H265+ (ZPV0) compression \n" );
		break ;
	case DVP_FId_H265P_V6_Compression : 
		printf( "\n digital image H265+ (ZPV6) compression \n" );
		break ;
	case DVP_FId_H265P_V8_Compression : 
		printf( "\n digital image H265+ (ZPV8) compression \n" );
		break ;
	case DVP_FId_H265P_V9_Compression : 
		printf( "\n digital image H265+ (ZPV9) compression \n" );
		break ;
	
	/* Image Decompression */

	case DVP_FId_H265P_V0_Decompression : 
		printf( "\n digital image H265+ (ZPV0) decopmress \n" );
		break ;
	case DVP_FId_H265P_V6_Decompression : 
		printf( "\n digital image H265+ (ZPV6) decopmress \n" );
		break ;
	case DVP_FId_H265P_V8_Decompression : 
		printf( "\n digital image H265+ (ZPV8) decopmress \n" );
		break ;
	case DVP_FId_H265P_V9_Decompression : 
		printf( "\n digital image H265+ (ZPV9) decopmress \n" );
		break ;

	}

	printf( "written by pengzhenxp@yahoo.com.cn \n\n" );

}

void dvp_init( void* dvp, int width, int height )
{

	//if( m_bRecieveWnd ) return ;

	dvp_ctx * lp_dvp     = (dvp_ctx*)(dvp) ;
	dvp_ctx * lp_dvp_enc = (dvp_ctx*)(dvp) ;
	dvp_ctx * lp_dvp_dec = (dvp_ctx*)(dvp) ;

	// dvp system 

	lp_dvp->m_handle = 0 ; /* handle */ 

	lp_dvp->width  = width ;  /* 352 */ /* picture width. (must be a multiple of 16) */
	lp_dvp->height = height ; /* 288 */ /* picture height. (must be a multiple of 16) */

	//lp_dvp->wavelets   = 0 ;
	//lp_dvp->frame_number = 0 ;
	//lp_dvp->bands   = 2 ;
	//lp_dvp->bands_c = 2 ;
	//lp_dvp->mv_table = NULL ;

	dvp_open( lp_dvp ) ; /* dvp open */

	// dvp encoder 

	lp_dvp_enc->m_handle = lp_dvp->m_handle; /* handle */ 

	lp_dvp_enc->codec = FOURCC_ZPV0  ; /* FOURCC_ZPV0 ~~~ FOURCC_ZPV9 */
	lp_dvp_enc->wavelets = 0  ; /* wavelets */ /* wavelets < 0:b97, 1:b53, 2:haar > */

	lp_dvp_enc->width  = lp_dvp->width ;  /* 352 */ /* picture width. (must be a multiple of 16) */
	lp_dvp_enc->height = lp_dvp->height ; /* 288 */ /* picture height. (must be a multiple of 16) */

	lp_dvp_enc->frame_number  = 0  ; /* frame number */ 
	lp_dvp_enc->frame_rate    = 25 ; /* frames/second */ /* <25,30> */ 
	lp_dvp_enc->bit_rate      = 300*1000 ; /* bits/second */ /* <300*1000> */
	lp_dvp_enc->bit_rate_type = 0 ; /* 0 : BRT_ABR(ABR) 1 : BRT_VBR(VBR) 2 : BRT_CBR(CBR) */
	
	lp_dvp_enc->gop   = 512 ; /* group of picture */ /* if gop = 0, none P (POT_P) */
	lp_dvp_enc->gop_b = 0 ; /* group of picture B (POT_B) */ /* 0 : 2 (B) 1 : 4 (B) */
	lp_dvp_enc->ratio = 1 ; /* ratio of background to foreground */ /* if ratio = 0, none background */

	lp_dvp_enc->previous_process = 0 ; /* previous process */ /* <0,1,2,3,4> */
	lp_dvp_enc->post_process = 4 ; /* post process */ /* <0,1,2,3,4> */

	dvp_encode_open( lp_dvp_enc ) ; /* dvp encode open */

	// dvp decoder
	
	lp_dvp_dec->m_handle = lp_dvp->m_handle; /* handle */ 

	lp_dvp_dec->width  = lp_dvp->width ;  /* 352 */ /* picture width. (must be a multiple of 16) */
	lp_dvp_dec->height = lp_dvp->height ; /* 288 */ /* picture height. (must be a multiple of 16) */

	dvp_decode_open( lp_dvp_dec ) ; /* dvp decode open */
}

static void dvp_exit( void* dvp )
{

	dvp_ctx* lp_dvp = (dvp_ctx*)( dvp ) ;

	dvp_close( lp_dvp ) ;

}

void write_avi_init() 
{
	avi_context * lp_write_avi = & m_write_avi ;
	dvp_ctx * lp_dvp_ctx = & m_dvp_ctx ;  

	memset( lp_write_avi, 0x00, sizeof(avi_context) ) ;

	lp_write_avi->video_tag = FOURCC_VIDEO ; 

	lp_write_avi->video_Handler = lp_dvp_ctx->codec ;  

	//lp_write_avi->width  = 352 ;
	//lp_write_avi->height = 288 ;
	//lp_write_avi->frame_rate = 25 ; 

	lp_write_avi->width  = lp_dvp_ctx->width ;
	lp_write_avi->height = lp_dvp_ctx->height ;
	lp_write_avi->frame_rate = lp_dvp_ctx->frame_rate ; 

	lp_write_avi->rgb_bit_count = 32 ; /* RGB32 */
	
}

static int dvp_read_file( void* dvp, int function_id, unsigned int size )
{

	int f_flag = 0 ;

	if( Dvp_Decompression(function_id) ) 
	{
		f_flag = fread( & m_dvp_ctx.bitstream_length , 1, sizeof(int), m_fp_in_v)  == sizeof(int) ;
		f_flag = fread( m_dvp_ctx.bitstream , 1, m_dvp_ctx.bitstream_length, m_fp_in_v ) == m_dvp_ctx.bitstream_length ;
	}
	else
	{
		f_flag = fread( m_dvp_ctx.lpYUV420P_Y, sizeof(char), size,   m_fp_in_v) == size ; 
	}
	
	return f_flag ;
}

static void dvp_write_file( void* dvp, int function_id, unsigned int size )
{
	
	if( Dvp_Compression(function_id) ) 
	{
		
		if( m_dvp_ctx.bitstream_length )
		{
#ifdef __OUT_RAW__
		fwrite( & m_dvp_ctx.bitstream_length , 1, sizeof(int), m_file_out_raw_v) ;
		fwrite( m_dvp_ctx.bitstream , 1, m_dvp_ctx.bitstream_length, m_file_out_raw_v ) ;
#endif //__OUT_RAW__

		write_avi_packet( &m_write_avi, m_write_avi.video_tag,
			              (char*)(m_dvp_ctx.bitstream)-8 , m_dvp_ctx.bitstream_length ) ;

		m_write_avi.frame_number++ ;
		}

	}
	else
	{
		fwrite( m_dvp_ctx.lpYUV420P_Y, sizeof(char), size, m_file_out_v); 
	}

}

static void dvp_process( void* dvp, int function_id, int fv_flag, unsigned int size )
{

	unsigned int dwTotalCycles = 0 ;
	unsigned int dwStartCycles = 0 ;

	int frames = 0 ; 

	while( fv_flag )
	{
		/* read file */
		
		fv_flag = dvp_read_file( dvp, function_id, size ) ;

		if( !fv_flag ) continue ;

		/* read cycles */ 
		
		dwStartCycles = hmpv_read_fcnt() ;
		
		/* dvp function_id */ 
		
		if( m_Dvp_Functions( dvp ) == davp_success ) m_dvp_ctx.frame_number++ ;

		/* write cycles */ 
		
		dwTotalCycles += hmpv_read_fcnt() - dwStartCycles ;
		
		/* write file */
		
		dvp_write_file( dvp, function_id, size ) ;
		
		printf("dvp tansform frames %d \r", ++frames ); 
	}

	/* report */ 
	
	dvp_report ( dwTotalCycles,  frames ) ; 

}

static void dvp_main(int argc,char **argv)
{	
	char *lpYUV420P      = 0 ;
	char* lpVideoOutData = 0 ;

	char *lpYUV420P_Y  = 0 ;
	char *lpYUV420P_U  = 0 ;
	char *lpYUV420P_V  = 0 ;
	
	int width=0;
	int height=0;
	int function_id =0;
	unsigned int size   = 0;
	int fv_flag = 1 ;

	/* parameter */ 
	
	get_parameter( &m_dvp_ctx , NULL , argc,  argv ) ; 

	width  = m_dvp_ctx.width ;
	height = m_dvp_ctx.height ; 

	function_id = m_function_id;
	
	/* file open */ 
	
	m_fp_in_v    = fopen(m_in_file_name,"rb"); 
	if( ! m_fp_in_v ) { printf("can't open file : %s \n", m_in_file_name ); return ; }

	m_file_out_v = fopen(m_out_file_name,"wb");
	if( ! m_file_out_v ) { printf("can't open file : %s \n", m_file_out_v ); return ; }

#ifdef __OUT_RAW__
	m_file_out_raw_v = fopen(m_out_raw_file_name,"wb"); 
	//if( ! m_file_out_raw_v ) printf("can't open file : %s \n", m_file_out_raw_v );
#endif //__OUT_RAW__
		
	/* dvp open */ 
	
	dvp_init( &m_dvp_ctx, width, height ) ;

	/* dvp function_id */

	Get_Dvp_Functions( function_id ) ;
	
	/* dvp data pointor */ 
	
	size   = width*height ; 
	
	lpYUV420P      = (char *)M_ALLOC( size*3/2 + 128 ) ; 
	lpVideoOutData = (char *)M_ALLOC( (256*1024L) ) ;
	
	lpYUV420P      +=  8 ; // for write avi head 
	lpVideoOutData +=  8 ; // for write avi head

	lpYUV420P_Y = lpYUV420P ;
	lpYUV420P_U = lpYUV420P + (size) ;
	lpYUV420P_V = lpYUV420P + (size)*5/4 ;
	
	/* dvp bitstream pointor */ 

	m_dvp_ctx.bitstream   = lpVideoOutData ;
	m_dvp_ctx.bitstream   = lpVideoOutData ;

	/*write avi init */
	write_avi_init()  ;
	/* write avi head */
	write_avi_header( &m_write_avi , m_out_file_name )  ;

	m_dvp_ctx.bands   = 2 ; /* */ 

	m_dvp_ctx.lpYUV420P_Y  = lpYUV420P_Y ;
	m_dvp_ctx.lpYUV420P_U  = lpYUV420P_U ;
	m_dvp_ctx.lpYUV420P_V  = lpYUV420P_V ;

	dvp_process( &m_dvp_ctx, function_id, fv_flag, size*3/2 ) ; 

	/* write avi trailer */
	
	write_avi_trailer( &m_write_avi , m_out_file_name )  ;

	/* dvp close */ 
	
	dvp_exit( &m_dvp_ctx ) ;
	
	lpYUV420P      -=  8 ; // for write avi head 
	lpVideoOutData -=  8 ; // for write avi head

	M_FREE( lpYUV420P );  
	M_FREE( lpVideoOutData );  
	
	/* file close */ 
	
	if(m_fp_in_v) fclose(m_fp_in_v);
	if(m_file_out_v) fclose(m_file_out_v);
#ifdef __OUT_RAW__
	if(m_file_out_raw_v) fclose(m_file_out_raw_v);
#endif //__OUT_RAW__

}


⌨️ 快捷键说明

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