--- ray/src/px/pfilt.c 1991/04/18 14:35:21 1.16 +++ ray/src/px/pfilt.c 1993/06/18 16:20:16 2.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,47 +10,49 @@ static char SCCSid[] = "$SunId$ LBL"; * 9/26/85 */ -#include +#include "standard.h" #include #include "color.h" -extern char *malloc(); +#include "resolu.h" + +#include "paths.h" + extern float *matchlamp(); -#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) +#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) -#define CHECKRAD 1.5 /* radius to check for filtering */ +#define CHECKRAD 1.5 /* radius to check for filtering */ COLOR exposure = WHTCOLOR; /* exposure for the frame */ -double rad = 0.0; /* output pixel radius for filtering */ +double rad = 0.0; /* output pixel radius for filtering */ 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 */ +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 */ -double hotlvl = 1000.0; /* level considered "hot" */ +double hotlvl = 100.0; /* level considered "hot" */ int npts = 0; /* (half) number of points for stars */ -double spread = 1e-4; /* spread for star points */ +double spread = 1e-4; /* spread for star points */ -#define TEMPLATE "/usr/tmp/pfXXXXXX" - char *tfname = NULL; char *lampdat = "lamp.tab"; /* lamp data file */ +int order; /* scanline ordering of input */ int xres, yres; /* resolution of input */ -double inpaspect = 1.0; /* pixel aspect ratio of input */ +double inpaspect = 1.0; /* pixel aspect ratio of input */ int correctaspect = 0; /* aspect ratio correction? */ int wrongformat = 0; @@ -69,30 +71,33 @@ main(argc, argv) int argc; char **argv; { - extern char *mktemp(); - extern double atof(), pow(); extern long ftell(); extern int quit(), headline(); FILE *fin; float *lampcolor; char *lamptype = NULL; long fpos; - double outaspect = 0.0; - double d; - int i; - + double outaspect = 0.0; + double d; + int i, j; +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif if (signal(SIGINT, quit) == SIG_IGN) signal(SIGINT, SIG_IGN); if (signal(SIGHUP, quit) == SIG_IGN) signal(SIGINT, SIG_IGN); signal(SIGTERM, quit); signal(SIGPIPE, quit); -#ifdef SIGXCPU +#ifdef SIGXCPU signal(SIGXCPU, quit); signal(SIGXFSZ, quit); #endif - progname = argv[0]; + progname = argv[0] = fixargv0(argv[0]); for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -196,9 +201,9 @@ char **argv; 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]; + for (i = 0; i < 3; i++) + if (lampcolor[i] > 1e-4) + colval(exposure,i) /= lampcolor[i]; freelamps(); } /* open input file */ @@ -238,10 +243,12 @@ char **argv; /* add new header info. */ printargs(i, argv, stdout); /* get picture size */ - if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { + if ((order = fgetresolu(&xres, &yres, fin)) < 0) { fprintf(stderr, "%s: bad picture size\n", progname); quit(1); } + if (!(order & YMAJOR)) + inpaspect = 1.0/inpaspect; /* compute output resolution */ if (ncols <= 0) ncols = x_c*xres + .5; @@ -285,6 +292,8 @@ char *s; fputs(s, stdout); /* copy to output */ if (isaspect(s)) /* get aspect ratio */ inpaspect *= aspectval(s); + else if (isexpos(s)) + hotlvl *= exposval(s); else if (isformat(s)) { formatval(fmt, s); wrongformat = strcmp(fmt, COLRFMT); @@ -322,13 +331,13 @@ FILE *in; } for (i = 0; i < yres; i++) { if (freadscan(scan, xres, in) < 0) { - nrows = nrows * i / yres; /* adjust frame */ + nrows = (long)nrows * i / yres; /* adjust frame */ if (nrows <= 0) { fprintf(stderr, "%s: empty frame\n", progname); quit(1); } fprintf(stderr, "%s: warning - partial frame (%d%%)\n", - progname, 100*i/yres); + progname, (int)(100L*i/yres)); yres = i; y_r = (double)nrows/yres; break; @@ -345,7 +354,7 @@ FILE *in; int yread; int ycent, xcent; int r, c; - + pass2init(); scan2init(); yread = 0; @@ -388,7 +397,7 @@ FILE *in; scan2init() /* prepare scanline arrays */ { COLOR ctmp; - double d; + double d; register int i; if (rad <= 0.0) { @@ -403,7 +412,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)); @@ -419,7 +428,7 @@ scan2init() /* prepare scanline arrays */ } /* record pixel aspect ratio */ if (!correctaspect) { - d = x_c / y_r; + d = order & YMAJOR ? x_c/y_r : y_r/x_c ; if (!FEQ(d,1.0)) fputaspect(d, stdout); } @@ -435,7 +444,7 @@ scan2init() /* prepare scanline arrays */ fputcolcor(ctmp, stdout); printf("\n"); /* write out resolution */ - fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); + fputresolu(order, ncols, nrows, stdout); }