1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Combine picture files according to calcomp functions. |
6 |
|
* |
7 |
|
* 1/4/89 |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include <stdio.h> |
11 |
< |
|
15 |
< |
#include <errno.h> |
16 |
< |
|
10 |
> |
#include "platform.h" |
11 |
> |
#include "standard.h" |
12 |
|
#include "color.h" |
18 |
– |
|
13 |
|
#include "calcomp.h" |
14 |
+ |
#include "view.h" |
15 |
|
|
16 |
|
#define MAXINP 32 /* maximum number of input files */ |
17 |
< |
#define WINSIZ 9 /* scanline window size */ |
18 |
< |
#define MIDSCN 4 /* current scan position */ |
17 |
> |
#define WINSIZ 64 /* scanline window size */ |
18 |
> |
#define MIDSCN ((WINSIZ-1)/2+1) |
19 |
|
|
25 |
– |
#define BRT (-1) /* special index for brightness */ |
26 |
– |
|
20 |
|
struct { |
21 |
< |
char *name; /* file name */ |
21 |
> |
char *name; /* file or command name */ |
22 |
|
FILE *fp; /* stream pointer */ |
23 |
+ |
VIEW vw; /* view for picture */ |
24 |
+ |
RESOLU rs; /* image resolution and orientation */ |
25 |
+ |
float pa; /* pixel aspect ratio */ |
26 |
|
COLOR *scan[WINSIZ]; /* input scanline window */ |
27 |
|
COLOR coef; /* coefficient */ |
28 |
+ |
COLOR expos; /* recorded exposure */ |
29 |
|
} input[MAXINP]; /* input pictures */ |
30 |
|
|
31 |
|
int nfiles; /* number of input files */ |
32 |
|
|
33 |
< |
char *vcolin[3] = {"ri", "gi", "bi"}; |
37 |
< |
char *vcolout[3] = {"ro", "go", "bo"}; |
38 |
< |
#define vbrtin "li" |
39 |
< |
#define vbrtout "lo" |
33 |
> |
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
34 |
|
|
35 |
< |
#define vnfiles "nfiles" |
36 |
< |
#define vxres "xres" |
37 |
< |
#define vyres "yres" |
38 |
< |
#define vxpos "x" |
39 |
< |
#define vypos "y" |
35 |
> |
char Command[] = "<Command>"; |
36 |
> |
char vcolin[3][4] = {"ri", "gi", "bi"}; |
37 |
> |
char vcolout[3][4] = {"ro", "go", "bo"}; |
38 |
> |
char vbrtin[] = "li"; |
39 |
> |
char vbrtout[] = "lo"; |
40 |
> |
char vcolexp[3][4] = {"re", "ge", "be"}; |
41 |
> |
char vbrtexp[] = "le"; |
42 |
> |
char vpixaspect[] = "pa"; |
43 |
|
|
44 |
+ |
char vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; |
45 |
+ |
|
46 |
+ |
char vpsize[] = "S"; |
47 |
+ |
|
48 |
+ |
char vnfiles[] = "nfiles"; |
49 |
+ |
char vwhteff[] = "WE"; |
50 |
+ |
char vxmax[] = "xmax"; |
51 |
+ |
char vymax[] = "ymax"; |
52 |
+ |
char vxres[] = "xres"; |
53 |
+ |
char vyres[] = "yres"; |
54 |
+ |
char vxpos[] = "x"; |
55 |
+ |
char vypos[] = "y"; |
56 |
+ |
|
57 |
|
int nowarn = 0; /* no warning messages? */ |
58 |
|
|
59 |
< |
int original = 0; /* origninal values? */ |
59 |
> |
int xmax = 0, ymax = 0; /* input resolution */ |
60 |
|
|
61 |
< |
int xres=0, yres=0; /* picture resolution */ |
61 |
> |
int xscan, yscan; /* input position */ |
62 |
|
|
63 |
< |
int xpos, ypos; /* picture position */ |
63 |
> |
int xres, yres; /* output resolution */ |
64 |
|
|
65 |
< |
int wrongformat = 0; |
65 |
> |
int xpos, ypos; /* output position */ |
66 |
|
|
67 |
+ |
char *progname; /* global argv[0] */ |
68 |
|
|
69 |
< |
tputs(s) /* put out string preceded by a tab */ |
70 |
< |
char *s; |
60 |
< |
{ |
61 |
< |
char fmt[32]; |
62 |
< |
double d; |
63 |
< |
COLOR ctmp; |
69 |
> |
int wrongformat = 0; |
70 |
> |
int gotview; |
71 |
|
|
72 |
< |
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 |
< |
} |
72 |
> |
FILE *popen(); |
73 |
|
|
74 |
< |
} |
74 |
> |
extern char *emalloc(); |
75 |
|
|
76 |
|
|
77 |
|
main(argc, argv) |
78 |
|
int argc; |
79 |
|
char *argv[]; |
80 |
|
{ |
81 |
< |
extern double l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); |
81 |
> |
int original; |
82 |
|
double f; |
83 |
|
int a, i; |
84 |
< |
|
85 |
< |
funset(vcolin[RED], 1, '=', l_redin); |
86 |
< |
funset(vcolin[GRN], 1, '=', l_grnin); |
87 |
< |
funset(vcolin[BLU], 1, '=', l_bluin); |
88 |
< |
funset(vbrtin, 1, '=', l_brtin); |
89 |
< |
|
97 |
< |
for (a = 1; a < argc; a++) |
84 |
> |
SET_DEFAULT_BINARY(); |
85 |
> |
SET_FILE_BINARY(stdin); |
86 |
> |
SET_FILE_BINARY(stdout); |
87 |
> |
progname = argv[0]; |
88 |
> |
/* scan options */ |
89 |
> |
for (a = 1; a < argc; a++) { |
90 |
|
if (argv[a][0] == '-') |
91 |
|
switch (argv[a][1]) { |
100 |
– |
case '\0': |
101 |
– |
case 's': |
102 |
– |
case 'c': |
103 |
– |
goto getfiles; |
92 |
|
case 'x': |
105 |
– |
xres = atoi(argv[++a]); |
106 |
– |
break; |
93 |
|
case 'y': |
94 |
< |
yres = atoi(argv[++a]); |
95 |
< |
break; |
94 |
> |
a++; |
95 |
> |
continue; |
96 |
|
case 'w': |
97 |
|
nowarn = !nowarn; |
98 |
< |
break; |
113 |
< |
case 'o': |
114 |
< |
original = !original; |
115 |
< |
break; |
98 |
> |
continue; |
99 |
|
case 'f': |
117 |
– |
fcompile(argv[++a]); |
118 |
– |
break; |
100 |
|
case 'e': |
101 |
< |
scompile(argv[++a], NULL, 0); |
102 |
< |
break; |
122 |
< |
default: |
123 |
< |
goto usage; |
101 |
> |
a++; |
102 |
> |
continue; |
103 |
|
} |
104 |
< |
else |
105 |
< |
break; |
106 |
< |
getfiles: |
107 |
< |
for (nfiles = 0; nfiles < MAXINP; nfiles++) |
104 |
> |
break; |
105 |
> |
} |
106 |
> |
newheader("RADIANCE", stdout); /* start header */ |
107 |
> |
fputnow(stdout); |
108 |
> |
/* process files */ |
109 |
> |
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
110 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
111 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
112 |
+ |
input[nfiles].vw = stdview; |
113 |
+ |
input[nfiles].pa = 1.0; |
114 |
+ |
} |
115 |
|
nfiles = 0; |
116 |
+ |
original = 0; |
117 |
|
for ( ; a < argc; a++) { |
118 |
|
if (nfiles >= MAXINP) { |
119 |
|
eputs(argv[0]); |
126 |
|
input[nfiles].name = "<stdin>"; |
127 |
|
input[nfiles].fp = stdin; |
128 |
|
break; |
129 |
+ |
case 'o': |
130 |
+ |
original++; |
131 |
+ |
continue; |
132 |
|
case 's': |
133 |
|
f = atof(argv[++a]); |
134 |
|
scalecolor(input[nfiles].coef, f); |
142 |
|
goto usage; |
143 |
|
} |
144 |
|
else { |
145 |
< |
input[nfiles].name = argv[a]; |
146 |
< |
input[nfiles].fp = fopen(argv[a], "r"); |
145 |
> |
if (argv[a][0] == '!') { |
146 |
> |
input[nfiles].name = Command; |
147 |
> |
input[nfiles].fp = popen(argv[a]+1, "r"); |
148 |
> |
} else { |
149 |
> |
input[nfiles].name = argv[a]; |
150 |
> |
input[nfiles].fp = fopen(argv[a], "r"); |
151 |
> |
} |
152 |
|
if (input[nfiles].fp == NULL) { |
153 |
|
perror(argv[a]); |
154 |
|
quit(1); |
155 |
|
} |
156 |
|
} |
157 |
< |
fputs(input[nfiles].name, stdout); |
158 |
< |
fputs(":\n", stdout); |
159 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
160 |
< |
if (wrongformat) { |
161 |
< |
eputs(input[nfiles].name); |
162 |
< |
eputs(": not in Radiance picture format\n"); |
163 |
< |
quit(1); |
157 |
> |
checkfile(); |
158 |
> |
if (original) { |
159 |
> |
colval(input[nfiles].coef,RED) /= |
160 |
> |
colval(input[nfiles].expos,RED); |
161 |
> |
colval(input[nfiles].coef,GRN) /= |
162 |
> |
colval(input[nfiles].expos,GRN); |
163 |
> |
colval(input[nfiles].coef,BLU) /= |
164 |
> |
colval(input[nfiles].expos,BLU); |
165 |
> |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
166 |
|
} |
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)); |
167 |
|
nfiles++; |
168 |
+ |
original = 0; |
169 |
|
} |
170 |
+ |
init(); /* set constants */ |
171 |
+ |
/* go back and get expressions */ |
172 |
+ |
for (a = 1; a < argc; a++) { |
173 |
+ |
if (argv[a][0] == '-') |
174 |
+ |
switch (argv[a][1]) { |
175 |
+ |
case 'x': |
176 |
+ |
varset(vxres, ':', eval(argv[++a])); |
177 |
+ |
continue; |
178 |
+ |
case 'y': |
179 |
+ |
varset(vyres, ':', eval(argv[++a])); |
180 |
+ |
continue; |
181 |
+ |
case 'w': |
182 |
+ |
continue; |
183 |
+ |
case 'f': |
184 |
+ |
fcompile(argv[++a]); |
185 |
+ |
continue; |
186 |
+ |
case 'e': |
187 |
+ |
scompile(argv[++a], NULL, 0); |
188 |
+ |
continue; |
189 |
+ |
} |
190 |
+ |
break; |
191 |
+ |
} |
192 |
+ |
/* set/get output resolution */ |
193 |
+ |
if (!vardefined(vxres)) |
194 |
+ |
varset(vxres, ':', (double)xmax); |
195 |
+ |
if (!vardefined(vyres)) |
196 |
+ |
varset(vyres, ':', (double)ymax); |
197 |
+ |
xres = varvalue(vxres) + .5; |
198 |
+ |
yres = varvalue(vyres) + .5; |
199 |
+ |
if (xres <= 0 || yres <= 0) { |
200 |
+ |
eputs(argv[0]); |
201 |
+ |
eputs(": illegal output resolution\n"); |
202 |
+ |
quit(1); |
203 |
+ |
} |
204 |
+ |
/* complete header */ |
205 |
|
printargs(argc, argv, stdout); |
206 |
< |
fputformat(COLRFMT, stdout); |
206 |
> |
if (strcmp(ourfmt, PICFMT)) |
207 |
> |
fputformat(ourfmt, stdout); /* print format if known */ |
208 |
|
putchar('\n'); |
209 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
209 |
> |
fprtresolu(xres, yres, stdout); |
210 |
> |
/* combine pictures */ |
211 |
|
combine(); |
212 |
|
quit(0); |
213 |
|
usage: |
214 |
|
eputs("Usage: "); |
215 |
|
eputs(argv[0]); |
216 |
|
eputs( |
217 |
< |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); |
217 |
> |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
218 |
|
quit(1); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
+ |
tabputs(s) /* put out string preceded by a tab */ |
223 |
+ |
char *s; |
224 |
+ |
{ |
225 |
+ |
char fmt[32]; |
226 |
+ |
double d; |
227 |
+ |
COLOR ctmp; |
228 |
+ |
|
229 |
+ |
if (isheadid(s)) /* header id */ |
230 |
+ |
return(0); /* don't echo */ |
231 |
+ |
if (formatval(fmt, s)) { /* check format */ |
232 |
+ |
if (globmatch(ourfmt, fmt)) { |
233 |
+ |
wrongformat = 0; |
234 |
+ |
strcpy(ourfmt, fmt); |
235 |
+ |
} else |
236 |
+ |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
237 |
+ |
return(0); /* don't echo */ |
238 |
+ |
} |
239 |
+ |
if (isexpos(s)) { /* exposure */ |
240 |
+ |
d = exposval(s); |
241 |
+ |
scalecolor(input[nfiles].expos, d); |
242 |
+ |
} else if (iscolcor(s)) { /* color correction */ |
243 |
+ |
colcorval(ctmp, s); |
244 |
+ |
multcolor(input[nfiles].expos, ctmp); |
245 |
+ |
} else if (isaspect(s)) |
246 |
+ |
input[nfiles].pa *= aspectval(s); |
247 |
+ |
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
248 |
+ |
gotview++; |
249 |
+ |
/* echo line */ |
250 |
+ |
putchar('\t'); |
251 |
+ |
return(fputs(s, stdout)); |
252 |
+ |
} |
253 |
+ |
|
254 |
+ |
|
255 |
+ |
checkfile() /* ready a file */ |
256 |
+ |
{ |
257 |
+ |
register int i; |
258 |
+ |
/* process header */ |
259 |
+ |
gotview = 0; |
260 |
+ |
fputs(input[nfiles].name, stdout); |
261 |
+ |
fputs(":\n", stdout); |
262 |
+ |
getheader(input[nfiles].fp, tabputs, NULL); |
263 |
+ |
if (wrongformat < 0) { |
264 |
+ |
eputs(input[nfiles].name); |
265 |
+ |
eputs(": not a Radiance picture\n"); |
266 |
+ |
quit(1); |
267 |
+ |
} |
268 |
+ |
if (wrongformat > 0) { |
269 |
+ |
wputs(input[nfiles].name); |
270 |
+ |
wputs(": warning -- incompatible picture format\n"); |
271 |
+ |
} |
272 |
+ |
if (!gotview || setview(&input[nfiles].vw) != NULL) |
273 |
+ |
input[nfiles].vw.type = 0; |
274 |
+ |
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
275 |
+ |
eputs(input[nfiles].name); |
276 |
+ |
eputs(": bad picture size\n"); |
277 |
+ |
quit(1); |
278 |
+ |
} |
279 |
+ |
if (xmax == 0 && ymax == 0) { |
280 |
+ |
xmax = scanlen(&input[nfiles].rs); |
281 |
+ |
ymax = numscans(&input[nfiles].rs); |
282 |
+ |
} else if (scanlen(&input[nfiles].rs) != xmax || |
283 |
+ |
numscans(&input[nfiles].rs) != ymax) { |
284 |
+ |
eputs(input[nfiles].name); |
285 |
+ |
eputs(": resolution mismatch\n"); |
286 |
+ |
quit(1); |
287 |
+ |
} |
288 |
+ |
/* allocate scanlines */ |
289 |
+ |
for (i = 0; i < WINSIZ; i++) |
290 |
+ |
input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR)); |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
|
294 |
+ |
double |
295 |
+ |
rgb_bright(clr) |
296 |
+ |
COLOR clr; |
297 |
+ |
{ |
298 |
+ |
return(bright(clr)); |
299 |
+ |
} |
300 |
+ |
|
301 |
+ |
|
302 |
+ |
double |
303 |
+ |
xyz_bright(clr) |
304 |
+ |
COLOR clr; |
305 |
+ |
{ |
306 |
+ |
return(clr[CIEY]); |
307 |
+ |
} |
308 |
+ |
|
309 |
+ |
|
310 |
+ |
double (*ourbright)() = rgb_bright; |
311 |
+ |
|
312 |
+ |
|
313 |
+ |
init() /* perform final setup */ |
314 |
+ |
{ |
315 |
+ |
double l_colin(char *), l_expos(char *), l_pixaspect(char *), |
316 |
+ |
l_ray(char *), l_psize(char *); |
317 |
+ |
register int i; |
318 |
+ |
/* define constants */ |
319 |
+ |
varset("PI", ':', PI); |
320 |
+ |
varset(vnfiles, ':', (double)nfiles); |
321 |
+ |
varset(vxmax, ':', (double)xmax); |
322 |
+ |
varset(vymax, ':', (double)ymax); |
323 |
+ |
/* set functions */ |
324 |
+ |
for (i = 0; i < 3; i++) { |
325 |
+ |
funset(vcolexp[i], 1, ':', l_expos); |
326 |
+ |
funset(vcolin[i], 1, '=', l_colin); |
327 |
+ |
} |
328 |
+ |
funset(vbrtexp, 1, ':', l_expos); |
329 |
+ |
funset(vbrtin, 1, '=', l_colin); |
330 |
+ |
funset(vpixaspect, 1, ':', l_pixaspect); |
331 |
+ |
for (i = 0; i < 7; i++) |
332 |
+ |
funset(vray[i], 1, '=', l_ray); |
333 |
+ |
funset(vpsize, 1, '=', l_psize); |
334 |
+ |
/* set brightness function */ |
335 |
+ |
if (!strcmp(ourfmt, CIEFMT)) { |
336 |
+ |
varset(vwhteff, ':', 1.0); |
337 |
+ |
ourbright = xyz_bright; |
338 |
+ |
} else |
339 |
+ |
varset(vwhteff, ':', WHTEFFICACY); |
340 |
+ |
} |
341 |
+ |
|
342 |
+ |
|
343 |
|
combine() /* combine pictures */ |
344 |
|
{ |
345 |
|
EPNODE *coldef[3], *brtdef; |
357 |
|
brtdef = eparse(vbrtout); |
358 |
|
else |
359 |
|
brtdef = NULL; |
222 |
– |
/* define constants */ |
223 |
– |
varset(vnfiles, ':', (double)nfiles); |
224 |
– |
varset(vxres, ':', (double)xres); |
225 |
– |
varset(vyres, ':', (double)yres); |
360 |
|
/* allocate scanline */ |
361 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
362 |
< |
/* initialize input */ |
363 |
< |
initinp(); |
362 |
> |
/* set input position */ |
363 |
> |
yscan = ymax+MIDSCN; |
364 |
|
/* combine files */ |
365 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
366 |
|
advance(); |
367 |
|
varset(vypos, '=', (double)ypos); |
368 |
|
for (xpos = 0; xpos < xres; xpos++) { |
369 |
+ |
xscan = (long)xpos*xmax/xres; |
370 |
|
varset(vxpos, '=', (double)xpos); |
371 |
|
eclock++; |
372 |
|
if (brtdef != NULL) { |
381 |
|
} else { |
382 |
|
d = 0.0; |
383 |
|
for (i = 0; i < nfiles; i++) |
384 |
< |
d += colval(input[i].scan[MIDSCN][xpos],j); |
384 |
> |
d += colval(input[i].scan[MIDSCN][xscan],j); |
385 |
|
} |
386 |
|
if (d < 0.0) |
387 |
|
d = 0.0; |
394 |
|
quit(1); |
395 |
|
} |
396 |
|
} |
397 |
< |
efree(scanout); |
397 |
> |
efree((char *)scanout); |
398 |
|
} |
399 |
|
|
400 |
|
|
401 |
< |
initinp() /* initilize scan windows */ |
401 |
> |
advance() /* read in data for next scanline */ |
402 |
|
{ |
403 |
< |
for (ypos = yres+(MIDSCN-1); ypos >= yres; ypos--) |
404 |
< |
advance(); |
403 |
> |
int ytarget; |
404 |
> |
register COLOR *st; |
405 |
> |
register int i, j; |
406 |
> |
|
407 |
> |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
408 |
> |
for (i = 0; i < nfiles; i++) { |
409 |
> |
st = input[i].scan[WINSIZ-1]; |
410 |
> |
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
411 |
> |
input[i].scan[j] = input[i].scan[j-1]; |
412 |
> |
input[i].scan[0] = st; |
413 |
> |
if (yscan <= MIDSCN) /* hit bottom? */ |
414 |
> |
continue; |
415 |
> |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
416 |
> |
eputs(input[i].name); |
417 |
> |
eputs(": read error\n"); |
418 |
> |
quit(1); |
419 |
> |
} |
420 |
> |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
421 |
> |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
422 |
> |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
423 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
424 |
> |
multcolor(st[j], input[i].coef); |
425 |
> |
} |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
< |
advance() /* read in next scanline */ |
429 |
> |
double |
430 |
> |
l_expos(nam) /* return picture exposure */ |
431 |
> |
register char *nam; |
432 |
|
{ |
433 |
< |
register COLOR *st; |
276 |
< |
register int i, j; |
433 |
> |
register int fn, n; |
434 |
|
|
435 |
< |
for (i = 0; i < nfiles; i++) { |
436 |
< |
st = input[i].scan[WINSIZ-1]; |
437 |
< |
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
438 |
< |
input[i].scan[j] = input[i].scan[j-1]; |
439 |
< |
input[i].scan[0] = st; |
440 |
< |
if (ypos < MIDSCN) /* hit bottom */ |
441 |
< |
continue; |
442 |
< |
if (freadscan(st, xres, input[i].fp) < 0) { |
443 |
< |
eputs(input[i].name); |
444 |
< |
eputs(": read error\n"); |
445 |
< |
quit(1); |
289 |
< |
} |
290 |
< |
for (j = 0; j < xres; j++) /* adjust color */ |
291 |
< |
multcolor(st[j], input[i].coef); |
292 |
< |
} |
435 |
> |
fn = argument(1) - .5; |
436 |
> |
if (fn < 0 || fn >= nfiles) |
437 |
> |
return(1.0); |
438 |
> |
if (nam == vbrtexp) |
439 |
> |
return((*ourbright)(input[fn].expos)); |
440 |
> |
n = 3; |
441 |
> |
while (n--) |
442 |
> |
if (nam == vcolexp[n]) |
443 |
> |
return(colval(input[fn].expos,n)); |
444 |
> |
eputs("Bad call to l_expos()!\n"); |
445 |
> |
quit(1); |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
|
double |
450 |
< |
colin(ci) /* return color value for picture */ |
298 |
< |
register int ci; |
450 |
> |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
451 |
|
{ |
452 |
< |
int n, fn; |
453 |
< |
register int xoff, yoff; |
452 |
> |
register int fn; |
453 |
> |
|
454 |
> |
fn = argument(1) - .5; |
455 |
> |
if (fn < 0 || fn >= nfiles) |
456 |
> |
return(1.0); |
457 |
> |
return(input[fn].pa); |
458 |
> |
} |
459 |
> |
|
460 |
> |
|
461 |
> |
double |
462 |
> |
l_colin(nam) /* return color value for picture */ |
463 |
> |
register char *nam; |
464 |
> |
{ |
465 |
> |
int fn; |
466 |
> |
register int n, xoff, yoff; |
467 |
|
double d; |
468 |
|
|
469 |
< |
fn = (d = argument(1)) - .5; |
470 |
< |
if (d <= -.5 || fn >= nfiles) { |
469 |
> |
fn = argument(1) - .5; |
470 |
> |
if (fn < 0 || fn >= nfiles) { |
471 |
|
errno = EDOM; |
472 |
|
return(0.0); |
473 |
|
} |
309 |
– |
if (d < .5) |
310 |
– |
return((double)nfiles); |
474 |
|
xoff = yoff = 0; |
475 |
|
n = nargum(); |
476 |
|
if (n >= 2) { |
477 |
|
d = argument(2); |
478 |
|
if (d < 0.0) { |
479 |
|
xoff = d-.5; |
480 |
< |
if (xpos+xoff < 0) |
481 |
< |
xoff = -xpos; |
480 |
> |
if (xscan+xoff < 0) |
481 |
> |
xoff = -xscan; |
482 |
|
} else { |
483 |
|
xoff = d+.5; |
484 |
< |
if (xpos+xoff >= xres) |
485 |
< |
xoff = xres-1-xpos; |
484 |
> |
if (xscan+xoff >= xmax) |
485 |
> |
xoff = xmax-1-xscan; |
486 |
|
} |
487 |
|
} |
488 |
|
if (n >= 3) { |
491 |
|
yoff = d-.5; |
492 |
|
if (yoff+MIDSCN < 0) |
493 |
|
yoff = -MIDSCN; |
494 |
< |
if (ypos+yoff < 0) |
495 |
< |
yoff = -ypos; |
494 |
> |
if (yscan+yoff < 0) |
495 |
> |
yoff = -yscan; |
496 |
|
} else { |
497 |
|
yoff = d+.5; |
498 |
|
if (yoff+MIDSCN >= WINSIZ) |
499 |
|
yoff = WINSIZ-1-MIDSCN; |
500 |
< |
if (ypos+yoff >= yres) |
501 |
< |
yoff = yres-1-ypos; |
500 |
> |
if (yscan+yoff >= ymax) |
501 |
> |
yoff = ymax-1-yscan; |
502 |
|
} |
503 |
|
} |
504 |
< |
if (ci == BRT) |
505 |
< |
return(bright(input[fn].scan[MIDSCN+yoff][xpos+xoff])); |
506 |
< |
return(colval(input[fn].scan[MIDSCN+yoff][xpos+xoff],ci)); |
504 |
> |
if (nam == vbrtin) |
505 |
> |
return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
506 |
> |
n = 3; |
507 |
> |
while (n--) |
508 |
> |
if (nam == vcolin[n]) |
509 |
> |
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
510 |
> |
eputs("Bad call to l_colin()!\n"); |
511 |
> |
quit(1); |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
|
double |
516 |
< |
l_redin() /* get red color */ |
516 |
> |
l_ray(nam) /* return ray origin or direction */ |
517 |
> |
register char *nam; |
518 |
|
{ |
519 |
< |
return(colin(RED)); |
520 |
< |
} |
519 |
> |
static unsigned long ltick[MAXINP]; |
520 |
> |
static FVECT lorg[MAXINP], ldir[MAXINP]; |
521 |
> |
static double ldist[MAXINP]; |
522 |
> |
RREAL loc[2]; |
523 |
> |
int fn; |
524 |
> |
register int i; |
525 |
|
|
526 |
< |
|
527 |
< |
double |
528 |
< |
l_grnin() /* get green color */ |
529 |
< |
{ |
530 |
< |
return(colin(GRN)); |
526 |
> |
fn = argument(1) - .5; |
527 |
> |
if (fn < 0 || fn >= nfiles) { |
528 |
> |
errno = EDOM; |
529 |
> |
return(0.0); |
530 |
> |
} |
531 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
532 |
> |
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
533 |
> |
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
534 |
> |
ldist[fn] = -1.0; |
535 |
> |
if (input[fn].vw.type == 0) |
536 |
> |
errno = EDOM; |
537 |
> |
else { |
538 |
> |
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
539 |
> |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
540 |
> |
&input[fn].vw, loc[0], loc[1]); |
541 |
> |
} |
542 |
> |
ltick[fn] = eclock; |
543 |
> |
} |
544 |
> |
if (nam == vray[i=6]) |
545 |
> |
return(ldist[fn]); |
546 |
> |
while (i--) |
547 |
> |
if (nam == vray[i]) |
548 |
> |
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
549 |
> |
eputs("Bad call to l_ray()!\n"); |
550 |
> |
quit(1); |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
|
double |
555 |
< |
l_bluin() /* get blue color */ |
555 |
> |
l_psize(char *nm) /* compute pixel size in steradians */ |
556 |
|
{ |
557 |
< |
return(colin(BLU)); |
558 |
< |
} |
557 |
> |
static unsigned long ltick[MAXINP]; |
558 |
> |
static double psize[MAXINP]; |
559 |
> |
FVECT dir0, org, dirx, diry; |
560 |
> |
RREAL locx[2], locy[2]; |
561 |
> |
double d; |
562 |
> |
int fn; |
563 |
> |
register int i; |
564 |
|
|
565 |
< |
|
566 |
< |
double |
567 |
< |
l_brtin() /* get brightness value */ |
568 |
< |
{ |
569 |
< |
return(colin(BRT)); |
565 |
> |
d = argument(1); |
566 |
> |
if (d < .5 || d >= nfiles+.5) { |
567 |
> |
errno = EDOM; |
568 |
> |
return(0.0); |
569 |
> |
} |
570 |
> |
fn = d - .5; |
571 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
572 |
> |
psize[fn] = 0.0; |
573 |
> |
if (input[fn].vw.type == 0) |
574 |
> |
errno = EDOM; |
575 |
> |
else if (input[fn].vw.type != VT_PAR && |
576 |
> |
funvalue(vray[6], 1, &d) >= 0) { |
577 |
> |
for (i = 0; i < 3; i++) |
578 |
> |
dir0[i] = funvalue(vray[3+i], 1, &d); |
579 |
> |
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
580 |
> |
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
581 |
> |
if (viewray(org, dirx, &input[fn].vw, |
582 |
> |
locx[0], locx[1]) >= 0 && |
583 |
> |
viewray(org, diry, &input[fn].vw, |
584 |
> |
locy[0], locy[1]) >= 0) { |
585 |
> |
/* approximate solid angle */ |
586 |
> |
for (i = 0; i < 3; i++) { |
587 |
> |
dirx[i] -= dir0[i]; |
588 |
> |
diry[i] -= dir0[i]; |
589 |
> |
} |
590 |
> |
fcross(dir0, dirx, diry); |
591 |
> |
psize[fn] = sqrt(DOT(dir0,dir0)); |
592 |
> |
} |
593 |
> |
} |
594 |
> |
ltick[fn] = eclock; |
595 |
> |
} |
596 |
> |
return(psize[fn]); |
597 |
|
} |
598 |
|
|
599 |
|
|
600 |
+ |
void |
601 |
|
wputs(msg) |
602 |
|
char *msg; |
603 |
|
{ |
606 |
|
} |
607 |
|
|
608 |
|
|
609 |
+ |
void |
610 |
|
eputs(msg) |
611 |
|
char *msg; |
612 |
|
{ |
614 |
|
} |
615 |
|
|
616 |
|
|
617 |
< |
quit(code) |
618 |
< |
int code; |
617 |
> |
void |
618 |
> |
quit(code) /* exit gracefully */ |
619 |
> |
int code; |
620 |
|
{ |
621 |
+ |
register int i; |
622 |
+ |
/* close input files */ |
623 |
+ |
for (i = 0; i < nfiles; i++) |
624 |
+ |
if (input[i].name == Command) |
625 |
+ |
pclose(input[i].fp); |
626 |
+ |
else |
627 |
+ |
fclose(input[i].fp); |
628 |
|
exit(code); |
629 |
|
} |