--- ray/src/px/pf2.c 1991/11/12 16:05:24 2.1 +++ ray/src/px/pf2.c 1996/04/02 10:32:29 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -6,19 +6,19 @@ static char SCCSid[] = "$SunId$ LBL"; /* * pf2.c - routines used by pfilt. - * - * 10/3/85 */ #include +#include + #include "random.h" #include "color.h" -#define PI 3.14159265359 +#define PI 3.14159265359 -#define FTINY (1e-6) +#define FTINY (1e-6) extern int nrows, ncols; /* number of rows and columns for output */ @@ -36,53 +36,61 @@ extern char *progname; extern COLOR exposure; /* exposure for frame */ -#define AVGLVL 0.5 /* target mean brightness */ +extern double (*ourbright)(); /* brightness calculation function */ -double avgbrt; /* average picture brightness */ +#define AVGLVL 0.5 /* target mean brightness */ -typedef struct hotpix { /* structure for avgbrt pixels */ +double avgbrt; /* average picture brightness */ +long npix; /* # pixels in average */ + +typedef struct hotpix { /* structure for avgbrt pixels */ struct hotpix *next; /* next in list */ COLOR val; /* pixel color */ short x, y; /* pixel position */ float slope; /* random slope for diffraction */ } HOTPIX; -HOTPIX *head; /* head of avgbrt pixel list */ +HOTPIX *head; /* head of avgbrt pixel list */ -double sprdfact; /* computed spread factor */ +double sprdfact; /* computed spread factor */ pass1init() /* prepare for first pass */ { avgbrt = 0.0; + npix = 0; head = NULL; } pass1default() /* for single pass */ { - avgbrt = AVGLVL * xres * yres; + avgbrt = AVGLVL; + npix = 1; head = NULL; } pass1scan(scan, y) /* process first pass scanline */ -register COLOR *scan; +register COLOR *scan; int y; { extern char *malloc(); - extern double tan(), sqrt(); - double cbrt; + double cbrt; register int x; - register HOTPIX *hp; + register HOTPIX *hp; for (x = 0; x < xres; x++) { - cbrt = bright(scan[x]); + cbrt = (*ourbright)(scan[x]); - if (avghot || cbrt < hotlvl) - avgbrt += cbrt; + if (cbrt <= 0) + continue; + if (avghot || cbrt < hotlvl) { + avgbrt += cbrt; + npix++; + } if (npts && cbrt >= hotlvl) { hp = (HOTPIX *)malloc(sizeof(HOTPIX)); if (hp == NULL) { @@ -103,27 +111,27 @@ int y; pass2init() /* prepare for final pass */ { - avgbrt /= (double)xres * yres; - - if (avgbrt <= FTINY) { - fprintf(stderr, "%s: picture too dark\n", progname); + if (!npix) { + fprintf(stderr, "%s: picture too dark or too bright\n", + progname); quit(1); } + avgbrt /= (double)npix; scalecolor(exposure, AVGLVL/avgbrt); - sprdfact = spread / (hotlvl * bright(exposure)) + sprdfact = spread / (hotlvl * (*ourbright)(exposure)) * ((double)xres*xres + (double)yres*yres) / 4.0; } pass2scan(scan, y) /* process final pass scanline */ -register COLOR *scan; +register COLOR *scan; int y; { int xmin, xmax; register int x; - register HOTPIX *hp; + register HOTPIX *hp; for (hp = head; hp != NULL; hp = hp->next) { if (hp->slope > FTINY) { @@ -154,10 +162,10 @@ int y; starpoint(fcol, x, y, hp) /* pixel is on the star's point */ COLOR fcol; int x, y; -register HOTPIX *hp; +register HOTPIX *hp; { COLOR ctmp; - double d2; + double d2; d2 = (double)(x - hp->x)*(x - hp->x) + (double)(y - hp->y)*(y - hp->y); if (d2 > sprdfact) {