| 1 | 
– | 
/* Copyright (c) 1997 Regents of the University of California */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 2 | 
> | 
static const char       RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 * Convert colors and spectral ranges. | 
| 6 | 
+ | 
 * Added von Kries white-balance calculations 10/01 (GW). | 
| 7 | 
+ | 
 * | 
| 8 | 
+ | 
 * Externals declared in color.h | 
| 9 | 
  | 
 */ | 
| 10 | 
  | 
 | 
| 11 | 
+ | 
#include "copyright.h" | 
| 12 | 
+ | 
 | 
| 13 | 
+ | 
#include <stdio.h> | 
| 14 | 
+ | 
#include <string.h> | 
| 15 | 
  | 
#include "color.h" | 
| 16 | 
  | 
 | 
| 17 | 
+ | 
#define CEPS    1e-4                    /* color epsilon */ | 
| 18 | 
  | 
 | 
| 19 | 
< | 
RGBPRIMS  stdprims = STDPRIMS;          /* standard primary chromaticities */ | 
| 19 | 
> | 
#define CEQ(v1,v2)      ((v1) <= (v2)+CEPS && (v2) <= (v1)+CEPS) | 
| 20 | 
  | 
 | 
| 21 | 
+ | 
#define XYEQ(c1,c2)     (CEQ((c1)[CIEX],(c2)[CIEX]) && CEQ((c1)[CIEY],(c2)[CIEY])) | 
| 22 | 
+ | 
 | 
| 23 | 
+ | 
 | 
| 24 | 
+ | 
RGBPRIMS  stdprims = STDPRIMS;  /* standard primary chromaticities */ | 
| 25 | 
+ | 
 | 
| 26 | 
  | 
COLOR  cblack = BLKCOLOR;               /* global black color */ | 
| 27 | 
  | 
COLOR  cwhite = WHTCOLOR;               /* global white color */ | 
| 28 | 
  | 
 | 
| 29 | 
+ | 
float  xyneu[2] = {1./3., 1./3.};       /* neutral xy chromaticities */ | 
| 30 | 
+ | 
 | 
| 31 | 
  | 
/* | 
| 32 | 
  | 
 *      The following table contains the CIE tristimulus integrals | 
| 33 | 
  | 
 *  for X, Y, and Z.  The table is cumulative, so that | 
| 57 | 
  | 
        } | 
| 58 | 
  | 
}; | 
| 59 | 
  | 
 | 
| 60 | 
< | 
COLORMAT  xyz2rgbmat = {                /* XYZ to RGB */ | 
| 60 | 
> | 
COLORMAT  xyz2rgbmat = {                /* XYZ to RGB (no white balance) */ | 
| 61 | 
  | 
        {(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD, | 
| 62 | 
  | 
         (CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD, | 
| 63 | 
  | 
         (CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD}, | 
| 69 | 
  | 
         (CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD} | 
| 70 | 
  | 
}; | 
| 71 | 
  | 
 | 
| 72 | 
< | 
COLORMAT  rgb2xyzmat = {                /* RGB to XYZ */ | 
| 72 | 
> | 
COLORMAT  rgb2xyzmat = {                /* RGB to XYZ (no white balance) */ | 
| 73 | 
  | 
        {CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D}, | 
| 74 | 
  | 
        {CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D}, | 
| 75 | 
  | 
        {(1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D, | 
| 77 | 
  | 
         (1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D} | 
| 78 | 
  | 
}; | 
| 79 | 
  | 
 | 
| 80 | 
+ | 
COLORMAT  vkmat = {             /* Sharp primary matrix */ | 
| 81 | 
+ | 
        { 1.2694, -0.0988, -0.1706}, | 
| 82 | 
+ | 
        {-0.8364,  1.8006,  0.0357}, | 
| 83 | 
+ | 
        { 0.0297, -0.0315,  1.0018} | 
| 84 | 
+ | 
}; | 
| 85 | 
  | 
 | 
| 86 | 
+ | 
COLORMAT  ivkmat = {            /* inverse Sharp primary matrix */ | 
| 87 | 
+ | 
        { 0.8156,  0.0472,  0.1372}, | 
| 88 | 
+ | 
        { 0.3791,  0.5769,  0.0440}, | 
| 89 | 
+ | 
        {-0.0123,  0.0167,  0.9955} | 
| 90 | 
+ | 
}; | 
| 91 | 
  | 
 | 
| 92 | 
< | 
spec_rgb(col, s, e)             /* compute RGB color from spectral range */ | 
| 93 | 
< | 
COLOR  col; | 
| 94 | 
< | 
int  s, e; | 
| 92 | 
> | 
 | 
| 93 | 
> | 
void | 
| 94 | 
> | 
spec_rgb(                       /* compute RGB color from spectral range */ | 
| 95 | 
> | 
COLOR  col, | 
| 96 | 
> | 
int  s, | 
| 97 | 
> | 
int  e | 
| 98 | 
> | 
) | 
| 99 | 
  | 
{ | 
| 100 | 
  | 
        COLOR  ciecolor; | 
| 101 | 
  | 
 | 
| 104 | 
  | 
} | 
| 105 | 
  | 
 | 
| 106 | 
  | 
 | 
| 107 | 
< | 
spec_cie(col, s, e)             /* compute a color from a spectral range */ | 
| 108 | 
< | 
COLOR  col;             /* returned color */ | 
| 109 | 
< | 
int  s, e;              /* starting and ending wavelengths */ | 
| 107 | 
> | 
void | 
| 108 | 
> | 
spec_cie(                       /* compute a color from a spectral range */ | 
| 109 | 
> | 
COLOR  col,             /* returned color */ | 
| 110 | 
> | 
int  s,                 /* starting and ending wavelengths */ | 
| 111 | 
> | 
int  e | 
| 112 | 
> | 
) | 
| 113 | 
  | 
{ | 
| 114 | 
  | 
        register int  i, d, r; | 
| 115 | 
  | 
         | 
| 141 | 
  | 
} | 
| 142 | 
  | 
 | 
| 143 | 
  | 
 | 
| 144 | 
< | 
cie_rgb(rgb, xyz)               /* convert CIE color to standard RGB */ | 
| 145 | 
< | 
COLOR   rgb, xyz; | 
| 144 | 
> | 
void | 
| 145 | 
> | 
cie_rgb(                        /* convert CIE color to standard RGB */ | 
| 146 | 
> | 
COLOR   rgb, | 
| 147 | 
> | 
COLOR  xyz | 
| 148 | 
> | 
) | 
| 149 | 
  | 
{ | 
| 150 | 
  | 
        colortrans(rgb, xyz2rgbmat, xyz); | 
| 151 | 
  | 
        clipgamut(rgb, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); | 
| 153 | 
  | 
 | 
| 154 | 
  | 
 | 
| 155 | 
  | 
int | 
| 156 | 
< | 
clipgamut(col, brt, gamut, lower, upper)        /* clip to gamut cube */ | 
| 157 | 
< | 
COLOR  col; | 
| 158 | 
< | 
double  brt; | 
| 159 | 
< | 
int  gamut; | 
| 160 | 
< | 
COLOR  lower, upper; | 
| 156 | 
> | 
clipgamut(                      /* clip to gamut cube */ | 
| 157 | 
> | 
COLOR  col, | 
| 158 | 
> | 
double  brt, | 
| 159 | 
> | 
int  gamut, | 
| 160 | 
> | 
COLOR  lower, | 
| 161 | 
> | 
COLOR  upper | 
| 162 | 
> | 
) | 
| 163 | 
  | 
{ | 
| 164 | 
  | 
        int  rflags = 0; | 
| 165 | 
  | 
        double  brtmin, brtmax, v, vv; | 
| 200 | 
  | 
} | 
| 201 | 
  | 
 | 
| 202 | 
  | 
 | 
| 203 | 
< | 
colortrans(c2, mat, c1)         /* convert c1 by mat and put into c2 */ | 
| 204 | 
< | 
register COLORMAT  mat; | 
| 205 | 
< | 
register COLOR  c1, c2; | 
| 203 | 
> | 
void | 
| 204 | 
> | 
colortrans(                     /* convert c1 by mat and put into c2 */ | 
| 205 | 
> | 
register COLOR  c2, | 
| 206 | 
> | 
register COLORMAT  mat, | 
| 207 | 
> | 
register COLOR  c1 | 
| 208 | 
> | 
) | 
| 209 | 
  | 
{ | 
| 210 | 
  | 
        COLOR   cout; | 
| 211 | 
  | 
 | 
| 217 | 
  | 
} | 
| 218 | 
  | 
 | 
| 219 | 
  | 
 | 
| 220 | 
< | 
multcolormat(m3, m2, m1)        /* multiply m1 by m2 and put into m3 */ | 
| 221 | 
< | 
COLORMAT  m1, m2, m3;           /* m3 can be either m1 or m2 w/o harm */ | 
| 220 | 
> | 
void | 
| 221 | 
> | 
multcolormat(                   /* multiply m1 by m2 and put into m3 */ | 
| 222 | 
> | 
COLORMAT  m3,                   /* m3 can be either m1 or m2 w/o harm */ | 
| 223 | 
> | 
COLORMAT  m2, | 
| 224 | 
> | 
COLORMAT  m1 | 
| 225 | 
> | 
) | 
| 226 | 
  | 
{ | 
| 227 | 
  | 
        COLORMAT  mt; | 
| 228 | 
  | 
        register int  i, j; | 
| 236 | 
  | 
} | 
| 237 | 
  | 
 | 
| 238 | 
  | 
 | 
| 239 | 
< | 
compxyz2rgbmat(mat, pr)         /* compute conversion from CIE to RGB space */ | 
| 240 | 
< | 
COLORMAT  mat; | 
| 241 | 
< | 
register RGBPRIMS  pr; | 
| 239 | 
> | 
int | 
| 240 | 
> | 
colorprimsOK(                   /* are color primaries reasonable? */ | 
| 241 | 
> | 
RGBPRIMS  pr | 
| 242 | 
> | 
) | 
| 243 | 
  | 
{ | 
| 244 | 
+ | 
        int     i; | 
| 245 | 
+ | 
         | 
| 246 | 
+ | 
        for (i = 0; i < 4; i++) { | 
| 247 | 
+ | 
                if ((pr[i][CIEX] <= -.5 | (pr[i][CIEY] <= -.5)) | 
| 248 | 
+ | 
                        return(0); | 
| 249 | 
+ | 
                if ((pr[i][CIEX] >= 1.5) | (pr[i][CIEY] >= 1.5)) | 
| 250 | 
+ | 
                        return(0); | 
| 251 | 
+ | 
                if (pr[i][CIEX] + pr[i][CIEY] >= 1.5) | 
| 252 | 
+ | 
                        return(0); | 
| 253 | 
+ | 
        } | 
| 254 | 
+ | 
        return(1); | 
| 255 | 
+ | 
} | 
| 256 | 
+ | 
 | 
| 257 | 
+ | 
 | 
| 258 | 
+ | 
 | 
| 259 | 
+ | 
int | 
| 260 | 
+ | 
compxyz2rgbmat(                 /* compute conversion from CIE to RGB space */ | 
| 261 | 
+ | 
COLORMAT  mat, | 
| 262 | 
+ | 
register RGBPRIMS  pr | 
| 263 | 
+ | 
) | 
| 264 | 
+ | 
{ | 
| 265 | 
  | 
        double  C_rD, C_gD, C_bD; | 
| 266 | 
  | 
 | 
| 267 | 
  | 
        if (pr == stdprims) {   /* can use xyz2rgbmat */ | 
| 268 | 
  | 
                cpcolormat(mat, xyz2rgbmat); | 
| 269 | 
< | 
                return; | 
| 269 | 
> | 
                return(1); | 
| 270 | 
  | 
        } | 
| 271 | 
+ | 
        if (CEQ(pr[WHT][CIEX],0.) | CEQ(pr[WHT][CIEY],0.)) | 
| 272 | 
+ | 
                return(0); | 
| 273 | 
  | 
        C_rD = (1./pr[WHT][CIEY]) * | 
| 274 | 
  | 
                        ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) - | 
| 275 | 
  | 
                          pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) + | 
| 276 | 
  | 
                  pr[GRN][CIEX]*pr[BLU][CIEY] - pr[BLU][CIEX]*pr[GRN][CIEY] ) ; | 
| 277 | 
+ | 
        if (CEQ(C_rD,0.)) | 
| 278 | 
+ | 
                return(0); | 
| 279 | 
  | 
        C_gD = (1./pr[WHT][CIEY]) * | 
| 280 | 
  | 
                        ( pr[WHT][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) - | 
| 281 | 
  | 
                          pr[WHT][CIEY]*(pr[BLU][CIEX] - pr[RED][CIEX]) - | 
| 282 | 
  | 
                  pr[RED][CIEX]*pr[BLU][CIEY] + pr[BLU][CIEX]*pr[RED][CIEY] ) ; | 
| 283 | 
+ | 
        if (CEQ(C_gD,0.)) | 
| 284 | 
+ | 
                return(0); | 
| 285 | 
  | 
        C_bD = (1./pr[WHT][CIEY]) * | 
| 286 | 
  | 
                        ( pr[WHT][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) - | 
| 287 | 
  | 
                          pr[WHT][CIEY]*(pr[RED][CIEX] - pr[GRN][CIEX]) + | 
| 288 | 
  | 
                  pr[RED][CIEX]*pr[GRN][CIEY] - pr[GRN][CIEX]*pr[RED][CIEY] ) ; | 
| 289 | 
< | 
 | 
| 289 | 
> | 
        if (CEQ(C_bD,0.)) | 
| 290 | 
> | 
                return(0); | 
| 291 | 
  | 
        mat[0][0] = (pr[GRN][CIEY] - pr[BLU][CIEY] - | 
| 292 | 
  | 
                        pr[BLU][CIEX]*pr[GRN][CIEY] + | 
| 293 | 
  | 
                        pr[BLU][CIEY]*pr[GRN][CIEX])/C_rD ; | 
| 312 | 
  | 
                        pr[RED][CIEX]*pr[GRN][CIEY])/C_bD ; | 
| 313 | 
  | 
        mat[2][2] = (pr[RED][CIEX]*pr[GRN][CIEY] - | 
| 314 | 
  | 
                        pr[GRN][CIEX]*pr[RED][CIEY])/C_bD ; | 
| 315 | 
+ | 
        return(1); | 
| 316 | 
  | 
} | 
| 317 | 
  | 
 | 
| 318 | 
  | 
 | 
| 319 | 
< | 
comprgb2xyzmat(mat, pr)         /* compute conversion from RGB to CIE space */ | 
| 320 | 
< | 
COLORMAT  mat; | 
| 321 | 
< | 
register RGBPRIMS  pr; | 
| 319 | 
> | 
int | 
| 320 | 
> | 
comprgb2xyzmat(                 /* compute conversion from RGB to CIE space */ | 
| 321 | 
> | 
COLORMAT  mat, | 
| 322 | 
> | 
register RGBPRIMS  pr | 
| 323 | 
> | 
) | 
| 324 | 
  | 
{ | 
| 325 | 
  | 
        double  C_rD, C_gD, C_bD, D; | 
| 326 | 
  | 
 | 
| 327 | 
  | 
        if (pr == stdprims) {   /* can use rgb2xyzmat */ | 
| 328 | 
  | 
                cpcolormat(mat, rgb2xyzmat); | 
| 329 | 
< | 
                return; | 
| 329 | 
> | 
                return(1); | 
| 330 | 
  | 
        } | 
| 331 | 
+ | 
        if (CEQ(pr[WHT][CIEX],0.) | CEQ(pr[WHT][CIEY],0.)) | 
| 332 | 
+ | 
                return(0); | 
| 333 | 
  | 
        C_rD = (1./pr[WHT][CIEY]) * | 
| 334 | 
  | 
                        ( pr[WHT][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) - | 
| 335 | 
  | 
                          pr[WHT][CIEY]*(pr[GRN][CIEX] - pr[BLU][CIEX]) + | 
| 345 | 
  | 
        D = pr[RED][CIEX]*(pr[GRN][CIEY] - pr[BLU][CIEY]) + | 
| 346 | 
  | 
                        pr[GRN][CIEX]*(pr[BLU][CIEY] - pr[RED][CIEY]) + | 
| 347 | 
  | 
                        pr[BLU][CIEX]*(pr[RED][CIEY] - pr[GRN][CIEY]) ; | 
| 348 | 
+ | 
        if (CEQ(D,0.)) | 
| 349 | 
+ | 
                return(0); | 
| 350 | 
  | 
        mat[0][0] = pr[RED][CIEX]*C_rD/D; | 
| 351 | 
  | 
        mat[0][1] = pr[GRN][CIEX]*C_gD/D; | 
| 352 | 
  | 
        mat[0][2] = pr[BLU][CIEX]*C_bD/D; | 
| 356 | 
  | 
        mat[2][0] = (1.-pr[RED][CIEX]-pr[RED][CIEY])*C_rD/D; | 
| 357 | 
  | 
        mat[2][1] = (1.-pr[GRN][CIEX]-pr[GRN][CIEY])*C_gD/D; | 
| 358 | 
  | 
        mat[2][2] = (1.-pr[BLU][CIEX]-pr[BLU][CIEY])*C_bD/D; | 
| 359 | 
+ | 
        return(1); | 
| 360 | 
  | 
} | 
| 361 | 
  | 
 | 
| 362 | 
  | 
 | 
| 363 | 
< | 
comprgb2rgbmat(mat, pr1, pr2)   /* compute conversion from RGB1 to RGB2 */ | 
| 364 | 
< | 
COLORMAT  mat; | 
| 365 | 
< | 
RGBPRIMS  pr1, pr2; | 
| 363 | 
> | 
int | 
| 364 | 
> | 
comprgb2rgbmat(                 /* compute conversion from RGB1 to RGB2 */ | 
| 365 | 
> | 
COLORMAT  mat, | 
| 366 | 
> | 
RGBPRIMS  pr1, | 
| 367 | 
> | 
RGBPRIMS  pr2 | 
| 368 | 
> | 
) | 
| 369 | 
  | 
{ | 
| 370 | 
  | 
        COLORMAT  pr1toxyz, xyztopr2; | 
| 371 | 
  | 
 | 
| 373 | 
  | 
                mat[0][0] = mat[1][1] = mat[2][2] = 1.0; | 
| 374 | 
  | 
                mat[0][1] = mat[0][2] = mat[1][0] = | 
| 375 | 
  | 
                mat[1][2] = mat[2][0] = mat[2][1] = 0.0; | 
| 376 | 
< | 
                return; | 
| 376 | 
> | 
                return(1); | 
| 377 | 
  | 
        } | 
| 378 | 
< | 
        comprgb2xyzmat(pr1toxyz, pr1); | 
| 379 | 
< | 
        compxyz2rgbmat(xyztopr2, pr2); | 
| 378 | 
> | 
        if (!comprgb2xyzmat(pr1toxyz, pr1)) | 
| 379 | 
> | 
                return(0); | 
| 380 | 
> | 
        if (!compxyz2rgbmat(xyztopr2, pr2)) | 
| 381 | 
> | 
                return(0); | 
| 382 | 
  | 
                                /* combine transforms */ | 
| 383 | 
  | 
        multcolormat(mat, pr1toxyz, xyztopr2); | 
| 384 | 
+ | 
        return(1); | 
| 385 | 
+ | 
} | 
| 386 | 
+ | 
 | 
| 387 | 
+ | 
 | 
| 388 | 
+ | 
int | 
| 389 | 
+ | 
compxyzWBmat(                   /* CIE von Kries transform from wht1 to wht2 */ | 
| 390 | 
+ | 
COLORMAT  mat, | 
| 391 | 
+ | 
float  wht1[2], | 
| 392 | 
+ | 
float  wht2[2] | 
| 393 | 
+ | 
) | 
| 394 | 
+ | 
{ | 
| 395 | 
+ | 
        COLOR   cw1, cw2; | 
| 396 | 
+ | 
        if (XYEQ(wht1,wht2)) { | 
| 397 | 
+ | 
                mat[0][0] = mat[1][1] = mat[2][2] = 1.0; | 
| 398 | 
+ | 
                mat[0][1] = mat[0][2] = mat[1][0] = | 
| 399 | 
+ | 
                mat[1][2] = mat[2][0] = mat[2][1] = 0.0; | 
| 400 | 
+ | 
                return(1); | 
| 401 | 
+ | 
        } | 
| 402 | 
+ | 
        if (CEQ(wht1[CIEX],0.) | CEQ(wht1[CIEY],0.)) | 
| 403 | 
+ | 
                return(0); | 
| 404 | 
+ | 
        cw1[RED] = wht1[CIEX]/wht1[CIEY]; | 
| 405 | 
+ | 
        cw1[GRN] = 1.; | 
| 406 | 
+ | 
        cw1[BLU] = (1. - wht1[CIEX] - wht1[CIEY])/wht1[CIEY]; | 
| 407 | 
+ | 
        colortrans(cw1, vkmat, cw1); | 
| 408 | 
+ | 
        if (CEQ(wht2[CIEX],0.) | CEQ(wht2[CIEY],0.)) | 
| 409 | 
+ | 
                return(0); | 
| 410 | 
+ | 
        cw2[RED] = wht2[CIEX]/wht2[CIEY]; | 
| 411 | 
+ | 
        cw2[GRN] = 1.; | 
| 412 | 
+ | 
        cw2[BLU] = (1. - wht2[CIEX] - wht2[CIEY])/wht2[CIEY]; | 
| 413 | 
+ | 
        colortrans(cw2, vkmat, cw2); | 
| 414 | 
+ | 
        if (CEQ(cw1[RED],0.) | CEQ(cw1[GRN],0.) | CEQ(cw1[BLU],0.)) | 
| 415 | 
+ | 
                return(0); | 
| 416 | 
+ | 
        mat[0][0] = cw2[RED]/cw1[RED]; | 
| 417 | 
+ | 
        mat[1][1] = cw2[GRN]/cw1[GRN]; | 
| 418 | 
+ | 
        mat[2][2] = cw2[BLU]/cw1[BLU]; | 
| 419 | 
+ | 
        mat[0][1] = mat[0][2] = mat[1][0] = | 
| 420 | 
+ | 
        mat[1][2] = mat[2][0] = mat[2][1] = 0.0; | 
| 421 | 
+ | 
        multcolormat(mat, vkmat, mat); | 
| 422 | 
+ | 
        multcolormat(mat, mat, ivkmat); | 
| 423 | 
+ | 
        return(1); | 
| 424 | 
+ | 
} | 
| 425 | 
+ | 
 | 
| 426 | 
+ | 
 | 
| 427 | 
+ | 
int | 
| 428 | 
+ | 
compxyz2rgbWBmat(               /* von Kries conversion from CIE to RGB space */ | 
| 429 | 
+ | 
COLORMAT  mat, | 
| 430 | 
+ | 
RGBPRIMS  pr | 
| 431 | 
+ | 
) | 
| 432 | 
+ | 
{ | 
| 433 | 
+ | 
        COLORMAT        wbmat; | 
| 434 | 
+ | 
 | 
| 435 | 
+ | 
        if (!compxyz2rgbmat(mat, pr)) | 
| 436 | 
+ | 
                return(0); | 
| 437 | 
+ | 
        if (XYEQ(pr[WHT],xyneu)) | 
| 438 | 
+ | 
                return(1); | 
| 439 | 
+ | 
        if (!compxyzWBmat(wbmat, xyneu, pr[WHT])) | 
| 440 | 
+ | 
                return(0); | 
| 441 | 
+ | 
        multcolormat(mat, wbmat, mat); | 
| 442 | 
+ | 
        return(1); | 
| 443 | 
+ | 
} | 
| 444 | 
+ | 
 | 
| 445 | 
+ | 
int | 
| 446 | 
+ | 
comprgb2xyzWBmat(               /* von Kries conversion from RGB to CIE space */ | 
| 447 | 
+ | 
COLORMAT  mat, | 
| 448 | 
+ | 
RGBPRIMS  pr | 
| 449 | 
+ | 
) | 
| 450 | 
+ | 
{ | 
| 451 | 
+ | 
        COLORMAT        wbmat; | 
| 452 | 
+ | 
         | 
| 453 | 
+ | 
        if (!comprgb2xyzmat(mat, pr)) | 
| 454 | 
+ | 
                return(0); | 
| 455 | 
+ | 
        if (XYEQ(pr[WHT],xyneu)) | 
| 456 | 
+ | 
                return(1); | 
| 457 | 
+ | 
        if (!compxyzWBmat(wbmat, pr[WHT], xyneu)) | 
| 458 | 
+ | 
                return(0); | 
| 459 | 
+ | 
        multcolormat(mat, mat, wbmat); | 
| 460 | 
+ | 
        return(1); | 
| 461 | 
+ | 
} | 
| 462 | 
+ | 
 | 
| 463 | 
+ | 
int | 
| 464 | 
+ | 
comprgb2rgbWBmat(               /* von Kries conversion from RGB1 to RGB2 */ | 
| 465 | 
+ | 
COLORMAT  mat, | 
| 466 | 
+ | 
RGBPRIMS  pr1, | 
| 467 | 
+ | 
RGBPRIMS  pr2 | 
| 468 | 
+ | 
) | 
| 469 | 
+ | 
{ | 
| 470 | 
+ | 
        COLORMAT  pr1toxyz, xyztopr2, wbmat; | 
| 471 | 
+ | 
 | 
| 472 | 
+ | 
        if (pr1 == pr2) { | 
| 473 | 
+ | 
                mat[0][0] = mat[1][1] = mat[2][2] = 1.0; | 
| 474 | 
+ | 
                mat[0][1] = mat[0][2] = mat[1][0] = | 
| 475 | 
+ | 
                mat[1][2] = mat[2][0] = mat[2][1] = 0.0; | 
| 476 | 
+ | 
                return(1); | 
| 477 | 
+ | 
        } | 
| 478 | 
+ | 
        if (!comprgb2xyzmat(pr1toxyz, pr1)) | 
| 479 | 
+ | 
                return(0); | 
| 480 | 
+ | 
        if (!compxyzWBmat(wbmat, pr1[WHT], pr2[WHT])) | 
| 481 | 
+ | 
                return(0); | 
| 482 | 
+ | 
        if (!compxyz2rgbmat(xyztopr2, pr2)) | 
| 483 | 
+ | 
                return(0); | 
| 484 | 
+ | 
                                /* combine transforms */ | 
| 485 | 
+ | 
        multcolormat(mat, pr1toxyz, wbmat); | 
| 486 | 
+ | 
        multcolormat(mat, mat, xyztopr2); | 
| 487 | 
+ | 
        return(1); | 
| 488 | 
  | 
} |