ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.9
Committed: Fri Jan 2 12:47:01 2004 UTC (20 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.8: +9 -3 lines
Log Message:
Fixed typing/prototype of getheader() and its callback.

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.9 static const char RCSid[] = "$Id: pextrem.c,v 2.8 2003/07/03 22:41:44 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     main(argc, argv)
54     int argc;
55     char *argv[];
56     {
57     int i;
58     int xres, yres;
59     int y;
60     register int x;
61     COLR *scan;
62     COLR cmin, cmax;
63     int xmin, ymin, xmax, ymax;
64 schorsch 2.7 SET_DEFAULT_BINARY();
65 schorsch 2.6 SET_FILE_BINARY(stdin);
66 greg 2.1 for (i = 1; i < argc; i++) /* get options */
67     if (!strcmp(argv[i], "-o"))
68     orig++;
69     else
70     break;
71    
72     if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
73     fprintf(stderr, "%s: can't open input \"%s\"\n",
74     argv[0], argv[i]);
75     exit(1);
76     }
77     /* get our header */
78     if (getheader(stdin, headline, NULL) < 0 || wrongformat ||
79     fgetresolu(&xres, &yres, stdin) < 0) {
80     fprintf(stderr, "%s: bad picture format\n", argv[0]);
81     exit(1);
82     }
83     if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
84     fprintf(stderr, "%s: out of memory\n", argv[0]);
85     exit(1);
86     }
87     setcolr(cmin, 1e10, 1e10, 1e10);
88     setcolr(cmax, 0., 0., 0.);
89     /* find extrema */
90     for (y = yres-1; y >= 0; y--) {
91     if (freadcolrs(scan, xres, stdin) < 0) {
92     fprintf(stderr, "%s: read error on input\n", argv[0]);
93     exit(1);
94     }
95     for (x = xres; x-- > 0; ) {
96     if (scan[x][EXP] > cmax[EXP] ||
97     (scan[x][EXP] == cmax[EXP] &&
98     normbright(scan[x]) >
99     normbright(cmax))) {
100     copycolr(cmax, scan[x]);
101     xmax = x; ymax = y;
102     }
103     if (scan[x][EXP] < cmin[EXP] ||
104     (scan[x][EXP] == cmin[EXP] &&
105     normbright(scan[x]) <
106     normbright(cmin))) {
107     copycolr(cmin, scan[x]);
108     xmin = x; ymin = y;
109     }
110     }
111     }
112 greg 2.5 free((void *)scan);
113 greg 2.1 printf("%d %d\t%e %e %e\n", xmin, ymin,
114     colrval(cmin,RED)/colval(expos,RED),
115     colrval(cmin,GRN)/colval(expos,GRN),
116     colrval(cmin,BLU)/colval(expos,BLU));
117     printf("%d %d\t%e %e %e\n", xmax, ymax,
118     colrval(cmax,RED)/colval(expos,RED),
119     colrval(cmax,GRN)/colval(expos,GRN),
120     colrval(cmax,BLU)/colval(expos,BLU));
121     exit(0);
122     }