ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.10
Committed: Sun Mar 28 20:33:14 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6, rad3R6P1
Changes since 2.9: +6 -4 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.10 static const char RCSid[] = "$Id: pextrem.c,v 2.9 2004/01/02 12:47:01 schorsch 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.8 #include <string.h>
11 schorsch 2.6
12     #include "platform.h"
13 greg 2.1 #include "color.h"
14 schorsch 2.9 #include "resolu.h"
15 greg 2.1
16    
17     int orig = 0;
18    
19     int wrongformat = 0;
20    
21     COLOR expos = WHTCOLOR;
22    
23 schorsch 2.9 static gethfunc headline;
24 greg 2.2
25 schorsch 2.9
26     static int
27     headline( /* check header line */
28     char *s,
29     void *p
30     )
31 greg 2.1 {
32     char fmt[32];
33     double d;
34     COLOR ctmp;
35    
36     if (isformat(s)) { /* format */
37     formatval(fmt, s);
38 greg 2.5 wrongformat = !globmatch(PICFMT, fmt);
39 greg 2.1 }
40     if (!orig)
41 gwlarson 2.4 return(0);
42 greg 2.1 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 gwlarson 2.4 return(0);
50 greg 2.1 }
51    
52    
53 schorsch 2.10 int
54     main(
55     int argc,
56     char *argv[]
57     )
58 greg 2.1 {
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 schorsch 2.7 SET_DEFAULT_BINARY();
67 schorsch 2.6 SET_FILE_BINARY(stdin);
68 greg 2.1 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, 1e10, 1e10, 1e10);
90     setcolr(cmax, 0., 0., 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 greg 2.5 free((void *)scan);
115 greg 2.1 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     }