1 |
– |
/* Copyright (c) 1986 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> |
9 |
+ |
#include <stdlib.h> |
10 |
+ |
#include <math.h> |
11 |
|
|
12 |
+ |
#include "rterror.h" |
13 |
|
#include "random.h" |
16 |
– |
|
14 |
|
#include "color.h" |
15 |
+ |
#include "pfilt.h" |
16 |
|
|
17 |
< |
#define PI 3.14159265359 |
17 |
> |
#define PI 3.14159265359 |
18 |
> |
#define FTINY (1e-6) |
19 |
|
|
20 |
< |
#define FTINY (1e-6) |
20 |
> |
#define AVGLVL 0.5 /* target mean brightness */ |
21 |
|
|
22 |
< |
extern int nrows, ncols; /* number of rows and columns for output */ |
22 |
> |
double avgbrt; /* average picture brightness */ |
23 |
> |
long npix; /* # pixels in average */ |
24 |
|
|
25 |
< |
extern int xres, yres; /* x and y resolution */ |
26 |
< |
|
27 |
< |
extern int avghot; /* true means average in avgbrt spots */ |
28 |
< |
|
29 |
< |
extern double hotlvl; /* brightness considered "hot" */ |
30 |
< |
|
31 |
< |
extern int npts; /* # of points for stars */ |
32 |
< |
|
33 |
< |
extern double spread; /* spread for star points */ |
34 |
< |
|
35 |
< |
extern char *progname; |
36 |
< |
|
37 |
< |
extern COLOR exposure; /* exposure for frame */ |
38 |
< |
|
39 |
< |
#define AVGLVL 0.5 /* target mean brightness */ |
40 |
< |
|
41 |
< |
double avgbrt; /* average picture brightness */ |
42 |
< |
|
43 |
< |
typedef struct hotpix { /* structure for avgbrt pixels */ |
25 |
> |
typedef struct hotpix { /* structure for avgbrt pixels */ |
26 |
|
struct hotpix *next; /* next in list */ |
27 |
|
COLOR val; /* pixel color */ |
28 |
|
short x, y; /* pixel position */ |
29 |
|
float slope; /* random slope for diffraction */ |
30 |
|
} HOTPIX; |
31 |
|
|
32 |
< |
HOTPIX *head; /* head of avgbrt pixel list */ |
32 |
> |
HOTPIX *head; /* head of avgbrt pixel list */ |
33 |
|
|
34 |
< |
double sprdfact; /* computed spread factor */ |
34 |
> |
double sprdfact; /* computed spread factor */ |
35 |
|
|
36 |
+ |
static void starpoint(COLOR fcol, int x, int y, HOTPIX *hp); |
37 |
|
|
38 |
< |
pass1init() /* prepare for first pass */ |
38 |
> |
|
39 |
> |
void |
40 |
> |
pass1init(void) /* prepare for first pass */ |
41 |
|
{ |
42 |
|
avgbrt = 0.0; |
43 |
+ |
npix = 0; |
44 |
|
head = NULL; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
< |
pass1default() /* for single pass */ |
48 |
> |
void |
49 |
> |
pass1default(void) /* for single pass */ |
50 |
|
{ |
51 |
< |
avgbrt = AVGLVL * xres * yres; |
51 |
> |
avgbrt = AVGLVL; |
52 |
> |
npix = 1; |
53 |
|
head = NULL; |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
< |
pass1scan(scan, y) /* process first pass scanline */ |
58 |
< |
register COLOR *scan; |
59 |
< |
int y; |
57 |
> |
void |
58 |
> |
pass1scan( /* process first pass scanline */ |
59 |
> |
COLOR *scan, |
60 |
> |
int y |
61 |
> |
) |
62 |
|
{ |
63 |
< |
extern char *malloc(); |
64 |
< |
extern double tan(), sqrt(); |
65 |
< |
double cbrt; |
76 |
< |
register int x; |
77 |
< |
register HOTPIX *hp; |
63 |
> |
double cbrt; |
64 |
> |
int x; |
65 |
> |
HOTPIX *hp; |
66 |
|
|
67 |
|
for (x = 0; x < xres; x++) { |
68 |
|
|
69 |
< |
cbrt = bright(scan[x]); |
69 |
> |
cbrt = (*ourbright)(scan[x]); |
70 |
|
|
71 |
< |
if (avghot || cbrt < hotlvl) |
72 |
< |
avgbrt += cbrt; |
71 |
> |
if (cbrt <= 0) |
72 |
> |
continue; |
73 |
|
|
74 |
+ |
if (avghot || cbrt < hotlvl) { |
75 |
+ |
avgbrt += cbrt; |
76 |
+ |
npix++; |
77 |
+ |
} |
78 |
|
if (npts && cbrt >= hotlvl) { |
79 |
|
hp = (HOTPIX *)malloc(sizeof(HOTPIX)); |
80 |
|
if (hp == NULL) { |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
< |
pass2init() /* prepare for final pass */ |
96 |
> |
void |
97 |
> |
pass2init(void) /* prepare for final pass */ |
98 |
|
{ |
99 |
< |
avgbrt /= (double)xres * yres; |
100 |
< |
|
101 |
< |
if (avgbrt <= FTINY) { |
109 |
< |
fprintf(stderr, "%s: picture too dark\n", progname); |
99 |
> |
if (!npix) { |
100 |
> |
fprintf(stderr, "%s: picture too dark or too bright\n", |
101 |
> |
progname); |
102 |
|
quit(1); |
103 |
|
} |
104 |
+ |
avgbrt /= (double)npix; |
105 |
|
|
106 |
|
scalecolor(exposure, AVGLVL/avgbrt); |
107 |
|
|
108 |
< |
sprdfact = spread / (hotlvl * bright(exposure)) |
108 |
> |
sprdfact = spread / (hotlvl * (*ourbright)(exposure)) |
109 |
|
* ((double)xres*xres + (double)yres*yres) / 4.0; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
< |
pass2scan(scan, y) /* process final pass scanline */ |
114 |
< |
register COLOR *scan; |
115 |
< |
int y; |
113 |
> |
void |
114 |
> |
pass2scan( /* process final pass scanline */ |
115 |
> |
COLOR *scan, |
116 |
> |
int y |
117 |
> |
) |
118 |
|
{ |
119 |
|
int xmin, xmax; |
120 |
< |
register int x; |
121 |
< |
register HOTPIX *hp; |
120 |
> |
int x; |
121 |
> |
HOTPIX *hp; |
122 |
|
|
123 |
|
for (hp = head; hp != NULL; hp = hp->next) { |
124 |
|
if (hp->slope > FTINY) { |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
< |
starpoint(fcol, x, y, hp) /* pixel is on the star's point */ |
150 |
< |
COLOR fcol; |
151 |
< |
int x, y; |
152 |
< |
register HOTPIX *hp; |
149 |
> |
static void |
150 |
> |
starpoint( /* pixel is on the star's point */ |
151 |
> |
COLOR fcol, |
152 |
> |
int x, |
153 |
> |
int y, |
154 |
> |
HOTPIX *hp |
155 |
> |
) |
156 |
|
{ |
157 |
|
COLOR ctmp; |
158 |
< |
double d2; |
158 |
> |
double d2; |
159 |
|
|
160 |
|
d2 = (double)(x - hp->x)*(x - hp->x) + (double)(y - hp->y)*(y - hp->y); |
161 |
|
if (d2 > sprdfact) { |