ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
Revision: 2.9
Committed: Fri Jan 2 12:47:01 2004 UTC (20 years, 4 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.8: +9 -3 lines
Log Message:
Fixed typing/prototype of getheader() and its callback.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: pextrem.c,v 2.8 2003/07/03 22:41:44 schorsch Exp $";
3 #endif
4 /*
5 * Find extrema points in a Radiance picture.
6 */
7
8 #include <stdio.h>
9 #include <math.h>
10 #include <string.h>
11
12 #include "platform.h"
13 #include "color.h"
14 #include "resolu.h"
15
16
17 int orig = 0;
18
19 int wrongformat = 0;
20
21 COLOR expos = WHTCOLOR;
22
23 static gethfunc headline;
24
25
26 static int
27 headline( /* check header line */
28 char *s,
29 void *p
30 )
31 {
32 char fmt[32];
33 double d;
34 COLOR ctmp;
35
36 if (isformat(s)) { /* format */
37 formatval(fmt, s);
38 wrongformat = !globmatch(PICFMT, fmt);
39 }
40 if (!orig)
41 return(0);
42 if (isexpos(s)) { /* exposure */
43 d = exposval(s);
44 scalecolor(expos, d);
45 } else if (iscolcor(s)) { /* color correction */
46 colcorval(ctmp, s);
47 multcolor(expos, ctmp);
48 }
49 return(0);
50 }
51
52
53 main(argc, argv)
54 int argc;
55 char *argv[];
56 {
57 int i;
58 int xres, yres;
59 int y;
60 register int x;
61 COLR *scan;
62 COLR cmin, cmax;
63 int xmin, ymin, xmax, ymax;
64 SET_DEFAULT_BINARY();
65 SET_FILE_BINARY(stdin);
66 for (i = 1; i < argc; i++) /* get options */
67 if (!strcmp(argv[i], "-o"))
68 orig++;
69 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 if (getheader(stdin, headline, NULL) < 0 || wrongformat ||
79 fgetresolu(&xres, &yres, stdin) < 0) {
80 fprintf(stderr, "%s: bad picture format\n", argv[0]);
81 exit(1);
82 }
83 if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
84 fprintf(stderr, "%s: out of memory\n", argv[0]);
85 exit(1);
86 }
87 setcolr(cmin, 1e10, 1e10, 1e10);
88 setcolr(cmax, 0., 0., 0.);
89 /* find extrema */
90 for (y = yres-1; y >= 0; y--) {
91 if (freadcolrs(scan, xres, stdin) < 0) {
92 fprintf(stderr, "%s: read error on input\n", argv[0]);
93 exit(1);
94 }
95 for (x = xres; x-- > 0; ) {
96 if (scan[x][EXP] > cmax[EXP] ||
97 (scan[x][EXP] == cmax[EXP] &&
98 normbright(scan[x]) >
99 normbright(cmax))) {
100 copycolr(cmax, scan[x]);
101 xmax = x; ymax = y;
102 }
103 if (scan[x][EXP] < cmin[EXP] ||
104 (scan[x][EXP] == cmin[EXP] &&
105 normbright(scan[x]) <
106 normbright(cmin))) {
107 copycolr(cmin, scan[x]);
108 xmin = x; ymin = y;
109 }
110 }
111 }
112 free((void *)scan);
113 printf("%d %d\t%e %e %e\n", xmin, ymin,
114 colrval(cmin,RED)/colval(expos,RED),
115 colrval(cmin,GRN)/colval(expos,GRN),
116 colrval(cmin,BLU)/colval(expos,BLU));
117 printf("%d %d\t%e %e %e\n", xmax, ymax,
118 colrval(cmax,RED)/colval(expos,RED),
119 colrval(cmax,GRN)/colval(expos,GRN),
120 colrval(cmax,BLU)/colval(expos,BLU));
121 exit(0);
122 }