--- ray/src/common/spec_rgb.c 2024/01/17 17:36:20 2.32 +++ ray/src/common/spec_rgb.c 2024/08/14 20:05:23 2.34 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: spec_rgb.c,v 2.32 2024/01/17 17:36:20 greg Exp $"; +static const char RCSid[] = "$Id: spec_rgb.c,v 2.34 2024/08/14 20:05:23 greg Exp $"; #endif /* * Convert colors and spectral ranges. @@ -277,7 +277,7 @@ int e static double spec_dot( /* spectrum dot-product with cumulative observer */ - SCOLOR scol, + const SCOLOR scol, int ncs, const float wlpt[4], const unsigned short cumul[], @@ -312,7 +312,7 @@ spec_dot( /* spectrum dot-product with cumulative ob void scolor2cie( /* accurate conversion from spectrum to XYZ */ COLOR col, - SCOLOR scol, + const SCOLOR scol, int ncs, const float wlpt[4] ) @@ -330,7 +330,7 @@ scolor2cie( /* accurate conversion from spectrum to void scolor2rgb( /* accurate conversion from spectrum to RGB */ COLOR col, - SCOLOR scol, + const SCOLOR scol, int ncs, const float wlpt[4] ) @@ -346,9 +346,39 @@ scolor2rgb( /* accurate conversion from spectrum to } +void +scolor_out( /* prepare (spectral) color for output */ + COLORV *cout, + RGBPRIMS pr, + const SCOLOR cres +) +{ + static COLORMAT xyz2myp; + static RGBPRIMP lastp = NULL; + + if (!pr) { /* output is spectral */ + copyscolor(cout, cres); + } else if (pr == stdprims) { /* output is standard RGB */ + scolor_rgb(cout, cres); + } else if (pr == xyzprims) { /* output is XYZ */ + scolor_cie(cout, cres); + scalecolor(cout, WHTEFFICACY); + } else if (NCSAMP > 3) { /* spectral -> custom RGB */ + COLOR xyz; + if (lastp != pr) + compxyz2rgbWBmat(xyz2myp, lastp=pr); + scolor_cie(xyz, cres); + colortrans(cout, xyz2myp, xyz); + clipgamut(cout, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); + } else { /* else copy unknown RGB */ + copycolor(cout, cres); + } +} + + double scolor2photopic( /* compute scotopic integral for spectral color */ - SCOLOR scol, + const SCOLOR scol, int ncs, const float wlpt[4] ) @@ -362,7 +392,7 @@ scolor2photopic( /* compute scotopic integral for spe double scolor2scotopic( /* compute Y channel for spectral color */ - SCOLOR scol, + const SCOLOR scol, int ncs, const float wlpt[4] ) @@ -373,7 +403,7 @@ scolor2scotopic( /* compute Y channel for spectral co double scolor2melanopic( /* compute melanopic integral for spectral color */ - SCOLOR scol, + const SCOLOR scol, int ncs, const float wlpt[4] ) @@ -384,7 +414,7 @@ scolor2melanopic( /* compute melanopic integral for s double scolor_photopic( /* compute scotopic integral for spectral color */ - SCOLOR scol + const SCOLOR scol ) { return(scolor2photopic(scol, NCSAMP, WLPART)); @@ -393,7 +423,7 @@ scolor_photopic( /* compute scotopic integral for spe double scolor_scotopic( /* compute Y channel for spectral color */ - SCOLOR scol + const SCOLOR scol ) { return(scolor2scotopic(scol, NCSAMP, WLPART)); @@ -402,7 +432,7 @@ scolor_scotopic( /* compute Y channel for spectral co double scolor_melanopic( /* compute melanopic integral for spectral color */ - SCOLOR scol + const SCOLOR scol ) { return(scolor2melanopic(scol, NCSAMP, WLPART)); @@ -439,7 +469,7 @@ convertscolorcol( /* any uniform spectrum to working void cie_rgb( /* convert CIE color to standard RGB */ COLOR rgb, -COLOR xyz +const COLOR xyz ) { colortrans(rgb, xyz2rgbmat, xyz); @@ -452,8 +482,8 @@ clipgamut( /* clip to gamut cube */ COLOR col, double brt, int gamut, -COLOR lower, -COLOR upper +const COLOR lower, +const COLOR upper ) { int rflags = 0; @@ -498,8 +528,8 @@ COLOR upper void colortrans( /* convert c1 by mat and put into c2 */ COLOR c2, -COLORMAT mat, -COLOR c1 +const COLORMAT mat, +const COLOR c1 ) { COLOR cout; @@ -515,8 +545,8 @@ COLOR c1 void multcolormat( /* multiply m1 by m2 and put into m3 */ COLORMAT m3, /* m3 can be either m1 or m2 w/o harm */ -COLORMAT m2, -COLORMAT m1 +const COLORMAT m2, +const COLORMAT m1 ) { COLORMAT mt; @@ -708,8 +738,8 @@ RGBPRIMS pr2 int compxyzWBmat( /* CIE von Kries transform from wht1 to wht2 */ COLORMAT mat, -float wht1[2], -float wht2[2] +const float wht1[2], +const float wht2[2] ) { COLOR cw1, cw2;