This is colormap.c in view mode; [Download] [Up]
#include <stdio.h> #include <sys/types.h> #include "ooglutil.h" #include "color.h" ColorA builtin[] = {0.8, 0.1, 0.1, 0.75, 0.1, 0.65, 0.4, 0.75, 0.1, 0.1, 0.8, 0.75, 0.9, 0.6, 0, 0.75, 0, 0.6, 0.8, 0.75, 0.5, 0, 0.9, 0.75, .7, .15, .1, .75, .2, .2, .8, .75, .9, .6, .02, .75, .1, .3, .8, .75, .1, .7, .2, .75, .8, .8, .4, .75, .7, .7, 0, .75, .7, 0, .7, .75, 0, .7, .7, .75, .9, 0, .2, .75, .2, .9, 0, .75, 0, .2, .9, .75, .75, .75, .75, .75, .8, .4, 0, .75, .8, .4, 0, .75, 0, .4, .8, .75, 0, .4, .8, .75, 0, .8, .4, .75, 0, .8, .4, .75, .4, 0, .8, .75}; ColorA *colormap = NULL; static int cnt; static int doneread = 0; static char default_name[] = "sample.cmap"; int readcmap(cmapfname) char *cmapfname; { FILE *fp; int size = 256; if (cmapfname == NULL) cmapfname = findfile(NULL, default_name); doneread = 1; if(cmapfname == NULL || (fp = fopen(cmapfname,"r")) == NULL) goto ZXCV; cnt = 0; colormap = (ColorA *) malloc(sizeof(ColorA) * size); while (fscanf(fp, "%f%f%f%f", &colormap[cnt].r, &colormap[cnt].g, &colormap[cnt].b, &colormap[cnt].a) == 4) { cnt++; if (cnt > size) { size *= 2; colormap = (ColorA *) realloc(colormap, sizeof(ColorA) * size); if (colormap == NULL) goto ZXCV; } } return(cnt); /* fprintf(stderr,"readcmap: %d entries read\n",cnt); */ ZXCV: colormap = builtin; cnt = sizeof(builtin); return(cnt); } ColorA GetCmapEntry(n) int n; { if (!doneread) { char *cmapfile; extern char *getenv(); if((cmapfile = getenv("CMAP_FILE")) != NULL) fprintf(stderr,"Using CMAP_FILE environment variable to read color map\n"); readcmap(cmapfile); } if (n < 0 || n > cnt) return(colormap[0]); else return (colormap[n]); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.