ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/psum.c
Revision: 1.1
Committed: Thu Feb 2 10:49:30 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

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