ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.11
Committed: Thu Jun 2 18:13:47 2005 UTC (18 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad5R0, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R8, rad3R9, rad4R2P1
Changes since 2.10: +3 -3 lines
Log Message:
Fixed maximum reporting for images that are everywhere zero

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: pextrem.c,v 2.10 2004/03/28 20:33:14 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 #include "resolu.h"
15
16
17 int orig = 0;
18
19 int wrongformat = 0;
20
21 COLOR expos = WHTCOLOR;
22
23 static gethfunc headline;
24
25
26 static int
27 headline( /* check header line */
28 char *s,
29 void *p
30 )
31 {
32 char fmt[32];
33 double d;
34 COLOR ctmp;
35
36 if (isformat(s)) { /* format */
37 formatval(fmt, s);
38 wrongformat = !globmatch(PICFMT, fmt);
39 }
40 if (!orig)
41 return(0);
42 if (isexpos(s)) { /* exposure */
43 d = exposval(s);
44 scalecolor(expos, d);
45 } else if (iscolcor(s)) { /* color correction */
46 colcorval(ctmp, s);
47 multcolor(expos, ctmp);
48 }
49 return(0);
50 }
51
52
53 int
54 main(
55 int argc,
56 char *argv[]
57 )
58 {
59 int i;
60 int xres, yres;
61 int y;
62 register int x;
63 COLR *scan;
64 COLR cmin, cmax;
65 int xmin, ymin, xmax, ymax;
66 SET_DEFAULT_BINARY();
67 SET_FILE_BINARY(stdin);
68 for (i = 1; i < argc; i++) /* get options */
69 if (!strcmp(argv[i], "-o"))
70 orig++;
71 else
72 break;
73
74 if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
75 fprintf(stderr, "%s: can't open input \"%s\"\n",
76 argv[0], argv[i]);
77 exit(1);
78 }
79 /* get our header */
80 if (getheader(stdin, headline, NULL) < 0 || wrongformat ||
81 fgetresolu(&xres, &yres, stdin) < 0) {
82 fprintf(stderr, "%s: bad picture format\n", argv[0]);
83 exit(1);
84 }
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, 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) {
94 fprintf(stderr, "%s: read error on input\n", argv[0]);
95 exit(1);
96 }
97 for (x = xres; x-- > 0; ) {
98 if (scan[x][EXP] > cmax[EXP] ||
99 (scan[x][EXP] == cmax[EXP] &&
100 normbright(scan[x]) >
101 normbright(cmax))) {
102 copycolr(cmax, scan[x]);
103 xmax = x; ymax = y;
104 }
105 if (scan[x][EXP] < cmin[EXP] ||
106 (scan[x][EXP] == cmin[EXP] &&
107 normbright(scan[x]) <
108 normbright(cmin))) {
109 copycolr(cmin, scan[x]);
110 xmin = x; ymin = y;
111 }
112 }
113 }
114 free((void *)scan);
115 printf("%d %d\t%e %e %e\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,
120 colrval(cmax,RED)/colval(expos,RED),
121 colrval(cmax,GRN)/colval(expos,GRN),
122 colrval(cmax,BLU)/colval(expos,BLU));
123 exit(0);
124 }