--- ray/src/px/pf2.c 1992/10/02 16:23:20 2.3 +++ 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,8 +6,6 @@ static char SCCSid[] = "$SunId$ LBL"; /* * pf2.c - routines used by pfilt. - * - * 10/3/85 */ #include @@ -38,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 */ @@ -57,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; } @@ -79,11 +82,15 @@ int y; 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 +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; }