1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* pf2.c - routines used by pfilt. |
9 |
– |
* |
10 |
– |
* 10/3/85 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
14 |
< |
|
15 |
< |
#include <math.h> |
16 |
< |
|
8 |
> |
#include "pfilt.h" |
9 |
|
#include "random.h" |
10 |
|
|
19 |
– |
#include "color.h" |
20 |
– |
|
21 |
– |
#define PI 3.14159265359 |
22 |
– |
|
23 |
– |
#define FTINY (1e-6) |
24 |
– |
|
25 |
– |
extern int nrows, ncols; /* number of rows and columns for output */ |
26 |
– |
|
27 |
– |
extern int xres, yres; /* x and y resolution */ |
28 |
– |
|
29 |
– |
extern int avghot; /* true means average in avgbrt spots */ |
30 |
– |
|
31 |
– |
extern double hotlvl; /* brightness considered "hot" */ |
32 |
– |
|
33 |
– |
extern int npts; /* # of points for stars */ |
34 |
– |
|
35 |
– |
extern double spread; /* spread for star points */ |
36 |
– |
|
37 |
– |
extern char *progname; |
38 |
– |
|
39 |
– |
extern COLOR exposure; /* exposure for frame */ |
40 |
– |
|
11 |
|
#define AVGLVL 0.5 /* target mean brightness */ |
12 |
|
|
13 |
|
double avgbrt; /* average picture brightness */ |
14 |
+ |
long npix; /* # pixels in average */ |
15 |
|
|
16 |
|
typedef struct hotpix { /* structure for avgbrt pixels */ |
17 |
|
struct hotpix *next; /* next in list */ |
24 |
|
|
25 |
|
double sprdfact; /* computed spread factor */ |
26 |
|
|
27 |
+ |
static void starpoint(SCOLOR fcol, int x, int y, HOTPIX *hp); |
28 |
|
|
29 |
< |
pass1init() /* prepare for first pass */ |
29 |
> |
|
30 |
> |
void |
31 |
> |
pass1init(void) /* prepare for first pass */ |
32 |
|
{ |
33 |
|
avgbrt = 0.0; |
34 |
+ |
npix = 0; |
35 |
|
head = NULL; |
36 |
|
} |
37 |
|
|
38 |
|
|
39 |
< |
pass1default() /* for single pass */ |
39 |
> |
void |
40 |
> |
pass1default(void) /* for single pass */ |
41 |
|
{ |
42 |
< |
avgbrt = AVGLVL * xres * yres; |
42 |
> |
avgbrt = AVGLVL; |
43 |
> |
npix = 1; |
44 |
|
head = NULL; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
< |
pass1scan(scan, y) /* process first pass scanline */ |
49 |
< |
register COLOR *scan; |
50 |
< |
int y; |
48 |
> |
void |
49 |
> |
pass1scan( /* process first pass scanline */ |
50 |
> |
COLORV *scan, |
51 |
> |
int y |
52 |
> |
) |
53 |
|
{ |
75 |
– |
extern char *malloc(); |
54 |
|
double cbrt; |
55 |
< |
register int x; |
56 |
< |
register HOTPIX *hp; |
55 |
> |
int x; |
56 |
> |
HOTPIX *hp; |
57 |
|
|
58 |
|
for (x = 0; x < xres; x++) { |
59 |
|
|
60 |
< |
cbrt = bright(scan[x]); |
60 |
> |
cbrt = (*ourbright)(scan+x*NCSAMP); |
61 |
|
|
62 |
< |
if (avghot || cbrt < hotlvl) |
63 |
< |
avgbrt += cbrt; |
62 |
> |
if (cbrt <= 0) |
63 |
> |
continue; |
64 |
|
|
65 |
+ |
if (avghot || cbrt < hotlvl) { |
66 |
+ |
avgbrt += cbrt; |
67 |
+ |
npix++; |
68 |
+ |
} |
69 |
|
if (npts && cbrt >= hotlvl) { |
70 |
|
hp = (HOTPIX *)malloc(sizeof(HOTPIX)); |
71 |
|
if (hp == NULL) { |
73 |
|
progname); |
74 |
|
quit(1); |
75 |
|
} |
76 |
< |
copycolor(hp->val, scan[x]); |
76 |
> |
scolor_color(hp->val, scan+x*NCSAMP); |
77 |
|
hp->x = x; |
78 |
|
hp->y = y; |
79 |
< |
hp->slope = tan(PI*(0.5-(random()%npts+0.5)/npts)); |
79 |
> |
hp->slope = ttan(PI*(0.5-(irandom(npts)+0.5)/npts)); |
80 |
|
hp->next = head; |
81 |
|
head = hp; |
82 |
|
} |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
< |
pass2init() /* prepare for final pass */ |
87 |
> |
void |
88 |
> |
pass2init(void) /* prepare for final pass */ |
89 |
|
{ |
90 |
< |
avgbrt /= (double)xres * yres; |
91 |
< |
|
92 |
< |
if (avgbrt <= FTINY) { |
110 |
< |
fprintf(stderr, "%s: picture too dark\n", progname); |
90 |
> |
if (!npix) { |
91 |
> |
fprintf(stderr, "%s: picture too dark or too bright\n", |
92 |
> |
progname); |
93 |
|
quit(1); |
94 |
|
} |
95 |
+ |
avgbrt /= (double)npix; |
96 |
|
|
97 |
|
scalecolor(exposure, AVGLVL/avgbrt); |
98 |
|
|
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
< |
pass2scan(scan, y) /* process final pass scanline */ |
105 |
< |
register COLOR *scan; |
106 |
< |
int y; |
104 |
> |
void |
105 |
> |
pass2scan( /* process final pass scanline */ |
106 |
> |
COLORV *scan, |
107 |
> |
int y |
108 |
> |
) |
109 |
|
{ |
110 |
|
int xmin, xmax; |
111 |
< |
register int x; |
112 |
< |
register HOTPIX *hp; |
111 |
> |
int x; |
112 |
> |
HOTPIX *hp; |
113 |
|
|
114 |
|
for (hp = head; hp != NULL; hp = hp->next) { |
115 |
|
if (hp->slope > FTINY) { |
130 |
|
if (xmax >= xres) |
131 |
|
xmax = xres-1; |
132 |
|
for (x = xmin; x <= xmax; x++) |
133 |
< |
starpoint(scan[x], x, y, hp); |
133 |
> |
starpoint(scan+x*NCSAMP, x, y, hp); |
134 |
|
} |
135 |
|
for (x = 0; x < xres; x++) |
136 |
< |
multcolor(scan[x], exposure); |
136 |
> |
smultcolor(scan+x*NCSAMP, exposure); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
< |
starpoint(fcol, x, y, hp) /* pixel is on the star's point */ |
141 |
< |
COLOR fcol; |
142 |
< |
int x, y; |
143 |
< |
register HOTPIX *hp; |
140 |
> |
static void |
141 |
> |
starpoint( /* pixel is on the star's point */ |
142 |
> |
SCOLOR fcol, |
143 |
> |
int x, |
144 |
> |
int y, |
145 |
> |
HOTPIX *hp |
146 |
> |
) |
147 |
|
{ |
148 |
|
COLOR ctmp; |
149 |
|
double d2; |
155 |
|
return; |
156 |
|
copycolor(ctmp, hp->val); |
157 |
|
scalecolor(ctmp, d2); |
158 |
< |
addcolor(fcol, ctmp); |
158 |
> |
saddcolor(fcol, ctmp); |
159 |
|
} else if (d2 > FTINY) { |
160 |
< |
addcolor(fcol, hp->val); |
160 |
> |
saddcolor(fcol, hp->val); |
161 |
|
} |
162 |
|
} |