ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.8
Committed: Thu Jul 3 22:41:44 2003 UTC (20 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.7: +2 -1 lines
Log Message:
Reduced compile problems on Windows.

File Contents

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