ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.5
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.4: +3 -8 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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