9 |
|
|
10 |
|
#include "platform.h" |
11 |
|
#include "standard.h" |
12 |
< |
#include "rtprocess.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 { |
68 |
|
|
69 |
|
char *progname; /* global argv[0] */ |
70 |
|
|
71 |
+ |
int echoheader = 1; |
72 |
|
int wrongformat = 0; |
73 |
|
int gotview; |
74 |
|
|
75 |
|
|
76 |
< |
static gethfunc tabputs; |
76 |
> |
static gethfunc headline; |
77 |
|
static void checkfile(void); |
78 |
|
static double rgb_bright(COLOR clr); |
79 |
|
static double xyz_bright(COLOR clr); |
96 |
|
int original; |
97 |
|
double f; |
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++; |
201 |
|
continue; |
202 |
|
case 'w': |
203 |
|
continue; |
204 |
+ |
case 'h': |
205 |
+ |
continue; |
206 |
|
case 'f': |
207 |
|
fcompile(argv[++a]); |
208 |
|
continue; |
212 |
|
} |
213 |
|
break; |
214 |
|
} |
215 |
< |
/* set/get output resolution */ |
207 |
< |
if (!vardefined(vxres)) |
208 |
< |
varset(vxres, ':', (double)xmax); |
209 |
< |
if (!vardefined(vyres)) |
210 |
< |
varset(vyres, ':', (double)ymax); |
215 |
> |
/* get output resolution */ |
216 |
|
xres = varvalue(vxres) + .5; |
217 |
|
yres = varvalue(vyres) + .5; |
218 |
|
if (xres <= 0 || yres <= 0) { |
233 |
|
eputs("Usage: "); |
234 |
|
eputs(argv[0]); |
235 |
|
eputs( |
236 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
236 |
> |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); |
237 |
|
quit(1); |
238 |
|
return 1; /* pro forma return */ |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
static int |
243 |
< |
tabputs( /* put out string preceded by a tab */ |
243 |
> |
headline( /* check header line & echo if requested */ |
244 |
|
char *s, |
245 |
|
void *p |
246 |
|
) |
269 |
|
input[nfiles].pa *= aspectval(s); |
270 |
|
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
271 |
|
gotview++; |
272 |
< |
/* echo line */ |
273 |
< |
putchar('\t'); |
274 |
< |
return(fputs(s, stdout)); |
272 |
> |
|
273 |
> |
if (echoheader) { /* echo line */ |
274 |
> |
putchar('\t'); |
275 |
> |
return(fputs(s, stdout)); |
276 |
> |
} |
277 |
> |
return(0); |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
static void |
282 |
|
checkfile(void) /* ready a file */ |
283 |
|
{ |
284 |
< |
register int i; |
284 |
> |
int i; |
285 |
|
/* process header */ |
286 |
|
gotview = 0; |
287 |
< |
fputs(input[nfiles].name, stdout); |
288 |
< |
fputs(":\n", stdout); |
289 |
< |
getheader(input[nfiles].fp, tabputs, NULL); |
287 |
> |
if (echoheader) { |
288 |
> |
fputs(input[nfiles].name, stdout); |
289 |
> |
fputs(":\n", stdout); |
290 |
> |
} |
291 |
> |
getheader(input[nfiles].fp, headline, NULL); |
292 |
|
if (wrongformat < 0) { |
293 |
|
eputs(input[nfiles].name); |
294 |
|
eputs(": not a Radiance picture\n"); |
344 |
|
static void |
345 |
|
init(void) /* perform final setup */ |
346 |
|
{ |
347 |
< |
register int i; |
347 |
> |
int i; |
348 |
|
/* define constants */ |
349 |
|
varset("PI", ':', PI); |
350 |
|
varset(vnfiles, ':', (double)nfiles); |
367 |
|
ourbright = xyz_bright; |
368 |
|
} else |
369 |
|
varset(vwhteff, ':', WHTEFFICACY); |
370 |
+ |
/* these may be overridden */ |
371 |
+ |
varset(vxres, ':', (double)xmax); |
372 |
+ |
varset(vyres, ':', (double)ymax); |
373 |
|
} |
374 |
|
|
375 |
|
|
379 |
|
EPNODE *coldef[3], *brtdef; |
380 |
|
COLOR *scanout; |
381 |
|
double d; |
382 |
< |
register int i, j; |
382 |
> |
int i, j; |
383 |
|
/* check defined variables */ |
384 |
|
for (j = 0; j < 3; j++) { |
385 |
|
if (vardefined(vcolout[j])) |
400 |
|
advance(); |
401 |
|
varset(vypos, '=', (double)ypos); |
402 |
|
for (xpos = 0; xpos < xres; xpos++) { |
403 |
< |
xscan = (long)xpos*xmax/xres; |
403 |
> |
xscan = (xpos+.5)*xmax/xres; |
404 |
|
varset(vxpos, '=', (double)xpos); |
405 |
|
eclock++; |
406 |
|
if (brtdef != NULL) { |
436 |
|
advance(void) /* read in data for next scanline */ |
437 |
|
{ |
438 |
|
int ytarget; |
439 |
< |
register COLOR *st; |
440 |
< |
register int i, j; |
439 |
> |
COLOR *st; |
440 |
> |
int i, j; |
441 |
|
|
442 |
< |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
442 |
> |
for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) |
443 |
|
for (i = 0; i < nfiles; i++) { |
444 |
|
st = input[i].scan[WINSIZ-1]; |
445 |
|
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
452 |
|
eputs(": read error\n"); |
453 |
|
quit(1); |
454 |
|
} |
455 |
< |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
456 |
< |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
444 |
< |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
445 |
< |
for (j = 0; j < xmax; j++) /* adjust color */ |
446 |
< |
multcolor(st[j], input[i].coef); |
455 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
456 |
> |
multcolor(st[j], input[i].coef); |
457 |
|
} |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
|
static double |
462 |
|
l_expos( /* return picture exposure */ |
463 |
< |
register char *nam |
463 |
> |
char *nam |
464 |
|
) |
465 |
|
{ |
466 |
< |
register int fn, n; |
466 |
> |
int fn, n; |
467 |
> |
double d; |
468 |
|
|
469 |
< |
fn = argument(1) - .5; |
470 |
< |
if (fn < 0 || fn >= nfiles) |
471 |
< |
return(1.0); |
469 |
> |
d = argument(1); |
470 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
471 |
> |
errno = EDOM; |
472 |
> |
return(0.0); |
473 |
> |
} |
474 |
> |
if (d < 0.5) |
475 |
> |
return((double)nfiles); |
476 |
> |
fn = d - 0.5; |
477 |
|
if (nam == vbrtexp) |
478 |
|
return((*ourbright)(input[fn].expos)); |
479 |
|
n = 3; |
489 |
|
static double |
490 |
|
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
491 |
|
{ |
492 |
< |
register int fn; |
492 |
> |
int fn; |
493 |
> |
double d; |
494 |
|
|
495 |
< |
fn = argument(1) - .5; |
496 |
< |
if (fn < 0 || fn >= nfiles) |
497 |
< |
return(1.0); |
495 |
> |
d = argument(1); |
496 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
497 |
> |
errno = EDOM; |
498 |
> |
return(0.0); |
499 |
> |
} |
500 |
> |
if (d < 0.5) |
501 |
> |
return((double)nfiles); |
502 |
> |
fn = d - 0.5; |
503 |
|
return(input[fn].pa); |
504 |
|
} |
505 |
|
|
506 |
|
|
507 |
|
static double |
508 |
|
l_colin( /* return color value for picture */ |
509 |
< |
register char *nam |
509 |
> |
char *nam |
510 |
|
) |
511 |
|
{ |
512 |
|
int fn; |
513 |
< |
register int n, xoff, yoff; |
513 |
> |
int n, xoff, yoff; |
514 |
|
double d; |
515 |
|
|
516 |
< |
fn = argument(1) - .5; |
517 |
< |
if (fn < 0 || fn >= nfiles) { |
516 |
> |
d = argument(1); |
517 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
518 |
|
errno = EDOM; |
519 |
|
return(0.0); |
520 |
|
} |
521 |
+ |
if (d < 0.5) |
522 |
+ |
return((double)nfiles); |
523 |
+ |
fn = d - 0.5; |
524 |
|
xoff = yoff = 0; |
525 |
|
n = nargum(); |
526 |
|
if (n >= 2) { |
565 |
|
|
566 |
|
static double |
567 |
|
l_ray( /* return ray origin or direction */ |
568 |
< |
register char *nam |
568 |
> |
char *nam |
569 |
|
) |
570 |
|
{ |
571 |
|
static unsigned long ltick[MAXINP]; |
572 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
573 |
|
static double ldist[MAXINP]; |
574 |
|
RREAL loc[2]; |
575 |
+ |
double d; |
576 |
|
int fn; |
577 |
< |
register int i; |
577 |
> |
int i; |
578 |
|
|
579 |
< |
fn = argument(1) - .5; |
580 |
< |
if (fn < 0 || fn >= nfiles) { |
579 |
> |
d = argument(1); |
580 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
581 |
|
errno = EDOM; |
582 |
|
return(0.0); |
583 |
|
} |
584 |
+ |
if (d < 0.5) |
585 |
+ |
return((double)nfiles); |
586 |
+ |
fn = d - 0.5; |
587 |
|
if (ltick[fn] != eclock) { /* need to compute? */ |
588 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
589 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
617 |
|
RREAL locx[2], locy[2]; |
618 |
|
double d; |
619 |
|
int fn; |
620 |
< |
register int i; |
620 |
> |
int i; |
621 |
|
|
622 |
|
d = argument(1); |
623 |
< |
if (d < .5 || d >= nfiles+.5) { |
623 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
624 |
|
errno = EDOM; |
625 |
|
return(0.0); |
626 |
|
} |
627 |
< |
fn = d - .5; |
627 |
> |
if (d < 0.5) |
628 |
> |
return((double)nfiles); |
629 |
> |
fn = d - 0.5; |
630 |
|
if (ltick[fn] != eclock) { /* need to compute? */ |
631 |
|
psize[fn] = 0.0; |
632 |
|
if (input[fn].vw.type == 0) |
674 |
|
extern void |
675 |
|
quit(int code) /* exit gracefully */ |
676 |
|
{ |
677 |
< |
register int i; |
677 |
> |
int i; |
678 |
|
/* close input files */ |
679 |
|
for (i = 0; i < nfiles; i++) |
680 |
|
if (input[i].name == Command) |