1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
6 |
|
|
7 |
|
/* |
8 |
|
* pf2.c - routines used by pfilt. |
9 |
– |
* |
10 |
– |
* 10/3/85 |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
|
13 |
+ |
#include <math.h> |
14 |
+ |
|
15 |
|
#include "random.h" |
16 |
|
|
17 |
|
#include "color.h" |
36 |
|
|
37 |
|
extern COLOR exposure; /* exposure for frame */ |
38 |
|
|
39 |
+ |
extern double (*ourbright)(); /* brightness calculation function */ |
40 |
+ |
|
41 |
|
#define AVGLVL 0.5 /* target mean brightness */ |
42 |
|
|
43 |
|
double avgbrt; /* average picture brightness */ |
44 |
+ |
long npix; /* # pixels in average */ |
45 |
|
|
46 |
|
typedef struct hotpix { /* structure for avgbrt pixels */ |
47 |
|
struct hotpix *next; /* next in list */ |
58 |
|
pass1init() /* prepare for first pass */ |
59 |
|
{ |
60 |
|
avgbrt = 0.0; |
61 |
+ |
npix = 0; |
62 |
|
head = NULL; |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
pass1default() /* for single pass */ |
67 |
|
{ |
68 |
< |
avgbrt = AVGLVL * xres * yres; |
68 |
> |
avgbrt = AVGLVL; |
69 |
> |
npix = 1; |
70 |
|
head = NULL; |
71 |
|
} |
72 |
|
|
76 |
|
int y; |
77 |
|
{ |
78 |
|
extern char *malloc(); |
74 |
– |
extern double tan(), sqrt(); |
79 |
|
double cbrt; |
80 |
|
register int x; |
81 |
|
register HOTPIX *hp; |
82 |
|
|
83 |
|
for (x = 0; x < xres; x++) { |
84 |
|
|
85 |
< |
cbrt = bright(scan[x]); |
85 |
> |
cbrt = (*ourbright)(scan[x]); |
86 |
|
|
87 |
< |
if (avghot || cbrt < hotlvl) |
88 |
< |
avgbrt += cbrt; |
87 |
> |
if (cbrt <= 0) |
88 |
> |
continue; |
89 |
|
|
90 |
+ |
if (avghot || cbrt < hotlvl) { |
91 |
+ |
avgbrt += cbrt; |
92 |
+ |
npix++; |
93 |
+ |
} |
94 |
|
if (npts && cbrt >= hotlvl) { |
95 |
|
hp = (HOTPIX *)malloc(sizeof(HOTPIX)); |
96 |
|
if (hp == NULL) { |
111 |
|
|
112 |
|
pass2init() /* prepare for final pass */ |
113 |
|
{ |
114 |
< |
avgbrt /= (double)xres * yres; |
115 |
< |
|
116 |
< |
if (avgbrt <= FTINY) { |
109 |
< |
fprintf(stderr, "%s: picture too dark\n", progname); |
114 |
> |
if (!npix) { |
115 |
> |
fprintf(stderr, "%s: picture too dark or too bright\n", |
116 |
> |
progname); |
117 |
|
quit(1); |
118 |
|
} |
119 |
+ |
avgbrt /= (double)npix; |
120 |
|
|
121 |
|
scalecolor(exposure, AVGLVL/avgbrt); |
122 |
|
|
123 |
< |
sprdfact = spread / (hotlvl * bright(exposure)) |
123 |
> |
sprdfact = spread / (hotlvl * (*ourbright)(exposure)) |
124 |
|
* ((double)xres*xres + (double)yres*yres) / 4.0; |
125 |
|
} |
126 |
|
|