ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/psum.c
Revision: 2.5
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.4: +4 -6 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.5 static const char RCSid[] = "$Id$";
3 greg 1.1 #endif
4     /*
5     * psum.c - program to sum pictures.
6     *
7     * 10/14/86
8     */
9    
10     #include <stdio.h>
11    
12 greg 2.3 #include <math.h>
13    
14 greg 1.1 #include "color.h"
15    
16    
17     #define MAXFILE 8
18    
19     int xsiz, ysiz;
20    
21     char *progname;
22    
23     char *fname[MAXFILE]; /* the file names */
24     FILE *fptr[MAXFILE]; /* the file pointers */
25     COLOR scale[MAXFILE]; /* scaling factors */
26     int nfile; /* number of files */
27    
28    
29 gwlarson 2.4 int
30 greg 1.1 tabputs(s) /* print line preceded by a tab */
31     char *s;
32     {
33     putc('\t', stdout);
34 gwlarson 2.4 return(fputs(s, stdout));
35 greg 1.1 }
36    
37    
38     main(argc, argv)
39     int argc;
40     char *argv[];
41     {
42 greg 2.2 double d;
43 greg 1.1 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 greg 1.2 if (fgetresolu(&xres, &yres, fptr[nfile]) != (YMAJOR|YDECR)) {
100 greg 1.1 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 greg 1.2 putchar('\n');
116     fputresolu(YMAJOR|YDECR, xsiz, ysiz, stdout);
117 greg 1.1
118     psum();
119    
120     quit(0);
121     }
122    
123    
124     psum() /* sum the files */
125     {
126     COLOR *scanin, *scanout;
127     int y, i;
128     register int x;
129    
130     scanin = (COLOR *)malloc(xsiz*sizeof(COLOR));
131     scanout = (COLOR *)malloc(xsiz*sizeof(COLOR));
132     if (scanin == NULL || scanout == NULL) {
133     fprintf(stderr, "%s: out of memory\n", progname);
134     quit(1);
135     }
136     for (y = ysiz-1; y >= 0; y--) {
137     for (x = 0; x < xsiz; x++)
138     setcolor(scanout[x], 0.0, 0.0, 0.0);
139     for (i = 0; i < nfile; i++) {
140     if (freadscan(scanin, xsiz, fptr[i]) < 0) {
141     fprintf(stderr, "%s: read error on file: %s\n",
142     progname, fname[i]);
143     quit(1);
144     }
145     for (x = 0; x < xsiz; x++)
146     multcolor(scanin[x], scale[i]);
147     for (x = 0; x < xsiz; x++)
148     addcolor(scanout[x], scanin[x]);
149     }
150     if (fwritescan(scanout, xsiz, stdout) < 0) {
151     fprintf(stderr, "%s: write error\n", progname);
152     quit(1);
153     }
154     }
155 greg 2.5 free((void *)scanin);
156     free((void *)scanout);
157 greg 1.1 }
158    
159    
160 greg 2.5 void
161 greg 1.1 quit(code) /* exit gracefully */
162     int code;
163     {
164     exit(code);
165     }