25 |
|
#define BRT (-1) /* special index for brightness */ |
26 |
|
|
27 |
|
struct { |
28 |
< |
char *name; /* file name */ |
28 |
> |
char *name; /* file or command name */ |
29 |
|
FILE *fp; /* stream pointer */ |
30 |
|
COLOR *scan[WINSIZ]; /* input scanline window */ |
31 |
|
COLOR coef; /* coefficient */ |
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 |
+ |
FILE *popen(); |
65 |
|
|
66 |
+ |
|
67 |
|
main(argc, argv) |
68 |
|
int argc; |
69 |
|
char *argv[]; |
70 |
|
{ |
71 |
+ |
char buf[128]; |
72 |
+ |
int original; |
73 |
|
double f; |
74 |
|
int a, i; |
75 |
|
/* scan options */ |
77 |
|
if (argv[a][0] == '-') |
78 |
|
switch (argv[a][1]) { |
79 |
|
case 'x': |
72 |
– |
xres = atoi(argv[++a]); |
73 |
– |
continue; |
80 |
|
case 'y': |
81 |
< |
yres = atoi(argv[++a]); |
81 |
> |
a++; |
82 |
|
continue; |
83 |
|
case 'w': |
84 |
|
nowarn = !nowarn; |
96 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
97 |
|
} |
98 |
|
nfiles = 0; |
99 |
+ |
original = 0; |
100 |
|
for ( ; a < argc; a++) { |
101 |
|
if (nfiles >= MAXINP) { |
102 |
|
eputs(argv[0]); |
126 |
|
} |
127 |
|
else { |
128 |
|
input[nfiles].name = argv[a]; |
129 |
< |
input[nfiles].fp = fopen(argv[a], "r"); |
129 |
> |
input[nfiles].fp = argv[a][0]=='!' ? |
130 |
> |
popen(argv[a]+1, "r") : |
131 |
> |
fopen(argv[a], "r"); |
132 |
|
if (input[nfiles].fp == NULL) { |
133 |
|
perror(argv[a]); |
134 |
|
quit(1); |
135 |
|
} |
136 |
|
} |
137 |
|
checkfile(); |
138 |
< |
original = 0; |
138 |
> |
if (original) { |
139 |
> |
colval(input[nfiles].coef,RED) /= |
140 |
> |
colval(input[nfiles].expos,RED); |
141 |
> |
colval(input[nfiles].coef,GRN) /= |
142 |
> |
colval(input[nfiles].expos,GRN); |
143 |
> |
colval(input[nfiles].coef,BLU) /= |
144 |
> |
colval(input[nfiles].expos,BLU); |
145 |
> |
} |
146 |
|
nfiles++; |
147 |
+ |
original = 0; |
148 |
|
} |
149 |
< |
init(); /* set constant expressions */ |
149 |
> |
init(); /* set constants */ |
150 |
|
/* go back and get expressions */ |
151 |
|
for (a = 1; a < argc; a++) { |
152 |
|
if (argv[a][0] == '-') |
153 |
|
switch (argv[a][1]) { |
154 |
|
case 'x': |
155 |
+ |
strcpy(buf, vxres); |
156 |
+ |
strcat(buf, ":"); |
157 |
+ |
strcat(buf, argv[++a]); |
158 |
+ |
scompile(buf, NULL, 0); |
159 |
+ |
continue; |
160 |
|
case 'y': |
161 |
< |
a++; |
161 |
> |
strcpy(buf, vyres); |
162 |
> |
strcat(buf, ":"); |
163 |
> |
strcat(buf, argv[++a]); |
164 |
> |
scompile(buf, NULL, 0); |
165 |
|
continue; |
166 |
|
case 'w': |
167 |
|
continue; |
174 |
|
} |
175 |
|
break; |
176 |
|
} |
177 |
+ |
/* set/get output resolution */ |
178 |
+ |
if (!vardefined(vxres)) |
179 |
+ |
varset(vxres, ':', (double)xmax); |
180 |
+ |
if (!vardefined(vyres)) |
181 |
+ |
varset(vyres, ':', (double)ymax); |
182 |
+ |
xres = varvalue(vxres) + .5; |
183 |
+ |
yres = varvalue(vyres) + .5; |
184 |
+ |
if (xres <= 0 || yres <= 0) { |
185 |
+ |
eputs(argv[0]); |
186 |
+ |
eputs(": illegal output resolution\n"); |
187 |
+ |
quit(1); |
188 |
+ |
} |
189 |
|
/* complete header */ |
190 |
|
printargs(argc, argv, stdout); |
191 |
|
fputformat(COLRFMT, stdout); |
198 |
|
eputs("Usage: "); |
199 |
|
eputs(argv[0]); |
200 |
|
eputs( |
201 |
< |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); |
201 |
> |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); |
202 |
|
quit(1); |
203 |
|
} |
204 |
|
|
218 |
|
if (isexpos(s)) { /* exposure */ |
219 |
|
d = exposval(s); |
220 |
|
scalecolor(input[nfiles].expos, d); |
184 |
– |
if (original) |
185 |
– |
scalecolor(input[nfiles].coef, 1.0/d); |
221 |
|
} else if (iscolcor(s)) { /* color correction */ |
222 |
|
colcorval(ctmp, s); |
223 |
|
multcolor(input[nfiles].expos, ctmp); |
189 |
– |
if (original) { |
190 |
– |
colval(input[nfiles].coef,RED) /= colval(ctmp,RED); |
191 |
– |
colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); |
192 |
– |
colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); |
193 |
– |
} |
224 |
|
} |
225 |
|
/* echo line */ |
226 |
|
putchar('\t'); |
230 |
|
|
231 |
|
checkfile() /* ready a file */ |
232 |
|
{ |
233 |
+ |
int xinp, yinp; |
234 |
|
register int i; |
235 |
|
/* process header */ |
236 |
|
fputs(input[nfiles].name, stdout); |
241 |
|
eputs(": not in Radiance picture format\n"); |
242 |
|
quit(1); |
243 |
|
} |
244 |
< |
if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) { |
244 |
> |
if (fgetresolu(&xinp, &yinp, input[nfiles].fp) != (YMAJOR|YDECR)) { |
245 |
|
eputs(input[nfiles].name); |
246 |
|
eputs(": bad picture size\n"); |
247 |
|
quit(1); |
248 |
|
} |
249 |
< |
if (xres == 0 && yres == 0) { |
250 |
< |
xres = xpos; |
251 |
< |
yres = ypos; |
252 |
< |
} else if (xpos != xres || ypos != yres) { |
249 |
> |
if (xmax == 0 && ymax == 0) { |
250 |
> |
xmax = xinp; |
251 |
> |
ymax = yinp; |
252 |
> |
} else if (xinp != xmax || yinp != ymax) { |
253 |
|
eputs(input[nfiles].name); |
254 |
|
eputs(": resolution mismatch\n"); |
255 |
|
quit(1); |
256 |
|
} |
257 |
|
/* allocate scanlines */ |
258 |
|
for (i = 0; i < WINSIZ; i++) |
259 |
< |
input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); |
259 |
> |
input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR)); |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
< |
init() /* perform final setup */ |
263 |
> |
init() /* perform final setup */ |
264 |
|
{ |
265 |
|
double l_colin(), l_expos(); |
266 |
|
register int i; |
236 |
– |
/* prime input */ |
237 |
– |
for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) |
238 |
– |
advance(); |
267 |
|
/* define constants */ |
268 |
|
varset(vnfiles, ':', (double)nfiles); |
269 |
< |
varset(vxres, ':', (double)xres); |
270 |
< |
varset(vyres, ':', (double)yres); |
269 |
> |
varset(vxmax, ':', (double)xmax); |
270 |
> |
varset(vymax, ':', (double)ymax); |
271 |
|
/* set functions */ |
272 |
|
for (i = 0; i < 3; i++) { |
273 |
|
funset(vcolexp[i], 1, ':', l_expos); |
297 |
|
brtdef = NULL; |
298 |
|
/* allocate scanline */ |
299 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
300 |
+ |
/* set input position */ |
301 |
+ |
yscan = ymax+MIDSCN; |
302 |
|
/* combine files */ |
303 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
304 |
|
advance(); |
305 |
|
varset(vypos, '=', (double)ypos); |
306 |
|
for (xpos = 0; xpos < xres; xpos++) { |
307 |
+ |
xscan = (long)xpos*xmax/xres; |
308 |
|
varset(vxpos, '=', (double)xpos); |
309 |
|
eclock++; |
310 |
|
if (brtdef != NULL) { |
319 |
|
} else { |
320 |
|
d = 0.0; |
321 |
|
for (i = 0; i < nfiles; i++) |
322 |
< |
d += colval(input[i].scan[MIDSCN][xpos],j); |
322 |
> |
d += colval(input[i].scan[MIDSCN][xscan],j); |
323 |
|
} |
324 |
|
if (d < 0.0) |
325 |
|
d = 0.0; |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
< |
advance() /* read in next scanline */ |
339 |
> |
advance() /* read in data for next scanline */ |
340 |
|
{ |
341 |
+ |
int ytarget; |
342 |
|
register COLOR *st; |
343 |
|
register int i, j; |
344 |
|
|
345 |
< |
for (i = 0; i < nfiles; i++) { |
346 |
< |
st = input[i].scan[WINSIZ-1]; |
347 |
< |
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
348 |
< |
input[i].scan[j] = input[i].scan[j-1]; |
349 |
< |
input[i].scan[0] = st; |
350 |
< |
if (ypos < MIDSCN) /* hit bottom */ |
351 |
< |
continue; |
352 |
< |
if (freadscan(st, xres, input[i].fp) < 0) { |
353 |
< |
eputs(input[i].name); |
354 |
< |
eputs(": read error\n"); |
355 |
< |
quit(1); |
345 |
> |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
346 |
> |
for (i = 0; i < nfiles; i++) { |
347 |
> |
st = input[i].scan[WINSIZ-1]; |
348 |
> |
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
349 |
> |
input[i].scan[j] = input[i].scan[j-1]; |
350 |
> |
input[i].scan[0] = st; |
351 |
> |
if (yscan <= MIDSCN) /* hit bottom? */ |
352 |
> |
continue; |
353 |
> |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
354 |
> |
eputs(input[i].name); |
355 |
> |
eputs(": read error\n"); |
356 |
> |
quit(1); |
357 |
> |
} |
358 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
359 |
> |
multcolor(st[j], input[i].coef); |
360 |
|
} |
325 |
– |
for (j = 0; j < xres; j++) /* adjust color */ |
326 |
– |
multcolor(st[j], input[i].coef); |
327 |
– |
} |
361 |
|
} |
362 |
|
|
363 |
|
|
366 |
|
register char *nam; |
367 |
|
{ |
368 |
|
register int fn, n; |
336 |
– |
double d; |
369 |
|
|
370 |
< |
d = argument(1); |
371 |
< |
if (d > -.5 && d < .5) |
372 |
< |
return((double)nfiles); |
341 |
< |
fn = d - .5; |
342 |
< |
if (fn < 0 || fn >= nfiles) { |
343 |
< |
errno = EDOM; |
344 |
< |
return(0.0); |
345 |
< |
} |
370 |
> |
fn = argument(1) - .5; |
371 |
> |
if (fn < 0 || fn >= nfiles) |
372 |
> |
return(1.0); |
373 |
|
if (nam == vbrtexp) |
374 |
|
return(bright(input[fn].expos)); |
375 |
|
n = 3; |
403 |
|
d = argument(2); |
404 |
|
if (d < 0.0) { |
405 |
|
xoff = d-.5; |
406 |
< |
if (xpos+xoff < 0) |
407 |
< |
xoff = -xpos; |
406 |
> |
if (xscan+xoff < 0) |
407 |
> |
xoff = -xscan; |
408 |
|
} else { |
409 |
|
xoff = d+.5; |
410 |
< |
if (xpos+xoff >= xres) |
411 |
< |
xoff = xres-1-xpos; |
410 |
> |
if (xscan+xoff >= xmax) |
411 |
> |
xoff = xmax-1-xscan; |
412 |
|
} |
413 |
|
} |
414 |
|
if (n >= 3) { |
417 |
|
yoff = d-.5; |
418 |
|
if (yoff+MIDSCN < 0) |
419 |
|
yoff = -MIDSCN; |
420 |
< |
if (ypos+yoff < 0) |
421 |
< |
yoff = -ypos; |
420 |
> |
if (yscan+yoff < 0) |
421 |
> |
yoff = -yscan; |
422 |
|
} else { |
423 |
|
yoff = d+.5; |
424 |
|
if (yoff+MIDSCN >= WINSIZ) |
425 |
|
yoff = WINSIZ-1-MIDSCN; |
426 |
< |
if (ypos+yoff >= yres) |
427 |
< |
yoff = yres-1-ypos; |
426 |
> |
if (yscan+yoff >= ymax) |
427 |
> |
yoff = ymax-1-yscan; |
428 |
|
} |
429 |
|
} |
430 |
|
if (nam == vbrtin) |
431 |
< |
return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); |
431 |
> |
return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
432 |
|
n = 3; |
433 |
|
while (n--) |
434 |
|
if (nam == vcolin[n]) |
435 |
< |
return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n)); |
435 |
> |
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
436 |
|
eputs("Bad call to l_colin()!\n"); |
437 |
|
quit(1); |
438 |
|
} |