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

📄 xvid_bench.c

📁 TMS320C6713Xvid视频压缩算法源代码.rar
💻 C
📖 第 1 页 / 共 4 页
字号:
	assert(S->Nb>0);	Norm = 1. / (double)S->Nb;	printf("\n== Max absolute values of errors ==\n");	for(i=0; i<64; i++) {		printf("  %4ld", S->Max_Errors[i]);		if ((i&7)==7) printf("\n");	}	printf("\n== Mean square errors ==\n");	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Sqr_Errors[i];		printf(" %.3f", Err);		if ((i&7)==7) printf("\n");	}	printf("\n== Mean errors ==\n");	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Errors[i];		printf(" %.3f", Err);		if ((i&7)==7) printf("\n");	}	printf("\n");}static const char *CHECK(double v, double l) {	if (fabs(v)<=l) return "ok";	else return "FAIL!";}void report_stats(STATS_8x8 *S, const double *Limits){	int i;	double Norm, PE, PMSE, OMSE, PME, OME;	assert(S->Nb>0);	Norm = 1. / (double)S->Nb;	PE = 0.;	for(i=0; i<64; i++) {		if (PE<S->Max_Errors[i])			PE = S->Max_Errors[i];	}	PMSE = 0.;	OMSE = 0.;	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Sqr_Errors[i];		OMSE += Err;		if (PMSE < Err) PMSE = Err;	}	OMSE /= 64.;	PME = 0.;	OME = 0.;	for(i=0; i<64; i++)	{		double Err = Norm * (double)S->Errors[i];		OME += Err;		Err = fabs(Err);		if (PME < Err) PME = Err;	}	OME /= 64.;	printf( "Peak error:   %4.4f\n", PE );	printf( "Peak MSE:     %4.4f\n", PMSE );	printf( "Overall MSE:  %4.4f\n", OMSE );	printf( "Peak ME:      %4.4f\n", PME );	printf( "Overall ME:   %4.4f\n", OME );	if (Limits!=0)	{		printf( "[PE<=%.4f %s]  ", Limits[0], CHECK(PE,   Limits[0]) );		printf( "\n" );		printf( "[PMSE<=%.4f %s]", Limits[1], CHECK(PMSE, Limits[1]) );		printf( "[OMSE<=%.4f %s]", Limits[2], CHECK(OMSE, Limits[2]) );		printf( "\n" );		printf( "[PME<=%.4f %s] ", Limits[3], CHECK(PME , Limits[3]) );		printf( "[OME<=%.4f %s] ", Limits[4], CHECK(OME , Limits[4]) );		printf( "\n" );	}}///* ////////////////////////////////////////////////////// *//* Pseudo-random generator specified by IEEE 1180 */static long ieee_seed = 1;static void ieee_reseed(long s) {	ieee_seed = s;}static long ieee_rand(int Min, int Max){	static double z = (double) 0x7fffffff;	long i,j;	double x;	ieee_seed = (ieee_seed * 1103515245) + 12345;	i = ieee_seed & 0x7ffffffe;	x = ((double) i) / z;	x *= (Max-Min+1);	j = (long)x;	j = j + Min;	assert(j>=Min && j<=Max);	return (short)j;}#define CLAMP(x, M)   (x) = ((x)<-(M)) ? (-(M)) : ((x)>=(M) ? ((M)-1) : (x))static double Cos[8][8];static void init_ref_dct(){	int i, j;	for(i=0; i<8; i++)	{		double scale = (i == 0) ? sqrt(0.125) : 0.5;		for (j=0; j<8; j++)			Cos[i][j] = scale*cos( (M_PI/8.0)*i*(j + 0.5) );	}}void ref_idct(short *M){	int i, j, k;	double Tmp[8][8];	for(i=0; i<8; i++) {		for(j=0; j<8; j++)		{			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[k][j]*M[8*i+k];			Tmp[i][j] = Sum;		}	}	for(i=0; i<8; i++) {		for(j=0; j<8; j++) {			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[k][i]*Tmp[k][j];			M[8*i+j] = (short)floor(Sum + .5);		}	}}void ref_fdct(short *M){	int i, j, k;	double Tmp[8][8];	for(i=0; i<8; i++) {		for(j=0; j<8; j++)		{			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[j][k]*M[8*i+k];			Tmp[i][j] = Sum;		}	}	for(i=0; i<8; i++) {		for(j=0; j<8; j++) {			double Sum = 0.0;			for (k=0; k<8; k++) Sum += Cos[i][k]*Tmp[k][j];			M[8*i+j] = (short)floor(Sum + 0.5);		}	}}void test_IEEE1180_compliance(int Min, int Max, int Sign){	static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };	int Loops = 10000;	int i, m, n;	DECLARE_ALIGNED_MATRIX(Blk0, 8, 8, short, 16); /* reference */	DECLARE_ALIGNED_MATRIX(Blk,  8, 8, short, 16);	DECLARE_ALIGNED_MATRIX(iBlk, 8, 8, short, 16);	DECLARE_ALIGNED_MATRIX(Ref_FDCT, 8, 8, short, 16);	DECLARE_ALIGNED_MATRIX(Ref_IDCT, 8, 8, short, 16);	STATS_8x8 FStats; /* forward dct stats */	STATS_8x8 IStats; /* inverse dct stats */	CPU *cpu;	init_ref_dct();	for(cpu = cpu_list; cpu->name!=0; ++cpu)	{		if (!init_cpu(cpu))			continue;		printf( "\n===== IEEE test for %s ==== (Min=%d Max=%d Sign=%d Loops=%d)\n",				cpu->name, Min, Max, Sign, Loops);		init_stats(&IStats);		init_stats(&FStats);		ieee_reseed(1);		for(n=0; n<Loops; ++n)		{			for(i=0; i<64; ++i)				Blk0[i] = (short)ieee_rand(Min,Max) * Sign;			/* hmm, I'm not quite sure this is exactly */			/* the tests described in the norm. check... */			memcpy(Ref_FDCT, Blk0, 64*sizeof(short));			ref_fdct(Ref_FDCT);			for(i=0; i<64; i++) CLAMP( Ref_FDCT[i], 2048 );			memcpy(Blk, Blk0, 64*sizeof(short));			emms(); fdct(Blk); emms();			for(i=0; i<64; i++) CLAMP( Blk[i], 2048 );			store_stats(&FStats, Blk, Ref_FDCT);			memcpy(Ref_IDCT, Ref_FDCT, 64*sizeof(short));			ref_idct(Ref_IDCT);			for (i=0; i<64; i++) CLAMP( Ref_IDCT[i], 256 );			memcpy(iBlk, Ref_FDCT, 64*sizeof(short));			emms(); idct(iBlk); emms();			for(i=0; i<64; i++) CLAMP( iBlk[i], 256 );			store_stats(&IStats, iBlk, Ref_IDCT);		}		printf( "\n  -- FDCT report --\n" );//    print_stats(&FStats);		report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */		for(i=0; i<64; i++) Blk[i] = 0;		emms(); fdct(Blk); emms();		for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;		printf( "FDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );		printf( "\n  -- IDCT report --\n" );//    print_stats(&IStats);		report_stats(&IStats, ILimits);		for(i=0; i<64; i++) Blk[i] = 0;		emms(); idct(Blk); emms();		for(m=i=0; i<64; i++) if (Blk[i]!=0) m++;		printf( "IDCT(0) == 0 ?  %s\n", (m!=0) ? "NOPE!" : "yup." );	}}void test_dct_saturation(int Min, int Max){/* test behaviour on input range fringe */	int i, n, p;	CPU *cpu;//  const short IDCT_MAX =  2047;  /* 12bits input *///  const short IDCT_MIN = -2048;//  const short IDCT_OUT =   256;  /* 9bits ouput */	const int Partitions = 4;	const int Loops = 10000 / Partitions;	init_ref_dct();	for(cpu = cpu_list; cpu->name!=0; ++cpu)	{		short Blk0[64], Blk[64];		STATS_8x8 Stats;		if (!init_cpu(cpu))			continue;		printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",				cpu->name, Min, Max );		/* FDCT tests // */		init_stats(&Stats);		/* test each computation channels separately */		for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;		ref_fdct(Blk0);		emms(); fdct(Blk); emms();		store_stats(&Stats, Blk, Blk0);		for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Min : 0;		ref_fdct(Blk0);		emms(); fdct(Blk); emms();		store_stats(&Stats, Blk, Blk0);		/* randomly saturated inputs */		for(p=0; p<Partitions; ++p)		{			for(n=0; n<Loops; ++n)			{				for(i=0; i<64; ++i)					Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? Max : Min;				ref_fdct(Blk0);				emms(); fdct(Blk); emms();				store_stats(&Stats, Blk, Blk0);			}		}		printf( "\n  -- FDCT saturation report --\n" );		report_stats(&Stats, 0);		/* IDCT tests // */#if 0		/* no finished yet */		init_stats(&Stats);/* test each computation channel separately */		for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0;		ref_idct(Blk0);		emms(); idct(Blk); emms();		for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }		store_stats(&Stats, Blk, Blk0);		for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MIN : 0;		ref_idct(Blk0);		emms(); idct(Blk); emms();		for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }		store_stats(&Stats, Blk, Blk0);		/* randomly saturated inputs */		for(p=0; p<Partitions; ++p)		{			for(n=0; n<Loops; ++n)			{				for(i=0; i<64; ++i)					Blk0[i] = Blk[i] = (ieee_rand(0,Partitions)>=p)? IDCT_MAX : IDCT_MIN;				ref_idct(Blk0);				emms(); idct(Blk); emms();				for(i=0; i<64; i++) { CLAMP(Blk0[i],IDCT_OUT); CLAMP(Blk[i],IDCT_OUT); }				store_stats(&Stats, Blk, Blk0);			}		}		printf( "\n  -- IDCT saturation report --\n" );		print_stats(&Stats);		report_stats(&Stats, 0);#endif	}}/********************************************************************* * measure raw decoding speed *********************************************************************/void test_dec(const char *name, int width, int height, int with_chksum){	FILE *f = 0;	void *dechandle = 0;	int xerr;	xvid_gbl_init_t xinit;	xvid_dec_create_t xparam;	xvid_dec_frame_t xframe;	double t = 0.;	int nb = 0;	uint8_t *buf = 0;	uint8_t *rgb_out = 0;	int buf_size, pos;	uint32_t chksum = 0;	memset(&xinit, 0, sizeof(xinit));	xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;	xinit.version = XVID_VERSION;	xvid_global(NULL, 0, &xinit, NULL);	memset(&xparam, 0, sizeof(xparam));	xparam.width = width;	xparam.height = height;	xparam.version = XVID_VERSION;	xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);	if (xerr==XVID_ERR_FAIL) {		printf("can't init decoder (err=%d)\n", xerr);		return;	}	dechandle = xparam.handle;	f = fopen(name, "rb");	if (f==0) {		printf( "can't open file '%s'\n", name);		return;	}	fseek(f, 0, SEEK_END);	buf_size = ftell(f);	fseek(f, 0, SEEK_SET);	if (buf_size<=0) {		printf("error while stating file\n");		goto End;	}	else printf( "Input size: %d\n", buf_size);	buf = malloc(buf_size); /* should be enuf' */	rgb_out = calloc(4, width*height);  /* <-room for _RGB24 */	if (buf==0 || rgb_out==0) {		printf( "malloc failed!\n" );		goto End;	}	if (fread(buf, buf_size, 1, f)!=1) {		printf( "file-read failed\n" );		goto End;	}	nb = 0;	pos = 0;	t = -gettime_usec();	while(1) {		memset(&xframe, 0, sizeof(xframe));		xframe.version = XVID_VERSION;		xframe.bitstream = buf + pos;		xframe.length = buf_size - pos;		xframe.output.plane[0] = rgb_out;		xframe.output.stride[0] = width;		xframe.output.csp = XVID_CSP_BGR;		xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);		nb++;		pos += xframe.length;		if (with_chksum) {			int k = width*height;			uint32_t *ptr = (uint32_t *)rgb_out;			while(k-->0) chksum += *ptr++;		}		if (pos==buf_size)			break;		if (xerr==XVID_ERR_FAIL) {			printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);			break;		}	}	t += gettime_usec();	if (t>0.)		printf( "%d frames decoded in %.3f s -> %.1f FPS\n", nb, t*1.e-6f, (float)(nb*1.e6f/t) );	if (with_chksum)		printf("checksum: 0x%.8x\n", chksum);

⌨️ 快捷键说明

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