1 |
greg |
2.1 |
#ifndef lint |
2 |
greg |
2.16 |
static const char RCSid[] = "$Id: pextrem.c,v 2.15 2022/02/04 20:11:49 greg Exp $"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
/* |
5 |
greg |
2.16 |
* Find extrema points in a Radiance picture (RGBE, XYZE, or HyperSpectral) |
6 |
greg |
2.1 |
*/ |
7 |
|
|
|
8 |
greg |
2.3 |
#include <math.h> |
9 |
schorsch |
2.6 |
|
10 |
greg |
2.14 |
#include "rtio.h" |
11 |
schorsch |
2.6 |
#include "platform.h" |
12 |
greg |
2.1 |
#include "color.h" |
13 |
schorsch |
2.9 |
#include "resolu.h" |
14 |
greg |
2.1 |
|
15 |
|
|
|
16 |
|
|
int orig = 0; |
17 |
|
|
|
18 |
greg |
2.15 |
COLOR expos = WHTCOLOR; |
19 |
greg |
2.1 |
|
20 |
greg |
2.15 |
char fmt[MAXFMTLEN]; |
21 |
greg |
2.1 |
|
22 |
schorsch |
2.9 |
static gethfunc headline; |
23 |
greg |
2.2 |
|
24 |
schorsch |
2.9 |
|
25 |
|
|
static int |
26 |
|
|
headline( /* check header line */ |
27 |
|
|
char *s, |
28 |
|
|
void *p |
29 |
|
|
) |
30 |
greg |
2.1 |
{ |
31 |
|
|
double d; |
32 |
|
|
COLOR ctmp; |
33 |
|
|
|
34 |
greg |
2.15 |
if (formatval(fmt, s)) /* format */ |
35 |
|
|
return(0); |
36 |
greg |
2.16 |
if (iswlsplit(s)) { /* wavelength splits */ |
37 |
|
|
wlsplitval(WLPART, s); |
38 |
|
|
return(0); |
39 |
|
|
} |
40 |
|
|
if (isncomp(s)) { /* # spectral components */ |
41 |
|
|
NCSAMP = ncompval(s); |
42 |
|
|
return(0); |
43 |
|
|
} |
44 |
|
|
if (!orig) /* don't undo exposure? */ |
45 |
gwlarson |
2.4 |
return(0); |
46 |
greg |
2.1 |
if (isexpos(s)) { /* exposure */ |
47 |
|
|
d = exposval(s); |
48 |
|
|
scalecolor(expos, d); |
49 |
|
|
} else if (iscolcor(s)) { /* color correction */ |
50 |
|
|
colcorval(ctmp, s); |
51 |
|
|
multcolor(expos, ctmp); |
52 |
|
|
} |
53 |
gwlarson |
2.4 |
return(0); |
54 |
greg |
2.1 |
} |
55 |
|
|
|
56 |
|
|
|
57 |
schorsch |
2.10 |
int |
58 |
|
|
main( |
59 |
|
|
int argc, |
60 |
|
|
char *argv[] |
61 |
|
|
) |
62 |
greg |
2.1 |
{ |
63 |
|
|
int i; |
64 |
|
|
int xres, yres; |
65 |
|
|
int y; |
66 |
greg |
2.16 |
int x; |
67 |
|
|
COLRV *scan; |
68 |
|
|
SCOLR cmin, cmax; |
69 |
|
|
COLOR tcol; |
70 |
greg |
2.1 |
int xmin, ymin, xmax, ymax; |
71 |
greg |
2.16 |
|
72 |
schorsch |
2.7 |
SET_DEFAULT_BINARY(); |
73 |
schorsch |
2.6 |
SET_FILE_BINARY(stdin); |
74 |
greg |
2.1 |
for (i = 1; i < argc; i++) /* get options */ |
75 |
|
|
if (!strcmp(argv[i], "-o")) |
76 |
greg |
2.15 |
orig = 1; |
77 |
|
|
else if (!strcmp(argv[i], "-O")) |
78 |
|
|
orig = -1; |
79 |
greg |
2.1 |
else |
80 |
|
|
break; |
81 |
|
|
|
82 |
|
|
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
83 |
|
|
fprintf(stderr, "%s: can't open input \"%s\"\n", |
84 |
|
|
argv[0], argv[i]); |
85 |
greg |
2.16 |
return(1); |
86 |
greg |
2.1 |
} |
87 |
|
|
/* get our header */ |
88 |
greg |
2.16 |
if (getheader(stdin, headline, NULL) < 0 || |
89 |
|
|
(!globmatch(PICFMT, fmt) && strcmp(fmt, SPECFMT)) || |
90 |
greg |
2.1 |
fgetresolu(&xres, &yres, stdin) < 0) { |
91 |
|
|
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
92 |
greg |
2.16 |
return(1); |
93 |
|
|
} |
94 |
|
|
if (setspectrsamp(CNDX, WLPART) < 0) { |
95 |
|
|
fprintf(stderr, "%s: bad wavelength split or component count", |
96 |
|
|
argv[0]); |
97 |
|
|
return(1); |
98 |
greg |
2.1 |
} |
99 |
greg |
2.15 |
if (orig < 0 && !strcmp(CIEFMT, fmt)) |
100 |
|
|
scalecolor(expos, 1./WHTEFFICACY); |
101 |
greg |
2.16 |
if ((scan = (COLRV *)malloc(xres*sizeof(COLRV)*(NCSAMP+1))) == NULL) { |
102 |
greg |
2.1 |
fprintf(stderr, "%s: out of memory\n", argv[0]); |
103 |
greg |
2.16 |
return(1); |
104 |
greg |
2.1 |
} |
105 |
greg |
2.16 |
setscolr(cmin, 1e30, 1e30, 1e30); xmin=ymin=0; |
106 |
|
|
scolrblack(cmax); xmax=ymax=0; |
107 |
greg |
2.1 |
/* find extrema */ |
108 |
|
|
for (y = yres-1; y >= 0; y--) { |
109 |
greg |
2.16 |
if (freadscolrs(scan, NCSAMP, xres, stdin) < 0) { |
110 |
greg |
2.1 |
fprintf(stderr, "%s: read error on input\n", argv[0]); |
111 |
greg |
2.16 |
return(1); |
112 |
greg |
2.1 |
} |
113 |
|
|
for (x = xres; x-- > 0; ) { |
114 |
greg |
2.16 |
const COLRV * sclr = scan + x*(NCSAMP+1); |
115 |
|
|
if (sclr[CNDX[EXP]] > cmax[CNDX[EXP]] || |
116 |
|
|
(sclr[CNDX[EXP]] == cmax[CNDX[EXP]] && |
117 |
|
|
normpbright(sclr) > normpbright(cmax))) { |
118 |
|
|
copyscolr(cmax, sclr); |
119 |
greg |
2.1 |
xmax = x; ymax = y; |
120 |
|
|
} |
121 |
greg |
2.16 |
if (sclr[CNDX[EXP]] < cmin[CNDX[EXP]] || |
122 |
|
|
(sclr[CNDX[EXP]] == cmin[CNDX[EXP]] && |
123 |
|
|
normpbright(sclr) < normpbright(cmin))) { |
124 |
|
|
copyscolr(cmin, sclr); |
125 |
greg |
2.1 |
xmin = x; ymin = y; |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
} |
129 |
greg |
2.16 |
free(scan); |
130 |
|
|
scolr_color(tcol, cmin); |
131 |
greg |
2.12 |
printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin, |
132 |
greg |
2.16 |
colval(tcol,RED)/colval(expos,RED), |
133 |
|
|
colval(tcol,GRN)/colval(expos,GRN), |
134 |
|
|
colval(tcol,BLU)/colval(expos,BLU)); |
135 |
|
|
scolr_color(tcol, cmax); |
136 |
greg |
2.12 |
printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax, |
137 |
greg |
2.16 |
colval(tcol,RED)/colval(expos,RED), |
138 |
|
|
colval(tcol,GRN)/colval(expos,GRN), |
139 |
|
|
colval(tcol,BLU)/colval(expos,BLU)); |
140 |
|
|
return(0); |
141 |
greg |
2.1 |
} |