--- ray/src/common/spec_rgb.c 1995/10/15 14:08:01 2.5 +++ ray/src/common/spec_rgb.c 1997/01/30 19:14:39 2.7 @@ -1,4 +1,4 @@ -/* Copyright (c) 1990 Regents of the University of California */ +/* Copyright (c) 1997 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -109,18 +109,21 @@ int s, e; /* starting and ending wavelengths */ } -colortrans(c2, mat, c1) /* convert c1 by mat and put into c2 */ +colortrans(c2, mat, c1, noneg) /* convert c1 by mat and put into c2 */ register COLORMAT mat; register COLOR c1, c2; +int noneg; { static float cout[3]; cout[0] = mat[0][0]*c1[0] + mat[0][1]*c1[1] + mat[0][2]*c1[2]; cout[1] = mat[1][0]*c1[0] + mat[1][1]*c1[1] + mat[1][2]*c1[2]; cout[2] = mat[2][0]*c1[0] + mat[2][1]*c1[1] + mat[2][2]*c1[2]; - if((c2[0] = cout[0]) < 0.) c2[0] = 0.; - if((c2[1] = cout[1]) < 0.) c2[1] = 0.; - if((c2[2] = cout[2]) < 0.) c2[2] = 0.; + if (!noneg) + return; + if ((c2[0] = cout[0]) < 0.) c2[0] = 0.; + if ((c2[1] = cout[1]) < 0.) c2[1] = 0.; + if ((c2[2] = cout[2]) < 0.) c2[2] = 0.; } @@ -145,6 +148,10 @@ register RGBPRIMS pr; { double C_rD, C_gD, C_bD; + if (pr == stdprims) { /* can use xyz2rgbmat */ + cpcolormat(mat, xyz2rgbmat); + return; + } C_rD = (1./pr[WHT][CIEY]) * ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) - pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) + @@ -191,6 +198,10 @@ register RGBPRIMS pr; { double C_rD, C_gD, C_bD, D; + if (pr == stdprims) { /* can use rgb2xyzmat */ + cpcolormat(mat, rgb2xyzmat); + return; + } C_rD = (1./pr[WHT][CIEY]) * ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) - pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) + @@ -224,14 +235,14 @@ RGBPRIMS pr1, pr2; { COLORMAT pr1toxyz, xyztopr2; - if (pr1 == stdprims) /* can use rgb2xyzmat */ - cpcolormat(pr1toxyz, rgb2xyzmat); - else /* otherwise compute it */ - comprgb2xyzmat(pr1toxyz, pr1); - if (pr2 == stdprims) /* can use xyz2rgbmat */ - cpcolormat(xyztopr2, xyz2rgbmat); - else /* otherwise compute it */ - compxyz2rgbmat(xyztopr2, pr2); + if (pr1 == pr2) { + mat[0][0] = mat[1][1] = mat[2][2] = 1.0; + mat[0][1] = mat[0][2] = mat[1][0] = + mat[1][2] = mat[2][0] = mat[2][1] = 0.0; + return; + } + comprgb2xyzmat(pr1toxyz, pr1); + compxyz2rgbmat(xyztopr2, pr2); /* combine transforms */ multcolormat(mat, pr1toxyz, xyztopr2); }