ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.14
Committed: Fri Jul 19 17:37:56 2019 UTC (4 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R3
Changes since 2.13: +2 -3 lines
Log Message:
Moved declarations and definitions for header.c from resolu.h to rtio.h

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.14 static const char RCSid[] = "$Id: pextrem.c,v 2.13 2018/08/02 18:33:44 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     int wrongformat = 0;
19    
20     COLOR expos = WHTCOLOR;
21    
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 greg 2.13 char fmt[MAXFMTLEN];
32 greg 2.1 double d;
33     COLOR ctmp;
34    
35     if (isformat(s)) { /* format */
36     formatval(fmt, s);
37 greg 2.5 wrongformat = !globmatch(PICFMT, fmt);
38 greg 2.1 }
39     if (!orig)
40 gwlarson 2.4 return(0);
41 greg 2.1 if (isexpos(s)) { /* exposure */
42     d = exposval(s);
43     scalecolor(expos, d);
44     } else if (iscolcor(s)) { /* color correction */
45     colcorval(ctmp, s);
46     multcolor(expos, ctmp);
47     }
48 gwlarson 2.4 return(0);
49 greg 2.1 }
50    
51    
52 schorsch 2.10 int
53     main(
54     int argc,
55     char *argv[]
56     )
57 greg 2.1 {
58     int i;
59     int xres, yres;
60     int y;
61     register int x;
62     COLR *scan;
63     COLR cmin, cmax;
64     int xmin, ymin, xmax, ymax;
65 schorsch 2.7 SET_DEFAULT_BINARY();
66 schorsch 2.6 SET_FILE_BINARY(stdin);
67 greg 2.1 for (i = 1; i < argc; i++) /* get options */
68     if (!strcmp(argv[i], "-o"))
69     orig++;
70     else
71     break;
72    
73     if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
74     fprintf(stderr, "%s: can't open input \"%s\"\n",
75     argv[0], argv[i]);
76     exit(1);
77     }
78     /* get our header */
79     if (getheader(stdin, headline, NULL) < 0 || wrongformat ||
80     fgetresolu(&xres, &yres, stdin) < 0) {
81     fprintf(stderr, "%s: bad picture format\n", argv[0]);
82     exit(1);
83     }
84     if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
85     fprintf(stderr, "%s: out of memory\n", argv[0]);
86     exit(1);
87     }
88 greg 2.11 setcolr(cmin, 1e30, 1e30, 1e30);
89     setcolr(cmax, 0., 0., 0.); xmax=ymax=0;
90 greg 2.1 /* find extrema */
91     for (y = yres-1; y >= 0; y--) {
92     if (freadcolrs(scan, xres, stdin) < 0) {
93     fprintf(stderr, "%s: read error on input\n", argv[0]);
94     exit(1);
95     }
96     for (x = xres; x-- > 0; ) {
97     if (scan[x][EXP] > cmax[EXP] ||
98     (scan[x][EXP] == cmax[EXP] &&
99     normbright(scan[x]) >
100     normbright(cmax))) {
101     copycolr(cmax, scan[x]);
102     xmax = x; ymax = y;
103     }
104     if (scan[x][EXP] < cmin[EXP] ||
105     (scan[x][EXP] == cmin[EXP] &&
106     normbright(scan[x]) <
107     normbright(cmin))) {
108     copycolr(cmin, scan[x]);
109     xmin = x; ymin = y;
110     }
111     }
112     }
113 greg 2.5 free((void *)scan);
114 greg 2.12 printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin,
115 greg 2.1 colrval(cmin,RED)/colval(expos,RED),
116     colrval(cmin,GRN)/colval(expos,GRN),
117     colrval(cmin,BLU)/colval(expos,BLU));
118 greg 2.12 printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax,
119 greg 2.1 colrval(cmax,RED)/colval(expos,RED),
120     colrval(cmax,GRN)/colval(expos,GRN),
121     colrval(cmax,BLU)/colval(expos,BLU));
122     exit(0);
123     }