ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.3
Committed: Tue Oct 19 17:23:31 1993 UTC (30 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -0 lines
Log Message:
added math.h include

File Contents

# Content
1 /* Copyright (c) 1992 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Find extrema points in a Radiance picture.
9 */
10
11 #include <stdio.h>
12 #include <math.h>
13 #ifdef MSDOS
14 #include <fcntl.h>
15 #endif
16 #include "color.h"
17
18
19 int orig = 0;
20
21 int wrongformat = 0;
22
23 COLOR expos = WHTCOLOR;
24
25 extern char *malloc();
26
27
28 headline(s) /* check header line */
29 char *s;
30 {
31 char fmt[32];
32 double d;
33 COLOR ctmp;
34
35 if (isformat(s)) { /* format */
36 formatval(fmt, s);
37 wrongformat = strcmp(fmt, COLRFMT);
38 }
39 if (!orig)
40 return;
41 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 }
49
50
51 main(argc, argv)
52 int argc;
53 char *argv[];
54 {
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 #ifdef MSDOS
63 extern int _fmode;
64 _fmode = O_BINARY;
65 setmode(fileno(stdin), O_BINARY);
66 #endif
67 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 setcolr(cmin, 1e10, 1e10, 1e10);
89 setcolr(cmax, 0., 0., 0.);
90 /* 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 free((char *)scan);
114 printf("%d %d\t%e %e %e\n", xmin, ymin,
115 colrval(cmin,RED)/colval(expos,RED),
116 colrval(cmin,GRN)/colval(expos,GRN),
117 colrval(cmin,BLU)/colval(expos,BLU));
118 printf("%d %d\t%e %e %e\n", xmax, ymax,
119 colrval(cmax,RED)/colval(expos,RED),
120 colrval(cmax,GRN)/colval(expos,GRN),
121 colrval(cmax,BLU)/colval(expos,BLU));
122 exit(0);
123 }