7 |
|
* 1/4/89 |
8 |
|
*/ |
9 |
|
|
10 |
– |
#include "standard.h" |
10 |
|
#include "platform.h" |
11 |
+ |
#include "standard.h" |
12 |
+ |
#include "paths.h" |
13 |
|
#include "color.h" |
14 |
|
#include "calcomp.h" |
15 |
|
#include "view.h" |
16 |
|
|
17 |
< |
#define MAXINP 32 /* maximum number of input files */ |
18 |
< |
#define WINSIZ 64 /* 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 { |
31 |
|
|
32 |
|
int nfiles; /* number of input files */ |
33 |
|
|
34 |
+ |
VIEW commvw; /* common view parameters */ |
35 |
+ |
|
36 |
|
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
37 |
|
|
38 |
+ |
char StandardInput[] = "<stdin>"; |
39 |
|
char Command[] = "<Command>"; |
40 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
41 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
70 |
|
|
71 |
|
char *progname; /* global argv[0] */ |
72 |
|
|
73 |
+ |
int echoheader = 1; |
74 |
|
int wrongformat = 0; |
75 |
|
int gotview; |
76 |
|
|
72 |
– |
FILE *popen(); |
77 |
|
|
78 |
< |
extern char *emalloc(); |
78 |
> |
static gethfunc headline; |
79 |
> |
static void checkfile(void); |
80 |
> |
static double rgb_bright(COLOR clr); |
81 |
> |
static double xyz_bright(COLOR clr); |
82 |
> |
static void init(void); |
83 |
> |
static void combine(void); |
84 |
> |
static void advance(void); |
85 |
> |
static double l_expos(char *nam); |
86 |
> |
static double l_pixaspect(char *nm); |
87 |
> |
static double l_colin(char *nam); |
88 |
> |
static double l_ray(char *nam); |
89 |
> |
static double l_psize(char *nm); |
90 |
|
|
91 |
|
|
92 |
< |
main(argc, argv) |
93 |
< |
int argc; |
94 |
< |
char *argv[]; |
92 |
> |
int |
93 |
> |
main( |
94 |
> |
int argc, |
95 |
> |
char *argv[] |
96 |
> |
) |
97 |
|
{ |
98 |
|
int original; |
99 |
|
double f; |
100 |
< |
int a, i; |
100 |
> |
int a; |
101 |
> |
|
102 |
|
SET_DEFAULT_BINARY(); |
103 |
|
SET_FILE_BINARY(stdin); |
104 |
|
SET_FILE_BINARY(stdout); |
105 |
|
progname = argv[0]; |
106 |
+ |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
107 |
+ |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
108 |
|
/* scan options */ |
109 |
|
for (a = 1; a < argc; a++) { |
110 |
|
if (argv[a][0] == '-') |
116 |
|
case 'w': |
117 |
|
nowarn = !nowarn; |
118 |
|
continue; |
119 |
+ |
case 'h': |
120 |
+ |
echoheader = !echoheader; |
121 |
+ |
continue; |
122 |
|
case 'f': |
123 |
|
case 'e': |
124 |
|
a++; |
146 |
|
if (argv[a][0] == '-') |
147 |
|
switch (argv[a][1]) { |
148 |
|
case '\0': |
149 |
< |
input[nfiles].name = "<stdin>"; |
149 |
> |
input[nfiles].name = StandardInput; |
150 |
|
input[nfiles].fp = stdin; |
151 |
|
break; |
152 |
|
case 'o': |
203 |
|
continue; |
204 |
|
case 'w': |
205 |
|
continue; |
206 |
+ |
case 'h': |
207 |
+ |
continue; |
208 |
|
case 'f': |
209 |
|
fcompile(argv[++a]); |
210 |
|
continue; |
214 |
|
} |
215 |
|
break; |
216 |
|
} |
217 |
< |
/* set/get output resolution */ |
193 |
< |
if (!vardefined(vxres)) |
194 |
< |
varset(vxres, ':', (double)xmax); |
195 |
< |
if (!vardefined(vyres)) |
196 |
< |
varset(vyres, ':', (double)ymax); |
217 |
> |
/* get output resolution */ |
218 |
|
xres = varvalue(vxres) + .5; |
219 |
|
yres = varvalue(vyres) + .5; |
220 |
|
if (xres <= 0 || yres <= 0) { |
224 |
|
} |
225 |
|
/* complete header */ |
226 |
|
printargs(argc, argv, stdout); |
227 |
+ |
if (commvw.type) { |
228 |
+ |
fputs(VIEWSTR, stdout); |
229 |
+ |
fprintview(&commvw, stdout); |
230 |
+ |
fputc('\n', stdout); |
231 |
+ |
} |
232 |
|
if (strcmp(ourfmt, PICFMT)) |
233 |
|
fputformat(ourfmt, stdout); /* print format if known */ |
234 |
|
putchar('\n'); |
240 |
|
eputs("Usage: "); |
241 |
|
eputs(argv[0]); |
242 |
|
eputs( |
243 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
243 |
> |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); |
244 |
|
quit(1); |
245 |
+ |
return 1; /* pro forma return */ |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
< |
tabputs(s) /* put out string preceded by a tab */ |
250 |
< |
char *s; |
249 |
> |
static int |
250 |
> |
headline( /* check header line & echo if requested */ |
251 |
> |
char *s, |
252 |
> |
void *p |
253 |
> |
) |
254 |
|
{ |
255 |
|
char fmt[32]; |
256 |
|
double d; |
276 |
|
input[nfiles].pa *= aspectval(s); |
277 |
|
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
278 |
|
gotview++; |
279 |
< |
/* echo line */ |
280 |
< |
putchar('\t'); |
281 |
< |
return(fputs(s, stdout)); |
279 |
> |
|
280 |
> |
if (echoheader) { /* echo line */ |
281 |
> |
putchar('\t'); |
282 |
> |
return(fputs(s, stdout)); |
283 |
> |
} |
284 |
> |
return(0); |
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
< |
checkfile() /* ready a file */ |
288 |
> |
static void |
289 |
> |
checkfile(void) /* ready a file */ |
290 |
|
{ |
291 |
< |
register int i; |
291 |
> |
int i; |
292 |
|
/* process header */ |
293 |
|
gotview = 0; |
294 |
< |
fputs(input[nfiles].name, stdout); |
295 |
< |
fputs(":\n", stdout); |
296 |
< |
getheader(input[nfiles].fp, tabputs, NULL); |
294 |
> |
if (echoheader) { |
295 |
> |
fputs(input[nfiles].name, stdout); |
296 |
> |
fputs(":\n", stdout); |
297 |
> |
} |
298 |
> |
getheader(input[nfiles].fp, headline, NULL); |
299 |
|
if (wrongformat < 0) { |
300 |
|
eputs(input[nfiles].name); |
301 |
|
eputs(": not a Radiance picture\n"); |
307 |
|
} |
308 |
|
if (!gotview || setview(&input[nfiles].vw) != NULL) |
309 |
|
input[nfiles].vw.type = 0; |
310 |
+ |
else if (!commvw.type) |
311 |
+ |
commvw = input[nfiles].vw; |
312 |
|
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
313 |
|
eputs(input[nfiles].name); |
314 |
|
eputs(": bad picture size\n"); |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
< |
double |
333 |
< |
rgb_bright(clr) |
334 |
< |
COLOR clr; |
332 |
> |
static double |
333 |
> |
rgb_bright( |
334 |
> |
COLOR clr |
335 |
> |
) |
336 |
|
{ |
337 |
|
return(bright(clr)); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
< |
double |
342 |
< |
xyz_bright(clr) |
343 |
< |
COLOR clr; |
341 |
> |
static double |
342 |
> |
xyz_bright( |
343 |
> |
COLOR clr |
344 |
> |
) |
345 |
|
{ |
346 |
|
return(clr[CIEY]); |
347 |
|
} |
350 |
|
double (*ourbright)() = rgb_bright; |
351 |
|
|
352 |
|
|
353 |
< |
init() /* perform final setup */ |
353 |
> |
static void |
354 |
> |
init(void) /* perform final setup */ |
355 |
|
{ |
356 |
< |
double l_colin(char *), l_expos(char *), l_pixaspect(char *), |
316 |
< |
l_ray(char *), l_psize(char *); |
317 |
< |
register int i; |
356 |
> |
int i; |
357 |
|
/* define constants */ |
358 |
|
varset("PI", ':', PI); |
359 |
|
varset(vnfiles, ':', (double)nfiles); |
376 |
|
ourbright = xyz_bright; |
377 |
|
} else |
378 |
|
varset(vwhteff, ':', WHTEFFICACY); |
379 |
+ |
/* these may be overridden */ |
380 |
+ |
varset(vxres, ':', (double)xmax); |
381 |
+ |
varset(vyres, ':', (double)ymax); |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
< |
combine() /* combine pictures */ |
385 |
> |
static void |
386 |
> |
combine(void) /* combine pictures */ |
387 |
|
{ |
388 |
|
EPNODE *coldef[3], *brtdef; |
389 |
|
COLOR *scanout; |
390 |
|
double d; |
391 |
< |
register int i, j; |
391 |
> |
int i, j; |
392 |
|
/* check defined variables */ |
393 |
|
for (j = 0; j < 3; j++) { |
394 |
|
if (vardefined(vcolout[j])) |
409 |
|
advance(); |
410 |
|
varset(vypos, '=', (double)ypos); |
411 |
|
for (xpos = 0; xpos < xres; xpos++) { |
412 |
< |
xscan = (long)xpos*xmax/xres; |
412 |
> |
xscan = (xpos+.5)*xmax/xres; |
413 |
|
varset(vxpos, '=', (double)xpos); |
414 |
|
eclock++; |
415 |
|
if (brtdef != NULL) { |
441 |
|
} |
442 |
|
|
443 |
|
|
444 |
< |
advance() /* read in data for next scanline */ |
444 |
> |
static void |
445 |
> |
advance(void) /* read in data for next scanline */ |
446 |
|
{ |
447 |
|
int ytarget; |
448 |
< |
register COLOR *st; |
449 |
< |
register int i, j; |
448 |
> |
COLOR *st; |
449 |
> |
int i, j; |
450 |
|
|
451 |
< |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
451 |
> |
for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) |
452 |
|
for (i = 0; i < nfiles; i++) { |
453 |
|
st = input[i].scan[WINSIZ-1]; |
454 |
|
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
461 |
|
eputs(": read error\n"); |
462 |
|
quit(1); |
463 |
|
} |
464 |
< |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
465 |
< |
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); |
464 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
465 |
> |
multcolor(st[j], input[i].coef); |
466 |
|
} |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
< |
double |
471 |
< |
l_expos(nam) /* return picture exposure */ |
472 |
< |
register char *nam; |
470 |
> |
static double |
471 |
> |
l_expos( /* return picture exposure */ |
472 |
> |
char *nam |
473 |
> |
) |
474 |
|
{ |
475 |
< |
register int fn, n; |
475 |
> |
int fn, n; |
476 |
> |
double d; |
477 |
|
|
478 |
< |
fn = argument(1) - .5; |
479 |
< |
if (fn < 0 || fn >= nfiles) |
480 |
< |
return(1.0); |
478 |
> |
d = argument(1); |
479 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
480 |
> |
errno = EDOM; |
481 |
> |
return(0.0); |
482 |
> |
} |
483 |
> |
if (d < 0.5) |
484 |
> |
return((double)nfiles); |
485 |
> |
fn = d - 0.5; |
486 |
|
if (nam == vbrtexp) |
487 |
|
return((*ourbright)(input[fn].expos)); |
488 |
|
n = 3; |
491 |
|
return(colval(input[fn].expos,n)); |
492 |
|
eputs("Bad call to l_expos()!\n"); |
493 |
|
quit(1); |
494 |
+ |
return 1; /* pro forma return */ |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
< |
double |
498 |
> |
static double |
499 |
|
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
500 |
|
{ |
501 |
< |
register int fn; |
501 |
> |
int fn; |
502 |
> |
double d; |
503 |
|
|
504 |
< |
fn = argument(1) - .5; |
505 |
< |
if (fn < 0 || fn >= nfiles) |
506 |
< |
return(1.0); |
504 |
> |
d = argument(1); |
505 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
506 |
> |
errno = EDOM; |
507 |
> |
return(0.0); |
508 |
> |
} |
509 |
> |
if (d < 0.5) |
510 |
> |
return((double)nfiles); |
511 |
> |
fn = d - 0.5; |
512 |
|
return(input[fn].pa); |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
< |
double |
517 |
< |
l_colin(nam) /* return color value for picture */ |
518 |
< |
register char *nam; |
516 |
> |
static double |
517 |
> |
l_colin( /* return color value for picture */ |
518 |
> |
char *nam |
519 |
> |
) |
520 |
|
{ |
521 |
|
int fn; |
522 |
< |
register int n, xoff, yoff; |
522 |
> |
int n, xoff, yoff; |
523 |
|
double d; |
524 |
|
|
525 |
< |
fn = argument(1) - .5; |
526 |
< |
if (fn < 0 || fn >= nfiles) { |
525 |
> |
d = argument(1); |
526 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
527 |
|
errno = EDOM; |
528 |
|
return(0.0); |
529 |
|
} |
530 |
+ |
if (d < 0.5) |
531 |
+ |
return((double)nfiles); |
532 |
+ |
fn = d - 0.5; |
533 |
|
xoff = yoff = 0; |
534 |
|
n = nargum(); |
535 |
|
if (n >= 2) { |
568 |
|
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
569 |
|
eputs("Bad call to l_colin()!\n"); |
570 |
|
quit(1); |
571 |
+ |
return 1; /* pro forma return */ |
572 |
|
} |
573 |
|
|
574 |
|
|
575 |
< |
double |
576 |
< |
l_ray(nam) /* return ray origin or direction */ |
577 |
< |
register char *nam; |
575 |
> |
static double |
576 |
> |
l_ray( /* return ray origin or direction */ |
577 |
> |
char *nam |
578 |
> |
) |
579 |
|
{ |
580 |
|
static unsigned long ltick[MAXINP]; |
581 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
582 |
|
static double ldist[MAXINP]; |
583 |
|
RREAL loc[2]; |
584 |
+ |
double d; |
585 |
|
int fn; |
586 |
< |
register int i; |
586 |
> |
int i; |
587 |
|
|
588 |
< |
fn = argument(1) - .5; |
589 |
< |
if (fn < 0 || fn >= nfiles) { |
588 |
> |
d = argument(1); |
589 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
590 |
|
errno = EDOM; |
591 |
|
return(0.0); |
592 |
|
} |
593 |
+ |
if (d < 0.5) |
594 |
+ |
return((double)nfiles); |
595 |
+ |
fn = d - 0.5; |
596 |
|
if (ltick[fn] != eclock) { /* need to compute? */ |
597 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
598 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
613 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
614 |
|
eputs("Bad call to l_ray()!\n"); |
615 |
|
quit(1); |
616 |
+ |
return 1; /* pro forma return */ |
617 |
|
} |
618 |
|
|
619 |
|
|
620 |
< |
double |
620 |
> |
static double |
621 |
|
l_psize(char *nm) /* compute pixel size in steradians */ |
622 |
|
{ |
623 |
|
static unsigned long ltick[MAXINP]; |
626 |
|
RREAL locx[2], locy[2]; |
627 |
|
double d; |
628 |
|
int fn; |
629 |
< |
register int i; |
629 |
> |
int i; |
630 |
|
|
631 |
|
d = argument(1); |
632 |
< |
if (d < .5 || d >= nfiles+.5) { |
632 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
633 |
|
errno = EDOM; |
634 |
|
return(0.0); |
635 |
|
} |
636 |
< |
fn = d - .5; |
636 |
> |
if (d < 0.5) |
637 |
> |
return((double)nfiles); |
638 |
> |
fn = d - 0.5; |
639 |
|
if (ltick[fn] != eclock) { /* need to compute? */ |
640 |
|
psize[fn] = 0.0; |
641 |
|
if (input[fn].vw.type == 0) |
642 |
|
errno = EDOM; |
643 |
|
else if (input[fn].vw.type != VT_PAR && |
644 |
< |
funvalue(vray[6], 1, &d) >= 0) { |
644 |
> |
funvalue(vray[6], 1, &d) >= -FTINY) { |
645 |
|
for (i = 0; i < 3; i++) |
646 |
|
dir0[i] = funvalue(vray[3+i], 1, &d); |
647 |
|
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
648 |
|
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
649 |
|
if (viewray(org, dirx, &input[fn].vw, |
650 |
< |
locx[0], locx[1]) >= 0 && |
650 |
> |
locx[0], locx[1]) >= -FTINY && |
651 |
|
viewray(org, diry, &input[fn].vw, |
652 |
< |
locy[0], locy[1]) >= 0) { |
652 |
> |
locy[0], locy[1]) >= -FTINY) { |
653 |
|
/* approximate solid angle */ |
654 |
|
for (i = 0; i < 3; i++) { |
655 |
|
dirx[i] -= dir0[i]; |
656 |
|
diry[i] -= dir0[i]; |
657 |
|
} |
658 |
|
fcross(dir0, dirx, diry); |
659 |
< |
psize[fn] = sqrt(DOT(dir0,dir0)); |
659 |
> |
psize[fn] = VLEN(dir0); |
660 |
|
} |
661 |
|
} |
662 |
|
ltick[fn] = eclock; |
665 |
|
} |
666 |
|
|
667 |
|
|
668 |
< |
void |
669 |
< |
wputs(msg) |
602 |
< |
char *msg; |
668 |
> |
extern void |
669 |
> |
wputs(char *msg) |
670 |
|
{ |
671 |
|
if (!nowarn) |
672 |
|
eputs(msg); |
673 |
|
} |
674 |
|
|
675 |
|
|
676 |
< |
void |
677 |
< |
eputs(msg) |
611 |
< |
char *msg; |
676 |
> |
extern void |
677 |
> |
eputs(char *msg) |
678 |
|
{ |
679 |
|
fputs(msg, stderr); |
680 |
|
} |
681 |
|
|
682 |
|
|
683 |
< |
void |
684 |
< |
quit(code) /* exit gracefully */ |
619 |
< |
int code; |
683 |
> |
extern void |
684 |
> |
quit(int code) /* exit gracefully */ |
685 |
|
{ |
686 |
< |
register int i; |
686 |
> |
int i; |
687 |
|
/* close input files */ |
688 |
|
for (i = 0; i < nfiles; i++) |
689 |
|
if (input[i].name == Command) |