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