1 |
< |
/* Copyright (c) 1989 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
18 |
|
|
19 |
|
#include "calcomp.h" |
20 |
|
|
21 |
< |
#define MAXINP 16 /* maximum number of input files */ |
21 |
> |
#define MAXINP 32 /* maximum number of input files */ |
22 |
|
|
23 |
|
struct { |
24 |
|
char *name; /* file name */ |
31 |
|
|
32 |
|
char *vcolin[3] = {"ri", "gi", "bi"}; |
33 |
|
char *vcolout[3] = {"ro", "go", "bo"}; |
34 |
+ |
#define vbrtin "li" |
35 |
+ |
#define vbrtout "lo" |
36 |
|
|
37 |
+ |
#define vnfiles "nfiles" |
38 |
+ |
#define vxres "xres" |
39 |
+ |
#define vyres "yres" |
40 |
|
#define vxpos "x" |
41 |
|
#define vypos "y" |
42 |
|
|
59 |
|
int argc; |
60 |
|
char *argv[]; |
61 |
|
{ |
62 |
< |
extern double l_redin(), l_grnin(), l_bluin(), atof(); |
62 |
> |
extern double l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); |
63 |
|
double f; |
64 |
|
int a; |
65 |
|
|
66 |
|
funset(vcolin[RED], 1, l_redin); |
67 |
|
funset(vcolin[GRN], 1, l_grnin); |
68 |
|
funset(vcolin[BLU], 1, l_bluin); |
69 |
+ |
funset(vbrtin, 1, l_brtin); |
70 |
|
|
71 |
|
for (a = 1; a < argc; a++) |
72 |
|
if (argv[a][0] == '-') |
88 |
|
fcompile(argv[++a]); |
89 |
|
break; |
90 |
|
case 'e': |
91 |
< |
scompile(NULL, argv[++a]); |
91 |
> |
scompile(argv[++a], NULL, 0); |
92 |
|
break; |
93 |
|
default: |
94 |
|
goto usage; |
127 |
|
input[nfiles].name = argv[a]; |
128 |
|
input[nfiles].fp = fopen(argv[a], "r"); |
129 |
|
if (input[nfiles].fp == NULL) { |
130 |
< |
eputs(argv[a]); |
125 |
< |
eputs(": cannot open\n"); |
130 |
> |
perror(argv[a]); |
131 |
|
quit(1); |
132 |
|
} |
133 |
|
} |
134 |
|
fputs(input[nfiles].name, stdout); |
135 |
|
fputs(":\n", stdout); |
136 |
|
getheader(input[nfiles].fp, tputs); |
137 |
< |
if (fscanf(input[nfiles].fp, "-Y %d +X %d\n", &ypos, &xpos) != 2) { |
137 |
> |
if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != |
138 |
> |
(YMAJOR|YDECR)) { |
139 |
|
eputs(input[nfiles].name); |
140 |
|
eputs(": bad picture size\n"); |
141 |
|
quit(1); |
153 |
|
} |
154 |
|
printargs(argc, argv, stdout); |
155 |
|
putchar('\n'); |
156 |
< |
printf("-Y %d +X %d\n", yres, xres); |
156 |
> |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
157 |
|
combine(); |
158 |
|
quit(0); |
159 |
|
usage: |
166 |
|
|
167 |
|
combine() /* combine pictures */ |
168 |
|
{ |
169 |
< |
int coldef[3]; |
169 |
> |
EPNODE *coldef[3], *brtdef; |
170 |
|
COLOR *scanout; |
171 |
+ |
double d; |
172 |
|
register int i, j; |
173 |
|
/* check defined variables */ |
174 |
< |
for (j = 0; j < 3; j++) |
175 |
< |
coldef[j] = vardefined(vcolout[j]); |
174 |
> |
for (j = 0; j < 3; j++) { |
175 |
> |
if (vardefined(vcolout[j])) |
176 |
> |
coldef[j] = eparse(vcolout[j]); |
177 |
> |
else |
178 |
> |
coldef[j] = NULL; |
179 |
> |
} |
180 |
> |
if (vardefined(vbrtout)) |
181 |
> |
brtdef = eparse(vbrtout); |
182 |
> |
else |
183 |
> |
brtdef = NULL; |
184 |
> |
/* predefine variables */ |
185 |
> |
varset(vnfiles, (double)nfiles); |
186 |
> |
varset(vxres, (double)xres); |
187 |
> |
varset(vyres, (double)yres); |
188 |
|
/* allocate scanline */ |
189 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
190 |
|
/* combine files */ |
191 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
192 |
< |
for (i = 0; i < nfiles; i++) |
193 |
< |
if (freadscan(input[i].scan, xres, input[i].fp) < 0) { |
194 |
< |
eputs(input[i].name); |
195 |
< |
eputs(": read error\n"); |
196 |
< |
quit(1); |
192 |
> |
for (i = 0; i < nfiles; i++) |
193 |
> |
if (freadscan(input[i].scan, xres, input[i].fp) < 0) { |
194 |
> |
eputs(input[i].name); |
195 |
> |
eputs(": read error\n"); |
196 |
> |
quit(1); |
197 |
> |
} |
198 |
> |
varset(vypos, (double)ypos); |
199 |
> |
for (xpos = 0; xpos < xres; xpos++) { |
200 |
> |
varset(vxpos, (double)xpos); |
201 |
> |
eclock++; |
202 |
> |
if (brtdef != NULL) { |
203 |
> |
d = evalue(brtdef); |
204 |
> |
if (d < 0.0) |
205 |
> |
d = 0.0; |
206 |
> |
setcolor(scanout[xpos], d, d, d); |
207 |
> |
} else { |
208 |
> |
for (j = 0; j < 3; j++) { |
209 |
> |
if (coldef[j] != NULL) { |
210 |
> |
colval(scanout[xpos],j) = evalue(coldef[j]); |
211 |
> |
} else { |
212 |
> |
colval(scanout[xpos],j) = 0.0; |
213 |
> |
for (i = 0; i < nfiles; i++) |
214 |
> |
colval(scanout[xpos],j) += |
215 |
> |
colval(input[i].coef,j) * |
216 |
> |
colval(input[i].scan[xpos],j); |
217 |
|
} |
218 |
< |
varset(vypos, (double)ypos); |
219 |
< |
for (xpos = 0; xpos < xres; xpos++) { |
220 |
< |
varset(vxpos, (double)xpos); |
182 |
< |
eclock++; |
183 |
< |
for (j = 0; j < 3; j++) |
184 |
< |
if (coldef[j]) { |
185 |
< |
colval(scanout[xpos],j) = |
186 |
< |
varvalue(vcolout[j]); |
187 |
< |
if (colval(scanout[xpos],j) < 0.0) |
188 |
< |
colval(scanout[xpos],j) = 0.0; |
189 |
< |
} else { |
190 |
< |
colval(scanout[xpos],j) = 0.0; |
191 |
< |
for (i = 0; i < nfiles; i++) |
192 |
< |
colval(scanout[xpos],j) += |
193 |
< |
colval(input[i].coef,j) * |
194 |
< |
colval(input[i].scan[xpos],j); |
195 |
< |
} |
218 |
> |
if (colval(scanout[xpos],j) < 0.0) |
219 |
> |
colval(scanout[xpos],j) = 0.0; |
220 |
> |
} |
221 |
|
} |
222 |
< |
if (fwritescan(scanout, xres, stdout) < 0) { |
223 |
< |
eputs("write error\n"); |
224 |
< |
quit(1); |
225 |
< |
} |
222 |
> |
} |
223 |
> |
if (fwritescan(scanout, xres, stdout) < 0) { |
224 |
> |
perror("write error"); |
225 |
> |
quit(1); |
226 |
> |
} |
227 |
|
} |
228 |
|
efree(scanout); |
229 |
|
} |
261 |
|
l_bluin() /* get blue color */ |
262 |
|
{ |
263 |
|
return(colin((int)(argument(1)+.5), BLU)); |
264 |
+ |
} |
265 |
+ |
|
266 |
+ |
|
267 |
+ |
double |
268 |
+ |
l_brtin() /* get brightness value */ |
269 |
+ |
{ |
270 |
+ |
register int fn; |
271 |
+ |
|
272 |
+ |
fn = argument(1)+.5; |
273 |
+ |
if (fn == 0) |
274 |
+ |
return((double)nfiles); |
275 |
+ |
if (fn < 1 || fn > nfiles) { |
276 |
+ |
errno = EDOM; |
277 |
+ |
return(0.0); |
278 |
+ |
} |
279 |
+ |
return(bright(input[fn-1].scan[xpos])); |
280 |
|
} |
281 |
|
|
282 |
|
|