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

📄 cgen.c

📁   这是一个高速多维插值算法。当我们建模以后
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* The end of the pixel processing loop */	dec(f);	line(f, "}");	/* The end of the function */	dec(f);	line(f, "}");	/* Undefine all the macros */	if (t->sort) {		if (t->it_xs) {			if (t->wo_xs) {				line(f,"#undef IT_WE");				line(f,"#undef IT_VO");			} else				line(f,"#undef IT_WO");			line(f,"#undef IT_IX");		} else {			line(f,"#undef IT_IT");		}		line(f,"#undef CEX");	} else {		if (t->it_xs) {			line(f,"#undef IT_IX");			line(f,"#undef IT_SX");		} else {			line(f,"#undef IT_IT");		}		line(f,"#undef SW_O");		if (t->wo_xs) {			line(f,"#undef SX_WE");			line(f,"#undef SX_VO");		} else {			line(f,"#undef SX_WO");		}	}	line(f,"#undef IM_O");	if (t->im_fn > 0) {		if (timp && t->im_fn > 1) 			line(f,"#undef IM_TP");		line(f,"#undef IM_FE");	}	if (t->im_pn > 0) {		line(f,"#undef IM_PE");	}	line(f,"#undef OT_E");	/* =============================================== */#ifdef VERBOSE	printf("Done interpolation code\n"); fflush(stdout);#endif /* VERBOSE */	/* =============================================== */	{		int sog = sizeof(genspec);	/* Size of genspec structure */		unsigned char *dp = (unsigned char *)g;		int s_stres, s_itres;	/* Save values */		s_stres = g->stres;		s_itres = g->itres;		g->stres = f->sxmxres;		/* Set maximum values */		g->itres = f->ixmxres;				/* Declare the generation structure data function */		cr(f);		line(f,"void");		line(f, "imdi_k%d_gen(",index);		line(f, "genspec *g			/* structure to be initialised */");		line(f, ") {");		inc(f);			/* Declare the genspec initialisation data */		line(f, "static unsigned char data[] = {");		inc(f);		for (i = 0; i < sog; i++) {			if ((i & 7) == 0)				sline(f,"");			mline(f, "0x%02x%s ", dp[i], (i+1) < sog ? "," : "", dp[i]);			if ((i & 7) == 7 || (i+1) == sog)				eline(f,"");		}		dec(f);		line(f, "};	/* Structure image */");		cr(f);		line(f, "memcpy(g, data, sizeof(data));	/* Initialise the structure */");		/* The end of the function */		dec(f);		line(f, "}");		g->stres = s_stres;		/* Restore entry values */		g->itres = s_itres;	}	/* =============================================== */	{		int sot = sizeof(tabspec);	/* Size of tabspec structure */		unsigned char *dp = (unsigned char *)t;		/* Declare the generation structure data function */		cr(f);		line(f,"void");		line(f, "imdi_k%d_tab(",index);		line(f, "tabspec *t			/* structure to be initialised */");		line(f, ") {");		inc(f);			/* Declare the genspec initialisation data */		line(f, "static unsigned char data[] = {");		inc(f);		for (i = 0; i < sot; i++) {			if ((i & 7) == 0)				sline(f,"");			mline(f, "0x%02x%s ", dp[i], (i+1) < sot ? "," : "", dp[i]);			if ((i & 7) == 7 || (i+1) == sot)				eline(f,"");		}		dec(f);		line(f, "};	/* Structure image */");		cr(f);		line(f, "memcpy(t, data, sizeof(data));	/* Initialise the structure */");		/* The end of the function */		dec(f);		line(f, "}");	}	/* =============================================== */	cr(f); cr(f); cr(f); cr(f); cr(f); cr(f);	return 0;}/* Return bits needed to store index into table of *//* given resolution and dimensionality. */static intcalc_bits(int dim,int res) {	return ceil(log((double)res) * (double)dim/log(2.0) - 1e-14);}/* Return maximum resolution possible given dimensionality *//* and number of index bits. */static intcalc_res(int dim,int bits) {	double fres;	fres = log(2.0) * (double)bits/(double)dim;	if (fres > 12 || (fres = exp(fres)) > 65536.0)		fres = 65536.0;		/* Limit to a sane value */	return (int)(fres + 1e-14);}/* Return bits needed to store a relative offset of 1, *//* into a table of given resolution, dimensionality , and *//* entry size. */static intcalc_obits(int dim,int res,int esize) {	double off;		/* Maximum diagonal offset value */	int bits;	if (res == 0 || res == 1)		return 0;	if (dim == 1)		off = esize;	else {		off = (double)esize * floor(exp(log((double)res) * dim - log(res-1.0)));	}	bits = ceil(log(off)/log(2.0) - 1e-14);	return bits;}/* Return maximum resolution possible given dimensionality *//* number of index bits, and entry size */static intcalc_ores(int dim,int bits,int esize) {	int res;	/* Find resolution. Stop at arbitrary 65536 */	for (res = 1; res < 65537; res++) {		int bn;		bn = calc_obits(dim, res, esize);		if (bn > bits) {			return res-1;		}	}	return res-1;}/* Output the introductory comments */static voiddoheader(	fileo *f) {	genspec *g = f->g;	tabspec *t = f->t;	mach_arch *a  = f->a;	int e;	/* - - - - - - - - - - - - */	/* Output file title block */	line(f,"/* Integer Multi-Dimensional Interpolation */");	line(f,"/* Interpolation Kernel Code */");	line(f,"/* Generated by cgen */");	line(f,"/* Copyright 2000 - 2002 Graeme W. Gill */");	line(f,"/* This material is licenced under the GNU GENERAL PUBLIC LICENCE :- */\n");	line(f,"/* see the Licence.txt file for licencing details.*/\n");	cr(f);	/* - - - - - - - - - - - - */	/* Output the specification */	line(f,"/*");	line(f,"   Interpolation kernel specs:");	cr(f);	line(f,"   Input channels per pixel = %d",g->id);	for (e = 0; e < g->id; e++) {		line(f,"   Input channel %d bits = %d",e, g->in.bpch[e]);		line(f,"   Input channel %d increment = %d",e, g->in.chi[e]);	}	if (g->in.pint != 0)		line(f,"   Input is channel interleaved");	else		line(f,"   Input is plane interleaved");	if (g->in.packed != 0)		line(f,"   Input channels are packed into one word");	else		line(f,"   Input channels are separate words");	if (t->it_ix)		line(f,"   Input value extraction is done in input table lookup");	cr(f);		line(f,"   Output channels per pixel = %d",g->od);	for (e = 0; e < g->od; e++) {		line(f,"   Output channel %d bits = %d",e, g->out.bpch[e]);		line(f,"   Output channel %d increment = %d",e, g->out.chi[e]);	}	if (g->out.pint != 0)		line(f,"   Output is channel interleaved");	else		line(f,"   Output is plane interleaved");	cr(f);	if (g->out.packed != 0)		line(f,"   Output channels are packed into one word");	else		line(f,"   Output channels are separate words");		if (t->sort)		line(f,"   Weight+voffset bits       = %d",t->sx_ab);	else		line(f,"   Simplex table index bits       = %d",t->sx_ab);	line(f,"   Interpolation table index bits = %d",t->ix_ab);	if (!t->sort)		line(f,"   Simplex table max resolution = %d",f->sxmxres);	line(f,"   Interpolation table max resolution = %d",f->ixmxres);	line(f," */");	cr(f);	/* - - - - - - - - - - - - */	line(f,"/*");	line(f,"   Machine architecture specs:");	cr(f);	if (a->bigend != 0)		line(f,"   Big Endian");	else		line(f,"   Little endian");	if (a->uwa != 0)		line(f,"   Using maximum sized memory accesses where possible");	else		line(f,"   Reading and writing pixel values separately");	line(f,"   Pointer size = %d bits",a->pbits);	cr(f);	for (e = 0; e < a->nords; e++) {		line(f,"   Ordinal size %2d bits is known as '%s'",		        a->ords[e].bits,a->ords[e].name);	}	line(f,"   Natural ordinal is '%s'", a->ords[a->natord].name);	cr(f);	for (e = 0; e < a->nints; e++) {		line(f,"   Integer size %2d bits is known as '%s'",		        a->ints[e].bits,a->ints[e].name);	}	line(f,"   Natural integer is '%s'", a->ints[a->natint].name);	cr(f);	line(f," */");	cr(f);}/* ---------------------------------------- *//* Architecture support *//* Find an ordinal with at least bits size *//* Return -1 if failed */int findord(fileo *f,int bits) {	mach_arch *a  = f->a;	int i;	for (i = 0; i < a->nords; i++) {		if (a->ords[i].bits >= bits)			return i;	}	return -1;}/* Round ordinal type up to natural size */int nord(	fileo *f,	int ov) {	if (ov >= 0 && ov < f->a->natord)		ov = f->a->natord;	return ov;}/* Find an ordinal with at least bits size, *//* or natural size, whichever is greater. *//* Return -1 if failed */int findnord(	fileo *f,	int bits) {	int ov;	ov = findord(f, bits);	ov = nord(f, ov);	return ov;}/* Find an integer with at least bits size *//* Return -1 if failed */int findint(	fileo *f,	int bits) {	mach_arch *a  = f->a;	int i;	for (i = 0; i < a->nints; i++) {		if (a->ints[i].bits >= bits)			return i;	}	return -1;}/* Round integer type up to natural size */int nint(	fileo *f,	int iv) {	if (iv >= 0 && iv < f->a->natint)		iv = f->a->natint;	return iv;}/* Find an interger with at least bits size, *//* or natural size, whichever is greater. *//* Return -1 if failed */int findnint(	fileo *f,	int bits) {	int iv;	iv = findint(f, bits);	iv = nint(f, iv);	return iv;}/* ------------------------------------ *//* File output support *//* Output a line to the file (including trailing \n) */voidline(fileo *f, char *fmt, ...){	int i;	va_list args;	/* Indent to the correct level */	for (i = 0; i < f->indt; i++)		fprintf(f->of,"	");		va_start(args, fmt);	vfprintf(f->of, fmt, args);	va_end(args);	fprintf(f->of, "\n");}/* Output the start of a line to the file) */voidsline(fileo *f, char *fmt, ...){	int i;	va_list args;	/* Indent to the correct level */	for (i = 0; i < f->indt; i++)		fprintf(f->of,"	");		va_start(args, fmt);	vfprintf(f->of, fmt, args);	va_end(args);}/* Output the middle of a line to the file) */voidmline(fileo *f, char *fmt, ...){	int i;	va_list args;	va_start(args, fmt);	vfprintf(f->of, fmt, args);	va_end(args);}/* Output the end of a line to the file (including trailing \n) */voideline(fileo *f, char *fmt, ...){	int i;	va_list args;	va_start(args, fmt);	vfprintf(f->of, fmt, args);	va_end(args);	fprintf(f->of, "\n");}/* ------------------------------------ */

⌨️ 快捷键说明

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