--- ray/src/px/pf2.c 1992/09/21 12:14:08 2.2 +++ ray/src/px/pf2.c 1996/04/02 10:32:29 2.5 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -6,12 +6,12 @@ static char SCCSid[] = "$SunId$ LBL"; /* * pf2.c - routines used by pfilt. - * - * 10/3/85 */ #include +#include + #include "random.h" #include "color.h" @@ -36,9 +36,12 @@ extern char *progname; extern COLOR exposure; /* exposure for frame */ +extern double (*ourbright)(); /* brightness calculation function */ + #define AVGLVL 0.5 /* target mean brightness */ double avgbrt; /* average picture brightness */ +long npix; /* # pixels in average */ typedef struct hotpix { /* structure for avgbrt pixels */ struct hotpix *next; /* next in list */ @@ -55,13 +58,15 @@ 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; } @@ -71,18 +76,21 @@ register COLOR *scan; int y; { extern char *malloc(); - extern double tan(), sqrt(); double cbrt; register int x; 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,16 +111,16 @@ 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; }