--- ray/src/px/pfilt.c 1989/04/11 21:50:05 1.4 +++ ray/src/px/pfilt.c 1990/12/08 13:23:47 1.14 @@ -16,8 +16,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" - extern char *malloc(); +extern float *matchlamp(); #define CHECKRAD 1.5 /* radius to check for filtering */ @@ -45,7 +45,11 @@ 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 xrad; /* x window size */ int yrad; /* y window size */ @@ -64,9 +68,12 @@ char **argv; extern char *mktemp(); extern double atof(), pow(); extern long ftell(); - extern int quit(); + extern int quit(), headline(); FILE *fin; + float *lampcolor; + char *lamptype = NULL; long fpos; + double outaspect = 0.0; double d; int i; @@ -88,18 +95,27 @@ char **argv; switch (argv[i][1]) { case 'x': i++; - if (argv[i][0] == '/') + if (argv[i][0] == '/') { x_c = 1.0/atof(argv[i]+1); - else + ncols = 0; + } else ncols = atoi(argv[i]); break; case 'y': i++; - if (argv[i][0] == '/') + if (argv[i][0] == '/') { y_r = 1.0/atof(argv[i]+1); - else + nrows = 0; + } else nrows = atoi(argv[i]); break; + case 'c': + correctaspect = !correctaspect; + break; + case 'p': + i++; + outaspect = atof(argv[i]); + break; case 'e': if (argv[i+1][0] == '+' || argv[i+1][0] == '-') d = pow(2.0, atof(argv[i+1])); @@ -123,10 +139,19 @@ char **argv; } i++; break; + case 'f': + lampdat = argv[++i]; + break; + case 't': + lamptype = argv[++i]; + break; case '1': singlepass = 1; break; - case 'p': + case '2': + singlepass = 0; + break; + case 'n': npts = atoi(argv[++i]) / 2; break; case 's': @@ -153,7 +178,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); + } + colval(exposure,RED) /= lampcolor[0]; + colval(exposure,GRN) /= lampcolor[1]; + colval(exposure,BLU) /= lampcolor[2]; + freelamps(); + } + /* open input file */ if (i == argc) { if (singlepass) fin = stdin; @@ -180,26 +218,31 @@ char **argv; fprintf(stderr, "%s: bad # file arguments\n", progname); quit(1); } - /* copy header */ - copyheader(fin, stdout); + /* get header */ + getheader(fin, headline); /* add new header info. */ printargs(i, argv, stdout); /* get picture size */ - if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) { + if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { fprintf(stderr, "%s: bad picture size\n", progname); quit(1); } - if (ncols > 0) - x_c = (double)ncols/xres; - else + /* compute output resolution */ + if (ncols <= 0) ncols = x_c*xres + .5; - if (nrows > 0) - y_r = (double)nrows/yres; - else + if (nrows <= 0) nrows = y_r*yres + .5; + if (outaspect > .01) { + d = inpaspect * yres/xres / outaspect; + if (d * ncols > nrows) + ncols = nrows / d; + else + nrows = ncols * d; + } + x_c = (double)ncols/xres; + y_r = (double)nrows/yres; - if (singlepass) { - /* skip exposure, etc. */ + if (singlepass) { /* skip exposure, etc. */ pass1default(); pass2(fin); quit(0); @@ -219,6 +262,15 @@ char **argv; } +headline(s) /* process line from header */ +char *s; +{ + fputs(s, stdout); /* copy to output */ + if (isaspect(s)) /* get aspect ratio */ + inpaspect *= aspectval(s); +} + + copyfile(in, out) /* copy a file */ register FILE *in, *out; { @@ -257,6 +309,7 @@ FILE *in; fprintf(stderr, "%s: warning - partial frame (%d%%)\n", progname, 100*i/yres); yres = i; + y_r = (double)nrows/yres; break; } pass1scan(scan, i); @@ -302,12 +355,18 @@ FILE *in; quit(1); } } + /* skip leftovers */ + while (yread < yres) { + if (freadscan(scanin[0], xres, in) < 0) + break; + yread++; + } } scan2init() /* prepare scanline arrays */ { - double e; + double d; register int i; if (rad <= 0.0) { @@ -336,11 +395,17 @@ scan2init() /* prepare scanline arrays */ fprintf(stderr, "%s: out of memory\n", progname); quit(1); } - e = bright(exposure); - if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ - printf("EXPOSURE=%e\n", e); + /* record pixel aspect and exposure */ + if (!correctaspect) { + d = x_c / y_r; + if (d < .99 || d > 1.01) + fputaspect(d, stdout); + } + d = bright(exposure); + if (d < .995 || d > 1.005) + fputexpos(d, stdout); printf("\n"); - printf("-Y %d +X %d\n", nrows, ncols); /* write picture size */ + fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ }