ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/psum.c
Revision: 2.7
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.6: +8 -4 lines
Log Message:
Fixed typing/prototype of getheader() and its callback.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: psum.c,v 2.6 2003/10/27 10:22:27 schorsch Exp $";
3 #endif
4 /*
5 * psum.c - program to sum pictures.
6 *
7 * 10/14/86
8 */
9
10 #include <stdio.h>
11 #include <math.h>
12
13 #include "color.h"
14 #include "resolu.h"
15 #include "rterror.h"
16
17
18 #define MAXFILE 8
19
20 int xsiz, ysiz;
21
22 char *progname;
23
24 char *fname[MAXFILE]; /* the file names */
25 FILE *fptr[MAXFILE]; /* the file pointers */
26 COLOR scale[MAXFILE]; /* scaling factors */
27 int nfile; /* number of files */
28
29 static gethfunc tabputs;
30
31
32 static int
33 tabputs( /* print line preceded by a tab */
34 char *s,
35 void *p
36 )
37 {
38 putc('\t', stdout);
39 return(fputs(s, stdout));
40 }
41
42
43 main(argc, argv)
44 int argc;
45 char *argv[];
46 {
47 double d;
48 int xres, yres;
49 int an;
50
51 progname = argv[0];
52
53 nfile = 0;
54 setcolor(scale[0], 1.0, 1.0, 1.0);
55
56 for (an = 1; an < argc; an++) {
57 if (nfile >= MAXFILE) {
58 fprintf(stderr, "%s: too many files\n", progname);
59 quit(1);
60 }
61 if (argv[an][0] == '-')
62 switch (argv[an][1]) {
63 case 's':
64 d = atof(argv[an+1]);
65 switch (argv[an][2]) {
66 case '\0':
67 scalecolor(scale[nfile], d);
68 break;
69 case 'r':
70 colval(scale[nfile],RED) *= d;
71 break;
72 case 'g':
73 colval(scale[nfile],GRN) *= d;
74 break;
75 case 'b':
76 colval(scale[nfile],BLU) *= d;
77 break;
78 default:
79 goto unkopt;
80 }
81 an++;
82 continue;
83 case '\0':
84 fptr[nfile] = stdin;
85 fname[nfile] = "<stdin>";
86 break;
87 default:;
88 unkopt:
89 fprintf(stderr, "%s: unknown option: %s\n",
90 progname, argv[an]);
91 quit(1);
92 }
93 else if ((fptr[nfile] = fopen(argv[an], "r")) == NULL) {
94 fprintf(stderr, "%s: can't open file: %s\n",
95 progname, argv[an]);
96 quit(1);
97 } else
98 fname[nfile] = argv[an];
99 /* get header */
100 fputs(fname[nfile], stdout);
101 fputs(":\n", stdout);
102 getheader(fptr[nfile], tabputs, NULL);
103 /* get picture size */
104 if (fgetresolu(&xres, &yres, fptr[nfile]) != (YMAJOR|YDECR)) {
105 fprintf(stderr, "%s: bad picture size\n", progname);
106 quit(1);
107 } else if (nfile == 0) {
108 xsiz = xres;
109 ysiz = yres;
110 } else if (xres != xsiz || yres != ysiz) {
111 fprintf(stderr, "%s: pictures are different sizes\n",
112 progname);
113 quit(1);
114 }
115 nfile++;
116 setcolor(scale[nfile], 1.0, 1.0, 1.0);
117 }
118 /* add new header info. */
119 printargs(argc, argv, stdout);
120 putchar('\n');
121 fputresolu(YMAJOR|YDECR, xsiz, ysiz, stdout);
122
123 psum();
124
125 quit(0);
126 }
127
128
129 psum() /* sum the files */
130 {
131 COLOR *scanin, *scanout;
132 int y, i;
133 register int x;
134
135 scanin = (COLOR *)malloc(xsiz*sizeof(COLOR));
136 scanout = (COLOR *)malloc(xsiz*sizeof(COLOR));
137 if (scanin == NULL || scanout == NULL) {
138 fprintf(stderr, "%s: out of memory\n", progname);
139 quit(1);
140 }
141 for (y = ysiz-1; y >= 0; y--) {
142 for (x = 0; x < xsiz; x++)
143 setcolor(scanout[x], 0.0, 0.0, 0.0);
144 for (i = 0; i < nfile; i++) {
145 if (freadscan(scanin, xsiz, fptr[i]) < 0) {
146 fprintf(stderr, "%s: read error on file: %s\n",
147 progname, fname[i]);
148 quit(1);
149 }
150 for (x = 0; x < xsiz; x++)
151 multcolor(scanin[x], scale[i]);
152 for (x = 0; x < xsiz; x++)
153 addcolor(scanout[x], scanin[x]);
154 }
155 if (fwritescan(scanout, xsiz, stdout) < 0) {
156 fprintf(stderr, "%s: write error\n", progname);
157 quit(1);
158 }
159 }
160 free((void *)scanin);
161 free((void *)scanout);
162 }
163
164
165 void
166 quit(code) /* exit gracefully */
167 int code;
168 {
169 exit(code);
170 }