1 |
– |
/* Copyright (c) 1992 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 "platform.h" |
11 |
|
#include "standard.h" |
12 |
< |
|
12 |
> |
#include "paths.h" |
13 |
|
#include "color.h" |
16 |
– |
|
17 |
– |
#include "resolu.h" |
18 |
– |
|
14 |
|
#include "calcomp.h" |
20 |
– |
|
15 |
|
#include "view.h" |
16 |
|
|
17 |
< |
#define MAXINP 32 /* maximum number of input files */ |
18 |
< |
#define WINSIZ 17 /* scanline window size */ |
17 |
> |
#define MAXINP 1024 /* maximum number of input files */ |
18 |
> |
#define WINSIZ 127 /* scanline window size */ |
19 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
20 |
|
|
21 |
|
struct { |
33 |
|
|
34 |
|
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
35 |
|
|
36 |
+ |
char StandardInput[] = "<stdin>"; |
37 |
|
char Command[] = "<Command>"; |
38 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
39 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
68 |
|
|
69 |
|
char *progname; /* global argv[0] */ |
70 |
|
|
71 |
+ |
int echoheader = 1; |
72 |
|
int wrongformat = 0; |
73 |
|
int gotview; |
74 |
|
|
79 |
– |
FILE *popen(); |
75 |
|
|
76 |
< |
extern char *emalloc(); |
76 |
> |
static gethfunc headline; |
77 |
> |
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 |
< |
main(argc, argv) |
91 |
< |
int argc; |
92 |
< |
char *argv[]; |
90 |
> |
int |
91 |
> |
main( |
92 |
> |
int argc, |
93 |
> |
char *argv[] |
94 |
> |
) |
95 |
|
{ |
96 |
|
int original; |
97 |
|
double f; |
98 |
< |
int a, i; |
99 |
< |
#ifdef MSDOS |
100 |
< |
extern int _fmode; |
101 |
< |
_fmode = O_BINARY; |
102 |
< |
setmode(fileno(stdin), O_BINARY); |
95 |
< |
setmode(fileno(stdout), O_BINARY); |
96 |
< |
#endif |
98 |
> |
int a; |
99 |
> |
|
100 |
> |
SET_DEFAULT_BINARY(); |
101 |
> |
SET_FILE_BINARY(stdin); |
102 |
> |
SET_FILE_BINARY(stdout); |
103 |
|
progname = argv[0]; |
104 |
+ |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
105 |
+ |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
106 |
|
/* scan options */ |
107 |
|
for (a = 1; a < argc; a++) { |
108 |
|
if (argv[a][0] == '-') |
114 |
|
case 'w': |
115 |
|
nowarn = !nowarn; |
116 |
|
continue; |
117 |
+ |
case 'h': |
118 |
+ |
echoheader = !echoheader; |
119 |
+ |
continue; |
120 |
|
case 'f': |
121 |
|
case 'e': |
122 |
|
a++; |
125 |
|
break; |
126 |
|
} |
127 |
|
newheader("RADIANCE", stdout); /* start header */ |
128 |
+ |
fputnow(stdout); |
129 |
|
/* process files */ |
130 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
131 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
132 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
133 |
< |
copystruct(&input[nfiles].vw, &stdview); |
133 |
> |
input[nfiles].vw = stdview; |
134 |
|
input[nfiles].pa = 1.0; |
135 |
|
} |
136 |
|
nfiles = 0; |
144 |
|
if (argv[a][0] == '-') |
145 |
|
switch (argv[a][1]) { |
146 |
|
case '\0': |
147 |
< |
input[nfiles].name = "<stdin>"; |
147 |
> |
input[nfiles].name = StandardInput; |
148 |
|
input[nfiles].fp = stdin; |
149 |
|
break; |
150 |
|
case 'o': |
183 |
|
colval(input[nfiles].expos,GRN); |
184 |
|
colval(input[nfiles].coef,BLU) /= |
185 |
|
colval(input[nfiles].expos,BLU); |
186 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
187 |
|
} |
188 |
|
nfiles++; |
189 |
|
original = 0; |
201 |
|
continue; |
202 |
|
case 'w': |
203 |
|
continue; |
204 |
+ |
case 'h': |
205 |
+ |
continue; |
206 |
|
case 'f': |
207 |
|
fcompile(argv[++a]); |
208 |
|
continue; |
237 |
|
eputs("Usage: "); |
238 |
|
eputs(argv[0]); |
239 |
|
eputs( |
240 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
240 |
> |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); |
241 |
|
quit(1); |
242 |
+ |
return 1; /* pro forma return */ |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
< |
tputs(s) /* put out string preceded by a tab */ |
247 |
< |
char *s; |
246 |
> |
static int |
247 |
> |
headline( /* check header line & echo if requested */ |
248 |
> |
char *s, |
249 |
> |
void *p |
250 |
> |
) |
251 |
|
{ |
252 |
|
char fmt[32]; |
253 |
|
double d; |
254 |
|
COLOR ctmp; |
255 |
|
|
256 |
|
if (isheadid(s)) /* header id */ |
257 |
< |
return; /* don't echo */ |
257 |
> |
return(0); /* don't echo */ |
258 |
|
if (formatval(fmt, s)) { /* check format */ |
259 |
|
if (globmatch(ourfmt, fmt)) { |
260 |
|
wrongformat = 0; |
261 |
|
strcpy(ourfmt, fmt); |
262 |
|
} else |
263 |
< |
wrongformat = 1; |
264 |
< |
return; /* don't echo */ |
263 |
> |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
264 |
> |
return(0); /* don't echo */ |
265 |
|
} |
266 |
|
if (isexpos(s)) { /* exposure */ |
267 |
|
d = exposval(s); |
273 |
|
input[nfiles].pa *= aspectval(s); |
274 |
|
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
275 |
|
gotview++; |
276 |
< |
/* echo line */ |
277 |
< |
putchar('\t'); |
278 |
< |
fputs(s, stdout); |
276 |
> |
|
277 |
> |
if (echoheader) { /* echo line */ |
278 |
> |
putchar('\t'); |
279 |
> |
return(fputs(s, stdout)); |
280 |
> |
} |
281 |
> |
return(0); |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
< |
checkfile() /* ready a file */ |
285 |
> |
static void |
286 |
> |
checkfile(void) /* ready a file */ |
287 |
|
{ |
288 |
< |
register int i; |
288 |
> |
int i; |
289 |
|
/* process header */ |
290 |
|
gotview = 0; |
291 |
< |
fputs(input[nfiles].name, stdout); |
292 |
< |
fputs(":\n", stdout); |
293 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
294 |
< |
if (wrongformat) { |
291 |
> |
if (echoheader) { |
292 |
> |
fputs(input[nfiles].name, stdout); |
293 |
> |
fputs(":\n", stdout); |
294 |
> |
} |
295 |
> |
getheader(input[nfiles].fp, headline, NULL); |
296 |
> |
if (wrongformat < 0) { |
297 |
|
eputs(input[nfiles].name); |
298 |
< |
eputs(": not in Radiance picture format\n"); |
298 |
> |
eputs(": not a Radiance picture\n"); |
299 |
|
quit(1); |
300 |
|
} |
301 |
+ |
if (wrongformat > 0) { |
302 |
+ |
wputs(input[nfiles].name); |
303 |
+ |
wputs(": warning -- incompatible picture format\n"); |
304 |
+ |
} |
305 |
|
if (!gotview || setview(&input[nfiles].vw) != NULL) |
306 |
|
input[nfiles].vw.type = 0; |
307 |
|
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
< |
double |
328 |
< |
rgb_bright(clr) |
329 |
< |
COLOR clr; |
327 |
> |
static double |
328 |
> |
rgb_bright( |
329 |
> |
COLOR clr |
330 |
> |
) |
331 |
|
{ |
332 |
|
return(bright(clr)); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
double |
337 |
< |
xyz_bright(clr) |
338 |
< |
COLOR clr; |
336 |
> |
static double |
337 |
> |
xyz_bright( |
338 |
> |
COLOR clr |
339 |
> |
) |
340 |
|
{ |
341 |
|
return(clr[CIEY]); |
342 |
|
} |
345 |
|
double (*ourbright)() = rgb_bright; |
346 |
|
|
347 |
|
|
348 |
< |
init() /* perform final setup */ |
348 |
> |
static void |
349 |
> |
init(void) /* perform final setup */ |
350 |
|
{ |
351 |
< |
double l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize(); |
320 |
< |
register int i; |
351 |
> |
int i; |
352 |
|
/* define constants */ |
353 |
|
varset("PI", ':', PI); |
354 |
|
varset(vnfiles, ':', (double)nfiles); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
combine() /* combine pictures */ |
377 |
> |
static void |
378 |
> |
combine(void) /* combine pictures */ |
379 |
|
{ |
380 |
|
EPNODE *coldef[3], *brtdef; |
381 |
|
COLOR *scanout; |
382 |
|
double d; |
383 |
< |
register int i, j; |
383 |
> |
int i, j; |
384 |
|
/* check defined variables */ |
385 |
|
for (j = 0; j < 3; j++) { |
386 |
|
if (vardefined(vcolout[j])) |
401 |
|
advance(); |
402 |
|
varset(vypos, '=', (double)ypos); |
403 |
|
for (xpos = 0; xpos < xres; xpos++) { |
404 |
< |
xscan = (long)xpos*xmax/xres; |
404 |
> |
xscan = (xpos+.5)*xmax/xres; |
405 |
|
varset(vxpos, '=', (double)xpos); |
406 |
|
eclock++; |
407 |
|
if (brtdef != NULL) { |
429 |
|
quit(1); |
430 |
|
} |
431 |
|
} |
432 |
< |
efree(scanout); |
432 |
> |
efree((char *)scanout); |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
< |
advance() /* read in data for next scanline */ |
436 |
> |
static void |
437 |
> |
advance(void) /* read in data for next scanline */ |
438 |
|
{ |
439 |
|
int ytarget; |
440 |
< |
register COLOR *st; |
441 |
< |
register int i, j; |
440 |
> |
COLOR *st; |
441 |
> |
int i, j; |
442 |
|
|
443 |
< |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
443 |
> |
for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) |
444 |
|
for (i = 0; i < nfiles; i++) { |
445 |
|
st = input[i].scan[WINSIZ-1]; |
446 |
|
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
453 |
|
eputs(": read error\n"); |
454 |
|
quit(1); |
455 |
|
} |
456 |
< |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
457 |
< |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
425 |
< |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
426 |
< |
for (j = 0; j < xmax; j++) /* adjust color */ |
427 |
< |
multcolor(st[j], input[i].coef); |
456 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
457 |
> |
multcolor(st[j], input[i].coef); |
458 |
|
} |
459 |
|
} |
460 |
|
|
461 |
|
|
462 |
< |
double |
463 |
< |
l_expos(nam) /* return picture exposure */ |
464 |
< |
register char *nam; |
462 |
> |
static double |
463 |
> |
l_expos( /* return picture exposure */ |
464 |
> |
char *nam |
465 |
> |
) |
466 |
|
{ |
467 |
< |
register int fn, n; |
467 |
> |
int fn, n; |
468 |
> |
double d; |
469 |
|
|
470 |
< |
fn = argument(1) - .5; |
471 |
< |
if (fn < 0 || fn >= nfiles) |
472 |
< |
return(1.0); |
470 |
> |
d = argument(1); |
471 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
472 |
> |
errno = EDOM; |
473 |
> |
return(0.0); |
474 |
> |
} |
475 |
> |
if (d < 0.5) |
476 |
> |
return((double)nfiles); |
477 |
> |
fn = d - 0.5; |
478 |
|
if (nam == vbrtexp) |
479 |
|
return((*ourbright)(input[fn].expos)); |
480 |
|
n = 3; |
483 |
|
return(colval(input[fn].expos,n)); |
484 |
|
eputs("Bad call to l_expos()!\n"); |
485 |
|
quit(1); |
486 |
+ |
return 1; /* pro forma return */ |
487 |
|
} |
488 |
|
|
489 |
|
|
490 |
< |
double |
491 |
< |
l_pixaspect() /* return pixel aspect ratio */ |
490 |
> |
static double |
491 |
> |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
492 |
|
{ |
493 |
< |
register int fn; |
493 |
> |
int fn; |
494 |
> |
double d; |
495 |
|
|
496 |
< |
fn = argument(1) - .5; |
497 |
< |
if (fn < 0 || fn >= nfiles) |
498 |
< |
return(1.0); |
496 |
> |
d = argument(1); |
497 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
498 |
> |
errno = EDOM; |
499 |
> |
return(0.0); |
500 |
> |
} |
501 |
> |
if (d < 0.5) |
502 |
> |
return((double)nfiles); |
503 |
> |
fn = d - 0.5; |
504 |
|
return(input[fn].pa); |
505 |
|
} |
506 |
|
|
507 |
|
|
508 |
< |
double |
509 |
< |
l_colin(nam) /* return color value for picture */ |
510 |
< |
register char *nam; |
508 |
> |
static double |
509 |
> |
l_colin( /* return color value for picture */ |
510 |
> |
char *nam |
511 |
> |
) |
512 |
|
{ |
513 |
|
int fn; |
514 |
< |
register int n, xoff, yoff; |
514 |
> |
int n, xoff, yoff; |
515 |
|
double d; |
516 |
|
|
517 |
< |
fn = argument(1) - .5; |
518 |
< |
if (fn < 0 || fn >= nfiles) { |
517 |
> |
d = argument(1); |
518 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
519 |
|
errno = EDOM; |
520 |
|
return(0.0); |
521 |
|
} |
522 |
+ |
if (d < 0.5) |
523 |
+ |
return((double)nfiles); |
524 |
+ |
fn = d - 0.5; |
525 |
|
xoff = yoff = 0; |
526 |
|
n = nargum(); |
527 |
|
if (n >= 2) { |
560 |
|
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
561 |
|
eputs("Bad call to l_colin()!\n"); |
562 |
|
quit(1); |
563 |
+ |
return 1; /* pro forma return */ |
564 |
|
} |
565 |
|
|
566 |
|
|
567 |
< |
double |
568 |
< |
l_ray(nam) /* return ray origin or direction */ |
569 |
< |
register char *nam; |
567 |
> |
static double |
568 |
> |
l_ray( /* return ray origin or direction */ |
569 |
> |
char *nam |
570 |
> |
) |
571 |
|
{ |
572 |
|
static unsigned long ltick[MAXINP]; |
573 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
574 |
|
static double ldist[MAXINP]; |
575 |
< |
FLOAT loc[2]; |
575 |
> |
RREAL loc[2]; |
576 |
> |
double d; |
577 |
|
int fn; |
578 |
< |
register int i; |
578 |
> |
int i; |
579 |
|
|
580 |
< |
fn = argument(1) - .5; |
581 |
< |
if (fn < 0 || fn >= nfiles) { |
580 |
> |
d = argument(1); |
581 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
582 |
|
errno = EDOM; |
583 |
|
return(0.0); |
584 |
|
} |
585 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
585 |
> |
if (d < 0.5) |
586 |
> |
return((double)nfiles); |
587 |
> |
fn = d - 0.5; |
588 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
589 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
590 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
591 |
|
ldist[fn] = -1.0; |
605 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
606 |
|
eputs("Bad call to l_ray()!\n"); |
607 |
|
quit(1); |
608 |
+ |
return 1; /* pro forma return */ |
609 |
|
} |
610 |
|
|
611 |
|
|
612 |
< |
double |
613 |
< |
l_psize() /* compute pixel size in steradians */ |
612 |
> |
static double |
613 |
> |
l_psize(char *nm) /* compute pixel size in steradians */ |
614 |
|
{ |
615 |
|
static unsigned long ltick[MAXINP]; |
616 |
|
static double psize[MAXINP]; |
617 |
|
FVECT dir0, org, dirx, diry; |
618 |
< |
FLOAT locx[2], locy[2]; |
618 |
> |
RREAL locx[2], locy[2]; |
619 |
|
double d; |
620 |
|
int fn; |
621 |
< |
register int i; |
621 |
> |
int i; |
622 |
|
|
623 |
|
d = argument(1); |
624 |
< |
if (d < .5 || d >= nfiles+.5) { |
624 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
625 |
|
errno = EDOM; |
626 |
|
return(0.0); |
627 |
|
} |
628 |
< |
fn = d - .5; |
629 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
628 |
> |
if (d < 0.5) |
629 |
> |
return((double)nfiles); |
630 |
> |
fn = d - 0.5; |
631 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
632 |
|
psize[fn] = 0.0; |
633 |
|
if (input[fn].vw.type == 0) |
634 |
|
errno = EDOM; |
635 |
|
else if (input[fn].vw.type != VT_PAR && |
636 |
< |
funvalue(vray[6], 1, &d) >= 0) { |
636 |
> |
funvalue(vray[6], 1, &d) >= -FTINY) { |
637 |
|
for (i = 0; i < 3; i++) |
638 |
|
dir0[i] = funvalue(vray[3+i], 1, &d); |
639 |
|
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
640 |
|
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
641 |
|
if (viewray(org, dirx, &input[fn].vw, |
642 |
< |
locx[0], locx[1]) >= 0 && |
642 |
> |
locx[0], locx[1]) >= -FTINY && |
643 |
|
viewray(org, diry, &input[fn].vw, |
644 |
< |
locy[0], locy[1]) >= 0) { |
644 |
> |
locy[0], locy[1]) >= -FTINY) { |
645 |
|
/* approximate solid angle */ |
646 |
|
for (i = 0; i < 3; i++) { |
647 |
|
dirx[i] -= dir0[i]; |
648 |
|
diry[i] -= dir0[i]; |
649 |
|
} |
650 |
|
fcross(dir0, dirx, diry); |
651 |
< |
psize[fn] = 0.5 * sqrt(DOT(dir0,dir0)); |
651 |
> |
psize[fn] = VLEN(dir0); |
652 |
|
} |
653 |
|
} |
654 |
|
ltick[fn] = eclock; |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
< |
wputs(msg) |
661 |
< |
char *msg; |
660 |
> |
extern void |
661 |
> |
wputs(char *msg) |
662 |
|
{ |
663 |
|
if (!nowarn) |
664 |
|
eputs(msg); |
665 |
|
} |
666 |
|
|
667 |
|
|
668 |
< |
eputs(msg) |
669 |
< |
char *msg; |
668 |
> |
extern void |
669 |
> |
eputs(char *msg) |
670 |
|
{ |
671 |
|
fputs(msg, stderr); |
672 |
|
} |
673 |
|
|
674 |
|
|
675 |
< |
quit(code) /* exit gracefully */ |
676 |
< |
int code; |
675 |
> |
extern void |
676 |
> |
quit(int code) /* exit gracefully */ |
677 |
|
{ |
678 |
< |
register int i; |
678 |
> |
int i; |
679 |
|
/* close input files */ |
680 |
|
for (i = 0; i < nfiles; i++) |
681 |
|
if (input[i].name == Command) |