--- ray/src/common/spec_rgb.c 2009/11/02 23:45:11 2.17 +++ ray/src/common/spec_rgb.c 2020/09/16 00:42:36 2.26 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: spec_rgb.c,v 2.17 2009/11/02 23:45:11 greg Exp $"; +static const char RCSid[] = "$Id: spec_rgb.c,v 2.26 2020/09/16 00:42:36 greg Exp $"; #endif /* * Convert colors and spectral ranges. @@ -16,9 +16,9 @@ static const char RCSid[] = "$Id: spec_rgb.c,v 2.17 20 #define CEPS 1e-4 /* color epsilon */ -#define CEQ(v1,v2) ((v1) <= (v2)+CEPS && (v2) <= (v1)+CEPS) +#define CEQ(v1,v2) (((v1) <= (v2)+CEPS) & ((v2) <= (v1)+CEPS)) -#define XYEQ(c1,c2) (CEQ((c1)[CIEX],(c2)[CIEX]) && CEQ((c1)[CIEY],(c2)[CIEY])) +#define XYEQ(c1,c2) (CEQ((c1)[CIEX],(c2)[CIEX]) & CEQ((c1)[CIEY],(c2)[CIEY])) RGBPRIMS stdprims = STDPRIMS; /* standard primary chromaticities */ @@ -38,7 +38,7 @@ float xyneu[2] = {1./3., 1./3.}; /* neutral xy chroma #define INCWL 10 /* wavelength increment */ #define NINC 40 /* # of values */ -static BYTE chroma[3][NINC] = { +static uby8 chroma[3][NINC] = { { /* X */ 0, 0, 0, 2, 6, 13, 22, 30, 36, 41, 42, 43, 43, 44, 46, 52, 60, 71, 87, 106, @@ -111,7 +111,7 @@ int s, /* starting and ending wavelengths */ int e ) { - register int i, d, r; + int i, d, r; s -= STARTWL; if (s < 0) @@ -164,7 +164,7 @@ COLOR upper int rflags = 0; double brtmin, brtmax, v, vv; COLOR cgry; - register int i; + int i; /* check for no check */ if (gamut == 0) return(0); /* check brightness limits */ @@ -202,9 +202,9 @@ COLOR upper void colortrans( /* convert c1 by mat and put into c2 */ -register COLOR c2, -register COLORMAT mat, -register COLOR c1 +COLOR c2, +COLORMAT mat, +COLOR c1 ) { COLOR cout; @@ -225,7 +225,7 @@ COLORMAT m1 ) { COLORMAT mt; - register int i, j; + int i, j; for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) @@ -241,16 +241,32 @@ colorprimsOK( /* are color primaries reasonable? */ RGBPRIMS pr ) { - int i; - - for (i = 0; i < 4; i++) { - if ((pr[i][CIEX] <= -CEPS) | (pr[i][CIEY] <= -CEPS)) + int i, j; + /* check white point */ + if ((pr[3][CIEX] <= CEPS) | (pr[3][CIEX] >= 1.-CEPS) | + (pr[3][CIEY] <= CEPS) | (pr[3][CIEY] >= 1.-CEPS)) + return(0); + for (i = 3; i--; ) /* check for XYZ color primaries */ + if (!CEQ(pr[i][CIEX],(i==0)) | !CEQ(pr[i][CIEY],(i==1))) + break; + if (i < 0) + return(-1); /* flag as XYZ color space */ + /* check color primaries */ + for (i = 0; i < 3; i++) { + if ((pr[i][CIEX] <= -2.) | (pr[i][CIEY] <= -2.)) return(0); - if ((pr[i][CIEX] >= 1.+CEPS) | (pr[i][CIEY] >= 1.+CEPS)) + if ((pr[i][CIEX] >= 3.) | (pr[i][CIEY] >= 3.)) return(0); - if (pr[i][CIEX] + pr[i][CIEY] >= 1.+CEPS) + if (pr[i][CIEX] + pr[i][CIEY] <= -2.) return(0); + if (pr[i][CIEX] + pr[i][CIEY] >= 3.) + return(0); } + for (i = 0; i < 4; i++) /* make sure space is 3-dimensional */ + for (j = i+1; j < 4; j++) + if (CEQ(pr[i][CIEX],pr[j][CIEX]) & + CEQ(pr[i][CIEY],pr[j][CIEY])) + return(0); return(1); } @@ -259,7 +275,7 @@ RGBPRIMS pr int compxyz2rgbmat( /* compute conversion from CIE to RGB space */ COLORMAT mat, -register RGBPRIMS pr +RGBPRIMS pr ) { double C_rD, C_gD, C_bD; @@ -319,7 +335,7 @@ register RGBPRIMS pr int comprgb2xyzmat( /* compute conversion from RGB to CIE space */ COLORMAT mat, -register RGBPRIMS pr +RGBPRIMS pr ) { double C_rD, C_gD, C_bD, D;