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

📄 imdi_gen.c

📁   这是一个高速多维插值算法。当我们建模以后
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	if (fclose(kheader) != 0) {		fprintf(stderr,"imdi_gen: unable to close file 'imdi_k.h'\n");		exit(-1);	}	/* Free the kname list */	for(lp = list; lp != NULL;) {		char *p = (char *)lp;		lp = lp->next;		free(p);	}	return 0;}void translate_pixrep(pixlayout *pl, char **desc, int *prec, imdi_pixrep rep, int dim, mach_arch *a);/* Translate between a gendesc and genspec */int 				/* Return number of combinations possible */set_genspec(genspec *gs,		/* Return specification */gendesc *gd,		/* Input description */int comb,			/* Combination index */mach_arch *a		/* Machine architecture */) {	int nc = 1;			/* Number of combinations */	int nidc, id;		/* Number of input dimension combinations, current index */	int nodc, od;		/* Number of output dimension combinations, current index */	int nirc, ir;		/* Number of input representation combinations, current index */	int norc, or;		/* Number of output representation combinations, current index */	int ndc, dir;		/* Number of direction combinations, current index */	/* Figure out how many combinations there are */	for (nidc = 0; gd->idcombs[nidc] != 0; nidc++)	/* Input dimension */		;	nc *= nidc;	for (nodc = 0; gd->odcombs[nodc] != 0; nodc++)	/* Output dimension */		;	nc *= nodc;	for (nirc = 0; gd->incombs[nirc] != 0; nirc++)	/* Input representation */		;	nc *= nirc;	for (norc = 0; gd->outcombs[norc] != 0; norc++)	/* Output representation */		;	if (nirc != norc) {		fprintf(stderr,"imdi_gen: Must be equal numberof input and output representations\n");		exit(-1);	}			for (ndc = 0; gd->dircombs[ndc] != 0; ndc++)	/* Direction */		;	nc *= ndc;	if (comb < nc) {	/* If we are within a legal combination */		int iprec, oprec;		char *idesc, *odesc;	/* Representation descriptions */		char *ddesc;			/* Direction description */		id = comb % nidc;		comb /= nidc;		od = comb % nodc;		comb /= nodc;		ir = comb % nirc;		comb /= nirc;		or = ir;			/* In and out combs track together */		dir = comb % ndc;		comb /= ndc;#ifdef VERBOSE		printf("Combination id = %d, od = %d, ir = %d, or = %d, dir = %d\n",		       id,od,ir,or,dir);#endif /* VERBOSE */		gs->id = gd->idcombs[id];		/* Input dimensions */		gs->itres = gd->itres[id];		/* Interpolation table resolution */		gs->stres = gd->stres[id];		/* Simplex table resolution */		gs->od = gd->odcombs[od];		/* Output dimensions */		if (gs->id > IXDI) {			fprintf(stderr,"imdi_gen: Input dimension %d exceeds limit %d\n",gs->id,IXDI);			exit(-1);		}		if (gs->od > IXDO) {			fprintf(stderr,"imdi_gen: Output dimension %d exceeds limit %d\n",gs->od,IXDO);			exit(-1);		}		/* Input representation */		gs->irep = gd->incombs[ir];		/* Keep a copy of this */		translate_pixrep(&gs->in,  &idesc, &iprec, gd->incombs[ir], gs->id, a);		gs->in_signed = 0x0;			/* Not used during generation, used at runtime setup */		/* Output representation */		gs->orep = gd->outcombs[or];		/* Keep a copy of this */		translate_pixrep(&gs->out, &odesc, &oprec, gd->outcombs[or], gs->od, a);		gs->out_signed = 0x0;				/* Not used during generation, used at runtime setup */		/* Make native precision the smaller of input and output representation */		gs->prec = iprec < oprec ? iprec : oprec;		gs->dir = gd->dircombs[dir];	/* Direction */		ddesc = gs->dir == backward ? "b" : "f";	/* Direction description */#ifdef VERBOSE		printf("translates to prec = %d, id = %d, od = %d, itres %d, stdres %d\n",		       gs->prec,gs->id,gs->od,gs->itres,gs->stres);#endif /* VERBOSE */		/* Create a concise description string */		sprintf(gs->kdesc,"%d_%d_%s_%s_%s", gs->id, gs->od, idesc, odesc, ddesc);	}	return nc;}voidtranslate_pixrep(pixlayout *pl,		/* pixlayout to initialise */char **desc,			/* Return description identifier */int *prec,			/* Return basic precision specifier (may be NULL) */imdi_pixrep rep,	/* Representation to be translated */int dim,			/* Number of dimensions (values/pixel) */mach_arch *a		/* Machine architecture */) {	switch (rep) {		case pixint8: {		/* 8 Bits per value, pixel interleaved, no padding */			int i;			/* Could optimise this to packed for dim == 4 ~~~~ */			pl->pint = 1;		/* pixel interleaved */			pl->packed = 0;		/* Not packed */				for (i = 0; i < dim; i++) {				pl->bpch[i] = 8;	/* Bits per channel */				pl->chi[i] = dim;	/* Channel increment */				pl->bov[i] = 0;		/* Bit offset to value within channel */				pl->bpv[i] = 8;		/* Bits per value within channel */			}						if (prec != NULL)				*prec = 8;			/* Basic 8 bit precision */			if (desc != NULL)				*desc = "i8";		/* Interleaved 8 bit */		} break;			case planeint8: {		/* 8 bits per value, plane interleaved */			int i;			pl->pint = 0;		/* Not pixel interleaved */			pl->packed = 0;		/* Not packed */				for (i = 0; i < dim; i++) {				pl->bpch[i] = 8;	/* Bits per channel */				pl->chi[i] = 1;		/* Channel increment */				pl->bov[i] = 0;		/* Bit offset to value within channel */				pl->bpv[i] = 8;		/* Bits per value within channel */			}						if (prec != NULL)				*prec = 8;			/* Basic 8 bit precision */			if (desc != NULL)				*desc = "p8";		/* Planar 8 bit */		} break;		case pixint16: {		/* 16 Bits per value, pixel interleaved, no padding */			int i;			/* Could optimise this to packed for dim == 4 ~~~~ */			pl->pint = 1;		/* pixel interleaved */			pl->packed = 0;		/* Not packed */				for (i = 0; i < dim; i++) {				pl->bpch[i] = 16;	/* Bits per channel */				pl->chi[i] = dim;	/* Channel increment */				pl->bov[i] = 0;		/* Bit offset to value within channel */				pl->bpv[i] = 16;	/* Bits per value within channel */			}						if (prec != NULL)				*prec = 16;			/* Basic 8 bit precision */			if (desc != NULL)				*desc = "i16";		/* Interleaved 16 bit */		} break;			case planeint16: {		/* 16 bits per value, plane interleaved */			int i;			pl->pint = 0;		/* Not pixel interleaved */			pl->packed = 0;		/* Not packed */				for (i = 0; i < dim; i++) {				pl->bpch[i] = 16;	/* Bits per channel */				pl->chi[i] = 1;		/* Channel increment */				pl->bov[i] = 0;		/* Bit offset to value within channel */				pl->bpv[i] = 16;	/* Bits per value within channel */			}						if (prec != NULL)				*prec = 16;			/* Basic 8 bit precision */			if (desc != NULL)				*desc = "p16";		/* Planar 8 bit */		} break;		default: {			fprintf(stderr,"Warning: Unknown pixel representation %d\n",rep);		} break;	}}/* Initialse the aritecture structure properly */voidset_architecture(mach_arch *ar) {	unsigned long etest = 0xff;	if (*((unsigned char *)&etest) == 0xff) {		ar->bigend = 0;		/* Little endian */	} else {		ar->bigend = 1;		/* Big endian endian */	}#ifdef __ppc__		/* Section tunable for PowerPC */	ar->uwa    = 0;		/* Use wide memory access */	ar->shfm   = 0;		/* Use shifts to mask values */	ar->oscale = 8;		/* Has scaled indexing up to * 8 */	ar->smmul  = 0;		/* Doesn't have fast small multiply for index scaling */	ar->nords  = 3;		/* Number of ord types */	ar->natord = 2;		/* Most natural type (assume unsigned int) */	ar->nints  = 3;		/* Number of int types */	ar->natint = 2;		/* Most natural type (assume int) */	ar->pbits = sizeof(void *) * 8;		/* Number of bits in a pointer */	ar->ords[0].bits = 8 * sizeof(unsigned char);	ar->ords[0].name = "unsigned char";	ar->ords[0].align = 1;	ar->ords[1].bits = 8 * sizeof(unsigned short);	ar->ords[1].name = "unsigned short";	ar->ords[1].align = 1;	ar->ords[2].bits = 8 * sizeof(unsigned int);	ar->ords[2].name = "unsigned int";	ar->ords[2].align = 1;#ifdef ALLOW64	ar->ords[3].bits = 8 * sizeof(unsigned longlong);	ar->ords[3].name = "unsigned " str_longlong ;	ar->ords[3].align = 0;#endif /* ALLOW64 */	ar->ints[0].bits = 8 * sizeof(signed char);	ar->ints[0].name = "signed char";	ar->ints[0].align = 1;	ar->ints[1].bits = 8 * sizeof(short);	ar->ints[1].name = "short";	ar->ints[1].align = 1;	ar->ints[2].bits = 8 * sizeof(int);	ar->ints[2].name = "int";	ar->ints[2].align = 1;#ifdef ALLOW64	ar->ints[3].bits = 8 * sizeof(longlong);	ar->ints[3].name = str_longlong ;	ar->ints[3].align = 0;#endif /* ALLOW64 */#else /* Currently assume x86 type */	ar->uwa    = 0;		/* Use wide memory access */	ar->shfm   = 0;		/* Use shifts to mask values */	ar->oscale = 8;		/* Has scaled indexing up to * 8 */	ar->smmul  = 0;		/* Doesn't have fast small multiply for index scaling */// ~~99	ar->nords  = 3;		/* Number of ord types */	ar->natord = 2;		/* Most natural type (assume unsigned int) */	ar->nints  = 3;		/* Number of int types */	ar->natint = 2;		/* Most natural type (assume int) */	ar->pbits = sizeof(void *) * 8;		/* Number of bits in a pointer */	ar->ords[0].bits = 8 * sizeof(unsigned char);	ar->ords[0].name = "unsigned char";	ar->ords[0].align = 1;	ar->ords[1].bits = 8 * sizeof(unsigned short);	ar->ords[1].name = "unsigned short";	ar->ords[1].align = 1;	ar->ords[2].bits = 8 * sizeof(unsigned int);	ar->ords[2].name = "unsigned int";	ar->ords[2].align = 1;#ifdef ALLOW64	ar->ords[3].bits = 8 * sizeof(unsigned longlong);	ar->ords[3].name = "unsigned " str_longlong ;	ar->ords[3].align = 0;#endif /* ALLOW64 */	ar->ints[0].bits = 8 * sizeof(signed char);	ar->ints[0].name = "signed char";	ar->ints[0].align = 1;	ar->ints[1].bits = 8 * sizeof(short);	ar->ints[1].name = "short";	ar->ints[1].align = 1;	ar->ints[2].bits = 8 * sizeof(int);	ar->ints[2].name = "int";	ar->ints[2].align = 1;#ifdef ALLOW64	ar->ints[3].bits = 8 * sizeof(longlong);	ar->ints[3].name = str_longlong ;	ar->ints[3].align = 0;#endif /* ALLOW64 */#endif	/* Processor Architecture */}

⌨️ 快捷键说明

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