--- ray/src/px/pfilt.c 1989/02/02 10:49:26 1.1 +++ ray/src/px/pfilt.c 1990/09/13 09:46:00 1.10 @@ -16,7 +16,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" - extern char *malloc(); #define CHECKRAD 1.5 /* radius to check for filtering */ @@ -28,6 +27,9 @@ double rad = 0.0; /* output pixel radius for filteri int nrows = 0; /* number of rows for output */ int ncols = 0; /* number of columns for output */ +double x_c = 1.0; /* ratio of output x size to input */ +double y_r = 1.0; /* ratio of output y size to input */ + int singlepass = 0; /* true means skip first pass */ int avghot = 0; /* true means average in bright spots */ @@ -43,9 +45,8 @@ double spread = 1e-4; /* spread for star points */ char *tfname = NULL; int xres, yres; /* resolution of input */ +double inpaspect = 1.0; /* pixel aspect ratio of input */ -double x_c, y_r; /* conversion factors */ - int xrad; /* x window size */ int yrad; /* y window size */ @@ -63,9 +64,10 @@ char **argv; extern char *mktemp(); extern double atof(), pow(); extern long ftell(); - extern int quit(); + extern int quit(), headline(); FILE *fin; long fpos; + double outaspect = 0.0; double d; int i; @@ -86,11 +88,25 @@ char **argv; if (argv[i][0] == '-') switch (argv[i][1]) { case 'x': - ncols = atoi(argv[++i]); + i++; + if (argv[i][0] == '/') { + x_c = 1.0/atof(argv[i]+1); + ncols = 0; + } else + ncols = atoi(argv[i]); break; case 'y': - nrows = atoi(argv[++i]); + i++; + if (argv[i][0] == '/') { + y_r = 1.0/atof(argv[i]+1); + nrows = 0; + } else + nrows = atoi(argv[i]); 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])); @@ -117,7 +133,10 @@ char **argv; case '1': singlepass = 1; break; - case 'p': + case '2': + singlepass = 0; + break; + case 'n': npts = atoi(argv[++i]) / 2; break; case 's': @@ -171,22 +190,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); } + /* compute output resolution */ if (ncols <= 0) - ncols = xres; + ncols = x_c*xres + .5; if (nrows <= 0) - nrows = yres; + 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); @@ -206,6 +234,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; { @@ -289,17 +326,20 @@ 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; - x_c = (double)ncols/xres; - y_r = (double)nrows/yres; - if (rad <= 0.0) { xrad = xres/ncols/2 + 1; yrad = yres/nrows/2 + 1; @@ -326,11 +366,15 @@ 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 */ + 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 */ }