#include #include #include #include #include #include #include #include #include "cement.h" #include "pnmutils.h" #include "file.h" #include "powLookup.h" #include "jpeg-6b/jpeglib.h" static int verbose=0; /* * this function doesn't return on error, it aborts. * * the filename provided is opened and read into the global * double vector 'powLookupTable[]', overwriting the default * values therein. the variables 'p' and 'powLookupExponent' * are zeroed. * * the input text file: * 1) should always have "L0\n" as the first three bytes. * 2) can have any comments delimited by '#' and '\n' * 3) blank lines are ignored * 4) an input line has: index value [0..255], whitespace, lightspace value * 5) all index values from 0 to 255 must be assigned a value for now. * since we know the response function for a reasonable camera should be * at least semimonotonic, we could fill in gaps etc... not today. */ void readlut(char *lut_filename, double *p, double *powLookupExponent) { // some variables used in reading a text file lut File *lutfile; double x; int i, j, k, lineno, maxlinelength=1024, lutsize=256; boolean isCommentLine, postWhitespace, *lutset, lutsetall; char *s; /* maali may 9 2000 */ if(lut_filename !=NULL) { if ((lutfile = fileopen(lut_filename, "r"))==NULL) { fprintf(stderr, "Unable to open %s.\n", lut_filename); exit(EXIT_FAILURE); } else { /* read in lut. things we want to add: * 3) header info (may be in comments) * e.g. name of assoc. imaging device */ isCommentLine=FALSE; postWhitespace=FALSE; maxlinelength=1024; lineno=0; // allocate and initialize 'lutset' and 's' lutset=((boolean*)malloc(lutsize*sizeof(boolean))); for (i=0; imax) { s[k]=filegetc(lutfile); if (s[k]=='#') { if (!postWhitespace) { isCommentLine=TRUE; } s[k] = 0; while((!fileeof(lutfile)) &&(filegetc(lutfile)!='\n')) { /* here we could process info from comments */ } break; } if (!isspace(s[k])) postWhitespace=TRUE; k++; } while((s[k-1]!='\n') &&(!fileeof(lutfile)) &&(k255)) { fprintf(stderr, "Index (%d) out of range [0..255]" " on line %3d of %s\n", j, lineno, lut_filename); exit(EXIT_FAILURE); } powLookupTable[j] = x; lutset[j] = TRUE; if (verbose) printf("lut[%3d]=%10.20g\n", j, powLookupTable[j]); }//i