| 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 |
|
* |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include "standard.h" |
| 11 |
< |
|
| 11 |
> |
#include "platform.h" |
| 12 |
|
#include "color.h" |
| 16 |
– |
|
| 17 |
– |
#include "resolu.h" |
| 18 |
– |
|
| 13 |
|
#include "calcomp.h" |
| 20 |
– |
|
| 14 |
|
#include "view.h" |
| 15 |
|
|
| 16 |
|
#define MAXINP 32 /* maximum number of input files */ |
| 17 |
< |
#define WINSIZ 17 /* scanline window size */ |
| 17 |
> |
#define WINSIZ 64 /* scanline window size */ |
| 18 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
| 19 |
|
|
| 20 |
|
struct { |
| 39 |
|
char vbrtout[] = "lo"; |
| 40 |
|
char vcolexp[3][4] = {"re", "ge", "be"}; |
| 41 |
|
char vbrtexp[] = "le"; |
| 42 |
+ |
char vpixaspect[] = "pa"; |
| 43 |
|
|
| 44 |
< |
char vray[6][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz"}; |
| 44 |
> |
char vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; |
| 45 |
|
|
| 46 |
|
char vpsize[] = "S"; |
| 47 |
|
|
| 48 |
|
char vnfiles[] = "nfiles"; |
| 49 |
+ |
char vwhteff[] = "WE"; |
| 50 |
|
char vxmax[] = "xmax"; |
| 51 |
|
char vymax[] = "ymax"; |
| 52 |
|
char vxres[] = "xres"; |
| 81 |
|
int original; |
| 82 |
|
double f; |
| 83 |
|
int a, i; |
| 84 |
< |
#ifdef MSDOS |
| 85 |
< |
extern int _fmode; |
| 86 |
< |
_fmode = O_BINARY; |
| 92 |
< |
setmode(fileno(stdin), O_BINARY); |
| 93 |
< |
setmode(fileno(stdout), O_BINARY); |
| 94 |
< |
#endif |
| 84 |
> |
SET_DEFAULT_BINARY(); |
| 85 |
> |
SET_FILE_BINARY(stdin); |
| 86 |
> |
SET_FILE_BINARY(stdout); |
| 87 |
|
progname = argv[0]; |
| 88 |
|
/* scan options */ |
| 89 |
|
for (a = 1; a < argc; a++) { |
| 104 |
|
break; |
| 105 |
|
} |
| 106 |
|
newheader("RADIANCE", stdout); /* start header */ |
| 107 |
+ |
fputnow(stdout); |
| 108 |
|
/* process files */ |
| 109 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
| 110 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
| 111 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
| 112 |
< |
copystruct(&input[nfiles].vw, &stdview); |
| 112 |
> |
input[nfiles].vw = stdview; |
| 113 |
|
input[nfiles].pa = 1.0; |
| 114 |
|
} |
| 115 |
|
nfiles = 0; |
| 162 |
|
colval(input[nfiles].expos,GRN); |
| 163 |
|
colval(input[nfiles].coef,BLU) /= |
| 164 |
|
colval(input[nfiles].expos,BLU); |
| 165 |
+ |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
| 166 |
|
} |
| 167 |
|
nfiles++; |
| 168 |
|
original = 0; |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
|
| 222 |
< |
tputs(s) /* put out string preceded by a tab */ |
| 222 |
> |
tabputs(s) /* put out string preceded by a tab */ |
| 223 |
|
char *s; |
| 224 |
|
{ |
| 225 |
|
char fmt[32]; |
| 227 |
|
COLOR ctmp; |
| 228 |
|
|
| 229 |
|
if (isheadid(s)) /* header id */ |
| 230 |
< |
return; /* don't echo */ |
| 230 |
> |
return(0); /* don't echo */ |
| 231 |
|
if (formatval(fmt, s)) { /* check format */ |
| 232 |
|
if (globmatch(ourfmt, fmt)) { |
| 233 |
|
wrongformat = 0; |
| 234 |
|
strcpy(ourfmt, fmt); |
| 235 |
|
} else |
| 236 |
< |
wrongformat = 1; |
| 237 |
< |
return; /* don't echo */ |
| 236 |
> |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
| 237 |
> |
return(0); /* don't echo */ |
| 238 |
|
} |
| 239 |
|
if (isexpos(s)) { /* exposure */ |
| 240 |
|
d = exposval(s); |
| 242 |
|
} else if (iscolcor(s)) { /* color correction */ |
| 243 |
|
colcorval(ctmp, s); |
| 244 |
|
multcolor(input[nfiles].expos, ctmp); |
| 245 |
< |
} else if (isaspect(s)) { |
| 245 |
> |
} else if (isaspect(s)) |
| 246 |
|
input[nfiles].pa *= aspectval(s); |
| 247 |
< |
} else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
| 247 |
> |
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
| 248 |
|
gotview++; |
| 249 |
|
/* echo line */ |
| 250 |
|
putchar('\t'); |
| 251 |
< |
fputs(s, stdout); |
| 251 |
> |
return(fputs(s, stdout)); |
| 252 |
|
} |
| 253 |
|
|
| 254 |
|
|
| 259 |
|
gotview = 0; |
| 260 |
|
fputs(input[nfiles].name, stdout); |
| 261 |
|
fputs(":\n", stdout); |
| 262 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
| 263 |
< |
if (wrongformat) { |
| 262 |
> |
getheader(input[nfiles].fp, tabputs, NULL); |
| 263 |
> |
if (wrongformat < 0) { |
| 264 |
|
eputs(input[nfiles].name); |
| 265 |
< |
eputs(": not in Radiance picture format\n"); |
| 265 |
> |
eputs(": not a Radiance picture\n"); |
| 266 |
|
quit(1); |
| 267 |
|
} |
| 268 |
+ |
if (wrongformat > 0) { |
| 269 |
+ |
wputs(input[nfiles].name); |
| 270 |
+ |
wputs(": warning -- incompatible picture format\n"); |
| 271 |
+ |
} |
| 272 |
|
if (!gotview || setview(&input[nfiles].vw) != NULL) |
| 273 |
|
input[nfiles].vw.type = 0; |
| 274 |
|
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
| 312 |
|
|
| 313 |
|
init() /* perform final setup */ |
| 314 |
|
{ |
| 315 |
< |
double l_colin(), l_expos(), l_ray(), l_psize(); |
| 315 |
> |
double l_colin(), l_expos(), l_pixaspect(), l_ray(), l_psize(); |
| 316 |
|
register int i; |
| 317 |
|
/* define constants */ |
| 318 |
+ |
varset("PI", ':', PI); |
| 319 |
|
varset(vnfiles, ':', (double)nfiles); |
| 320 |
|
varset(vxmax, ':', (double)xmax); |
| 321 |
|
varset(vymax, ':', (double)ymax); |
| 326 |
|
} |
| 327 |
|
funset(vbrtexp, 1, ':', l_expos); |
| 328 |
|
funset(vbrtin, 1, '=', l_colin); |
| 329 |
< |
for (i = 0; i < 6; i++) |
| 329 |
> |
funset(vpixaspect, 1, ':', l_pixaspect); |
| 330 |
> |
for (i = 0; i < 7; i++) |
| 331 |
|
funset(vray[i], 1, '=', l_ray); |
| 332 |
|
funset(vpsize, 1, '=', l_psize); |
| 333 |
|
/* set brightness function */ |
| 334 |
< |
if (!strcmp(ourfmt, CIEFMT)) |
| 334 |
> |
if (!strcmp(ourfmt, CIEFMT)) { |
| 335 |
> |
varset(vwhteff, ':', 1.0); |
| 336 |
|
ourbright = xyz_bright; |
| 337 |
+ |
} else |
| 338 |
+ |
varset(vwhteff, ':', WHTEFFICACY); |
| 339 |
|
} |
| 340 |
|
|
| 341 |
|
|
| 393 |
|
quit(1); |
| 394 |
|
} |
| 395 |
|
} |
| 396 |
< |
efree(scanout); |
| 396 |
> |
efree((char *)scanout); |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 446 |
|
|
| 447 |
|
|
| 448 |
|
double |
| 449 |
+ |
l_pixaspect() /* return pixel aspect ratio */ |
| 450 |
+ |
{ |
| 451 |
+ |
register int fn; |
| 452 |
+ |
|
| 453 |
+ |
fn = argument(1) - .5; |
| 454 |
+ |
if (fn < 0 || fn >= nfiles) |
| 455 |
+ |
return(1.0); |
| 456 |
+ |
return(input[fn].pa); |
| 457 |
+ |
} |
| 458 |
+ |
|
| 459 |
+ |
|
| 460 |
+ |
double |
| 461 |
|
l_colin(nam) /* return color value for picture */ |
| 462 |
|
register char *nam; |
| 463 |
|
{ |
| 465 |
|
register int n, xoff, yoff; |
| 466 |
|
double d; |
| 467 |
|
|
| 468 |
< |
d = argument(1); |
| 454 |
< |
if (d > -.5 && d < .5) |
| 455 |
< |
return((double)nfiles); |
| 456 |
< |
fn = d - .5; |
| 468 |
> |
fn = argument(1) - .5; |
| 469 |
|
if (fn < 0 || fn >= nfiles) { |
| 470 |
|
errno = EDOM; |
| 471 |
|
return(0.0); |
| 517 |
|
{ |
| 518 |
|
static unsigned long ltick[MAXINP]; |
| 519 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
| 520 |
< |
FLOAT loc[2]; |
| 521 |
< |
double d; |
| 520 |
> |
static double ldist[MAXINP]; |
| 521 |
> |
RREAL loc[2]; |
| 522 |
|
int fn; |
| 523 |
|
register int i; |
| 524 |
|
|
| 525 |
< |
d = argument(1); |
| 514 |
< |
if (d > -.5 && d < .5) |
| 515 |
< |
return((double)nfiles); |
| 516 |
< |
fn = d - .5; |
| 525 |
> |
fn = argument(1) - .5; |
| 526 |
|
if (fn < 0 || fn >= nfiles) { |
| 527 |
|
errno = EDOM; |
| 528 |
|
return(0.0); |
| 529 |
|
} |
| 530 |
< |
if (ltick[fn] < eclock) { /* need to compute? */ |
| 530 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
| 531 |
|
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
| 532 |
|
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
| 533 |
+ |
ldist[fn] = -1.0; |
| 534 |
|
if (input[fn].vw.type == 0) |
| 535 |
|
errno = EDOM; |
| 536 |
|
else { |
| 537 |
|
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
| 538 |
< |
if (viewray(lorg[fn], ldir[fn], |
| 539 |
< |
&input[fn].vw, loc[0], loc[1]) < 0) |
| 530 |
< |
errno = ERANGE; |
| 531 |
< |
ltick[fn] = eclock; |
| 538 |
> |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
| 539 |
> |
&input[fn].vw, loc[0], loc[1]); |
| 540 |
|
} |
| 541 |
+ |
ltick[fn] = eclock; |
| 542 |
|
} |
| 543 |
< |
i = 6; |
| 543 |
> |
if (nam == vray[i=6]) |
| 544 |
> |
return(ldist[fn]); |
| 545 |
|
while (i--) |
| 546 |
|
if (nam == vray[i]) |
| 547 |
|
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
| 555 |
|
{ |
| 556 |
|
static unsigned long ltick[MAXINP]; |
| 557 |
|
static double psize[MAXINP]; |
| 558 |
< |
FVECT dir0, org1, dir1; |
| 559 |
< |
FLOAT loc[2]; |
| 558 |
> |
FVECT dir0, org, dirx, diry; |
| 559 |
> |
RREAL locx[2], locy[2]; |
| 560 |
|
double d; |
| 561 |
|
int fn; |
| 562 |
+ |
register int i; |
| 563 |
|
|
| 564 |
|
d = argument(1); |
| 565 |
< |
if (d > -.5 && d < .5) |
| 555 |
< |
return((double)nfiles); |
| 556 |
< |
fn = d - .5; |
| 557 |
< |
if (fn < 0 || fn >= nfiles) { |
| 565 |
> |
if (d < .5 || d >= nfiles+.5) { |
| 566 |
|
errno = EDOM; |
| 567 |
|
return(0.0); |
| 568 |
|
} |
| 569 |
< |
if (ltick[fn] < eclock) /* need to compute? */ |
| 570 |
< |
if (input[fn].vw.type == 0 || input[fn].vw.type == VT_PAR) |
| 569 |
> |
fn = d - .5; |
| 570 |
> |
if (ltick[fn] != eclock) { /* need to compute? */ |
| 571 |
> |
psize[fn] = 0.0; |
| 572 |
> |
if (input[fn].vw.type == 0) |
| 573 |
|
errno = EDOM; |
| 574 |
< |
else { |
| 575 |
< |
errno = 0; |
| 576 |
< |
dir0[0] = funvalue(vray[3], 1, &d); |
| 577 |
< |
if (errno) |
| 578 |
< |
return(0.0); |
| 579 |
< |
dir0[1] = funvalue(vray[4], 1, &d); |
| 580 |
< |
if (errno) |
| 581 |
< |
return(0.0); |
| 582 |
< |
dir0[2] = funvalue(vray[5], 1, &d); |
| 583 |
< |
if (errno) |
| 574 |
< |
return(0.0); |
| 575 |
< |
pix2loc(loc, &input[fn].rs, xscan+1, ymax-yscan); |
| 576 |
< |
psize[fn] = 0.0; |
| 577 |
< |
if (viewray(org1, dir1, |
| 578 |
< |
&input[fn].vw, loc[0], loc[1]) < 0) |
| 579 |
< |
errno = ERANGE; |
| 580 |
< |
else { |
| 574 |
> |
else if (input[fn].vw.type != VT_PAR && |
| 575 |
> |
funvalue(vray[6], 1, &d) >= 0) { |
| 576 |
> |
for (i = 0; i < 3; i++) |
| 577 |
> |
dir0[i] = funvalue(vray[3+i], 1, &d); |
| 578 |
> |
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
| 579 |
> |
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
| 580 |
> |
if (viewray(org, dirx, &input[fn].vw, |
| 581 |
> |
locx[0], locx[1]) >= 0 && |
| 582 |
> |
viewray(org, diry, &input[fn].vw, |
| 583 |
> |
locy[0], locy[1]) >= 0) { |
| 584 |
|
/* approximate solid angle */ |
| 585 |
< |
psize[fn] = dist2(dir0, dir1) * input[fn].pa / |
| 586 |
< |
(1.0 + input[fn].pa*input[fn].pa); |
| 587 |
< |
ltick[fn] = eclock; |
| 585 |
> |
for (i = 0; i < 3; i++) { |
| 586 |
> |
dirx[i] -= dir0[i]; |
| 587 |
> |
diry[i] -= dir0[i]; |
| 588 |
> |
} |
| 589 |
> |
fcross(dir0, dirx, diry); |
| 590 |
> |
psize[fn] = sqrt(DOT(dir0,dir0)); |
| 591 |
|
} |
| 592 |
|
} |
| 593 |
+ |
ltick[fn] = eclock; |
| 594 |
+ |
} |
| 595 |
|
return(psize[fn]); |
| 596 |
|
} |
| 597 |
|
|
| 598 |
|
|
| 599 |
+ |
void |
| 600 |
|
wputs(msg) |
| 601 |
|
char *msg; |
| 602 |
|
{ |
| 605 |
|
} |
| 606 |
|
|
| 607 |
|
|
| 608 |
+ |
void |
| 609 |
|
eputs(msg) |
| 610 |
|
char *msg; |
| 611 |
|
{ |
| 613 |
|
} |
| 614 |
|
|
| 615 |
|
|
| 616 |
+ |
void |
| 617 |
|
quit(code) /* exit gracefully */ |
| 618 |
|
int code; |
| 619 |
|
{ |