--- ray/src/px/pf2.c 1992/10/02 16:23:20 2.3 +++ ray/src/px/pf2.c 2004/03/28 20:33:14 2.7 @@ -1,46 +1,26 @@ -/* 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.7 2004/03/28 20:33:14 schorsch Exp $"; #endif - /* * pf2.c - routines used by pfilt. - * - * 10/3/85 */ #include - +#include #include +#include "rterror.h" #include "random.h" - #include "color.h" +#include "pfilt.h" #define PI 3.14159265359 - #define FTINY (1e-6) -extern int nrows, ncols; /* number of rows and columns for output */ - -extern int xres, yres; /* x and y resolution */ - -extern int avghot; /* true means average in avgbrt spots */ - -extern double hotlvl; /* brightness considered "hot" */ - -extern int npts; /* # of points for stars */ - -extern double spread; /* spread for star points */ - -extern char *progname; - -extern COLOR exposure; /* exposure for frame */ - #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 */ @@ -53,37 +33,48 @@ HOTPIX *head; /* head of avgbrt pixel list */ double sprdfact; /* computed spread factor */ +static void starpoint(COLOR fcol, int x, int y, HOTPIX *hp); -pass1init() /* prepare for first pass */ + +extern void +pass1init(void) /* prepare for first pass */ { avgbrt = 0.0; + npix = 0; head = NULL; } -pass1default() /* for single pass */ +extern void +pass1default(void) /* for single pass */ { - avgbrt = AVGLVL * xres * yres; + avgbrt = AVGLVL; + npix = 1; head = NULL; } -pass1scan(scan, y) /* process first pass scanline */ -register COLOR *scan; -int y; +extern void +pass1scan( /* 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) { @@ -102,25 +93,28 @@ int y; } -pass2init() /* prepare for final pass */ +extern void +pass2init(void) /* 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; -int y; +extern void +pass2scan( /* process final pass scanline */ + register COLOR *scan, + int y +) { int xmin, xmax; register int x; @@ -152,10 +146,13 @@ int y; } -starpoint(fcol, x, y, hp) /* pixel is on the star's point */ -COLOR fcol; -int x, y; -register HOTPIX *hp; +static void +starpoint( /* pixel is on the star's point */ + COLOR fcol, + int x, + int y, + register HOTPIX *hp +) { COLOR ctmp; double d2;