ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.6
Committed: Thu Jun 5 19:29:34 2003 UTC (20 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.5: +5 -9 lines
Log Message:
Macros for setting binary file mode. Replacing MSDOS by _WIN32.

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.6 static const char RCSid[] = "$Id: pextrem.c,v 2.5 2003/02/22 02:07:27 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * Find extrema points in a Radiance picture.
6     */
7    
8     #include <stdio.h>
9 greg 2.3 #include <math.h>
10 schorsch 2.6
11     #include "platform.h"
12 greg 2.1 #include "color.h"
13    
14    
15     int orig = 0;
16    
17     int wrongformat = 0;
18    
19     COLOR expos = WHTCOLOR;
20    
21 greg 2.2
22 greg 2.1 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 greg 2.5 wrongformat = !globmatch(PICFMT, fmt);
32 greg 2.1 }
33     if (!orig)
34 gwlarson 2.4 return(0);
35 greg 2.1 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 gwlarson 2.4 return(0);
43 greg 2.1 }
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 schorsch 2.6 SET_DEFAULT_BINARY()
58     SET_FILE_BINARY(stdin);
59 greg 2.1 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 greg 2.5 free((void *)scan);
106 greg 2.1 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     }