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 1.3 by greg, Fri Dec 14 12:48:32 1990 UTC vs.
Revision 2.6 by greg, Wed Oct 2 11:05:18 1996 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 < #ifdef  NTSC
46 < static float  xyz2rgbmat[3][3] = {      /* XYZ to RGB (NTSC) */
47 <        1.73, -.48, -.26,
48 <        -.81, 1.65, -.02,
49 <         .08, -.17, 1.28,
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},
49 >        {(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD,
50 >         (CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD,
51 >         (CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD},
52 >        {(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD,
53 >         (CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD,
54 >         (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD}
55   };
56 < #else
57 < static float xyz2rgbmat[3][3] = {       /* XYZ to RGB (color monitor) */
58 <         2.739, -1.145, -.424,
59 <        -1.119,  2.029,  .033,
60 <          .138,  -.333, 1.105,
56 >
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,
61 >         (1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D,
62 >         (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D}
63   };
54 #endif
64  
65  
66  
# Line 78 | 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 94 | 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;
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 > 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 >        COLORMAT  mt;
131 >        register int  i, j;
132 >
133 >        for (i = 0; i < 3; i++)
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 >        if (pr == stdprims) {   /* can use xyz2rgbmat */
149 >                cpcolormat(mat, xyz2rgbmat);
150 >                return;
151          }
152 +        C_rD = (1./pr[WHT][CIEY]) *
153 +                        ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) -
154 +                          pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) +
155 +                  pr[GRN][CIEX]*pr[BLU][CIEY] - pr[BLU][CIEX]*pr[GRN][CIEY] ) ;
156 +        C_gD = (1./pr[WHT][CIEY]) *
157 +                        ( pr[WHT][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) -
158 +                          pr[WHT][CIEY]*(pr[BLU][CIEX] - pr[RED][CIEX]) -
159 +                  pr[RED][CIEX]*pr[BLU][CIEY] + pr[BLU][CIEX]*pr[RED][CIEY] ) ;
160 +        C_bD = (1./pr[WHT][CIEY]) *
161 +                        ( pr[WHT][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) -
162 +                          pr[WHT][CIEY]*(pr[RED][CIEX] - pr[GRN][CIEX]) +
163 +                  pr[RED][CIEX]*pr[GRN][CIEY] - pr[GRN][CIEX]*pr[RED][CIEY] ) ;
164 +
165 +        mat[0][0] = (pr[GRN][CIEY] - pr[BLU][CIEY] -
166 +                        pr[BLU][CIEX]*pr[GRN][CIEY] +
167 +                        pr[BLU][CIEY]*pr[GRN][CIEX])/C_rD ;
168 +        mat[0][1] = (pr[BLU][CIEX] - pr[GRN][CIEX] -
169 +                        pr[BLU][CIEX]*pr[GRN][CIEY] +
170 +                        pr[GRN][CIEX]*pr[BLU][CIEY])/C_rD ;
171 +        mat[0][2] = (pr[GRN][CIEX]*pr[BLU][CIEY] -
172 +                        pr[BLU][CIEX]*pr[GRN][CIEY])/C_rD ;
173 +        mat[1][0] = (pr[BLU][CIEY] - pr[RED][CIEY] -
174 +                        pr[BLU][CIEY]*pr[RED][CIEX] +
175 +                        pr[RED][CIEY]*pr[BLU][CIEX])/C_gD ;
176 +        mat[1][1] = (pr[RED][CIEX] - pr[BLU][CIEX] -
177 +                        pr[RED][CIEX]*pr[BLU][CIEY] +
178 +                        pr[BLU][CIEX]*pr[RED][CIEY])/C_gD ;
179 +        mat[1][2] = (pr[BLU][CIEX]*pr[RED][CIEY] -
180 +                        pr[RED][CIEX]*pr[BLU][CIEY])/C_gD ;
181 +        mat[2][0] = (pr[RED][CIEY] - pr[GRN][CIEY] -
182 +                        pr[RED][CIEY]*pr[GRN][CIEX] +
183 +                        pr[GRN][CIEY]*pr[RED][CIEX])/C_bD ;
184 +        mat[2][1] = (pr[GRN][CIEX] - pr[RED][CIEX] -
185 +                        pr[GRN][CIEX]*pr[RED][CIEY] +
186 +                        pr[RED][CIEX]*pr[GRN][CIEY])/C_bD ;
187 +        mat[2][2] = (pr[RED][CIEX]*pr[GRN][CIEY] -
188 +                        pr[GRN][CIEX]*pr[RED][CIEY])/C_bD ;
189 + }
190 +
191 +
192 + comprgb2xyzmat(mat, pr)         /* compute conversion from RGB to CIE space */
193 + COLORMAT  mat;
194 + register RGBPRIMS  pr;
195 + {
196 +        double  C_rD, C_gD, C_bD, D;
197 +
198 +        if (pr == stdprims) {   /* can use rgb2xyzmat */
199 +                cpcolormat(mat, rgb2xyzmat);
200 +                return;
201 +        }
202 +        C_rD = (1./pr[WHT][CIEY]) *
203 +                        ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) -
204 +                          pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) +
205 +                  pr[GRN][CIEX]*pr[BLU][CIEY] - pr[BLU][CIEX]*pr[GRN][CIEY] ) ;
206 +        C_gD = (1./pr[WHT][CIEY]) *
207 +                        ( pr[WHT][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) -
208 +                          pr[WHT][CIEY]*(pr[BLU][CIEX] - pr[RED][CIEX]) -
209 +                  pr[RED][CIEX]*pr[BLU][CIEY] + pr[BLU][CIEX]*pr[RED][CIEY] ) ;
210 +        C_bD = (1./pr[WHT][CIEY]) *
211 +                        ( pr[WHT][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) -
212 +                          pr[WHT][CIEY]*(pr[RED][CIEX] - pr[GRN][CIEX]) +
213 +                  pr[RED][CIEX]*pr[GRN][CIEY] - pr[GRN][CIEX]*pr[RED][CIEY] ) ;
214 +        D = pr[RED][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) +
215 +                        pr[GRN][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) +
216 +                        pr[BLU][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) ;
217 +        mat[0][0] = pr[RED][CIEX]*C_rD/D;
218 +        mat[0][1] = pr[GRN][CIEX]*C_gD/D;
219 +        mat[0][2] = pr[BLU][CIEX]*C_bD/D;
220 +        mat[1][0] = pr[RED][CIEY]*C_rD/D;
221 +        mat[1][1] = pr[GRN][CIEY]*C_gD/D;
222 +        mat[1][2] = pr[BLU][CIEY]*C_bD/D;
223 +        mat[2][0] = (1.-pr[RED][CIEX]-pr[RED][CIEY])*C_rD/D;
224 +        mat[2][1] = (1.-pr[GRN][CIEX]-pr[GRN][CIEY])*C_gD/D;
225 +        mat[2][2] = (1.-pr[BLU][CIEX]-pr[BLU][CIEY])*C_bD/D;
226 + }
227 +
228 +
229 + comprgb2rgbmat(mat, pr1, pr2)   /* compute conversion from RGB1 to RGB2 */
230 + COLORMAT  mat;
231 + RGBPRIMS  pr1, pr2;
232 + {
233 +        COLORMAT  pr1toxyz, xyztopr2;
234 +
235 +        if (pr1 == pr2) {
236 +                mat[0][0] = mat[1][1] = mat[2][2] = 1.0;
237 +                mat[0][1] = mat[0][2] = mat[1][0] =
238 +                mat[1][2] = mat[2][0] = mat[2][1] = 0.0;
239 +                return;
240 +        }
241 +        comprgb2xyzmat(pr1toxyz, pr1);
242 +        compxyz2rgbmat(xyztopr2, pr2);
243 +                                /* combine transforms */
244 +        multcolormat(mat, pr1toxyz, xyztopr2);
245   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines