1 |
< |
/* Copyright (c) 1986 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" |
18 |
|
|
19 |
< |
#define PI 3.14159265359 |
19 |
> |
#define PI 3.14159265359 |
20 |
|
|
21 |
< |
#define FTINY (1e-6) |
21 |
> |
#define FTINY (1e-6) |
22 |
|
|
23 |
|
extern int nrows, ncols; /* number of rows and columns for output */ |
24 |
|
|
36 |
|
|
37 |
|
extern COLOR exposure; /* exposure for frame */ |
38 |
|
|
39 |
< |
#define AVGLVL 0.5 /* target mean brightness */ |
39 |
> |
#define AVGLVL 0.5 /* target mean brightness */ |
40 |
|
|
41 |
< |
double avgbrt; /* average picture brightness */ |
41 |
> |
double avgbrt; /* average picture brightness */ |
42 |
> |
long npix; /* # pixels in average */ |
43 |
|
|
44 |
< |
typedef struct hotpix { /* structure for avgbrt pixels */ |
44 |
> |
typedef struct hotpix { /* structure for avgbrt pixels */ |
45 |
|
struct hotpix *next; /* next in list */ |
46 |
|
COLOR val; /* pixel color */ |
47 |
|
short x, y; /* pixel position */ |
48 |
|
float slope; /* random slope for diffraction */ |
49 |
|
} HOTPIX; |
50 |
|
|
51 |
< |
HOTPIX *head; /* head of avgbrt pixel list */ |
51 |
> |
HOTPIX *head; /* head of avgbrt pixel list */ |
52 |
|
|
53 |
< |
double sprdfact; /* computed spread factor */ |
53 |
> |
double sprdfact; /* computed spread factor */ |
54 |
|
|
55 |
|
|
56 |
|
pass1init() /* prepare for first pass */ |
57 |
|
{ |
58 |
|
avgbrt = 0.0; |
59 |
+ |
npix = 0; |
60 |
|
head = NULL; |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
pass1default() /* for single pass */ |
65 |
|
{ |
66 |
< |
avgbrt = AVGLVL * xres * yres; |
66 |
> |
avgbrt = AVGLVL; |
67 |
> |
npix = 1; |
68 |
|
head = NULL; |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
pass1scan(scan, y) /* process first pass scanline */ |
73 |
< |
register COLOR *scan; |
73 |
> |
register COLOR *scan; |
74 |
|
int y; |
75 |
|
{ |
76 |
|
extern char *malloc(); |
77 |
< |
extern double tan(), sqrt(); |
75 |
< |
double cbrt; |
77 |
> |
double cbrt; |
78 |
|
register int x; |
79 |
< |
register HOTPIX *hp; |
79 |
> |
register HOTPIX *hp; |
80 |
|
|
81 |
|
for (x = 0; x < xres; x++) { |
82 |
|
|
83 |
|
cbrt = bright(scan[x]); |
84 |
|
|
85 |
< |
if (avghot || cbrt < hotlvl) |
86 |
< |
avgbrt += cbrt; |
85 |
> |
if (cbrt <= 0) |
86 |
> |
continue; |
87 |
|
|
88 |
+ |
if (avghot || cbrt < hotlvl) { |
89 |
+ |
avgbrt += cbrt; |
90 |
+ |
npix++; |
91 |
+ |
} |
92 |
|
if (npts && cbrt >= hotlvl) { |
93 |
|
hp = (HOTPIX *)malloc(sizeof(HOTPIX)); |
94 |
|
if (hp == NULL) { |
109 |
|
|
110 |
|
pass2init() /* prepare for final pass */ |
111 |
|
{ |
112 |
< |
avgbrt /= (double)xres * yres; |
113 |
< |
|
114 |
< |
if (avgbrt <= FTINY) { |
109 |
< |
fprintf(stderr, "%s: picture too dark\n", progname); |
112 |
> |
if (!npix) { |
113 |
> |
fprintf(stderr, "%s: picture too dark or too bright\n", |
114 |
> |
progname); |
115 |
|
quit(1); |
116 |
|
} |
117 |
+ |
avgbrt /= (double)npix; |
118 |
|
|
119 |
|
scalecolor(exposure, AVGLVL/avgbrt); |
120 |
|
|
124 |
|
|
125 |
|
|
126 |
|
pass2scan(scan, y) /* process final pass scanline */ |
127 |
< |
register COLOR *scan; |
127 |
> |
register COLOR *scan; |
128 |
|
int y; |
129 |
|
{ |
130 |
|
int xmin, xmax; |
131 |
|
register int x; |
132 |
< |
register HOTPIX *hp; |
132 |
> |
register HOTPIX *hp; |
133 |
|
|
134 |
|
for (hp = head; hp != NULL; hp = hp->next) { |
135 |
|
if (hp->slope > FTINY) { |
160 |
|
starpoint(fcol, x, y, hp) /* pixel is on the star's point */ |
161 |
|
COLOR fcol; |
162 |
|
int x, y; |
163 |
< |
register HOTPIX *hp; |
163 |
> |
register HOTPIX *hp; |
164 |
|
{ |
165 |
|
COLOR ctmp; |
166 |
< |
double d2; |
166 |
> |
double d2; |
167 |
|
|
168 |
|
d2 = (double)(x - hp->x)*(x - hp->x) + (double)(y - hp->y)*(y - hp->y); |
169 |
|
if (d2 > sprdfact) { |