1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.39 |
static const char RCSid[] = "$Id: pcomb.c,v 2.38 2005/05/25 04:44:25 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 |
|
|
case 'f': |
202 |
|
|
fcompile(argv[++a]); |
203 |
|
|
continue; |
204 |
|
|
case 'e': |
205 |
|
|
scompile(argv[++a], NULL, 0); |
206 |
|
|
continue; |
207 |
|
|
} |
208 |
|
|
break; |
209 |
|
|
} |
210 |
greg |
1.18 |
/* set/get output resolution */ |
211 |
|
|
if (!vardefined(vxres)) |
212 |
|
|
varset(vxres, ':', (double)xmax); |
213 |
|
|
if (!vardefined(vyres)) |
214 |
|
|
varset(vyres, ':', (double)ymax); |
215 |
|
|
xres = varvalue(vxres) + .5; |
216 |
|
|
yres = varvalue(vyres) + .5; |
217 |
|
|
if (xres <= 0 || yres <= 0) { |
218 |
|
|
eputs(argv[0]); |
219 |
|
|
eputs(": illegal output resolution\n"); |
220 |
|
|
quit(1); |
221 |
|
|
} |
222 |
greg |
1.15 |
/* complete header */ |
223 |
|
|
printargs(argc, argv, stdout); |
224 |
greg |
2.16 |
if (strcmp(ourfmt, PICFMT)) |
225 |
|
|
fputformat(ourfmt, stdout); /* print format if known */ |
226 |
greg |
1.15 |
putchar('\n'); |
227 |
greg |
1.23 |
fprtresolu(xres, yres, stdout); |
228 |
greg |
1.15 |
/* combine pictures */ |
229 |
|
|
combine(); |
230 |
|
|
quit(0); |
231 |
|
|
usage: |
232 |
|
|
eputs("Usage: "); |
233 |
|
|
eputs(argv[0]); |
234 |
|
|
eputs( |
235 |
greg |
2.39 |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
236 |
greg |
1.15 |
quit(1); |
237 |
schorsch |
2.32 |
return 1; /* pro forma return */ |
238 |
greg |
1.15 |
} |
239 |
|
|
|
240 |
|
|
|
241 |
schorsch |
2.30 |
static int |
242 |
greg |
2.39 |
headline( /* check header line & echo if requested */ |
243 |
schorsch |
2.30 |
char *s, |
244 |
|
|
void *p |
245 |
|
|
) |
246 |
greg |
1.15 |
{ |
247 |
|
|
char fmt[32]; |
248 |
|
|
double d; |
249 |
|
|
COLOR ctmp; |
250 |
|
|
|
251 |
greg |
2.14 |
if (isheadid(s)) /* header id */ |
252 |
gwlarson |
2.21 |
return(0); /* don't echo */ |
253 |
greg |
2.14 |
if (formatval(fmt, s)) { /* check format */ |
254 |
greg |
2.16 |
if (globmatch(ourfmt, fmt)) { |
255 |
|
|
wrongformat = 0; |
256 |
|
|
strcpy(ourfmt, fmt); |
257 |
|
|
} else |
258 |
greg |
2.22 |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
259 |
gwlarson |
2.21 |
return(0); /* don't echo */ |
260 |
greg |
1.17 |
} |
261 |
|
|
if (isexpos(s)) { /* exposure */ |
262 |
|
|
d = exposval(s); |
263 |
|
|
scalecolor(input[nfiles].expos, d); |
264 |
|
|
} else if (iscolcor(s)) { /* color correction */ |
265 |
greg |
1.15 |
colcorval(ctmp, s); |
266 |
greg |
1.17 |
multcolor(input[nfiles].expos, ctmp); |
267 |
greg |
2.18 |
} else if (isaspect(s)) |
268 |
greg |
2.17 |
input[nfiles].pa *= aspectval(s); |
269 |
greg |
2.18 |
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
270 |
greg |
2.10 |
gotview++; |
271 |
greg |
2.39 |
|
272 |
|
|
if (echoheader) { /* echo line */ |
273 |
|
|
putchar('\t'); |
274 |
|
|
return(fputs(s, stdout)); |
275 |
|
|
} |
276 |
|
|
return(0); |
277 |
greg |
1.16 |
} |
278 |
greg |
1.15 |
|
279 |
greg |
1.16 |
|
280 |
schorsch |
2.32 |
static void |
281 |
|
|
checkfile(void) /* ready a file */ |
282 |
greg |
1.16 |
{ |
283 |
|
|
register int i; |
284 |
|
|
/* process header */ |
285 |
greg |
2.10 |
gotview = 0; |
286 |
greg |
2.39 |
if (echoheader) { |
287 |
|
|
fputs(input[nfiles].name, stdout); |
288 |
|
|
fputs(":\n", stdout); |
289 |
|
|
} |
290 |
|
|
getheader(input[nfiles].fp, headline, NULL); |
291 |
greg |
2.22 |
if (wrongformat < 0) { |
292 |
greg |
1.16 |
eputs(input[nfiles].name); |
293 |
greg |
2.22 |
eputs(": not a Radiance picture\n"); |
294 |
greg |
1.16 |
quit(1); |
295 |
|
|
} |
296 |
greg |
2.22 |
if (wrongformat > 0) { |
297 |
|
|
wputs(input[nfiles].name); |
298 |
|
|
wputs(": warning -- incompatible picture format\n"); |
299 |
|
|
} |
300 |
greg |
2.10 |
if (!gotview || setview(&input[nfiles].vw) != NULL) |
301 |
|
|
input[nfiles].vw.type = 0; |
302 |
|
|
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
303 |
greg |
1.16 |
eputs(input[nfiles].name); |
304 |
|
|
eputs(": bad picture size\n"); |
305 |
|
|
quit(1); |
306 |
|
|
} |
307 |
greg |
1.18 |
if (xmax == 0 && ymax == 0) { |
308 |
greg |
2.10 |
xmax = scanlen(&input[nfiles].rs); |
309 |
|
|
ymax = numscans(&input[nfiles].rs); |
310 |
|
|
} else if (scanlen(&input[nfiles].rs) != xmax || |
311 |
|
|
numscans(&input[nfiles].rs) != ymax) { |
312 |
greg |
1.16 |
eputs(input[nfiles].name); |
313 |
|
|
eputs(": resolution mismatch\n"); |
314 |
|
|
quit(1); |
315 |
|
|
} |
316 |
|
|
/* allocate scanlines */ |
317 |
|
|
for (i = 0; i < WINSIZ; i++) |
318 |
greg |
1.18 |
input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR)); |
319 |
greg |
1.15 |
} |
320 |
|
|
|
321 |
|
|
|
322 |
schorsch |
2.32 |
static double |
323 |
|
|
rgb_bright( |
324 |
|
|
COLOR clr |
325 |
|
|
) |
326 |
greg |
2.16 |
{ |
327 |
|
|
return(bright(clr)); |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
|
331 |
schorsch |
2.32 |
static double |
332 |
|
|
xyz_bright( |
333 |
|
|
COLOR clr |
334 |
|
|
) |
335 |
greg |
2.16 |
{ |
336 |
|
|
return(clr[CIEY]); |
337 |
|
|
} |
338 |
|
|
|
339 |
|
|
|
340 |
|
|
double (*ourbright)() = rgb_bright; |
341 |
|
|
|
342 |
|
|
|
343 |
schorsch |
2.32 |
static void |
344 |
|
|
init(void) /* perform final setup */ |
345 |
greg |
1.15 |
{ |
346 |
greg |
1.16 |
register int i; |
347 |
greg |
1.15 |
/* define constants */ |
348 |
greg |
2.19 |
varset("PI", ':', PI); |
349 |
greg |
1.15 |
varset(vnfiles, ':', (double)nfiles); |
350 |
greg |
1.18 |
varset(vxmax, ':', (double)xmax); |
351 |
|
|
varset(vymax, ':', (double)ymax); |
352 |
greg |
1.15 |
/* set functions */ |
353 |
|
|
for (i = 0; i < 3; i++) { |
354 |
greg |
1.17 |
funset(vcolexp[i], 1, ':', l_expos); |
355 |
greg |
1.15 |
funset(vcolin[i], 1, '=', l_colin); |
356 |
|
|
} |
357 |
greg |
1.17 |
funset(vbrtexp, 1, ':', l_expos); |
358 |
greg |
1.15 |
funset(vbrtin, 1, '=', l_colin); |
359 |
greg |
2.18 |
funset(vpixaspect, 1, ':', l_pixaspect); |
360 |
|
|
for (i = 0; i < 7; i++) |
361 |
greg |
2.10 |
funset(vray[i], 1, '=', l_ray); |
362 |
greg |
2.17 |
funset(vpsize, 1, '=', l_psize); |
363 |
greg |
2.16 |
/* set brightness function */ |
364 |
greg |
2.18 |
if (!strcmp(ourfmt, CIEFMT)) { |
365 |
|
|
varset(vwhteff, ':', 1.0); |
366 |
greg |
2.16 |
ourbright = xyz_bright; |
367 |
greg |
2.18 |
} else |
368 |
|
|
varset(vwhteff, ':', WHTEFFICACY); |
369 |
greg |
1.1 |
} |
370 |
|
|
|
371 |
|
|
|
372 |
schorsch |
2.32 |
static void |
373 |
|
|
combine(void) /* combine pictures */ |
374 |
greg |
1.1 |
{ |
375 |
greg |
1.8 |
EPNODE *coldef[3], *brtdef; |
376 |
greg |
1.1 |
COLOR *scanout; |
377 |
greg |
1.8 |
double d; |
378 |
greg |
1.1 |
register int i, j; |
379 |
|
|
/* check defined variables */ |
380 |
greg |
1.4 |
for (j = 0; j < 3; j++) { |
381 |
|
|
if (vardefined(vcolout[j])) |
382 |
|
|
coldef[j] = eparse(vcolout[j]); |
383 |
|
|
else |
384 |
|
|
coldef[j] = NULL; |
385 |
|
|
} |
386 |
greg |
1.8 |
if (vardefined(vbrtout)) |
387 |
|
|
brtdef = eparse(vbrtout); |
388 |
|
|
else |
389 |
|
|
brtdef = NULL; |
390 |
greg |
1.1 |
/* allocate scanline */ |
391 |
|
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
392 |
greg |
1.18 |
/* set input position */ |
393 |
|
|
yscan = ymax+MIDSCN; |
394 |
greg |
1.1 |
/* combine files */ |
395 |
|
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
396 |
greg |
1.14 |
advance(); |
397 |
greg |
1.11 |
varset(vypos, '=', (double)ypos); |
398 |
greg |
1.8 |
for (xpos = 0; xpos < xres; xpos++) { |
399 |
greg |
1.18 |
xscan = (long)xpos*xmax/xres; |
400 |
greg |
1.11 |
varset(vxpos, '=', (double)xpos); |
401 |
greg |
1.8 |
eclock++; |
402 |
|
|
if (brtdef != NULL) { |
403 |
|
|
d = evalue(brtdef); |
404 |
|
|
if (d < 0.0) |
405 |
|
|
d = 0.0; |
406 |
|
|
setcolor(scanout[xpos], d, d, d); |
407 |
|
|
} else { |
408 |
|
|
for (j = 0; j < 3; j++) { |
409 |
|
|
if (coldef[j] != NULL) { |
410 |
greg |
1.13 |
d = evalue(coldef[j]); |
411 |
greg |
1.8 |
} else { |
412 |
greg |
1.13 |
d = 0.0; |
413 |
greg |
1.8 |
for (i = 0; i < nfiles; i++) |
414 |
greg |
1.18 |
d += colval(input[i].scan[MIDSCN][xscan],j); |
415 |
greg |
1.1 |
} |
416 |
greg |
1.13 |
if (d < 0.0) |
417 |
|
|
d = 0.0; |
418 |
|
|
colval(scanout[xpos],j) = d; |
419 |
greg |
1.8 |
} |
420 |
greg |
1.1 |
} |
421 |
greg |
1.8 |
} |
422 |
|
|
if (fwritescan(scanout, xres, stdout) < 0) { |
423 |
|
|
perror("write error"); |
424 |
|
|
quit(1); |
425 |
|
|
} |
426 |
greg |
1.1 |
} |
427 |
greg |
2.22 |
efree((char *)scanout); |
428 |
greg |
1.1 |
} |
429 |
|
|
|
430 |
|
|
|
431 |
schorsch |
2.32 |
static void |
432 |
|
|
advance(void) /* read in data for next scanline */ |
433 |
greg |
1.14 |
{ |
434 |
greg |
1.18 |
int ytarget; |
435 |
greg |
1.14 |
register COLOR *st; |
436 |
|
|
register int i, j; |
437 |
|
|
|
438 |
greg |
1.18 |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
439 |
|
|
for (i = 0; i < nfiles; i++) { |
440 |
|
|
st = input[i].scan[WINSIZ-1]; |
441 |
|
|
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
442 |
|
|
input[i].scan[j] = input[i].scan[j-1]; |
443 |
|
|
input[i].scan[0] = st; |
444 |
|
|
if (yscan <= MIDSCN) /* hit bottom? */ |
445 |
|
|
continue; |
446 |
greg |
2.4 |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
447 |
greg |
1.18 |
eputs(input[i].name); |
448 |
|
|
eputs(": read error\n"); |
449 |
|
|
quit(1); |
450 |
|
|
} |
451 |
greg |
2.37 |
for (j = 0; j < xmax; j++) /* adjust color */ |
452 |
|
|
multcolor(st[j], input[i].coef); |
453 |
greg |
1.14 |
} |
454 |
|
|
} |
455 |
|
|
|
456 |
|
|
|
457 |
schorsch |
2.32 |
static double |
458 |
|
|
l_expos( /* return picture exposure */ |
459 |
|
|
register char *nam |
460 |
|
|
) |
461 |
greg |
1.1 |
{ |
462 |
greg |
1.15 |
register int fn, n; |
463 |
greg |
1.14 |
|
464 |
greg |
1.18 |
fn = argument(1) - .5; |
465 |
|
|
if (fn < 0 || fn >= nfiles) |
466 |
|
|
return(1.0); |
467 |
greg |
1.17 |
if (nam == vbrtexp) |
468 |
greg |
2.16 |
return((*ourbright)(input[fn].expos)); |
469 |
greg |
1.15 |
n = 3; |
470 |
|
|
while (n--) |
471 |
greg |
1.17 |
if (nam == vcolexp[n]) |
472 |
|
|
return(colval(input[fn].expos,n)); |
473 |
|
|
eputs("Bad call to l_expos()!\n"); |
474 |
greg |
1.15 |
quit(1); |
475 |
schorsch |
2.32 |
return 1; /* pro forma return */ |
476 |
greg |
1.15 |
} |
477 |
|
|
|
478 |
|
|
|
479 |
schorsch |
2.32 |
static double |
480 |
greg |
2.27 |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
481 |
greg |
2.18 |
{ |
482 |
|
|
register int fn; |
483 |
|
|
|
484 |
|
|
fn = argument(1) - .5; |
485 |
|
|
if (fn < 0 || fn >= nfiles) |
486 |
|
|
return(1.0); |
487 |
|
|
return(input[fn].pa); |
488 |
|
|
} |
489 |
|
|
|
490 |
|
|
|
491 |
schorsch |
2.32 |
static double |
492 |
|
|
l_colin( /* return color value for picture */ |
493 |
|
|
register char *nam |
494 |
|
|
) |
495 |
greg |
1.15 |
{ |
496 |
|
|
int fn; |
497 |
|
|
register int n, xoff, yoff; |
498 |
|
|
double d; |
499 |
|
|
|
500 |
greg |
2.18 |
fn = argument(1) - .5; |
501 |
greg |
1.16 |
if (fn < 0 || fn >= nfiles) { |
502 |
greg |
1.15 |
errno = EDOM; |
503 |
|
|
return(0.0); |
504 |
|
|
} |
505 |
greg |
1.14 |
xoff = yoff = 0; |
506 |
|
|
n = nargum(); |
507 |
|
|
if (n >= 2) { |
508 |
|
|
d = argument(2); |
509 |
|
|
if (d < 0.0) { |
510 |
|
|
xoff = d-.5; |
511 |
greg |
1.18 |
if (xscan+xoff < 0) |
512 |
|
|
xoff = -xscan; |
513 |
greg |
1.14 |
} else { |
514 |
|
|
xoff = d+.5; |
515 |
greg |
1.18 |
if (xscan+xoff >= xmax) |
516 |
|
|
xoff = xmax-1-xscan; |
517 |
greg |
1.14 |
} |
518 |
|
|
} |
519 |
|
|
if (n >= 3) { |
520 |
|
|
d = argument(3); |
521 |
|
|
if (d < 0.0) { |
522 |
|
|
yoff = d-.5; |
523 |
|
|
if (yoff+MIDSCN < 0) |
524 |
|
|
yoff = -MIDSCN; |
525 |
greg |
1.18 |
if (yscan+yoff < 0) |
526 |
|
|
yoff = -yscan; |
527 |
greg |
1.14 |
} else { |
528 |
|
|
yoff = d+.5; |
529 |
|
|
if (yoff+MIDSCN >= WINSIZ) |
530 |
|
|
yoff = WINSIZ-1-MIDSCN; |
531 |
greg |
1.18 |
if (yscan+yoff >= ymax) |
532 |
|
|
yoff = ymax-1-yscan; |
533 |
greg |
1.14 |
} |
534 |
|
|
} |
535 |
greg |
1.15 |
if (nam == vbrtin) |
536 |
greg |
2.16 |
return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
537 |
greg |
1.15 |
n = 3; |
538 |
|
|
while (n--) |
539 |
|
|
if (nam == vcolin[n]) |
540 |
greg |
1.18 |
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
541 |
greg |
1.15 |
eputs("Bad call to l_colin()!\n"); |
542 |
greg |
2.10 |
quit(1); |
543 |
schorsch |
2.32 |
return 1; /* pro forma return */ |
544 |
greg |
2.10 |
} |
545 |
|
|
|
546 |
|
|
|
547 |
schorsch |
2.32 |
static double |
548 |
|
|
l_ray( /* return ray origin or direction */ |
549 |
|
|
register char *nam |
550 |
|
|
) |
551 |
greg |
2.10 |
{ |
552 |
greg |
2.15 |
static unsigned long ltick[MAXINP]; |
553 |
greg |
2.10 |
static FVECT lorg[MAXINP], ldir[MAXINP]; |
554 |
greg |
2.18 |
static double ldist[MAXINP]; |
555 |
schorsch |
2.25 |
RREAL loc[2]; |
556 |
greg |
2.10 |
int fn; |
557 |
|
|
register int i; |
558 |
|
|
|
559 |
greg |
2.18 |
fn = argument(1) - .5; |
560 |
greg |
2.10 |
if (fn < 0 || fn >= nfiles) { |
561 |
|
|
errno = EDOM; |
562 |
|
|
return(0.0); |
563 |
|
|
} |
564 |
greg |
2.22 |
if (ltick[fn] != eclock) { /* need to compute? */ |
565 |
greg |
2.10 |
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
566 |
|
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
567 |
greg |
2.20 |
ldist[fn] = -1.0; |
568 |
greg |
2.10 |
if (input[fn].vw.type == 0) |
569 |
greg |
2.12 |
errno = EDOM; |
570 |
greg |
2.10 |
else { |
571 |
greg |
2.11 |
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
572 |
greg |
2.18 |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
573 |
|
|
&input[fn].vw, loc[0], loc[1]); |
574 |
greg |
2.10 |
} |
575 |
greg |
2.18 |
ltick[fn] = eclock; |
576 |
greg |
2.10 |
} |
577 |
greg |
2.18 |
if (nam == vray[i=6]) |
578 |
|
|
return(ldist[fn]); |
579 |
greg |
2.10 |
while (i--) |
580 |
|
|
if (nam == vray[i]) |
581 |
|
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
582 |
|
|
eputs("Bad call to l_ray()!\n"); |
583 |
greg |
1.15 |
quit(1); |
584 |
schorsch |
2.32 |
return 1; /* pro forma return */ |
585 |
greg |
2.17 |
} |
586 |
|
|
|
587 |
|
|
|
588 |
schorsch |
2.32 |
static double |
589 |
greg |
2.27 |
l_psize(char *nm) /* compute pixel size in steradians */ |
590 |
greg |
2.17 |
{ |
591 |
|
|
static unsigned long ltick[MAXINP]; |
592 |
|
|
static double psize[MAXINP]; |
593 |
greg |
2.18 |
FVECT dir0, org, dirx, diry; |
594 |
schorsch |
2.25 |
RREAL locx[2], locy[2]; |
595 |
greg |
2.17 |
double d; |
596 |
|
|
int fn; |
597 |
greg |
2.18 |
register int i; |
598 |
greg |
2.17 |
|
599 |
|
|
d = argument(1); |
600 |
greg |
2.18 |
if (d < .5 || d >= nfiles+.5) { |
601 |
greg |
2.17 |
errno = EDOM; |
602 |
|
|
return(0.0); |
603 |
|
|
} |
604 |
greg |
2.18 |
fn = d - .5; |
605 |
greg |
2.22 |
if (ltick[fn] != eclock) { /* need to compute? */ |
606 |
greg |
2.18 |
psize[fn] = 0.0; |
607 |
|
|
if (input[fn].vw.type == 0) |
608 |
greg |
2.17 |
errno = EDOM; |
609 |
greg |
2.18 |
else if (input[fn].vw.type != VT_PAR && |
610 |
greg |
2.36 |
funvalue(vray[6], 1, &d) >= -FTINY) { |
611 |
greg |
2.18 |
for (i = 0; i < 3; i++) |
612 |
|
|
dir0[i] = funvalue(vray[3+i], 1, &d); |
613 |
|
|
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
614 |
|
|
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
615 |
|
|
if (viewray(org, dirx, &input[fn].vw, |
616 |
greg |
2.35 |
locx[0], locx[1]) >= -FTINY && |
617 |
greg |
2.18 |
viewray(org, diry, &input[fn].vw, |
618 |
greg |
2.35 |
locy[0], locy[1]) >= -FTINY) { |
619 |
greg |
2.17 |
/* approximate solid angle */ |
620 |
greg |
2.18 |
for (i = 0; i < 3; i++) { |
621 |
|
|
dirx[i] -= dir0[i]; |
622 |
|
|
diry[i] -= dir0[i]; |
623 |
|
|
} |
624 |
|
|
fcross(dir0, dirx, diry); |
625 |
greg |
2.35 |
psize[fn] = VLEN(dir0); |
626 |
greg |
2.17 |
} |
627 |
|
|
} |
628 |
greg |
2.18 |
ltick[fn] = eclock; |
629 |
|
|
} |
630 |
greg |
2.17 |
return(psize[fn]); |
631 |
greg |
1.1 |
} |
632 |
|
|
|
633 |
|
|
|
634 |
schorsch |
2.29 |
extern void |
635 |
|
|
wputs(char *msg) |
636 |
greg |
1.1 |
{ |
637 |
|
|
if (!nowarn) |
638 |
|
|
eputs(msg); |
639 |
|
|
} |
640 |
|
|
|
641 |
|
|
|
642 |
schorsch |
2.29 |
extern void |
643 |
|
|
eputs(char *msg) |
644 |
greg |
1.1 |
{ |
645 |
|
|
fputs(msg, stderr); |
646 |
|
|
} |
647 |
|
|
|
648 |
|
|
|
649 |
schorsch |
2.29 |
extern void |
650 |
|
|
quit(int code) /* exit gracefully */ |
651 |
greg |
2.4 |
{ |
652 |
greg |
2.5 |
register int i; |
653 |
|
|
/* close input files */ |
654 |
|
|
for (i = 0; i < nfiles; i++) |
655 |
greg |
2.6 |
if (input[i].name == Command) |
656 |
|
|
pclose(input[i].fp); |
657 |
|
|
else |
658 |
|
|
fclose(input[i].fp); |
659 |
greg |
1.1 |
exit(code); |
660 |
|
|
} |