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 |
70 |
|
static RayReportCall ourtrace; |
71 |
|
static RayReportCall printvals; |
72 |
|
|
73 |
+ |
static void putscolor(COLORV *scol); |
74 |
+ |
|
75 |
|
static oputf_t *ray_out[32], *every_out[32]; |
76 |
|
static putf_t *putreal; |
77 |
|
|
80 |
|
int code |
81 |
|
) |
82 |
|
{ |
83 |
+ |
if (ray_pnprocs < 0) |
84 |
+ |
_exit(code); /* avoid flush in child */ |
85 |
+ |
|
86 |
|
int ec = myRTmanager.Cleanup(); |
87 |
|
|
88 |
|
if (ec) code = ec; |
99 |
|
case 'a': return("ascii"); |
100 |
|
case 'f': return("float"); |
101 |
|
case 'd': return("double"); |
102 |
< |
case 'c': return(COLRFMT); |
102 |
> |
case 'c': |
103 |
> |
if (out_prims == NULL) |
104 |
> |
return(SPECFMT); |
105 |
> |
if (out_prims == xyzprims) |
106 |
> |
return(CIEFMT); |
107 |
> |
return(COLRFMT); |
108 |
|
} |
109 |
|
return("unknown"); |
110 |
|
} |
195 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
196 |
|
error(SYSTEM, errmsg); |
197 |
|
} |
184 |
– |
#ifdef getc_unlocked |
185 |
– |
flockfile(inpfp); /* avoid lock/unlock overhead */ |
186 |
– |
#endif |
198 |
|
if (inform != 'a') |
199 |
|
SET_FILE_BINARY(inpfp); |
200 |
|
/* set up output */ |
214 |
|
if (every_out[0]) |
215 |
|
myRTmanager.SetTraceCall(ourtrace); |
216 |
|
myRTmanager.rtFlags |= RTdoFIFO; |
217 |
+ |
#ifdef getc_unlocked |
218 |
+ |
flockfile(inpfp); /* avoid lock/unlock overhead */ |
219 |
+ |
flockfile(stdout); |
220 |
+ |
#endif |
221 |
|
if (hresolu > 0) { // print resolution string if appropriate |
222 |
|
if (vresolu > 0) |
223 |
|
fprtresolu(hresolu, vresolu, stdout); |
264 |
|
{ |
265 |
|
const char *vs = outvals; |
266 |
|
oputf_t **table = ray_out; |
267 |
+ |
const int nco = (sens_curve != NULL) ? 1 : |
268 |
+ |
(out_prims != NULL) ? 3 : NCSAMP; |
269 |
|
int ncomp = 0; |
270 |
|
|
271 |
|
if (!*vs) |
304 |
|
break; |
305 |
|
case 'r': /* reflected contrib. */ |
306 |
|
*table++ = oputr; |
307 |
< |
ncomp += 3; |
307 |
> |
ncomp += nco; |
308 |
|
castonly = 0; |
309 |
|
break; |
310 |
|
case 'R': /* reflected distance */ |
314 |
|
break; |
315 |
|
case 'x': /* xmit contrib. */ |
316 |
|
*table++ = oputx; |
317 |
< |
ncomp += 3; |
317 |
> |
ncomp += nco; |
318 |
|
castonly = 0; |
319 |
|
break; |
320 |
|
case 'X': /* xmit distance */ |
324 |
|
break; |
325 |
|
case 'v': /* value */ |
326 |
|
*table++ = oputv; |
327 |
< |
ncomp += 3; |
327 |
> |
ncomp += nco; |
328 |
|
castonly = 0; |
329 |
|
break; |
330 |
|
case 'V': /* contribution */ |
331 |
|
*table++ = oputV; |
332 |
< |
ncomp += 3; |
332 |
> |
ncomp += nco; |
333 |
|
castonly = 0; |
334 |
|
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
335 |
|
error(WARNING, |
371 |
|
break; |
372 |
|
case 'W': /* coefficient */ |
373 |
|
*table++ = oputW; |
374 |
< |
ncomp += 3; |
374 |
> |
ncomp += nco; |
375 |
|
castonly = 0; |
376 |
|
if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0)) |
377 |
|
error(WARNING, |
411 |
|
return(ncomp); |
412 |
|
} |
413 |
|
|
414 |
< |
static void |
414 |
> |
static int |
415 |
|
printvals( /* print requested ray values */ |
416 |
|
RAY *r, void *cd |
417 |
|
) |
419 |
|
oputf_t **tp; |
420 |
|
|
421 |
|
if (ray_out[0] == NULL) |
422 |
< |
return; |
406 |
< |
#ifdef getc_unlocked |
407 |
< |
flockfile(stdout); |
408 |
< |
#endif |
422 |
> |
return 0; |
423 |
|
for (tp = ray_out; *tp != NULL; tp++) |
424 |
|
(**tp)(r); |
425 |
|
if (outform == 'a') |
426 |
|
putchar('\n'); |
427 |
< |
#ifdef getc_unlocked |
414 |
< |
funlockfile(stdout); |
415 |
< |
#endif |
427 |
> |
return 1; |
428 |
|
} |
429 |
|
|
430 |
|
void |
455 |
|
} |
456 |
|
} |
457 |
|
|
458 |
< |
static void |
458 |
> |
static int |
459 |
|
ourtrace( /* print ray values */ |
460 |
|
RAY *r, void *cd |
461 |
|
) |
463 |
|
oputf_t **tp; |
464 |
|
|
465 |
|
if (every_out[0] == NULL) |
466 |
< |
return; |
466 |
> |
return 0; |
467 |
|
if (r->ro == NULL) { |
468 |
|
if (traincl == 1) |
469 |
< |
return; |
469 |
> |
return 0; |
470 |
|
} else if (traincl != -1 && traincl != inset(traset, r->ro->omod)) |
471 |
< |
return; |
460 |
< |
#ifdef getc_unlocked |
461 |
< |
flockfile(stdout); |
462 |
< |
#endif |
471 |
> |
return 0; |
472 |
|
tabin(r); |
473 |
|
for (tp = every_out; *tp != NULL; tp++) |
474 |
|
(**tp)(r); |
475 |
|
if (outform == 'a') |
476 |
|
putchar('\n'); |
477 |
< |
#ifdef getc_unlocked |
469 |
< |
funlockfile(stdout); |
470 |
< |
#endif |
477 |
> |
return 1; |
478 |
|
} |
479 |
|
|
480 |
|
static void |
509 |
|
RAY *r |
510 |
|
) |
511 |
|
{ |
512 |
< |
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); |
512 |
> |
putscolor(r->mcol); |
513 |
|
} |
514 |
|
|
515 |
|
static void |
525 |
|
RAY *r |
526 |
|
) |
527 |
|
{ |
528 |
< |
RREAL cval[3]; |
528 |
> |
SCOLOR cdiff; |
529 |
|
|
530 |
< |
cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED); |
531 |
< |
cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN); |
532 |
< |
cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU); |
533 |
< |
(*putreal)(cval, 3); |
530 |
> |
copyscolor(cdiff, r->rcol); |
531 |
> |
sopscolor(cdiff, -=, r->mcol); |
532 |
> |
|
533 |
> |
putscolor(cdiff); |
534 |
|
} |
535 |
|
|
536 |
|
static void |
546 |
|
RAY *r |
547 |
|
) |
548 |
|
{ |
549 |
< |
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); |
549 |
> |
putscolor(r->rcol); |
550 |
|
} |
551 |
|
|
552 |
|
static void |
554 |
|
RAY *r |
555 |
|
) |
556 |
|
{ |
557 |
< |
RREAL contr[3]; |
557 |
> |
SCOLOR contr; |
558 |
|
|
559 |
|
raycontrib(contr, r, PRIMARY); |
560 |
< |
multcolor(contr, r->rcol); |
561 |
< |
(*putreal)(contr, 3); |
560 |
> |
smultscolor(contr, r->rcol); |
561 |
> |
putscolor(contr); |
562 |
|
} |
563 |
|
|
564 |
|
static void |
658 |
|
RAY *r |
659 |
|
) |
660 |
|
{ |
661 |
< |
RREAL contr[3]; |
661 |
> |
SCOLOR contr; |
662 |
|
/* shadow ray not on source? */ |
663 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
664 |
< |
setcolor(contr, 0.0, 0.0, 0.0); |
664 |
> |
scolorblack(contr); |
665 |
|
else |
666 |
|
raycontrib(contr, r, PRIMARY); |
667 |
|
|
668 |
< |
(*putreal)(contr, 3); |
668 |
> |
putscolor(contr); |
669 |
|
} |
670 |
|
|
671 |
|
static void |
764 |
|
error(INTERNAL, "putrgbe() not called with 3 components"); |
765 |
|
setcolr(cout, v[0], v[1], v[2]); |
766 |
|
putbinary(cout, sizeof(cout), 1, stdout); |
767 |
+ |
} |
768 |
+ |
|
769 |
+ |
static void |
770 |
+ |
putscolor(COLORV *scol) /* output (spectral) color */ |
771 |
+ |
{ |
772 |
+ |
static COLORMAT xyz2myrgbmat; |
773 |
+ |
SCOLOR my_scol; |
774 |
+ |
COLOR col; |
775 |
+ |
/* single channel output? */ |
776 |
+ |
if (sens_curve != NULL) { |
777 |
+ |
RREAL v = (*sens_curve)(scol) * out_scalefactor; |
778 |
+ |
(*putreal)(&v, 1); |
779 |
+ |
return; |
780 |
+ |
} |
781 |
+ |
if (out_scalefactor != 1.) { /* apply scalefactor if any */ |
782 |
+ |
copyscolor(my_scol, scol); |
783 |
+ |
scalescolor(my_scol, out_scalefactor); |
784 |
+ |
scol = my_scol; |
785 |
+ |
} |
786 |
+ |
if (out_prims == NULL) { /* full spectral reporting */ |
787 |
+ |
if (outform == 'c') { |
788 |
+ |
SCOLR sclr; |
789 |
+ |
scolor_scolr(sclr, scol); |
790 |
+ |
putbinary(sclr, LSCOLR, 1, stdout); |
791 |
+ |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
792 |
+ |
RREAL sreal[MAXCSAMP]; |
793 |
+ |
int i = NCSAMP; |
794 |
+ |
while (i--) sreal[i] = scol[i]; |
795 |
+ |
(*putreal)(sreal, NCSAMP); |
796 |
+ |
} else |
797 |
+ |
(*putreal)((RREAL *)scol, NCSAMP); |
798 |
+ |
return; |
799 |
+ |
} |
800 |
+ |
if (out_prims == xyzprims) { |
801 |
+ |
scolor_cie(col, scol); |
802 |
+ |
} else if (out_prims == stdprims) { |
803 |
+ |
scolor_rgb(col, scol); |
804 |
+ |
} else { |
805 |
+ |
COLOR xyz; |
806 |
+ |
if (xyz2myrgbmat[0][0] == 0) |
807 |
+ |
compxyz2rgbWBmat(xyz2myrgbmat, out_prims); |
808 |
+ |
scolor_cie(xyz, scol); |
809 |
+ |
colortrans(col, xyz2myrgbmat, xyz); |
810 |
+ |
clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); |
811 |
+ |
} |
812 |
+ |
if (outform == 'c') { |
813 |
+ |
COLR clr; |
814 |
+ |
setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU)); |
815 |
+ |
putbinary(clr, sizeof(COLR), 1, stdout); |
816 |
+ |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
817 |
+ |
RREAL creal[3]; |
818 |
+ |
copycolor(creal, col); |
819 |
+ |
(*putreal)(creal, 3); |
820 |
+ |
} else |
821 |
+ |
(*putreal)((RREAL *)col, 3); |
822 |
|
} |