29 |
|
FILE *fp; /* stream pointer */ |
30 |
|
COLOR *scan[WINSIZ]; /* input scanline window */ |
31 |
|
COLOR coef; /* coefficient */ |
32 |
+ |
COLOR expos; /* recorded exposure */ |
33 |
|
} input[MAXINP]; /* input pictures */ |
34 |
|
|
35 |
|
int nfiles; /* number of input files */ |
38 |
|
char *vcolout[3] = {"ro", "go", "bo"}; |
39 |
|
char vbrtin[] = "li"; |
40 |
|
char vbrtout[] = "lo"; |
41 |
< |
char *vcolcoef[3] = {"rc", "gc", "bc"}; |
42 |
< |
char vbrtcoef[] = "lc"; |
41 |
> |
char *vcolexp[3] = {"re", "ge", "be"}; |
42 |
> |
char vbrtexp[] = "le"; |
43 |
|
|
44 |
< |
#define vnfiles "nfiles" |
45 |
< |
#define vxres "xres" |
46 |
< |
#define vyres "yres" |
47 |
< |
#define vxpos "x" |
48 |
< |
#define vypos "y" |
44 |
> |
char vnfiles[] = "nfiles"; |
45 |
> |
char vxmax[] = "xmax"; |
46 |
> |
char vymax[] = "ymax"; |
47 |
> |
char vxres[] = "xres"; |
48 |
> |
char vyres[] = "yres"; |
49 |
> |
char vxpos[] = "x"; |
50 |
> |
char vypos[] = "y"; |
51 |
|
|
52 |
|
int nowarn = 0; /* no warning messages? */ |
53 |
|
|
54 |
< |
int original = 0; /* origninal values? */ |
54 |
> |
int xmax = 0, ymax = 0; /* input resolution */ |
55 |
|
|
56 |
< |
int xres=0, yres=0; /* picture resolution */ |
56 |
> |
int xscan, yscan; /* input position */ |
57 |
|
|
58 |
< |
int xpos, ypos; /* picture position */ |
58 |
> |
int xres, yres; /* output resolution */ |
59 |
|
|
60 |
+ |
int xpos, ypos; /* output position */ |
61 |
+ |
|
62 |
|
int wrongformat = 0; |
63 |
|
|
64 |
|
|
66 |
|
int argc; |
67 |
|
char *argv[]; |
68 |
|
{ |
69 |
+ |
char buf[128]; |
70 |
+ |
int original; |
71 |
|
double f; |
72 |
|
int a, i; |
73 |
|
/* scan options */ |
75 |
|
if (argv[a][0] == '-') |
76 |
|
switch (argv[a][1]) { |
77 |
|
case 'x': |
71 |
– |
xres = atoi(argv[++a]); |
72 |
– |
continue; |
78 |
|
case 'y': |
79 |
< |
yres = atoi(argv[++a]); |
79 |
> |
a++; |
80 |
|
continue; |
81 |
|
case 'w': |
82 |
|
nowarn = !nowarn; |
83 |
|
continue; |
79 |
– |
case 'o': |
80 |
– |
original = !original; |
81 |
– |
continue; |
84 |
|
case 'f': |
85 |
|
case 'e': |
86 |
+ |
a++; |
87 |
|
continue; |
88 |
|
} |
89 |
|
break; |
90 |
|
} |
91 |
|
/* process files */ |
92 |
< |
for (nfiles = 0; nfiles < MAXINP; nfiles++) |
92 |
> |
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
93 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
94 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
95 |
+ |
} |
96 |
|
nfiles = 0; |
97 |
+ |
original = 0; |
98 |
|
for ( ; a < argc; a++) { |
99 |
|
if (nfiles >= MAXINP) { |
100 |
|
eputs(argv[0]); |
107 |
|
input[nfiles].name = "<stdin>"; |
108 |
|
input[nfiles].fp = stdin; |
109 |
|
break; |
110 |
+ |
case 'o': |
111 |
+ |
original++; |
112 |
+ |
break; |
113 |
|
case 's': |
114 |
|
f = atof(argv[++a]); |
115 |
|
scalecolor(input[nfiles].coef, f); |
130 |
|
quit(1); |
131 |
|
} |
132 |
|
} |
133 |
+ |
checkfile(); |
134 |
+ |
if (original) { |
135 |
+ |
colval(input[nfiles].coef,RED) /= |
136 |
+ |
colval(input[nfiles].expos,RED); |
137 |
+ |
colval(input[nfiles].coef,GRN) /= |
138 |
+ |
colval(input[nfiles].expos,GRN); |
139 |
+ |
colval(input[nfiles].coef,BLU) /= |
140 |
+ |
colval(input[nfiles].expos,BLU); |
141 |
+ |
} |
142 |
|
nfiles++; |
143 |
+ |
original = 0; |
144 |
|
} |
145 |
< |
initfiles(); /* initialize files and variables */ |
145 |
> |
init(); /* set constants */ |
146 |
|
/* go back and get expressions */ |
147 |
|
for (a = 1; a < argc; a++) { |
148 |
|
if (argv[a][0] == '-') |
149 |
|
switch (argv[a][1]) { |
150 |
|
case 'x': |
151 |
+ |
strcpy(buf, vxres); |
152 |
+ |
strcat(buf, ":"); |
153 |
+ |
strcat(buf, argv[++a]); |
154 |
+ |
scompile(buf, NULL, 0); |
155 |
+ |
continue; |
156 |
|
case 'y': |
157 |
+ |
strcpy(buf, vyres); |
158 |
+ |
strcat(buf, ":"); |
159 |
+ |
strcat(buf, argv[++a]); |
160 |
+ |
scompile(buf, NULL, 0); |
161 |
+ |
continue; |
162 |
|
case 'w': |
134 |
– |
case 'o': |
163 |
|
continue; |
164 |
|
case 'f': |
165 |
|
fcompile(argv[++a]); |
170 |
|
} |
171 |
|
break; |
172 |
|
} |
173 |
+ |
/* set/get output resolution */ |
174 |
+ |
if (!vardefined(vxres)) |
175 |
+ |
varset(vxres, ':', (double)xmax); |
176 |
+ |
if (!vardefined(vyres)) |
177 |
+ |
varset(vyres, ':', (double)ymax); |
178 |
+ |
xres = varvalue(vxres) + .5; |
179 |
+ |
yres = varvalue(vyres) + .5; |
180 |
+ |
if (xres <= 0 || yres <= 0) { |
181 |
+ |
eputs(argv[0]); |
182 |
+ |
eputs(": illegal output resolution\n"); |
183 |
+ |
quit(1); |
184 |
+ |
} |
185 |
|
/* complete header */ |
186 |
|
printargs(argc, argv, stdout); |
187 |
|
fputformat(COLRFMT, stdout); |
209 |
|
if (isformat(s)) { /* check format */ |
210 |
|
formatval(fmt, s); |
211 |
|
wrongformat = strcmp(fmt, COLRFMT); |
212 |
< |
} else if (original && isexpos(s)) { /* exposure */ |
213 |
< |
d = 1.0/exposval(s); |
214 |
< |
scalecolor(input[nfiles].coef, d); |
215 |
< |
} else if (original && iscolcor(s)) { /* color correction */ |
212 |
> |
return; /* don't echo */ |
213 |
> |
} |
214 |
> |
if (isexpos(s)) { /* exposure */ |
215 |
> |
d = exposval(s); |
216 |
> |
scalecolor(input[nfiles].expos, d); |
217 |
> |
} else if (iscolcor(s)) { /* color correction */ |
218 |
|
colcorval(ctmp, s); |
219 |
< |
colval(input[nfiles].coef,RED) /= colval(ctmp,RED); |
178 |
< |
colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); |
179 |
< |
colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); |
180 |
< |
} else { /* echo unaffected line */ |
181 |
< |
putchar('\t'); |
182 |
< |
fputs(s, stdout); |
219 |
> |
multcolor(input[nfiles].expos, ctmp); |
220 |
|
} |
221 |
< |
|
221 |
> |
/* echo line */ |
222 |
> |
putchar('\t'); |
223 |
> |
fputs(s, stdout); |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
< |
initfiles() /* ready files and set variables */ |
227 |
> |
checkfile() /* ready a file */ |
228 |
|
{ |
229 |
< |
double l_colin(), l_coef(); |
230 |
< |
register int n, i; |
231 |
< |
/* process picture headers */ |
232 |
< |
for (n = 0; n < nfiles; n++) { |
233 |
< |
fputs(input[n].name, stdout); |
234 |
< |
fputs(":\n", stdout); |
235 |
< |
getheader(input[n].fp, tputs, NULL); |
236 |
< |
if (wrongformat) { |
237 |
< |
eputs(input[n].name); |
238 |
< |
eputs(": not in Radiance picture format\n"); |
200 |
< |
quit(1); |
201 |
< |
} |
202 |
< |
if (fgetresolu(&xpos, &ypos, input[n].fp) != (YMAJOR|YDECR)) { |
203 |
< |
eputs(input[n].name); |
204 |
< |
eputs(": bad picture size\n"); |
205 |
< |
quit(1); |
206 |
< |
} |
207 |
< |
if (xres == 0 && yres == 0) { |
208 |
< |
xres = xpos; |
209 |
< |
yres = ypos; |
210 |
< |
} else if (xpos != xres || ypos != yres) { |
211 |
< |
eputs(input[n].name); |
212 |
< |
eputs(": resolution mismatch\n"); |
213 |
< |
quit(1); |
214 |
< |
} |
215 |
< |
for (i = 0; i < WINSIZ; i++) |
216 |
< |
input[n].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); |
229 |
> |
int xinp, yinp; |
230 |
> |
register int i; |
231 |
> |
/* process header */ |
232 |
> |
fputs(input[nfiles].name, stdout); |
233 |
> |
fputs(":\n", stdout); |
234 |
> |
getheader(input[nfiles].fp, tputs, NULL); |
235 |
> |
if (wrongformat) { |
236 |
> |
eputs(input[nfiles].name); |
237 |
> |
eputs(": not in Radiance picture format\n"); |
238 |
> |
quit(1); |
239 |
|
} |
240 |
< |
/* prime input */ |
241 |
< |
for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) |
242 |
< |
advance(); |
240 |
> |
if (fgetresolu(&xinp, &yinp, input[nfiles].fp) != (YMAJOR|YDECR)) { |
241 |
> |
eputs(input[nfiles].name); |
242 |
> |
eputs(": bad picture size\n"); |
243 |
> |
quit(1); |
244 |
> |
} |
245 |
> |
if (xmax == 0 && ymax == 0) { |
246 |
> |
xmax = xinp; |
247 |
> |
ymax = yinp; |
248 |
> |
} else if (xinp != xmax || yinp != ymax) { |
249 |
> |
eputs(input[nfiles].name); |
250 |
> |
eputs(": resolution mismatch\n"); |
251 |
> |
quit(1); |
252 |
> |
} |
253 |
> |
/* allocate scanlines */ |
254 |
> |
for (i = 0; i < WINSIZ; i++) |
255 |
> |
input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR)); |
256 |
> |
} |
257 |
> |
|
258 |
> |
|
259 |
> |
init() /* perform final setup */ |
260 |
> |
{ |
261 |
> |
double l_colin(), l_expos(); |
262 |
> |
register int i; |
263 |
|
/* define constants */ |
264 |
|
varset(vnfiles, ':', (double)nfiles); |
265 |
< |
varset(vxres, ':', (double)xres); |
266 |
< |
varset(vyres, ':', (double)yres); |
265 |
> |
varset(vxmax, ':', (double)xmax); |
266 |
> |
varset(vymax, ':', (double)ymax); |
267 |
|
/* set functions */ |
268 |
|
for (i = 0; i < 3; i++) { |
269 |
< |
funset(vcolcoef[i], 1, ':', l_coef); |
269 |
> |
funset(vcolexp[i], 1, ':', l_expos); |
270 |
|
funset(vcolin[i], 1, '=', l_colin); |
271 |
|
} |
272 |
< |
funset(vbrtcoef, 1, ':', l_coef); |
272 |
> |
funset(vbrtexp, 1, ':', l_expos); |
273 |
|
funset(vbrtin, 1, '=', l_colin); |
274 |
|
} |
275 |
|
|
293 |
|
brtdef = NULL; |
294 |
|
/* allocate scanline */ |
295 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
296 |
+ |
/* set input position */ |
297 |
+ |
yscan = ymax+MIDSCN; |
298 |
|
/* combine files */ |
299 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
300 |
|
advance(); |
301 |
|
varset(vypos, '=', (double)ypos); |
302 |
|
for (xpos = 0; xpos < xres; xpos++) { |
303 |
+ |
xscan = (long)xpos*xmax/xres; |
304 |
|
varset(vxpos, '=', (double)xpos); |
305 |
|
eclock++; |
306 |
|
if (brtdef != NULL) { |
315 |
|
} else { |
316 |
|
d = 0.0; |
317 |
|
for (i = 0; i < nfiles; i++) |
318 |
< |
d += colval(input[i].scan[MIDSCN][xpos],j); |
318 |
> |
d += colval(input[i].scan[MIDSCN][xscan],j); |
319 |
|
} |
320 |
|
if (d < 0.0) |
321 |
|
d = 0.0; |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
< |
advance() /* read in next scanline */ |
335 |
> |
advance() /* read in data for next scanline */ |
336 |
|
{ |
337 |
+ |
int ytarget; |
338 |
|
register COLOR *st; |
339 |
|
register int i, j; |
340 |
|
|
341 |
< |
for (i = 0; i < nfiles; i++) { |
342 |
< |
st = input[i].scan[WINSIZ-1]; |
343 |
< |
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
344 |
< |
input[i].scan[j] = input[i].scan[j-1]; |
345 |
< |
input[i].scan[0] = st; |
346 |
< |
if (ypos < MIDSCN) /* hit bottom */ |
347 |
< |
continue; |
348 |
< |
if (freadscan(st, xres, input[i].fp) < 0) { |
349 |
< |
eputs(input[i].name); |
350 |
< |
eputs(": read error\n"); |
351 |
< |
quit(1); |
341 |
> |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
342 |
> |
for (i = 0; i < nfiles; i++) { |
343 |
> |
st = input[i].scan[WINSIZ-1]; |
344 |
> |
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
345 |
> |
input[i].scan[j] = input[i].scan[j-1]; |
346 |
> |
input[i].scan[0] = st; |
347 |
> |
if (yscan <= MIDSCN) /* hit bottom? */ |
348 |
> |
continue; |
349 |
> |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
350 |
> |
eputs(input[i].name); |
351 |
> |
eputs(": read error\n"); |
352 |
> |
quit(1); |
353 |
> |
} |
354 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
355 |
> |
multcolor(st[j], input[i].coef); |
356 |
|
} |
307 |
– |
for (j = 0; j < xres; j++) /* adjust color */ |
308 |
– |
multcolor(st[j], input[i].coef); |
309 |
– |
} |
357 |
|
} |
358 |
|
|
359 |
|
|
360 |
|
double |
361 |
< |
l_coef(nam) /* return picture coefficients */ |
361 |
> |
l_expos(nam) /* return picture exposure */ |
362 |
|
register char *nam; |
363 |
|
{ |
364 |
|
register int fn, n; |
318 |
– |
double d; |
365 |
|
|
366 |
< |
fn = (d = argument(1)) - .5; |
367 |
< |
if (d <= -.5 || fn >= nfiles) { |
368 |
< |
errno = EDOM; |
369 |
< |
return(0.0); |
370 |
< |
} |
325 |
< |
if (d < .5) |
326 |
< |
return((double)nfiles); |
327 |
< |
if (nam == vbrtcoef) |
328 |
< |
return(bright(input[fn].coef)); |
366 |
> |
fn = argument(1) - .5; |
367 |
> |
if (fn < 0 || fn >= nfiles) |
368 |
> |
return(1.0); |
369 |
> |
if (nam == vbrtexp) |
370 |
> |
return(bright(input[fn].expos)); |
371 |
|
n = 3; |
372 |
|
while (n--) |
373 |
< |
if (nam == vcolcoef[n]) |
374 |
< |
return(colval(input[fn].coef,n)); |
375 |
< |
eputs("Bad call to l_coef()!\n"); |
373 |
> |
if (nam == vcolexp[n]) |
374 |
> |
return(colval(input[fn].expos,n)); |
375 |
> |
eputs("Bad call to l_expos()!\n"); |
376 |
|
quit(1); |
377 |
|
} |
378 |
|
|
385 |
|
register int n, xoff, yoff; |
386 |
|
double d; |
387 |
|
|
388 |
< |
fn = (d = argument(1)) - .5; |
389 |
< |
if (d <= -.5 || fn >= nfiles) { |
388 |
> |
d = argument(1); |
389 |
> |
if (d > -.5 && d < .5) |
390 |
> |
return((double)nfiles); |
391 |
> |
fn = d - .5; |
392 |
> |
if (fn < 0 || fn >= nfiles) { |
393 |
|
errno = EDOM; |
394 |
|
return(0.0); |
395 |
|
} |
351 |
– |
if (d < .5) |
352 |
– |
return((double)nfiles); |
396 |
|
xoff = yoff = 0; |
397 |
|
n = nargum(); |
398 |
|
if (n >= 2) { |
399 |
|
d = argument(2); |
400 |
|
if (d < 0.0) { |
401 |
|
xoff = d-.5; |
402 |
< |
if (xpos+xoff < 0) |
403 |
< |
xoff = -xpos; |
402 |
> |
if (xscan+xoff < 0) |
403 |
> |
xoff = -xscan; |
404 |
|
} else { |
405 |
|
xoff = d+.5; |
406 |
< |
if (xpos+xoff >= xres) |
407 |
< |
xoff = xres-1-xpos; |
406 |
> |
if (xscan+xoff >= xmax) |
407 |
> |
xoff = xmax-1-xscan; |
408 |
|
} |
409 |
|
} |
410 |
|
if (n >= 3) { |
413 |
|
yoff = d-.5; |
414 |
|
if (yoff+MIDSCN < 0) |
415 |
|
yoff = -MIDSCN; |
416 |
< |
if (ypos+yoff < 0) |
417 |
< |
yoff = -ypos; |
416 |
> |
if (yscan+yoff < 0) |
417 |
> |
yoff = -yscan; |
418 |
|
} else { |
419 |
|
yoff = d+.5; |
420 |
|
if (yoff+MIDSCN >= WINSIZ) |
421 |
|
yoff = WINSIZ-1-MIDSCN; |
422 |
< |
if (ypos+yoff >= yres) |
423 |
< |
yoff = yres-1-ypos; |
422 |
> |
if (yscan+yoff >= ymax) |
423 |
> |
yoff = ymax-1-yscan; |
424 |
|
} |
425 |
|
} |
426 |
|
if (nam == vbrtin) |
427 |
< |
return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); |
427 |
> |
return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
428 |
|
n = 3; |
429 |
|
while (n--) |
430 |
|
if (nam == vcolin[n]) |
431 |
< |
return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n)); |
431 |
> |
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
432 |
|
eputs("Bad call to l_colin()!\n"); |
433 |
|
quit(1); |
434 |
|
} |