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 */ |
36 |
|
|
37 |
|
char *vcolin[3] = {"ri", "gi", "bi"}; |
38 |
|
char *vcolout[3] = {"ro", "go", "bo"}; |
39 |
< |
#define vbrtin "li" |
40 |
< |
#define vbrtout "lo" |
39 |
> |
char vbrtin[] = "li"; |
40 |
> |
char vbrtout[] = "lo"; |
41 |
> |
char *vcolexp[3] = {"re", "ge", "be"}; |
42 |
> |
char vbrtexp[] = "le"; |
43 |
|
|
44 |
|
#define vnfiles "nfiles" |
45 |
|
#define vxres "xres" |
58 |
|
int wrongformat = 0; |
59 |
|
|
60 |
|
|
58 |
– |
tputs(s) /* put out string preceded by a tab */ |
59 |
– |
char *s; |
60 |
– |
{ |
61 |
– |
char fmt[32]; |
62 |
– |
double d; |
63 |
– |
COLOR ctmp; |
64 |
– |
|
65 |
– |
if (isformat(s)) { /* check format */ |
66 |
– |
formatval(fmt, s); |
67 |
– |
wrongformat = strcmp(fmt, COLRFMT); |
68 |
– |
} else if (original && isexpos(s)) { /* exposure */ |
69 |
– |
d = 1.0/exposval(s); |
70 |
– |
scalecolor(input[nfiles].coef, d); |
71 |
– |
} else if (original && iscolcor(s)) { /* color correction */ |
72 |
– |
colcorval(ctmp, s); |
73 |
– |
colval(input[nfiles].coef,RED) /= colval(ctmp,RED); |
74 |
– |
colval(input[nfiles].coef,GRN) /= colval(ctmp,GRN); |
75 |
– |
colval(input[nfiles].coef,BLU) /= colval(ctmp,BLU); |
76 |
– |
} else { /* echo unaffected line */ |
77 |
– |
putchar('\t'); |
78 |
– |
fputs(s, stdout); |
79 |
– |
} |
80 |
– |
|
81 |
– |
} |
82 |
– |
|
83 |
– |
|
61 |
|
main(argc, argv) |
62 |
|
int argc; |
63 |
|
char *argv[]; |
64 |
|
{ |
88 |
– |
extern double l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); |
65 |
|
double f; |
66 |
|
int a, i; |
67 |
< |
|
68 |
< |
funset(vcolin[RED], 1, '=', l_redin); |
93 |
< |
funset(vcolin[GRN], 1, '=', l_grnin); |
94 |
< |
funset(vcolin[BLU], 1, '=', l_bluin); |
95 |
< |
funset(vbrtin, 1, '=', l_brtin); |
96 |
< |
|
97 |
< |
for (a = 1; a < argc; a++) |
67 |
> |
/* scan options */ |
68 |
> |
for (a = 1; a < argc; a++) { |
69 |
|
if (argv[a][0] == '-') |
70 |
|
switch (argv[a][1]) { |
100 |
– |
case '\0': |
101 |
– |
case 's': |
102 |
– |
case 'c': |
103 |
– |
goto getfiles; |
71 |
|
case 'x': |
72 |
|
xres = atoi(argv[++a]); |
73 |
< |
break; |
73 |
> |
continue; |
74 |
|
case 'y': |
75 |
|
yres = atoi(argv[++a]); |
76 |
< |
break; |
76 |
> |
continue; |
77 |
|
case 'w': |
78 |
|
nowarn = !nowarn; |
79 |
< |
break; |
113 |
< |
case 'o': |
114 |
< |
original = !original; |
115 |
< |
break; |
79 |
> |
continue; |
80 |
|
case 'f': |
117 |
– |
fcompile(argv[++a]); |
118 |
– |
break; |
81 |
|
case 'e': |
82 |
< |
scompile(argv[++a], NULL, 0); |
83 |
< |
break; |
122 |
< |
default: |
123 |
< |
goto usage; |
82 |
> |
a++; |
83 |
> |
continue; |
84 |
|
} |
85 |
< |
else |
86 |
< |
break; |
87 |
< |
getfiles: |
88 |
< |
for (nfiles = 0; nfiles < MAXINP; nfiles++) |
85 |
> |
break; |
86 |
> |
} |
87 |
> |
/* process files */ |
88 |
> |
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
89 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
90 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
91 |
+ |
} |
92 |
|
nfiles = 0; |
93 |
|
for ( ; a < argc; a++) { |
94 |
|
if (nfiles >= MAXINP) { |
102 |
|
input[nfiles].name = "<stdin>"; |
103 |
|
input[nfiles].fp = stdin; |
104 |
|
break; |
105 |
+ |
case 'o': |
106 |
+ |
original++; |
107 |
+ |
break; |
108 |
|
case 's': |
109 |
|
f = atof(argv[++a]); |
110 |
|
scalecolor(input[nfiles].coef, f); |
125 |
|
quit(1); |
126 |
|
} |
127 |
|
} |
128 |
< |
fputs(input[nfiles].name, stdout); |
129 |
< |
fputs(":\n", stdout); |
165 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
166 |
< |
if (wrongformat) { |
167 |
< |
eputs(input[nfiles].name); |
168 |
< |
eputs(": not in Radiance picture format\n"); |
169 |
< |
quit(1); |
170 |
< |
} |
171 |
< |
if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != |
172 |
< |
(YMAJOR|YDECR)) { |
173 |
< |
eputs(input[nfiles].name); |
174 |
< |
eputs(": bad picture size\n"); |
175 |
< |
quit(1); |
176 |
< |
} |
177 |
< |
if (xres == 0 && yres == 0) { |
178 |
< |
xres = xpos; |
179 |
< |
yres = ypos; |
180 |
< |
} else if (xpos != xres || ypos != yres) { |
181 |
< |
eputs(argv[0]); |
182 |
< |
eputs(": resolution mismatch\n"); |
183 |
< |
quit(1); |
184 |
< |
} |
185 |
< |
for (i = 0; i < WINSIZ; i++) |
186 |
< |
input[nfiles].scan[i] = |
187 |
< |
(COLOR *)emalloc(xres*sizeof(COLOR)); |
128 |
> |
checkfile(); |
129 |
> |
original = 0; |
130 |
|
nfiles++; |
131 |
|
} |
132 |
+ |
init(); /* set constant expressions */ |
133 |
+ |
/* go back and get expressions */ |
134 |
+ |
for (a = 1; a < argc; a++) { |
135 |
+ |
if (argv[a][0] == '-') |
136 |
+ |
switch (argv[a][1]) { |
137 |
+ |
case 'x': |
138 |
+ |
case 'y': |
139 |
+ |
a++; |
140 |
+ |
continue; |
141 |
+ |
case 'w': |
142 |
+ |
continue; |
143 |
+ |
case 'f': |
144 |
+ |
fcompile(argv[++a]); |
145 |
+ |
continue; |
146 |
+ |
case 'e': |
147 |
+ |
scompile(argv[++a], NULL, 0); |
148 |
+ |
continue; |
149 |
+ |
} |
150 |
+ |
break; |
151 |
+ |
} |
152 |
+ |
/* complete header */ |
153 |
|
printargs(argc, argv, stdout); |
154 |
|
fputformat(COLRFMT, stdout); |
155 |
|
putchar('\n'); |
156 |
|
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
157 |
+ |
/* combine pictures */ |
158 |
|
combine(); |
159 |
|
quit(0); |
160 |
|
usage: |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
+ |
tputs(s) /* put out string preceded by a tab */ |
170 |
+ |
char *s; |
171 |
+ |
{ |
172 |
+ |
char fmt[32]; |
173 |
+ |
double d; |
174 |
+ |
COLOR ctmp; |
175 |
+ |
|
176 |
+ |
if (isformat(s)) { /* check format */ |
177 |
+ |
formatval(fmt, s); |
178 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
179 |
+ |
return; /* don't echo */ |
180 |
+ |
} |
181 |
+ |
if (isexpos(s)) { /* exposure */ |
182 |
+ |
d = exposval(s); |
183 |
+ |
scalecolor(input[nfiles].expos, d); |
184 |
+ |
if (original) |
185 |
+ |
scalecolor(input[nfiles].coef, 1.0/d); |
186 |
+ |
} else if (iscolcor(s)) { /* color correction */ |
187 |
+ |
colcorval(ctmp, s); |
188 |
+ |
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 |
+ |
} |
194 |
+ |
} |
195 |
+ |
/* echo line */ |
196 |
+ |
putchar('\t'); |
197 |
+ |
fputs(s, stdout); |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
|
201 |
+ |
checkfile() /* ready a file */ |
202 |
+ |
{ |
203 |
+ |
register int i; |
204 |
+ |
/* process header */ |
205 |
+ |
fputs(input[nfiles].name, stdout); |
206 |
+ |
fputs(":\n", stdout); |
207 |
+ |
getheader(input[nfiles].fp, tputs, NULL); |
208 |
+ |
if (wrongformat) { |
209 |
+ |
eputs(input[nfiles].name); |
210 |
+ |
eputs(": not in Radiance picture format\n"); |
211 |
+ |
quit(1); |
212 |
+ |
} |
213 |
+ |
if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != (YMAJOR|YDECR)) { |
214 |
+ |
eputs(input[nfiles].name); |
215 |
+ |
eputs(": bad picture size\n"); |
216 |
+ |
quit(1); |
217 |
+ |
} |
218 |
+ |
if (xres == 0 && yres == 0) { |
219 |
+ |
xres = xpos; |
220 |
+ |
yres = ypos; |
221 |
+ |
} else if (xpos != xres || ypos != yres) { |
222 |
+ |
eputs(input[nfiles].name); |
223 |
+ |
eputs(": resolution mismatch\n"); |
224 |
+ |
quit(1); |
225 |
+ |
} |
226 |
+ |
/* allocate scanlines */ |
227 |
+ |
for (i = 0; i < WINSIZ; i++) |
228 |
+ |
input[nfiles].scan[i] = (COLOR *)emalloc(xres*sizeof(COLOR)); |
229 |
+ |
} |
230 |
+ |
|
231 |
+ |
|
232 |
+ |
init() /* perform final setup */ |
233 |
+ |
{ |
234 |
+ |
double l_colin(), l_expos(); |
235 |
+ |
register int i; |
236 |
+ |
/* prime input */ |
237 |
+ |
for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) |
238 |
+ |
advance(); |
239 |
+ |
/* define constants */ |
240 |
+ |
varset(vnfiles, ':', (double)nfiles); |
241 |
+ |
varset(vxres, ':', (double)xres); |
242 |
+ |
varset(vyres, ':', (double)yres); |
243 |
+ |
/* set functions */ |
244 |
+ |
for (i = 0; i < 3; i++) { |
245 |
+ |
funset(vcolexp[i], 1, ':', l_expos); |
246 |
+ |
funset(vcolin[i], 1, '=', l_colin); |
247 |
+ |
} |
248 |
+ |
funset(vbrtexp, 1, ':', l_expos); |
249 |
+ |
funset(vbrtin, 1, '=', l_colin); |
250 |
+ |
} |
251 |
+ |
|
252 |
+ |
|
253 |
|
combine() /* combine pictures */ |
254 |
|
{ |
255 |
|
EPNODE *coldef[3], *brtdef; |
267 |
|
brtdef = eparse(vbrtout); |
268 |
|
else |
269 |
|
brtdef = NULL; |
222 |
– |
/* define constants */ |
223 |
– |
varset(vnfiles, ':', (double)nfiles); |
224 |
– |
varset(vxres, ':', (double)xres); |
225 |
– |
varset(vyres, ':', (double)yres); |
270 |
|
/* allocate scanline */ |
271 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
228 |
– |
/* initialize input */ |
229 |
– |
initinp(); |
272 |
|
/* combine files */ |
273 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
274 |
|
advance(); |
305 |
|
} |
306 |
|
|
307 |
|
|
266 |
– |
initinp() /* initilize scan windows */ |
267 |
– |
{ |
268 |
– |
for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) |
269 |
– |
advance(); |
270 |
– |
} |
271 |
– |
|
272 |
– |
|
308 |
|
advance() /* read in next scanline */ |
309 |
|
{ |
310 |
|
register COLOR *st; |
329 |
|
|
330 |
|
|
331 |
|
double |
332 |
< |
colin(ci) /* return color value for picture */ |
333 |
< |
register int ci; |
332 |
> |
l_expos(nam) /* return picture exposure */ |
333 |
> |
register char *nam; |
334 |
|
{ |
335 |
< |
int n, fn; |
301 |
< |
register int xoff, yoff; |
335 |
> |
register int fn, n; |
336 |
|
double d; |
337 |
|
|
338 |
< |
fn = (d = argument(1)) - .5; |
339 |
< |
if (d <= -.5 || fn >= nfiles) { |
338 |
> |
d = argument(1); |
339 |
> |
if (d > -.5 && d < .5) |
340 |
> |
return((double)nfiles); |
341 |
> |
fn = d - .5; |
342 |
> |
if (fn < 0 || fn >= nfiles) { |
343 |
|
errno = EDOM; |
344 |
|
return(0.0); |
345 |
|
} |
346 |
< |
if (d < .5) |
346 |
> |
if (nam == vbrtexp) |
347 |
> |
return(bright(input[fn].expos)); |
348 |
> |
n = 3; |
349 |
> |
while (n--) |
350 |
> |
if (nam == vcolexp[n]) |
351 |
> |
return(colval(input[fn].expos,n)); |
352 |
> |
eputs("Bad call to l_expos()!\n"); |
353 |
> |
quit(1); |
354 |
> |
} |
355 |
> |
|
356 |
> |
|
357 |
> |
double |
358 |
> |
l_colin(nam) /* return color value for picture */ |
359 |
> |
register char *nam; |
360 |
> |
{ |
361 |
> |
int fn; |
362 |
> |
register int n, xoff, yoff; |
363 |
> |
double d; |
364 |
> |
|
365 |
> |
d = argument(1); |
366 |
> |
if (d > -.5 && d < .5) |
367 |
|
return((double)nfiles); |
368 |
+ |
fn = d - .5; |
369 |
+ |
if (fn < 0 || fn >= nfiles) { |
370 |
+ |
errno = EDOM; |
371 |
+ |
return(0.0); |
372 |
+ |
} |
373 |
|
xoff = yoff = 0; |
374 |
|
n = nargum(); |
375 |
|
if (n >= 2) { |
400 |
|
yoff = yres-1-ypos; |
401 |
|
} |
402 |
|
} |
403 |
< |
if (ci == BRT) |
403 |
> |
if (nam == vbrtin) |
404 |
|
return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); |
405 |
< |
return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],ci)); |
406 |
< |
} |
407 |
< |
|
408 |
< |
|
409 |
< |
double |
410 |
< |
l_redin() /* get red color */ |
349 |
< |
{ |
350 |
< |
return(colin(RED)); |
351 |
< |
} |
352 |
< |
|
353 |
< |
|
354 |
< |
double |
355 |
< |
l_grnin() /* get green color */ |
356 |
< |
{ |
357 |
< |
return(colin(GRN)); |
358 |
< |
} |
359 |
< |
|
360 |
< |
|
361 |
< |
double |
362 |
< |
l_bluin() /* get blue color */ |
363 |
< |
{ |
364 |
< |
return(colin(BLU)); |
365 |
< |
} |
366 |
< |
|
367 |
< |
|
368 |
< |
double |
369 |
< |
l_brtin() /* get brightness value */ |
370 |
< |
{ |
371 |
< |
return(colin(BRT)); |
405 |
> |
n = 3; |
406 |
> |
while (n--) |
407 |
> |
if (nam == vcolin[n]) |
408 |
> |
return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],n)); |
409 |
> |
eputs("Bad call to l_colin()!\n"); |
410 |
> |
quit(1); |
411 |
|
} |
412 |
|
|
413 |
|
|