1 |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* Find extrema points in a Radiance picture. |
9 |
*/ |
10 |
|
11 |
#include <stdio.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 = strcmp(fmt, COLRFMT); |
32 |
} |
33 |
if (!orig) |
34 |
return; |
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 |
} |
43 |
|
44 |
|
45 |
main(argc, argv) |
46 |
int argc; |
47 |
char *argv[]; |
48 |
{ |
49 |
int i; |
50 |
int xres, yres; |
51 |
int y; |
52 |
register int x; |
53 |
COLR *scan; |
54 |
COLR cmin, cmax; |
55 |
int xmin, ymin, xmax, ymax; |
56 |
|
57 |
for (i = 1; i < argc; i++) /* get options */ |
58 |
if (!strcmp(argv[i], "-o")) |
59 |
orig++; |
60 |
else |
61 |
break; |
62 |
|
63 |
if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) { |
64 |
fprintf(stderr, "%s: can't open input \"%s\"\n", |
65 |
argv[0], argv[i]); |
66 |
exit(1); |
67 |
} |
68 |
/* get our header */ |
69 |
if (getheader(stdin, headline, NULL) < 0 || wrongformat || |
70 |
fgetresolu(&xres, &yres, stdin) < 0) { |
71 |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
72 |
exit(1); |
73 |
} |
74 |
if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
75 |
fprintf(stderr, "%s: out of memory\n", argv[0]); |
76 |
exit(1); |
77 |
} |
78 |
setcolr(cmin, 1e10, 1e10, 1e10); |
79 |
setcolr(cmax, 0., 0., 0.); |
80 |
/* find extrema */ |
81 |
for (y = yres-1; y >= 0; y--) { |
82 |
if (freadcolrs(scan, xres, stdin) < 0) { |
83 |
fprintf(stderr, "%s: read error on input\n", argv[0]); |
84 |
exit(1); |
85 |
} |
86 |
for (x = xres; x-- > 0; ) { |
87 |
if (scan[x][EXP] > cmax[EXP] || |
88 |
(scan[x][EXP] == cmax[EXP] && |
89 |
normbright(scan[x]) > |
90 |
normbright(cmax))) { |
91 |
copycolr(cmax, scan[x]); |
92 |
xmax = x; ymax = y; |
93 |
} |
94 |
if (scan[x][EXP] < cmin[EXP] || |
95 |
(scan[x][EXP] == cmin[EXP] && |
96 |
normbright(scan[x]) < |
97 |
normbright(cmin))) { |
98 |
copycolr(cmin, scan[x]); |
99 |
xmin = x; ymin = y; |
100 |
} |
101 |
} |
102 |
} |
103 |
free((char *)scan); |
104 |
printf("%d %d\t%e %e %e\n", xmin, ymin, |
105 |
colrval(cmin,RED)/colval(expos,RED), |
106 |
colrval(cmin,GRN)/colval(expos,GRN), |
107 |
colrval(cmin,BLU)/colval(expos,BLU)); |
108 |
printf("%d %d\t%e %e %e\n", xmax, ymax, |
109 |
colrval(cmax,RED)/colval(expos,RED), |
110 |
colrval(cmax,GRN)/colval(expos,GRN), |
111 |
colrval(cmax,BLU)/colval(expos,BLU)); |
112 |
exit(0); |
113 |
} |