7 |
|
* 1/4/89 |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "platform.h" |
11 |
|
#include "standard.h" |
12 |
+ |
#include "rtprocess.h" |
13 |
|
#include "color.h" |
14 |
|
#include "calcomp.h" |
15 |
|
#include "view.h" |
16 |
|
|
17 |
< |
#define MAXINP 32 /* maximum number of input files */ |
17 |
> |
#define MAXINP 512 /* maximum number of input files */ |
18 |
|
#define WINSIZ 64 /* scanline window size */ |
19 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
20 |
|
|
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"}; |
71 |
|
int wrongformat = 0; |
72 |
|
int gotview; |
73 |
|
|
71 |
– |
FILE *popen(); |
74 |
|
|
75 |
< |
extern char *emalloc(); |
75 |
> |
static gethfunc tabputs; |
76 |
> |
static void checkfile(void); |
77 |
> |
static double rgb_bright(COLOR clr); |
78 |
> |
static double xyz_bright(COLOR clr); |
79 |
> |
static void init(void); |
80 |
> |
static void combine(void); |
81 |
> |
static void advance(void); |
82 |
> |
static double l_expos(char *nam); |
83 |
> |
static double l_pixaspect(char *nm); |
84 |
> |
static double l_colin(char *nam); |
85 |
> |
static double l_ray(char *nam); |
86 |
> |
static double l_psize(char *nm); |
87 |
|
|
88 |
|
|
89 |
< |
main(argc, argv) |
90 |
< |
int argc; |
91 |
< |
char *argv[]; |
89 |
> |
int |
90 |
> |
main( |
91 |
> |
int argc, |
92 |
> |
char *argv[] |
93 |
> |
) |
94 |
|
{ |
95 |
|
int original; |
96 |
|
double f; |
97 |
< |
int a, i; |
97 |
> |
int a; |
98 |
|
SET_DEFAULT_BINARY(); |
99 |
|
SET_FILE_BINARY(stdin); |
100 |
|
SET_FILE_BINARY(stdout); |
123 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
124 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
125 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
126 |
< |
copystruct(&input[nfiles].vw, &stdview); |
126 |
> |
input[nfiles].vw = stdview; |
127 |
|
input[nfiles].pa = 1.0; |
128 |
|
} |
129 |
|
nfiles = 0; |
137 |
|
if (argv[a][0] == '-') |
138 |
|
switch (argv[a][1]) { |
139 |
|
case '\0': |
140 |
< |
input[nfiles].name = "<stdin>"; |
140 |
> |
input[nfiles].name = StandardInput; |
141 |
|
input[nfiles].fp = stdin; |
142 |
|
break; |
143 |
|
case 'o': |
230 |
|
eputs( |
231 |
|
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
232 |
|
quit(1); |
233 |
+ |
return 1; /* pro forma return */ |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
< |
tabputs(s) /* put out string preceded by a tab */ |
238 |
< |
char *s; |
237 |
> |
static int |
238 |
> |
tabputs( /* put out string preceded by a tab */ |
239 |
> |
char *s, |
240 |
> |
void *p |
241 |
> |
) |
242 |
|
{ |
243 |
|
char fmt[32]; |
244 |
|
double d; |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
< |
checkfile() /* ready a file */ |
273 |
> |
static void |
274 |
> |
checkfile(void) /* ready a file */ |
275 |
|
{ |
276 |
|
register int i; |
277 |
|
/* process header */ |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
< |
double |
314 |
< |
rgb_bright(clr) |
315 |
< |
COLOR clr; |
313 |
> |
static double |
314 |
> |
rgb_bright( |
315 |
> |
COLOR clr |
316 |
> |
) |
317 |
|
{ |
318 |
|
return(bright(clr)); |
319 |
|
} |
320 |
|
|
321 |
|
|
322 |
< |
double |
323 |
< |
xyz_bright(clr) |
324 |
< |
COLOR clr; |
322 |
> |
static double |
323 |
> |
xyz_bright( |
324 |
> |
COLOR clr |
325 |
> |
) |
326 |
|
{ |
327 |
|
return(clr[CIEY]); |
328 |
|
} |
331 |
|
double (*ourbright)() = rgb_bright; |
332 |
|
|
333 |
|
|
334 |
< |
init() /* perform final setup */ |
334 |
> |
static void |
335 |
> |
init(void) /* perform final setup */ |
336 |
|
{ |
314 |
– |
double l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize(); |
337 |
|
register int i; |
338 |
|
/* define constants */ |
339 |
|
varset("PI", ':', PI); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
< |
combine() /* combine pictures */ |
363 |
> |
static void |
364 |
> |
combine(void) /* combine pictures */ |
365 |
|
{ |
366 |
|
EPNODE *coldef[3], *brtdef; |
367 |
|
COLOR *scanout; |
419 |
|
} |
420 |
|
|
421 |
|
|
422 |
< |
advance() /* read in data for next scanline */ |
422 |
> |
static void |
423 |
> |
advance(void) /* read in data for next scanline */ |
424 |
|
{ |
425 |
|
int ytarget; |
426 |
|
register COLOR *st; |
439 |
|
eputs(": read error\n"); |
440 |
|
quit(1); |
441 |
|
} |
442 |
< |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
443 |
< |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
420 |
< |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
421 |
< |
for (j = 0; j < xmax; j++) /* adjust color */ |
422 |
< |
multcolor(st[j], input[i].coef); |
442 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
443 |
> |
multcolor(st[j], input[i].coef); |
444 |
|
} |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
< |
double |
449 |
< |
l_expos(nam) /* return picture exposure */ |
450 |
< |
register char *nam; |
448 |
> |
static double |
449 |
> |
l_expos( /* return picture exposure */ |
450 |
> |
register char *nam |
451 |
> |
) |
452 |
|
{ |
453 |
|
register int fn, n; |
454 |
|
|
463 |
|
return(colval(input[fn].expos,n)); |
464 |
|
eputs("Bad call to l_expos()!\n"); |
465 |
|
quit(1); |
466 |
+ |
return 1; /* pro forma return */ |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
< |
double |
471 |
< |
l_pixaspect() /* return pixel aspect ratio */ |
470 |
> |
static double |
471 |
> |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
472 |
|
{ |
473 |
|
register int fn; |
474 |
|
|
479 |
|
} |
480 |
|
|
481 |
|
|
482 |
< |
double |
483 |
< |
l_colin(nam) /* return color value for picture */ |
484 |
< |
register char *nam; |
482 |
> |
static double |
483 |
> |
l_colin( /* return color value for picture */ |
484 |
> |
register char *nam |
485 |
> |
) |
486 |
|
{ |
487 |
|
int fn; |
488 |
|
register int n, xoff, yoff; |
531 |
|
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
532 |
|
eputs("Bad call to l_colin()!\n"); |
533 |
|
quit(1); |
534 |
+ |
return 1; /* pro forma return */ |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
< |
double |
539 |
< |
l_ray(nam) /* return ray origin or direction */ |
540 |
< |
register char *nam; |
538 |
> |
static double |
539 |
> |
l_ray( /* return ray origin or direction */ |
540 |
> |
register char *nam |
541 |
> |
) |
542 |
|
{ |
543 |
|
static unsigned long ltick[MAXINP]; |
544 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
545 |
|
static double ldist[MAXINP]; |
546 |
< |
FLOAT loc[2]; |
546 |
> |
RREAL loc[2]; |
547 |
|
int fn; |
548 |
|
register int i; |
549 |
|
|
572 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
573 |
|
eputs("Bad call to l_ray()!\n"); |
574 |
|
quit(1); |
575 |
+ |
return 1; /* pro forma return */ |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
< |
double |
580 |
< |
l_psize() /* compute pixel size in steradians */ |
579 |
> |
static double |
580 |
> |
l_psize(char *nm) /* compute pixel size in steradians */ |
581 |
|
{ |
582 |
|
static unsigned long ltick[MAXINP]; |
583 |
|
static double psize[MAXINP]; |
584 |
|
FVECT dir0, org, dirx, diry; |
585 |
< |
FLOAT locx[2], locy[2]; |
585 |
> |
RREAL locx[2], locy[2]; |
586 |
|
double d; |
587 |
|
int fn; |
588 |
|
register int i; |
598 |
|
if (input[fn].vw.type == 0) |
599 |
|
errno = EDOM; |
600 |
|
else if (input[fn].vw.type != VT_PAR && |
601 |
< |
funvalue(vray[6], 1, &d) >= 0) { |
601 |
> |
funvalue(vray[6], 1, &d) >= -FTINY) { |
602 |
|
for (i = 0; i < 3; i++) |
603 |
|
dir0[i] = funvalue(vray[3+i], 1, &d); |
604 |
|
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
605 |
|
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
606 |
|
if (viewray(org, dirx, &input[fn].vw, |
607 |
< |
locx[0], locx[1]) >= 0 && |
607 |
> |
locx[0], locx[1]) >= -FTINY && |
608 |
|
viewray(org, diry, &input[fn].vw, |
609 |
< |
locy[0], locy[1]) >= 0) { |
609 |
> |
locy[0], locy[1]) >= -FTINY) { |
610 |
|
/* approximate solid angle */ |
611 |
|
for (i = 0; i < 3; i++) { |
612 |
|
dirx[i] -= dir0[i]; |
613 |
|
diry[i] -= dir0[i]; |
614 |
|
} |
615 |
|
fcross(dir0, dirx, diry); |
616 |
< |
psize[fn] = sqrt(DOT(dir0,dir0)); |
616 |
> |
psize[fn] = VLEN(dir0); |
617 |
|
} |
618 |
|
} |
619 |
|
ltick[fn] = eclock; |
622 |
|
} |
623 |
|
|
624 |
|
|
625 |
< |
void |
626 |
< |
wputs(msg) |
600 |
< |
char *msg; |
625 |
> |
extern void |
626 |
> |
wputs(char *msg) |
627 |
|
{ |
628 |
|
if (!nowarn) |
629 |
|
eputs(msg); |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
< |
void |
634 |
< |
eputs(msg) |
609 |
< |
char *msg; |
633 |
> |
extern void |
634 |
> |
eputs(char *msg) |
635 |
|
{ |
636 |
|
fputs(msg, stderr); |
637 |
|
} |
638 |
|
|
639 |
|
|
640 |
< |
void |
641 |
< |
quit(code) /* exit gracefully */ |
617 |
< |
int code; |
640 |
> |
extern void |
641 |
> |
quit(int code) /* exit gracefully */ |
642 |
|
{ |
643 |
|
register int i; |
644 |
|
/* close input files */ |