--- ray/src/px/pf2.c 1992/10/02 16:23:20 2.3 +++ ray/src/px/pf2.c 2003/02/22 02:07:27 2.6 @@ -1,17 +1,14 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pf2.c,v 2.6 2003/02/22 02:07:27 greg Exp $"; #endif - /* * pf2.c - routines used by pfilt. - * - * 10/3/85 */ #include +#include + #include #include "random.h" @@ -38,9 +35,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 */ @@ -57,13 +57,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; } @@ -72,18 +74,21 @@ pass1scan(scan, y) /* process first pass scanline */ register COLOR *scan; int y; { - extern char *malloc(); 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) { @@ -104,16 +109,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; }