ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.4
Committed: Tue Oct 27 09:08:26 1998 UTC (25 years, 6 months ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 2.3: +2 -1 lines
Log Message:
changed getheader() to listen to return value of passed function

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(0);
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 return(0);
49 }
50
51
52 main(argc, argv)
53 int argc;
54 char *argv[];
55 {
56 int i;
57 int xres, yres;
58 int y;
59 register int x;
60 COLR *scan;
61 COLR cmin, cmax;
62 int xmin, ymin, xmax, ymax;
63 #ifdef MSDOS
64 extern int _fmode;
65 _fmode = O_BINARY;
66 setmode(fileno(stdin), O_BINARY);
67 #endif
68 for (i = 1; i < argc; i++) /* get options */
69 if (!strcmp(argv[i], "-o"))
70 orig++;
71 else
72 break;
73
74 if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
75 fprintf(stderr, "%s: can't open input \"%s\"\n",
76 argv[0], argv[i]);
77 exit(1);
78 }
79 /* get our header */
80 if (getheader(stdin, headline, NULL) < 0 || wrongformat ||
81 fgetresolu(&xres, &yres, stdin) < 0) {
82 fprintf(stderr, "%s: bad picture format\n", argv[0]);
83 exit(1);
84 }
85 if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
86 fprintf(stderr, "%s: out of memory\n", argv[0]);
87 exit(1);
88 }
89 setcolr(cmin, 1e10, 1e10, 1e10);
90 setcolr(cmax, 0., 0., 0.);
91 /* 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 free((char *)scan);
115 printf("%d %d\t%e %e %e\n", xmin, ymin,
116 colrval(cmin,RED)/colval(expos,RED),
117 colrval(cmin,GRN)/colval(expos,GRN),
118 colrval(cmin,BLU)/colval(expos,BLU));
119 printf("%d %d\t%e %e %e\n", xmax, ymax,
120 colrval(cmax,RED)/colval(expos,RED),
121 colrval(cmax,GRN)/colval(expos,GRN),
122 colrval(cmax,BLU)/colval(expos,BLU));
123 exit(0);
124 }