ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/spec_rgb.c
(Generate patch)

Comparing ray/src/common/spec_rgb.c (file contents):
Revision 2.4 by greg, Thu Jul 7 15:21:25 1994 UTC vs.
Revision 2.5 by greg, Sun Oct 15 14:08:01 1995 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include "color.h"
12  
13 +
14 + RGBPRIMS  stdprims = STDPRIMS;          /* standard primary chromaticities */
15 +
16   /*
17   *      The following table contains the CIE tristimulus integrals
18   *  for X, Y, and Z.  The table is cumulative, so that
# Line 39 | Line 42 | static BYTE  chroma[3][NINC] = {
42          }
43   };
44  
45 < static float  xyz2rgbmat[3][3] = {      /* XYZ to RGB */
45 > COLORMAT  xyz2rgbmat = {                /* XYZ to RGB */
46          {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD,
47           (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD,
48           (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD},
# Line 51 | Line 54 | static float  xyz2rgbmat[3][3] = {     /* XYZ to RGB */
54           (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD}
55   };
56  
57 < static float  rgb2xyzmat[3][3] = {      /* RGB to XYZ */
57 > COLORMAT  rgb2xyzmat = {                /* RGB to XYZ */
58          {CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D},
59          {CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D},
60          {(1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D,
# Line 84 | Line 87 | int  s, e;             /* starting and ending wavelengths */
87  
88          e -= STARTWL;
89          if (e <= s) {
90 <                col[RED] = col[GRN] = col[BLU] = 0.0;
90 >                col[CIEX] = col[CIEY] = col[CIEZ] = 0.0;
91                  return;
92          }
93          if (e >= INCWL*(NINC - 1))
# Line 100 | Line 103 | int  s, e;             /* starting and ending wavelengths */
103          for (i = 0; i < 3; i++)
104                  col[i] -= chroma[i][d]*(INCWL - r) - chroma[i][d + 1]*r;
105  
106 <        col[RED] = (col[RED] + 0.5) / (256*INCWL);
107 <        col[GRN] = (col[GRN] + 0.5) / (256*INCWL);
108 <        col[BLU] = (col[BLU] + 0.5) / (256*INCWL);
106 >        col[CIEX] = (col[CIEX] + 0.5) * (1./(256*INCWL));
107 >        col[CIEY] = (col[CIEY] + 0.5) * (1./(256*INCWL));
108 >        col[CIEZ] = (col[CIEZ] + 0.5) * (1./(256*INCWL));
109   }
110  
111  
112 < cie_rgb(rgbcolor, ciecolor)             /* convert CIE to RGB */
113 < register COLOR  rgbcolor, ciecolor;
112 > colortrans(c2, mat, c1)         /* convert c1 by mat and put into c2 */
113 > register COLORMAT  mat;
114 > register COLOR  c1, c2;
115   {
116 <        register int  i;
116 >        static float  cout[3];
117  
118 <        for (i = 0; i < 3; i++) {
119 <                rgbcolor[i] =   xyz2rgbmat[i][0]*ciecolor[0] +
120 <                                xyz2rgbmat[i][1]*ciecolor[1] +
121 <                                xyz2rgbmat[i][2]*ciecolor[2] ;
122 <                if (rgbcolor[i] < 0.0)
123 <                        rgbcolor[i] = 0.0;
120 <        }
118 >        cout[0] = mat[0][0]*c1[0] + mat[0][1]*c1[1] + mat[0][2]*c1[2];
119 >        cout[1] = mat[1][0]*c1[0] + mat[1][1]*c1[1] + mat[1][2]*c1[2];
120 >        cout[2] = mat[2][0]*c1[0] + mat[2][1]*c1[1] + mat[2][2]*c1[2];
121 >        if((c2[0] = cout[0]) < 0.) c2[0] = 0.;
122 >        if((c2[1] = cout[1]) < 0.) c2[1] = 0.;
123 >        if((c2[2] = cout[2]) < 0.) c2[2] = 0.;
124   }
125  
126  
127 < rgb_cie(ciecolor, rgbcolor)             /* convert RGB to CIE */
128 < register COLOR  ciecolor, rgbcolor;
127 > multcolormat(m3, m2, m1)        /* multiply m1 by m2 and put into m3 */
128 > COLORMAT  m1, m2, m3;           /* m3 can be either m1 or m2 w/o harm */
129   {
130 <        register int  i;
130 >        COLORMAT  mt;
131 >        register int  i, j;
132  
133          for (i = 0; i < 3; i++)
134 <                ciecolor[i] =   rgb2xyzmat[i][0]*rgbcolor[0] +
135 <                                rgb2xyzmat[i][1]*rgbcolor[1] +
136 <                                rgb2xyzmat[i][2]*rgbcolor[2] ;
134 >                for (j = 0; j < 3; j++)
135 >                        mt[i][j] =      m1[i][0]*m2[0][j] +
136 >                                        m1[i][1]*m2[1][j] +
137 >                                        m1[i][2]*m2[2][j] ;
138 >        cpcolormat(m3, mt);
139 > }
140 >
141 >
142 > compxyz2rgbmat(mat, pr)         /* compute conversion from CIE to RGB space */
143 > COLORMAT  mat;
144 > register RGBPRIMS  pr;
145 > {
146 >        double  C_rD, C_gD, C_bD;
147 >
148 >        C_rD = (1./pr[WHT][CIEY]) *
149 >                        ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) -
150 >                          pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) +
151 >                  pr[GRN][CIEX]*pr[BLU][CIEY] - pr[BLU][CIEX]*pr[GRN][CIEY] ) ;
152 >        C_gD = (1./pr[WHT][CIEY]) *
153 >                        ( pr[WHT][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) -
154 >                          pr[WHT][CIEY]*(pr[BLU][CIEX] - pr[RED][CIEX]) -
155 >                  pr[RED][CIEX]*pr[BLU][CIEY] + pr[BLU][CIEX]*pr[RED][CIEY] ) ;
156 >        C_bD = (1./pr[WHT][CIEY]) *
157 >                        ( pr[WHT][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) -
158 >                          pr[WHT][CIEY]*(pr[RED][CIEX] - pr[GRN][CIEX]) +
159 >                  pr[RED][CIEX]*pr[GRN][CIEY] - pr[GRN][CIEX]*pr[RED][CIEY] ) ;
160 >
161 >        mat[0][0] = (pr[GRN][CIEY] - pr[BLU][CIEY] -
162 >                        pr[BLU][CIEX]*pr[GRN][CIEY] +
163 >                        pr[BLU][CIEY]*pr[GRN][CIEX])/C_rD ;
164 >        mat[0][1] = (pr[BLU][CIEX] - pr[GRN][CIEX] -
165 >                        pr[BLU][CIEX]*pr[GRN][CIEY] +
166 >                        pr[GRN][CIEX]*pr[BLU][CIEY])/C_rD ;
167 >        mat[0][2] = (pr[GRN][CIEX]*pr[BLU][CIEY] -
168 >                        pr[BLU][CIEX]*pr[GRN][CIEY])/C_rD ;
169 >        mat[1][0] = (pr[BLU][CIEY] - pr[RED][CIEY] -
170 >                        pr[BLU][CIEY]*pr[RED][CIEX] +
171 >                        pr[RED][CIEY]*pr[BLU][CIEX])/C_gD ;
172 >        mat[1][1] = (pr[RED][CIEX] - pr[BLU][CIEX] -
173 >                        pr[RED][CIEX]*pr[BLU][CIEY] +
174 >                        pr[BLU][CIEX]*pr[RED][CIEY])/C_gD ;
175 >        mat[1][2] = (pr[BLU][CIEX]*pr[RED][CIEY] -
176 >                        pr[RED][CIEX]*pr[BLU][CIEY])/C_gD ;
177 >        mat[2][0] = (pr[RED][CIEY] - pr[GRN][CIEY] -
178 >                        pr[RED][CIEY]*pr[GRN][CIEX] +
179 >                        pr[GRN][CIEY]*pr[RED][CIEX])/C_bD ;
180 >        mat[2][1] = (pr[GRN][CIEX] - pr[RED][CIEX] -
181 >                        pr[GRN][CIEX]*pr[RED][CIEY] +
182 >                        pr[RED][CIEX]*pr[GRN][CIEY])/C_bD ;
183 >        mat[2][2] = (pr[RED][CIEX]*pr[GRN][CIEY] -
184 >                        pr[GRN][CIEX]*pr[RED][CIEY])/C_bD ;
185 > }
186 >
187 >
188 > comprgb2xyzmat(mat, pr)         /* compute conversion from RGB to CIE space */
189 > COLORMAT  mat;
190 > register RGBPRIMS  pr;
191 > {
192 >        double  C_rD, C_gD, C_bD, D;
193 >
194 >        C_rD = (1./pr[WHT][CIEY]) *
195 >                        ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) -
196 >                          pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) +
197 >                  pr[GRN][CIEX]*pr[BLU][CIEY] - pr[BLU][CIEX]*pr[GRN][CIEY] ) ;
198 >        C_gD = (1./pr[WHT][CIEY]) *
199 >                        ( pr[WHT][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) -
200 >                          pr[WHT][CIEY]*(pr[BLU][CIEX] - pr[RED][CIEX]) -
201 >                  pr[RED][CIEX]*pr[BLU][CIEY] + pr[BLU][CIEX]*pr[RED][CIEY] ) ;
202 >        C_bD = (1./pr[WHT][CIEY]) *
203 >                        ( pr[WHT][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) -
204 >                          pr[WHT][CIEY]*(pr[RED][CIEX] - pr[GRN][CIEX]) +
205 >                  pr[RED][CIEX]*pr[GRN][CIEY] - pr[GRN][CIEX]*pr[RED][CIEY] ) ;
206 >        D = pr[RED][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) +
207 >                        pr[GRN][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) +
208 >                        pr[BLU][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) ;
209 >        mat[0][0] = pr[RED][CIEX]*C_rD/D;
210 >        mat[0][1] = pr[GRN][CIEX]*C_gD/D;
211 >        mat[0][2] = pr[BLU][CIEX]*C_bD/D;
212 >        mat[1][0] = pr[RED][CIEY]*C_rD/D;
213 >        mat[1][1] = pr[GRN][CIEY]*C_gD/D;
214 >        mat[1][2] = pr[BLU][CIEY]*C_bD/D;
215 >        mat[2][0] = (1.-pr[RED][CIEX]-pr[RED][CIEY])*C_rD/D;
216 >        mat[2][1] = (1.-pr[GRN][CIEX]-pr[GRN][CIEY])*C_gD/D;
217 >        mat[2][2] = (1.-pr[BLU][CIEX]-pr[BLU][CIEY])*C_bD/D;
218 > }
219 >
220 >
221 > comprgb2rgbmat(mat, pr1, pr2)   /* compute conversion from RGB1 to RGB2 */
222 > COLORMAT  mat;
223 > RGBPRIMS  pr1, pr2;
224 > {
225 >        COLORMAT  pr1toxyz, xyztopr2;
226 >
227 >        if (pr1 == stdprims)    /* can use rgb2xyzmat */
228 >                cpcolormat(pr1toxyz, rgb2xyzmat);
229 >        else                    /* otherwise compute it */
230 >                comprgb2xyzmat(pr1toxyz, pr1);
231 >        if (pr2 == stdprims)    /* can use xyz2rgbmat */
232 >                cpcolormat(xyztopr2, xyz2rgbmat);
233 >        else                    /* otherwise compute it */
234 >                compxyz2rgbmat(xyztopr2, pr2);
235 >                                /* combine transforms */
236 >        multcolormat(mat, pr1toxyz, xyztopr2);
237   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines