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