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

📄 itest.c

📁   这是一个高速多维插值算法。当我们建模以后
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Verify and benchmark the imdi code *//* * Copyright 2000 - 2002 Graeme W. Gill * All rights reserved. * * This material is licenced under the GNU GENERAL PUBLIC LICENCE :- * see the Licence.txt file for licencing details. */#include <stdio.h>#include <stdlib.h>#include <time.h>#include "copyright.h"#include "config.h"#include "numlib.h"#include "imdi.h"#include "refi.h"/* Test parameters */#define TEST1					/* Test just one combination */#define FULL					/* Test full range */#undef VERBOSE					/* Report every conversion */#undef REPORT_ERRORS			/* Report conversion with large errors */#define TRAND					/* Test random in/out table contents */#define TCRAND					/* Test random clut table contents */#undef QUANTIZE				/* Quantize the target table values */#define TBUFSIZE (2 * 1024 * 1024)		/* Default number of pixels to test */#define ITERS 10					/* Itterations */double trans1(double in, double t);double trans2(double in, double t);/* Context for refi setup callbacks */typedef struct {	int id;	int od;	double icurve[MXDI];		/* Input curve factors */	double clut[MXDO][MXDI];	/* clut matrix factors */	double ocurve[MXDO];		/* Output curve factors */} rcntx;/* Input curve function */double input_curve(	void *cntx,	int ch,	double in_val) {	rcntx *rx = (rcntx *)cntx;#ifdef TRAND	double val;	val = trans1(in_val, rx->icurve[ch]);#ifdef QUANTIZE	val = ((int)(val * 255.0 + 0.5))/255.0;	/* Quantize to 8 bits */#endif	return val;#else	return in_val;#endif}/* Multi-dim table function */void md_table(void *cntx,double *out_vals,double *in_vals) {	rcntx *rx = (rcntx *)cntx;	int i, j;#ifdef TCRAND	for (j = 0; j < rx->od; j++) {		double val = 0.0;		for (i = 0; i < rx->id; i++) {			val += rx->clut[j][i] * in_vals[i];		}#ifdef QUANTIZE		val = ((int)(val * 255.0 + 0.5))/255.0;	/* Quantize to 8 bits */#endif		out_vals[j] = val;	}#else	for (j = 0; j < rx->od; j++)		out_vals[j] = in_vals[j % rx->id];#endif//printf("~1 out %f %f %f %f from %f\n", out_vals[0], out_vals[1], out_vals[2], out_vals[3], in_vals[0]);}/* Output curve function */double output_curve(void *cntx,int ch,double in_val) {	rcntx *rx = (rcntx *)cntx;#ifdef TRAND	double val;	val = trans2(in_val, rx->ocurve[ch]);#ifdef QUANTIZE	val = ((int)(val * 255.0 + 0.5))/255.0;	/* Quantize to 8 bits */#endif	return val;#else	return in_val;#endif}/* Complete reference interpolation */void refi_interp(refi *r, double *out_vals, double *in_vals);void usage(void) {	fprintf(stderr,"Regression test imdi code Version %s\n",ARGYLL_VERSION_STR);	fprintf(stderr,"usage: itest [-q] [-s]\n");	fprintf(stderr," -q            Quick test\n");	fprintf(stderr," -s            Stop on error\n");	fprintf(stderr," -r bits       Specify bits of randomness in input data\n");	exit(1);}intmain(int argc, char *argv[]) {	int fa,nfa;				/* argument we're looking at */	int quick = 0;	int stop = 0;	int rbits = 16;	int n, i, j, e;	int pix, iix, oix;	int ip, op, id, od;	int ires, cres, ores;	clock_t stime, ttime;	/* Start and total times */	double xtime;			/* Total execution time in seconds */	double npixels;			/* Number of pixels processed */	rcntx rx;	refi *r;	double ribuf[MXDI];	double robuf[MXDO];	imdi *s;	int iters;	unsigned long tbufsize;	unsigned char *ibuf;	unsigned char *obuf;	unsigned char *inp[MXDI];	unsigned char *outp[MXDO];	unsigned short *ibuf2;			/* 16 bit references */	unsigned short *obuf2;	double omxerr = 0;		/* Overall max error /1.0 */	/* Define combinations to test */#ifdef TEST1	int ids[] = { 3, 4, 0 };			/* Input dimensions */	int ods[] = { 3, 4, 0 };			/* Output dimensions */	int iprs[] = { 8, 16, 0 };	int oprs[] = { 8, 16, 0 };#else#ifndef FULL	int ids[] = { 1, 3, 4, 8, 0 };	int ods[] = { 1, 3, 4, 8, 0 };	int iprs[] = { 8, 8,  16, 0};	int oprs[] = { 8, 16, 16, 0};#else	int ids[] = { 1, 3, 4, 5, 6, 7, 8, 0 };	int ods[] = { 1, 3, 4, 5, 6, 7, 8, 0 };	int iprs[] = { 8, 8,  16, 0};	int oprs[] = { 8, 16, 16, 0};#endif#endif	/* Process the arguments */	for(fa = 1;fa < argc;fa++) {		nfa = fa;					/* skip to nfa if next argument is used */		if (argv[fa][0] == '-')	{	/* Look for any flags */			char *na = NULL;		/* next argument after flag, null if none */			if (argv[fa][2] != '\000')				na = &argv[fa][2];		/* next is directly after flag */			else {				if ((fa+1) < argc) {					if (argv[fa+1][0] != '-') {						nfa = fa + 1;						na = argv[nfa];		/* next is seperate non-flag argument */					}				}			}			if (argv[fa][1] == '?')				usage();			/* Quick test */			else if (argv[fa][1] == 'q' || argv[fa][1] == 'Q') {				quick = 1;			}			/* Stop on error */			else if (argv[fa][1] == 's' || argv[fa][1] == 'S') {				stop = 1;			}			/* Degree of data randomness */			else if (argv[fa][1] == 'r' || argv[fa][1] == 'R') {				fa = nfa;				if (na == NULL) usage();				rbits = atoi(na);				if (rbits < 0)					rbits = 1;				else if (rbits > 16)					rbits = 16;			}			else 				usage();		} else			break;	}	for (iix = 0; ids[iix] > 0; iix++) {			/* All input dimensions */		for (oix = 0; ods[oix] > 0; oix++) {		/* All output dimensions */			for (pix = 0; iprs[pix] > 0; pix++) {	/* All precisions */				int rmask = 0;				ip = iprs[pix];		/* Input precision */				op = oprs[pix];		/* Output precision */				id = ids[iix];		/* Input dimensions */				od = ods[oix];		/* Outpu dtimensions */				if (ip != 8 && ip != 16)					error("Can't handle input precision of %d in testing\n",ip);				if (op != 8 && op != 16)					error("Can't handle output precision of %d in testing\n",op);				if (id > MXDI)					error("Can't handle id greater than %d in testing\n",MXDI);				if (od > MXDO)					error("Can't handle od greater than %d in testing\n",MXDO);				printf("Testing id = %d, od = %d, ip = %d, op = %d\n",id,od,ip,op);				ires = 256;				switch (id) {					case 1:						cres = 257;						break;					case 2:					case 3:						cres = 33;						break;					case 4:						cres = 17;						break;					case 5:						cres = 7;						break;					case 6:						cres = 7;						break;					case 7:						cres = 5;						break;					case 8:						cres = 5;						break;					default:						cres = 3;				}				ores = 256;				/* Setup error messages */				error_program = "itest";				/* Create the reference first */				printf("About to create refi\n");				/* Create test curves */				rx.id = id;				rx.od = od;				rand32(0x1234);				for (i = 0; i < id; i++) {					rx.icurve[i] = d_rand(-1.0, 1.0);				}//printf("Matrix params =\n");				rand32(0x2345);				for (j = 0; j < od; j++) {					double s = 0.0;					for (i = 0; i < id; i++) {						double v = d_rand(1.0, 0.0);						rx.clut[j][i] = v;			/* Make them sum to 1.0 */						s += v;					}					for (i = 0; i < id; i++) {							rx.clut[j][i] /= s;//printf(" %f",rx.clut[j][i]);					}//printf("\n");				}				rand32(0x3456);				for (j = 0; j < od; j++) {					rx.ocurve[j] = d_rand(-1.0, 1.0);				}				r = new_refi(					id,				/* Number of input dimensions */					od,				/* Number of output dimensions */					ires,			/* Input table resolution */					cres,			/* clut resolution */					ores,			/* Output table resolution */					input_curve,	/* Callback functions */					md_table,					output_curve,					(void *)&rx		/* Context to callbacks */				);				if (r == NULL) {					error("new_refi failed");				}				/* Now crate the imdi we want to test, using the */				/* reference as a template */				printf("About to create imdi\n");				s = new_imdi(					id,				/* Number of input dimensions */

⌨️ 快捷键说明

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