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 |
|
* Find extrema points in a Radiance picture. |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
9 |
< |
#ifdef MSDOS |
10 |
< |
#include <fcntl.h> |
11 |
< |
#endif |
8 |
> |
#include <math.h> |
9 |
> |
|
10 |
> |
#include "rtio.h" |
11 |
> |
#include "platform.h" |
12 |
|
#include "color.h" |
13 |
+ |
#include "resolu.h" |
14 |
|
|
15 |
|
|
16 |
|
int orig = 0; |
17 |
|
|
20 |
– |
int wrongformat = 0; |
21 |
– |
|
18 |
|
COLOR expos = WHTCOLOR; |
19 |
|
|
20 |
< |
extern char *malloc(); |
20 |
> |
char fmt[MAXFMTLEN]; |
21 |
|
|
22 |
+ |
static gethfunc headline; |
23 |
|
|
24 |
< |
headline(s) /* check header line */ |
25 |
< |
char *s; |
24 |
> |
|
25 |
> |
static int |
26 |
> |
headline( /* check header line */ |
27 |
> |
char *s, |
28 |
> |
void *p |
29 |
> |
) |
30 |
|
{ |
30 |
– |
char fmt[32]; |
31 |
|
double d; |
32 |
|
COLOR ctmp; |
33 |
|
|
34 |
< |
if (isformat(s)) { /* format */ |
35 |
< |
formatval(fmt, s); |
36 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
37 |
< |
} |
34 |
> |
if (formatval(fmt, s)) /* format */ |
35 |
> |
return(0); |
36 |
|
if (!orig) |
37 |
< |
return; |
37 |
> |
return(0); |
38 |
|
if (isexpos(s)) { /* exposure */ |
39 |
|
d = exposval(s); |
40 |
|
scalecolor(expos, d); |
42 |
|
colcorval(ctmp, s); |
43 |
|
multcolor(expos, ctmp); |
44 |
|
} |
45 |
+ |
return(0); |
46 |
|
} |
47 |
|
|
48 |
|
|
49 |
< |
main(argc, argv) |
50 |
< |
int argc; |
51 |
< |
char *argv[]; |
49 |
> |
int |
50 |
> |
main( |
51 |
> |
int argc, |
52 |
> |
char *argv[] |
53 |
> |
) |
54 |
|
{ |
55 |
|
int i; |
56 |
|
int xres, yres; |
59 |
|
COLR *scan; |
60 |
|
COLR cmin, cmax; |
61 |
|
int xmin, ymin, xmax, ymax; |
62 |
< |
#ifdef MSDOS |
63 |
< |
extern int _fmode; |
63 |
< |
_fmode = O_BINARY; |
64 |
< |
setmode(fileno(stdin), O_BINARY); |
65 |
< |
#endif |
62 |
> |
SET_DEFAULT_BINARY(); |
63 |
> |
SET_FILE_BINARY(stdin); |
64 |
|
for (i = 1; i < argc; i++) /* get options */ |
65 |
|
if (!strcmp(argv[i], "-o")) |
66 |
< |
orig++; |
66 |
> |
orig = 1; |
67 |
> |
else if (!strcmp(argv[i], "-O")) |
68 |
> |
orig = -1; |
69 |
|
else |
70 |
|
break; |
71 |
|
|
75 |
|
exit(1); |
76 |
|
} |
77 |
|
/* get our header */ |
78 |
< |
if (getheader(stdin, headline, NULL) < 0 || wrongformat || |
78 |
> |
if (getheader(stdin, headline, NULL) < 0 || !globmatch(PICFMT, fmt) || |
79 |
|
fgetresolu(&xres, &yres, stdin) < 0) { |
80 |
|
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
81 |
|
exit(1); |
82 |
|
} |
83 |
+ |
if (orig < 0 && !strcmp(CIEFMT, fmt)) |
84 |
+ |
scalecolor(expos, 1./WHTEFFICACY); |
85 |
|
if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
86 |
|
fprintf(stderr, "%s: out of memory\n", argv[0]); |
87 |
|
exit(1); |
88 |
|
} |
89 |
< |
setcolr(cmin, 1e10, 1e10, 1e10); |
90 |
< |
setcolr(cmax, 0., 0., 0.); |
89 |
> |
setcolr(cmin, 1e30, 1e30, 1e30); |
90 |
> |
setcolr(cmax, 0., 0., 0.); xmax=ymax=0; |
91 |
|
/* find extrema */ |
92 |
|
for (y = yres-1; y >= 0; y--) { |
93 |
|
if (freadcolrs(scan, xres, stdin) < 0) { |
111 |
|
} |
112 |
|
} |
113 |
|
} |
114 |
< |
free((char *)scan); |
115 |
< |
printf("%d %d\t%e %e %e\n", xmin, ymin, |
114 |
> |
free((void *)scan); |
115 |
> |
printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin, |
116 |
|
colrval(cmin,RED)/colval(expos,RED), |
117 |
|
colrval(cmin,GRN)/colval(expos,GRN), |
118 |
|
colrval(cmin,BLU)/colval(expos,BLU)); |
119 |
< |
printf("%d %d\t%e %e %e\n", xmax, ymax, |
119 |
> |
printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax, |
120 |
|
colrval(cmax,RED)/colval(expos,RED), |
121 |
|
colrval(cmax,GRN)/colval(expos,GRN), |
122 |
|
colrval(cmax,BLU)/colval(expos,BLU)); |