| 39 |
|
|
| 40 |
|
extern int castonly; /* only doing ray-casting? */ |
| 41 |
|
|
| 42 |
+ |
extern double (*sens_curve)(SCOLOR scol); /* spectral conversion for 1-channel */ |
| 43 |
+ |
extern double out_scalefactor; /* output calibration scale factor */ |
| 44 |
+ |
extern RGBPRIMP out_prims; /* output color primitives (NULL if spectral) */ |
| 45 |
+ |
|
| 46 |
|
#ifndef MAXTSET |
| 47 |
|
#define MAXTSET 8191 /* maximum number in trace set */ |
| 48 |
|
#endif |
| 68 |
|
extern void tranotify(OBJECT obj); |
| 69 |
|
static void tabin(RAY *r); |
| 70 |
|
static RayReportCall ourtrace; |
| 67 |
– |
static RayReportCall printvals; |
| 71 |
|
|
| 72 |
+ |
RayReportCall printvals; /* print selected ray values */ |
| 73 |
+ |
|
| 74 |
+ |
void putscolor(COLORV *scol); /* convert/print spectral color */ |
| 75 |
+ |
|
| 76 |
|
static oputf_t *ray_out[32], *every_out[32]; |
| 70 |
– |
static putf_t *putreal; |
| 77 |
|
|
| 78 |
+ |
putf_t *putreal; /* put out real vector */ |
| 79 |
+ |
|
| 80 |
|
void |
| 81 |
|
quit( /* quit program */ |
| 82 |
|
int code |
| 83 |
|
) |
| 84 |
|
{ |
| 85 |
+ |
if (ray_pnprocs < 0) |
| 86 |
+ |
_exit(code); /* avoid flush in child */ |
| 87 |
+ |
|
| 88 |
|
int ec = myRTmanager.Cleanup(); |
| 89 |
|
|
| 90 |
|
if (ec) code = ec; |
| 101 |
|
case 'a': return("ascii"); |
| 102 |
|
case 'f': return("float"); |
| 103 |
|
case 'd': return("double"); |
| 104 |
< |
case 'c': return(COLRFMT); |
| 104 |
> |
case 'c': |
| 105 |
> |
if (out_prims == NULL) |
| 106 |
> |
return(SPECFMT); |
| 107 |
> |
if (out_prims == xyzprims) |
| 108 |
> |
return(CIEFMT); |
| 109 |
> |
return(COLRFMT); |
| 110 |
|
} |
| 111 |
|
return("unknown"); |
| 112 |
|
} |
| 197 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
| 198 |
|
error(SYSTEM, errmsg); |
| 199 |
|
} |
| 184 |
– |
#ifdef getc_unlocked |
| 185 |
– |
flockfile(inpfp); /* avoid lock/unlock overhead */ |
| 186 |
– |
#endif |
| 200 |
|
if (inform != 'a') |
| 201 |
|
SET_FILE_BINARY(inpfp); |
| 202 |
|
/* set up output */ |
| 216 |
|
if (every_out[0]) |
| 217 |
|
myRTmanager.SetTraceCall(ourtrace); |
| 218 |
|
myRTmanager.rtFlags |= RTdoFIFO; |
| 219 |
+ |
#ifdef getc_unlocked |
| 220 |
+ |
flockfile(inpfp); /* avoid lock/unlock overhead */ |
| 221 |
+ |
flockfile(stdout); |
| 222 |
+ |
#endif |
| 223 |
|
if (hresolu > 0) { // print resolution string if appropriate |
| 224 |
|
if (vresolu > 0) |
| 225 |
|
fprtresolu(hresolu, vresolu, stdout); |
| 238 |
|
pending |= (n > 1); // time to flush output? |
| 239 |
|
bool atZero = IsZeroVec(ivbuf[2*n-1]); |
| 240 |
|
if (pending & (atZero | (n == flushIntvl))) { |
| 241 |
< |
if (!myRTmanager.FlushQueue()) |
| 241 |
> |
if (myRTmanager.FlushQueue() <= 0) |
| 242 |
|
error(USER, "ray flush error"); |
| 243 |
|
fflush(stdout); |
| 244 |
|
pending = false; |
| 252 |
|
if (vcount) |
| 253 |
|
error(WARNING, feof(inpfp) ? "unexpected EOF on input" : |
| 254 |
|
"input read error"); |
| 255 |
< |
if (fflush(stdout) < 0) |
| 256 |
< |
error(SYSTEM, "write error"); |
| 255 |
> |
if (myRTmanager.FlushQueue() < 0 || fflush(stdout) < 0) |
| 256 |
> |
error(SYSTEM, "final flush error"); |
| 257 |
|
if (fname != NULL) { |
| 258 |
|
fclose(inpfp); |
| 259 |
|
inpfp = NULL; |
| 266 |
|
{ |
| 267 |
|
const char *vs = outvals; |
| 268 |
|
oputf_t **table = ray_out; |
| 269 |
+ |
const int nco = (sens_curve != NULL) ? 1 : |
| 270 |
+ |
(out_prims != NULL) ? 3 : NCSAMP; |
| 271 |
|
int ncomp = 0; |
| 272 |
|
|
| 273 |
|
if (!*vs) |
| 306 |
|
break; |
| 307 |
|
case 'r': /* reflected contrib. */ |
| 308 |
|
*table++ = oputr; |
| 309 |
< |
ncomp += 3; |
| 309 |
> |
ncomp += nco; |
| 310 |
|
castonly = 0; |
| 311 |
|
break; |
| 312 |
|
case 'R': /* reflected distance */ |
| 316 |
|
break; |
| 317 |
|
case 'x': /* xmit contrib. */ |
| 318 |
|
*table++ = oputx; |
| 319 |
< |
ncomp += 3; |
| 319 |
> |
ncomp += nco; |
| 320 |
|
castonly = 0; |
| 321 |
|
break; |
| 322 |
|
case 'X': /* xmit distance */ |
| 326 |
|
break; |
| 327 |
|
case 'v': /* value */ |
| 328 |
|
*table++ = oputv; |
| 329 |
< |
ncomp += 3; |
| 329 |
> |
ncomp += nco; |
| 330 |
|
castonly = 0; |
| 331 |
|
break; |
| 332 |
|
case 'V': /* contribution */ |
| 333 |
|
*table++ = oputV; |
| 334 |
< |
ncomp += 3; |
| 334 |
> |
ncomp += nco; |
| 335 |
|
castonly = 0; |
| 336 |
|
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
| 337 |
|
error(WARNING, |
| 373 |
|
break; |
| 374 |
|
case 'W': /* coefficient */ |
| 375 |
|
*table++ = oputW; |
| 376 |
< |
ncomp += 3; |
| 376 |
> |
ncomp += nco; |
| 377 |
|
castonly = 0; |
| 378 |
|
if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0)) |
| 379 |
|
error(WARNING, |
| 413 |
|
return(ncomp); |
| 414 |
|
} |
| 415 |
|
|
| 416 |
< |
static void |
| 416 |
> |
int |
| 417 |
|
printvals( /* print requested ray values */ |
| 418 |
|
RAY *r, void *cd |
| 419 |
|
) |
| 421 |
|
oputf_t **tp; |
| 422 |
|
|
| 423 |
|
if (ray_out[0] == NULL) |
| 424 |
< |
return; |
| 406 |
< |
#ifdef getc_unlocked |
| 407 |
< |
flockfile(stdout); |
| 408 |
< |
#endif |
| 424 |
> |
return 0; |
| 425 |
|
for (tp = ray_out; *tp != NULL; tp++) |
| 426 |
|
(**tp)(r); |
| 427 |
|
if (outform == 'a') |
| 428 |
|
putchar('\n'); |
| 429 |
< |
#ifdef getc_unlocked |
| 414 |
< |
funlockfile(stdout); |
| 415 |
< |
#endif |
| 429 |
> |
return 1; |
| 430 |
|
} |
| 431 |
|
|
| 432 |
|
void |
| 457 |
|
} |
| 458 |
|
} |
| 459 |
|
|
| 460 |
< |
static void |
| 460 |
> |
static int |
| 461 |
|
ourtrace( /* print ray values */ |
| 462 |
|
RAY *r, void *cd |
| 463 |
|
) |
| 465 |
|
oputf_t **tp; |
| 466 |
|
|
| 467 |
|
if (every_out[0] == NULL) |
| 468 |
< |
return; |
| 468 |
> |
return 0; |
| 469 |
|
if (r->ro == NULL) { |
| 470 |
|
if (traincl == 1) |
| 471 |
< |
return; |
| 471 |
> |
return 0; |
| 472 |
|
} else if (traincl != -1 && traincl != inset(traset, r->ro->omod)) |
| 473 |
< |
return; |
| 460 |
< |
#ifdef getc_unlocked |
| 461 |
< |
flockfile(stdout); |
| 462 |
< |
#endif |
| 473 |
> |
return 0; |
| 474 |
|
tabin(r); |
| 475 |
|
for (tp = every_out; *tp != NULL; tp++) |
| 476 |
|
(**tp)(r); |
| 477 |
|
if (outform == 'a') |
| 478 |
|
putchar('\n'); |
| 479 |
< |
#ifdef getc_unlocked |
| 469 |
< |
funlockfile(stdout); |
| 470 |
< |
#endif |
| 479 |
> |
return 1; |
| 480 |
|
} |
| 481 |
|
|
| 482 |
|
static void |
| 511 |
|
RAY *r |
| 512 |
|
) |
| 513 |
|
{ |
| 514 |
< |
RREAL cval[3]; |
| 506 |
< |
|
| 507 |
< |
cval[0] = colval(r->mcol,RED); |
| 508 |
< |
cval[1] = colval(r->mcol,GRN); |
| 509 |
< |
cval[2] = colval(r->mcol,BLU); |
| 510 |
< |
(*putreal)(cval, 3); |
| 514 |
> |
putscolor(r->mcol); |
| 515 |
|
} |
| 516 |
|
|
| 517 |
|
static void |
| 527 |
|
RAY *r |
| 528 |
|
) |
| 529 |
|
{ |
| 530 |
< |
RREAL cval[3]; |
| 530 |
> |
SCOLOR cdiff; |
| 531 |
|
|
| 532 |
< |
cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED); |
| 533 |
< |
cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN); |
| 534 |
< |
cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU); |
| 535 |
< |
(*putreal)(cval, 3); |
| 532 |
> |
copyscolor(cdiff, r->rcol); |
| 533 |
> |
sopscolor(cdiff, -=, r->mcol); |
| 534 |
> |
|
| 535 |
> |
putscolor(cdiff); |
| 536 |
|
} |
| 537 |
|
|
| 538 |
|
static void |
| 548 |
|
RAY *r |
| 549 |
|
) |
| 550 |
|
{ |
| 551 |
< |
RREAL cval[3]; |
| 548 |
< |
|
| 549 |
< |
cval[0] = colval(r->rcol,RED); |
| 550 |
< |
cval[1] = colval(r->rcol,GRN); |
| 551 |
< |
cval[2] = colval(r->rcol,BLU); |
| 552 |
< |
(*putreal)(cval, 3); |
| 551 |
> |
putscolor(r->rcol); |
| 552 |
|
} |
| 553 |
|
|
| 554 |
|
static void |
| 556 |
|
RAY *r |
| 557 |
|
) |
| 558 |
|
{ |
| 559 |
< |
RREAL contr[3]; |
| 559 |
> |
SCOLOR contr; |
| 560 |
|
|
| 561 |
|
raycontrib(contr, r, PRIMARY); |
| 562 |
< |
multcolor(contr, r->rcol); |
| 563 |
< |
(*putreal)(contr, 3); |
| 562 |
> |
smultscolor(contr, r->rcol); |
| 563 |
> |
putscolor(contr); |
| 564 |
|
} |
| 565 |
|
|
| 566 |
|
static void |
| 660 |
|
RAY *r |
| 661 |
|
) |
| 662 |
|
{ |
| 663 |
< |
RREAL contr[3]; |
| 663 |
> |
SCOLOR contr; |
| 664 |
|
/* shadow ray not on source? */ |
| 665 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
| 666 |
< |
setcolor(contr, 0.0, 0.0, 0.0); |
| 666 |
> |
scolorblack(contr); |
| 667 |
|
else |
| 668 |
|
raycontrib(contr, r, PRIMARY); |
| 669 |
|
|
| 670 |
< |
(*putreal)(contr, 3); |
| 670 |
> |
putscolor(contr); |
| 671 |
|
} |
| 672 |
|
|
| 673 |
|
static void |
| 766 |
|
error(INTERNAL, "putrgbe() not called with 3 components"); |
| 767 |
|
setcolr(cout, v[0], v[1], v[2]); |
| 768 |
|
putbinary(cout, sizeof(cout), 1, stdout); |
| 769 |
+ |
} |
| 770 |
+ |
|
| 771 |
+ |
void |
| 772 |
+ |
putscolor(COLORV *scol) /* output (spectral) color */ |
| 773 |
+ |
{ |
| 774 |
+ |
static COLORMAT xyz2myrgbmat; |
| 775 |
+ |
SCOLOR my_scol; |
| 776 |
+ |
COLOR col; |
| 777 |
+ |
/* single channel output? */ |
| 778 |
+ |
if (sens_curve != NULL) { |
| 779 |
+ |
RREAL v = (*sens_curve)(scol) * out_scalefactor; |
| 780 |
+ |
(*putreal)(&v, 1); |
| 781 |
+ |
return; |
| 782 |
+ |
} |
| 783 |
+ |
if (out_scalefactor != 1.) { /* apply scalefactor if any */ |
| 784 |
+ |
copyscolor(my_scol, scol); |
| 785 |
+ |
scalescolor(my_scol, out_scalefactor); |
| 786 |
+ |
scol = my_scol; |
| 787 |
+ |
} |
| 788 |
+ |
if (out_prims == NULL) { /* full spectral reporting */ |
| 789 |
+ |
if (outform == 'c') { |
| 790 |
+ |
SCOLR sclr; |
| 791 |
+ |
scolor_scolr(sclr, scol); |
| 792 |
+ |
putbinary(sclr, LSCOLR, 1, stdout); |
| 793 |
+ |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
| 794 |
+ |
RREAL sreal[MAXCSAMP]; |
| 795 |
+ |
int i = NCSAMP; |
| 796 |
+ |
while (i--) sreal[i] = scol[i]; |
| 797 |
+ |
(*putreal)(sreal, NCSAMP); |
| 798 |
+ |
} else |
| 799 |
+ |
(*putreal)((RREAL *)scol, NCSAMP); |
| 800 |
+ |
return; |
| 801 |
+ |
} |
| 802 |
+ |
if (out_prims == xyzprims) { |
| 803 |
+ |
scolor_cie(col, scol); |
| 804 |
+ |
} else if (out_prims == stdprims) { |
| 805 |
+ |
scolor_rgb(col, scol); |
| 806 |
+ |
} else { |
| 807 |
+ |
COLOR xyz; |
| 808 |
+ |
if (xyz2myrgbmat[0][0] == 0) |
| 809 |
+ |
compxyz2rgbWBmat(xyz2myrgbmat, out_prims); |
| 810 |
+ |
scolor_cie(xyz, scol); |
| 811 |
+ |
colortrans(col, xyz2myrgbmat, xyz); |
| 812 |
+ |
clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); |
| 813 |
+ |
} |
| 814 |
+ |
if (outform == 'c') { |
| 815 |
+ |
COLR clr; |
| 816 |
+ |
setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU)); |
| 817 |
+ |
putbinary(clr, sizeof(COLR), 1, stdout); |
| 818 |
+ |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
| 819 |
+ |
RREAL creal[3]; |
| 820 |
+ |
copycolor(creal, col); |
| 821 |
+ |
(*putreal)(creal, 3); |
| 822 |
+ |
} else |
| 823 |
+ |
(*putreal)((RREAL *)col, 3); |
| 824 |
|
} |