1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: pextrem.c,v 2.6 2003/06/05 19:29:34 schorsch Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* Find extrema points in a Radiance picture. |
6 |
*/ |
7 |
|
8 |
#include <stdio.h> |
9 |
#include <math.h> |
10 |
|
11 |
#include "platform.h" |
12 |
#include "color.h" |
13 |
|
14 |
|
15 |
int orig = 0; |
16 |
|
17 |
int wrongformat = 0; |
18 |
|
19 |
COLOR expos = WHTCOLOR; |
20 |
|
21 |
|
22 |
headline(s) /* check header line */ |
23 |
char *s; |
24 |
{ |
25 |
char fmt[32]; |
26 |
double d; |
27 |
COLOR ctmp; |
28 |
|
29 |
if (isformat(s)) { /* format */ |
30 |
formatval(fmt, s); |
31 |
wrongformat = !globmatch(PICFMT, fmt); |
32 |
} |
33 |
if (!orig) |
34 |
return(0); |
35 |
if (isexpos(s)) { /* exposure */ |
36 |
d = exposval(s); |
37 |
scalecolor(expos, d); |
38 |
} else if (iscolcor(s)) { /* color correction */ |
39 |
colcorval(ctmp, s); |
40 |
multcolor(expos, ctmp); |
41 |
} |
42 |
return(0); |
43 |
} |
44 |
|
45 |
|
46 |
main(argc, argv) |
47 |
int argc; |
48 |
char *argv[]; |
49 |
{ |
50 |
int i; |
51 |
int xres, yres; |
52 |
int y; |
53 |
register int x; |
54 |
COLR *scan; |
55 |
COLR cmin, cmax; |
56 |
int xmin, ymin, xmax, ymax; |
57 |
SET_DEFAULT_BINARY(); |
58 |
SET_FILE_BINARY(stdin); |
59 |
for (i = 1; i < argc; i++) /* get options */ |
60 |
if (!strcmp(argv[i], "-o")) |
61 |
orig++; |
62 |
else |
63 |
break; |
64 |
|
65 |
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
66 |
fprintf(stderr, "%s: can't open input \"%s\"\n", |
67 |
argv[0], argv[i]); |
68 |
exit(1); |
69 |
} |
70 |
/* get our header */ |
71 |
if (getheader(stdin, headline, NULL) < 0 || wrongformat || |
72 |
fgetresolu(&xres, &yres, stdin) < 0) { |
73 |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
74 |
exit(1); |
75 |
} |
76 |
if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
77 |
fprintf(stderr, "%s: out of memory\n", argv[0]); |
78 |
exit(1); |
79 |
} |
80 |
setcolr(cmin, 1e10, 1e10, 1e10); |
81 |
setcolr(cmax, 0., 0., 0.); |
82 |
/* find extrema */ |
83 |
for (y = yres-1; y >= 0; y--) { |
84 |
if (freadcolrs(scan, xres, stdin) < 0) { |
85 |
fprintf(stderr, "%s: read error on input\n", argv[0]); |
86 |
exit(1); |
87 |
} |
88 |
for (x = xres; x-- > 0; ) { |
89 |
if (scan[x][EXP] > cmax[EXP] || |
90 |
(scan[x][EXP] == cmax[EXP] && |
91 |
normbright(scan[x]) > |
92 |
normbright(cmax))) { |
93 |
copycolr(cmax, scan[x]); |
94 |
xmax = x; ymax = y; |
95 |
} |
96 |
if (scan[x][EXP] < cmin[EXP] || |
97 |
(scan[x][EXP] == cmin[EXP] && |
98 |
normbright(scan[x]) < |
99 |
normbright(cmin))) { |
100 |
copycolr(cmin, scan[x]); |
101 |
xmin = x; ymin = y; |
102 |
} |
103 |
} |
104 |
} |
105 |
free((void *)scan); |
106 |
printf("%d %d\t%e %e %e\n", xmin, ymin, |
107 |
colrval(cmin,RED)/colval(expos,RED), |
108 |
colrval(cmin,GRN)/colval(expos,GRN), |
109 |
colrval(cmin,BLU)/colval(expos,BLU)); |
110 |
printf("%d %d\t%e %e %e\n", xmax, ymax, |
111 |
colrval(cmax,RED)/colval(expos,RED), |
112 |
colrval(cmax,GRN)/colval(expos,GRN), |
113 |
colrval(cmax,BLU)/colval(expos,BLU)); |
114 |
exit(0); |
115 |
} |