ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.15
Committed: Fri Feb 4 20:11:49 2022 UTC (2 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 2.14: +11 -10 lines
Log Message:
feat(pvalue,pextrem): Added -O option to report watts/sr/meter^2 always

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.15 static const char RCSid[] = "$Id: pextrem.c,v 2.14 2019/07/19 17:37:56 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * Find extrema points in a Radiance picture.
6     */
7    
8 greg 2.3 #include <math.h>
9 schorsch 2.6
10 greg 2.14 #include "rtio.h"
11 schorsch 2.6 #include "platform.h"
12 greg 2.1 #include "color.h"
13 schorsch 2.9 #include "resolu.h"
14 greg 2.1
15    
16     int orig = 0;
17    
18 greg 2.15 COLOR expos = WHTCOLOR;
19 greg 2.1
20 greg 2.15 char fmt[MAXFMTLEN];
21 greg 2.1
22 schorsch 2.9 static gethfunc headline;
23 greg 2.2
24 schorsch 2.9
25     static int
26     headline( /* check header line */
27     char *s,
28     void *p
29     )
30 greg 2.1 {
31     double d;
32     COLOR ctmp;
33    
34 greg 2.15 if (formatval(fmt, s)) /* format */
35     return(0);
36 greg 2.1 if (!orig)
37 gwlarson 2.4 return(0);
38 greg 2.1 if (isexpos(s)) { /* exposure */
39     d = exposval(s);
40     scalecolor(expos, d);
41     } else if (iscolcor(s)) { /* color correction */
42     colcorval(ctmp, s);
43     multcolor(expos, ctmp);
44     }
45 gwlarson 2.4 return(0);
46 greg 2.1 }
47    
48    
49 schorsch 2.10 int
50     main(
51     int argc,
52     char *argv[]
53     )
54 greg 2.1 {
55     int i;
56     int xres, yres;
57     int y;
58     register int x;
59     COLR *scan;
60     COLR cmin, cmax;
61     int xmin, ymin, xmax, ymax;
62 schorsch 2.7 SET_DEFAULT_BINARY();
63 schorsch 2.6 SET_FILE_BINARY(stdin);
64 greg 2.1 for (i = 1; i < argc; i++) /* get options */
65     if (!strcmp(argv[i], "-o"))
66 greg 2.15 orig = 1;
67     else if (!strcmp(argv[i], "-O"))
68     orig = -1;
69 greg 2.1 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 greg 2.15 if (getheader(stdin, headline, NULL) < 0 || !globmatch(PICFMT, fmt) ||
79 greg 2.1 fgetresolu(&xres, &yres, stdin) < 0) {
80     fprintf(stderr, "%s: bad picture format\n", argv[0]);
81     exit(1);
82     }
83 greg 2.15 if (orig < 0 && !strcmp(CIEFMT, fmt))
84     scalecolor(expos, 1./WHTEFFICACY);
85 greg 2.1 if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
86     fprintf(stderr, "%s: out of memory\n", argv[0]);
87     exit(1);
88     }
89 greg 2.11 setcolr(cmin, 1e30, 1e30, 1e30);
90     setcolr(cmax, 0., 0., 0.); xmax=ymax=0;
91 greg 2.1 /* 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.12 printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin,
116 greg 2.1 colrval(cmin,RED)/colval(expos,RED),
117     colrval(cmin,GRN)/colval(expos,GRN),
118     colrval(cmin,BLU)/colval(expos,BLU));
119 greg 2.12 printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax,
120 greg 2.1 colrval(cmax,RED)/colval(expos,RED),
121     colrval(cmax,GRN)/colval(expos,GRN),
122     colrval(cmax,BLU)/colval(expos,BLU));
123     exit(0);
124     }