--- ray/src/px/pfilt.c 1990/11/28 11:13:23 1.12 +++ ray/src/px/pfilt.c 1991/10/28 08:10:18 1.18 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -17,7 +17,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" extern char *malloc(); +extern float *matchlamp(); +#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) + #define CHECKRAD 1.5 /* radius to check for filtering */ COLOR exposure = WHTCOLOR; /* exposure for the frame */ @@ -44,10 +47,14 @@ double spread = 1e-4; /* spread for star points */ char *tfname = NULL; +char *lampdat = "lamp.tab"; /* lamp data file */ + int xres, yres; /* resolution of input */ double inpaspect = 1.0; /* pixel aspect ratio of input */ int correctaspect = 0; /* aspect ratio correction? */ +int wrongformat = 0; + int xrad; /* x window size */ int yrad; /* y window size */ @@ -67,10 +74,12 @@ char **argv; extern long ftell(); extern int quit(), headline(); FILE *fin; + float *lampcolor; + char *lamptype = NULL; long fpos; double outaspect = 0.0; double d; - int i; + int i, j; if (signal(SIGINT, quit) == SIG_IGN) signal(SIGINT, SIG_IGN); @@ -116,6 +125,12 @@ char **argv; d = pow(2.0, atof(argv[i+1])); else d = atof(argv[i+1]); + if (d < 1e-20 || d > 1e20) { + fprintf(stderr, + "%s: exposure out of range\n", + argv[0]); + exit(1); + } switch (argv[i][2]) { case '\0': scalecolor(exposure, d); @@ -134,6 +149,12 @@ char **argv; } i++; break; + case 'f': + lampdat = argv[++i]; + break; + case 't': + lamptype = argv[++i]; + break; case '1': singlepass = 1; break; @@ -167,7 +188,20 @@ char **argv; } else break; - + /* get lamp data (if necessary) */ + if (lamptype != NULL) { + if (loadlamps(lampdat) < 0) + quit(1); + if ((lampcolor = matchlamp(lamptype)) == NULL) { + fprintf(stderr, "%s: unknown lamp type\n", lamptype); + quit(1); + } + for (i = 0; i < 3; i++) + if (lampcolor[i] > 1e-4) + colval(exposure,i) /= lampcolor[i]; + freelamps(); + } + /* open input file */ if (i == argc) { if (singlepass) fin = stdin; @@ -195,7 +229,12 @@ char **argv; quit(1); } /* get header */ - getheader(fin, headline); + getheader(fin, headline, NULL); + if (wrongformat) { + fprintf(stderr, "%s: input must be a Radiance picture\n", + progname); + quit(1); + } /* add new header info. */ printargs(i, argv, stdout); /* get picture size */ @@ -241,9 +280,15 @@ char **argv; headline(s) /* process line from header */ char *s; { + char fmt[32]; + fputs(s, stdout); /* copy to output */ if (isaspect(s)) /* get aspect ratio */ inpaspect *= aspectval(s); + else if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } } @@ -342,6 +387,7 @@ FILE *in; scan2init() /* prepare scanline arrays */ { + COLOR ctmp; double d; register int i; @@ -357,7 +403,7 @@ scan2init() /* prepare scanline arrays */ initmask(); /* initialize filter table */ } - barsize = 2 * yrad; + barsize = 2*yrad + 1; scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); for (i = 0; i < barsize; i++) { scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); @@ -371,17 +417,25 @@ scan2init() /* prepare scanline arrays */ fprintf(stderr, "%s: out of memory\n", progname); quit(1); } - /* record pixel aspect and exposure */ + /* record pixel aspect ratio */ if (!correctaspect) { d = x_c / y_r; - if (d < .99 || d > 1.01) + if (!FEQ(d,1.0)) fputaspect(d, stdout); } + /* record exposure */ d = bright(exposure); - if (d < .995 || d > 1.005) + if (!FEQ(d,1.0)) fputexpos(d, stdout); + /* record color correction */ + copycolor(ctmp, exposure); + scalecolor(ctmp, 1.0/d); + if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) || + !FEQ(colval(ctmp,GRN),colval(ctmp,BLU))) + fputcolcor(ctmp, stdout); printf("\n"); - fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ + /* write out resolution */ + fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); }