Back to index

radiance  4R0+20100331
Defines | Typedefs | Functions | Variables
color.h File Reference
#include <stdlib.h>

Go to the source code of this file.

Defines

#define RED   0
#define GRN   1
#define BLU   2
#define CIEX   0 /* or, if input is XYZ... */
#define CIEY   1
#define CIEZ   2
#define EXP   3 /* exponent same for either format */
#define COLXS   128 /* excess used for exponent */
#define WHT   3 /* used for RGBPRIMS type */
#define BYTE   unsigned char /* 8-bit unsigned integer */
#define copycolr(c1, c2)
#define colval(col, pri)   ((col)[pri])
#define setcolor(col, r, g, b)   ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
#define copycolor(c1, c2)   ((c1)[0]=(c2)[0],(c1)[1]=(c2)[1],(c1)[2]=(c2)[2])
#define scalecolor(col, sf)   ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf))
#define addcolor(c1, c2)   ((c1)[0]+=(c2)[0],(c1)[1]+=(c2)[1],(c1)[2]+=(c2)[2])
#define multcolor(c1, c2)   ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])
#define CIE_x_r   0.640 /* nominal CRT primaries */
#define CIE_y_r   0.330
#define CIE_x_g   0.290
#define CIE_y_g   0.600
#define CIE_x_b   0.150
#define CIE_y_b   0.060
#define CIE_x_w   0.3333 /* use true white */
#define CIE_y_w   0.3333
#define STDPRIMS
#define CIE_D
#define CIE_C_rD
#define CIE_C_gD
#define CIE_C_bD
#define CIE_rf   (CIE_y_r*CIE_C_rD/CIE_D)
#define CIE_gf   (CIE_y_g*CIE_C_gD/CIE_D)
#define CIE_bf   (CIE_y_b*CIE_C_bD/CIE_D)
#define bright(col)   (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
#define normbright(c)
#define MAXEFFICACY   683. /* defined maximum at 550 nm */
#define WHTEFFICACY   179. /* uniform white light */
#define D65EFFICACY   203. /* standard illuminant D65 */
#define INCEFFICACY   160. /* illuminant A (incand.) */
#define SUNEFFICACY   208. /* illuminant B (solar dir.) */
#define SKYEFFICACY   D65EFFICACY /* skylight (should be 110) */
#define DAYEFFICACY   D65EFFICACY /* combined sky and solar */
#define luminance(col)   (WHTEFFICACY * bright(col))
#define intens(col)
#define colrval(c, p)
#define WHTCOLOR   {1.0,1.0,1.0}
#define BLKCOLOR   {0.0,0.0,0.0}
#define WHTCOLR   {128,128,128,COLXS+1}
#define BLKCOLR   {0,0,0,0}
#define COLRFMT   "32-bit_rle_rgbe"
#define CIEFMT   "32-bit_rle_xyze"
#define PICFMT   "32-bit_rle_???e" /* matches either */
#define LPICFMT   15 /* max format id len */
#define EXPOSSTR   "EXPOSURE="
#define LEXPOSSTR   9
#define isexpos(hl)   (!strncmp(hl,EXPOSSTR,LEXPOSSTR))
#define exposval(hl)   atof((hl)+LEXPOSSTR)
#define fputexpos(ex, fp)   fprintf(fp,"%s%e\n",EXPOSSTR,ex)
#define ASPECTSTR   "PIXASPECT="
#define LASPECTSTR   10
#define isaspect(hl)   (!strncmp(hl,ASPECTSTR,LASPECTSTR))
#define aspectval(hl)   atof((hl)+LASPECTSTR)
#define fputaspect(pa, fp)   fprintf(fp,"%s%f\n",ASPECTSTR,pa)
#define PRIMARYSTR   "PRIMARIES="
#define LPRIMARYSTR   10
#define isprims(hl)   (!strncmp(hl,PRIMARYSTR,LPRIMARYSTR))
#define primsval(p, hl)
#define fputprims(p, fp)
#define COLCORSTR   "COLORCORR="
#define LCOLCORSTR   10
#define iscolcor(hl)   (!strncmp(hl,COLCORSTR,LCOLCORSTR))
#define colcorval(cc, hl)
#define fputcolcor(cc, fp)
#define CGAMUT_LOWER   01
#define CGAMUT_UPPER   02
#define CGAMUT   (CGAMUT_LOWER|CGAMUT_UPPER)
#define rgb_cie(xyz, rgb)   colortrans(xyz,rgb2xyzmat,rgb)
#define cpcolormat(md, ms)   memcpy((void *)md,(void *)ms,sizeof(COLORMAT))

Typedefs

typedef BYTE COLR [4]
typedef float COLORV
typedef COLORV COLOR [3]
typedef float RGBPRIMS [4][2]
typedef float(* RGBPRIMP )[2]
typedef float COLORMAT [3][3]

Functions

char * tempbuffer (unsigned int len)
int fwritecolrs (COLR *scanline, int len, FILE *fp)
int freadcolrs (COLR *scanline, int len, FILE *fp)
int fwritescan (COLOR *scanline, int len, FILE *fp)
int freadscan (COLOR *scanline, int len, FILE *fp)
void setcolr (COLR clr, double r, double g, double b)
void colr_color (COLOR col, COLR clr)
int bigdiff (COLOR c1, COLOR c2, double md)
void spec_rgb (COLOR col, int s, int e)
void spec_cie (COLOR col, int s, int e)
void cie_rgb (COLOR rgb, COLOR xyz)
int clipgamut (COLOR col, double brt, int gamut, COLOR lower, COLOR upper)
void colortrans (COLOR c2, COLORMAT mat, COLOR c1)
void multcolormat (COLORMAT m3, COLORMAT m2, COLORMAT m1)
int colorprimsOK (RGBPRIMS pr)
int compxyz2rgbmat (COLORMAT mat, RGBPRIMS pr)
int comprgb2xyzmat (COLORMAT mat, RGBPRIMS pr)
int comprgb2rgbmat (COLORMAT mat, RGBPRIMS pr1, RGBPRIMS pr2)
int compxyzWBmat (COLORMAT mat, float wht1[2], float wht2[2])
int compxyz2rgbWBmat (COLORMAT mat, RGBPRIMS pr)
int comprgb2xyzWBmat (COLORMAT mat, RGBPRIMS pr)
int comprgb2rgbWBmat (COLORMAT mat, RGBPRIMS pr1, RGBPRIMS pr2)
int setcolrcor (double(*f)(double, double), double a2)
int setcolrinv (double(*f)(double, double), double a2)
int setcolrgam (double g)
int colrs_gambs (COLR *scan, int len)
int gambs_colrs (COLR *scan, int len)
void shiftcolrs (COLR *scan, int len, int adjust)
void normcolrs (COLR *scan, int len, int adjust)

Variables

RGBPRIMS stdprims
COLORMAT rgb2xyzmat
COLORMAT xyz2rgbmat
COLOR cblack
COLOR cwhite

Define Documentation

#define addcolor (   c1,
  c2 
)    ((c1)[0]+=(c2)[0],(c1)[1]+=(c2)[1],(c1)[2]+=(c2)[2])

Definition at line 55 of file color.h.

#define ASPECTSTR   "PIXASPECT="

Definition at line 151 of file color.h.

#define aspectval (   hl)    atof((hl)+LASPECTSTR)

Definition at line 154 of file color.h.

#define BLKCOLOR   {0.0,0.0,0.0}

Definition at line 133 of file color.h.

#define BLKCOLR   {0,0,0,0}

Definition at line 135 of file color.h.

#define BLU   2

Definition at line 23 of file color.h.

#define bright (   col)    (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])

Definition at line 106 of file color.h.

#define BYTE   unsigned char /* 8-bit unsigned integer */

Definition at line 32 of file color.h.

Definition at line 197 of file color.h.

#define CGAMUT_LOWER   01

Definition at line 195 of file color.h.

#define CGAMUT_UPPER   02

Definition at line 196 of file color.h.

#define CIE_bf   (CIE_y_b*CIE_C_bD/CIE_D)

Definition at line 100 of file color.h.

#define CIE_C_bD
Value:
( (1./CIE_y_w) * \
                            ( CIE_x_w*(CIE_y_r - CIE_y_g) - \
                              CIE_y_w*(CIE_x_r - CIE_x_g) + \
                              CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r       ) )

Definition at line 93 of file color.h.

#define CIE_C_gD
Value:
( (1./CIE_y_w) * \
                            ( CIE_x_w*(CIE_y_b - CIE_y_r) - \
                              CIE_y_w*(CIE_x_b - CIE_x_r) - \
                              CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r       ) )

Definition at line 89 of file color.h.

#define CIE_C_rD
Value:
( (1./CIE_y_w) * \
                            ( CIE_x_w*(CIE_y_g - CIE_y_b) - \
                              CIE_y_w*(CIE_x_g - CIE_x_b) + \
                              CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g       ) )

Definition at line 85 of file color.h.

#define CIE_D
Value:
(      CIE_x_r*(CIE_y_g - CIE_y_b) + \
                            CIE_x_g*(CIE_y_b - CIE_y_r) + \
                            CIE_x_b*(CIE_y_r - CIE_y_g) )

Definition at line 82 of file color.h.

#define CIE_gf   (CIE_y_g*CIE_C_gD/CIE_D)

Definition at line 99 of file color.h.

#define CIE_rf   (CIE_y_r*CIE_C_rD/CIE_D)

Definition at line 98 of file color.h.

#define CIE_x_b   0.150

Definition at line 73 of file color.h.

#define CIE_x_g   0.290

Definition at line 71 of file color.h.

#define CIE_x_r   0.640 /* nominal CRT primaries */

Definition at line 69 of file color.h.

#define CIE_x_w   0.3333 /* use true white */

Definition at line 75 of file color.h.

#define CIE_y_b   0.060

Definition at line 74 of file color.h.

#define CIE_y_g   0.600

Definition at line 72 of file color.h.

#define CIE_y_r   0.330

Definition at line 70 of file color.h.

#define CIE_y_w   0.3333

Definition at line 76 of file color.h.

#define CIEFMT   "32-bit_rle_xyze"

Definition at line 139 of file color.h.

#define CIEX   0 /* or, if input is XYZ... */

Definition at line 24 of file color.h.

#define CIEY   1

Definition at line 25 of file color.h.

#define CIEZ   2

Definition at line 26 of file color.h.

#define COLCORSTR   "COLORCORR="

Definition at line 176 of file color.h.

#define colcorval (   cc,
  hl 
)
Value:
sscanf((hl)+LCOLCORSTR,"%f %f %f", \
                                   &(cc)[RED],&(cc)[GRN],&(cc)[BLU])

Definition at line 179 of file color.h.

#define COLRFMT   "32-bit_rle_rgbe"

Definition at line 138 of file color.h.

#define colrval (   c,
 
)
Value:
( (c)[EXP] ? \
                            ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \
                            0. )

Definition at line 128 of file color.h.

#define colval (   col,
  pri 
)    ((col)[pri])

Definition at line 47 of file color.h.

#define COLXS   128 /* excess used for exponent */

Definition at line 28 of file color.h.

#define copycolor (   c1,
  c2 
)    ((c1)[0]=(c2)[0],(c1)[1]=(c2)[1],(c1)[2]=(c2)[2])

Definition at line 51 of file color.h.

#define copycolr (   c1,
  c2 
)
Value:
(c1[0]=c2[0],c1[1]=c2[1], \
                            c1[2]=c2[2],c1[3]=c2[3])

Definition at line 44 of file color.h.

#define cpcolormat (   md,
  ms 
)    memcpy((void *)md,(void *)ms,sizeof(COLORMAT))

Definition at line 201 of file color.h.

#define D65EFFICACY   203. /* standard illuminant D65 */

Definition at line 114 of file color.h.

#define DAYEFFICACY   D65EFFICACY /* combined sky and solar */

Definition at line 118 of file color.h.

#define EXP   3 /* exponent same for either format */

Definition at line 27 of file color.h.

#define EXPOSSTR   "EXPOSURE="

Definition at line 144 of file color.h.

#define exposval (   hl)    atof((hl)+LEXPOSSTR)

Definition at line 147 of file color.h.

#define fputaspect (   pa,
  fp 
)    fprintf(fp,"%s%f\n",ASPECTSTR,pa)

Definition at line 155 of file color.h.

#define fputcolcor (   cc,
  fp 
)
Value:
fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
                                   (cc)[RED],(cc)[GRN],(cc)[BLU])

Definition at line 181 of file color.h.

#define fputexpos (   ex,
  fp 
)    fprintf(fp,"%s%e\n",EXPOSSTR,ex)

Definition at line 148 of file color.h.

#define fputprims (   p,
  fp 
)
Value:
fprintf(fp, \
                            "%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\
                                   PRIMARYSTR, \
                                   (p)[RED][CIEX],(p)[RED][CIEY], \
                                   (p)[GRN][CIEX],(p)[GRN][CIEY], \
                                   (p)[BLU][CIEX],(p)[BLU][CIEY], \
                                   (p)[WHT][CIEX],(p)[WHT][CIEY])

Definition at line 167 of file color.h.

#define GRN   1

Definition at line 22 of file color.h.

#define INCEFFICACY   160. /* illuminant A (incand.) */

Definition at line 115 of file color.h.

#define intens (   col)
Value:
( (col)[0] > (col)[1] \
                            ? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
                            : (col)[1] > (col)[2] ? (col)[1] : (col)[2] )

Definition at line 124 of file color.h.

#define isaspect (   hl)    (!strncmp(hl,ASPECTSTR,LASPECTSTR))

Definition at line 153 of file color.h.

#define iscolcor (   hl)    (!strncmp(hl,COLCORSTR,LCOLCORSTR))

Definition at line 178 of file color.h.

#define isexpos (   hl)    (!strncmp(hl,EXPOSSTR,LEXPOSSTR))

Definition at line 146 of file color.h.

#define isprims (   hl)    (!strncmp(hl,PRIMARYSTR,LPRIMARYSTR))

Definition at line 160 of file color.h.

#define LASPECTSTR   10

Definition at line 152 of file color.h.

#define LCOLCORSTR   10

Definition at line 177 of file color.h.

#define LEXPOSSTR   9

Definition at line 145 of file color.h.

#define LPICFMT   15 /* max format id len */

Definition at line 141 of file color.h.

#define LPRIMARYSTR   10

Definition at line 159 of file color.h.

#define luminance (   col)    (WHTEFFICACY * bright(col))

Definition at line 120 of file color.h.

#define MAXEFFICACY   683. /* defined maximum at 550 nm */

Definition at line 112 of file color.h.

#define multcolor (   c1,
  c2 
)    ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])

Definition at line 57 of file color.h.

#define normbright (   c)
Value:
( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
                         (long)(CIE_gf*256.+.5)*(c)[GRN] + \
                         (long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )

Definition at line 107 of file color.h.

#define PICFMT   "32-bit_rle_???e" /* matches either */

Definition at line 140 of file color.h.

#define PRIMARYSTR   "PRIMARIES="

Definition at line 158 of file color.h.

#define primsval (   p,
  hl 
)
Value:
sscanf((hl)+LPRIMARYSTR, \
                                   "%f %f %f %f %f %f %f %f", \
                                   &(p)[RED][CIEX],&(p)[RED][CIEY], \
                                   &(p)[GRN][CIEX],&(p)[GRN][CIEY], \
                                   &(p)[BLU][CIEX],&(p)[BLU][CIEY], \
                                   &(p)[WHT][CIEX],&(p)[WHT][CIEY])

Definition at line 161 of file color.h.

#define RED   0

Definition at line 21 of file color.h.

#define rgb_cie (   xyz,
  rgb 
)    colortrans(xyz,rgb2xyzmat,rgb)

Definition at line 199 of file color.h.

#define scalecolor (   col,
  sf 
)    ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf))

Definition at line 53 of file color.h.

#define setcolor (   col,
  r,
  g,
 
)    ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))

Definition at line 49 of file color.h.

#define SKYEFFICACY   D65EFFICACY /* skylight (should be 110) */

Definition at line 117 of file color.h.

#define STDPRIMS
Value:

Definition at line 79 of file color.h.

#define SUNEFFICACY   208. /* illuminant B (solar dir.) */

Definition at line 116 of file color.h.

#define WHT   3 /* used for RGBPRIMS type */

Definition at line 29 of file color.h.

#define WHTCOLOR   {1.0,1.0,1.0}

Definition at line 132 of file color.h.

#define WHTCOLR   {128,128,128,COLXS+1}

Definition at line 134 of file color.h.

#define WHTEFFICACY   179. /* uniform white light */

Definition at line 113 of file color.h.


Typedef Documentation

typedef COLORV COLOR[3]

Definition at line 37 of file color.h.

typedef float COLORMAT[3][3]

Definition at line 42 of file color.h.

typedef float COLORV

Definition at line 36 of file color.h.

typedef BYTE COLR[4]

Definition at line 34 of file color.h.

typedef float(* RGBPRIMP)[2]

Definition at line 40 of file color.h.

typedef float RGBPRIMS[4][2]

Definition at line 39 of file color.h.


Function Documentation

int bigdiff ( COLOR  c1,
COLOR  c2,
double  md 
)

Definition at line 304 of file color.c.

{
       register int  i;

       for (i = 0; i < 3; i++)
              if (colval(c1,i)-colval(c2,i) > md*colval(c2,i) ||
                     colval(c2,i)-colval(c1,i) > md*colval(c1,i))
                     return(1);
       return(0);
}

Here is the caller graph for this function:

void cie_rgb ( COLOR  rgb,
COLOR  xyz 
)

Definition at line 145 of file spec_rgb.c.

{
       colortrans(rgb, xyz2rgbmat, xyz);
       clipgamut(rgb, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int clipgamut ( COLOR  col,
double  brt,
int  gamut,
COLOR  lower,
COLOR  upper 
)

Definition at line 156 of file spec_rgb.c.

{
       int  rflags = 0;
       double  brtmin, brtmax, v, vv;
       COLOR  cgry;
       register int  i;
                                   /* check for no check */
       if (gamut == 0) return(0);
                                   /* check brightness limits */
       brtmin = 1./3.*(lower[0]+lower[1]+lower[2]);
       if (gamut & CGAMUT_LOWER && brt < brtmin) {
              copycolor(col, lower);
              return(CGAMUT_LOWER);
       }
       brtmax = 1./3.*(upper[0]+upper[1]+upper[2]);
       if (gamut & CGAMUT_UPPER && brt > brtmax) {
              copycolor(col, upper);
              return(CGAMUT_UPPER);
       }
                                   /* compute equivalent grey */
       v = (brt - brtmin)/(brtmax - brtmin);
       for (i = 0; i < 3; i++)
              cgry[i] = v*upper[i] + (1.-v)*lower[i];
       vv = 1.;                    /* check each limit */
       for (i = 0; i < 3; i++)
              if (gamut & CGAMUT_LOWER && col[i] < lower[i]) {
                     v = (lower[i] - cgry[i])/(col[i] - cgry[i]);
                     if (v < vv) vv = v;
                     rflags |= CGAMUT_LOWER;
              } else if (gamut & CGAMUT_UPPER && col[i] > upper[i]) {
                     v = (upper[i] - cgry[i])/(col[i] - cgry[i]);
                     if (v < vv) vv = v;
                     rflags |= CGAMUT_UPPER;
              }
       if (rflags)                 /* desaturate to cube face */
              for (i = 0; i < 3; i++)
                     col[i] = vv*col[i] + (1.-vv)*cgry[i];
       return(rflags);
}

Here is the caller graph for this function:

int colorprimsOK ( RGBPRIMS  pr)

Definition at line 240 of file spec_rgb.c.

{
       int    i, j;
       
       for (i = 0; i < 4; i++) {
              if ((pr[i][CIEX] <= -.5) | (pr[i][CIEY] <= -.5))
                     return(0);
              if ((pr[i][CIEX] >= 1.5) | (pr[i][CIEY] >= 1.5))
                     return(0);
              if (pr[i][CIEX] + pr[i][CIEY] >= 1.5)
                     return(0);
       }
       for (i = 0; i < 4; i++)
              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);
}
void colortrans ( COLOR  c2,
COLORMAT  mat,
COLOR  c1 
)

Here is the caller graph for this function:

void colr_color ( COLOR  col,
COLR  clr 
)

Definition at line 286 of file color.c.

{
       double  f;
       
       if (clr[EXP] == 0)
              col[RED] = col[GRN] = col[BLU] = 0.0;
       else {
              f = ldexp(1.0, (int)clr[EXP]-(COLXS+8));
              col[RED] = (clr[RED] + 0.5)*f;
              col[GRN] = (clr[GRN] + 0.5)*f;
              col[BLU] = (clr[BLU] + 0.5)*f;
       }
}

Here is the caller graph for this function:

int colrs_gambs ( COLR scan,
int  len 
)

Definition at line 83 of file colrops.c.

{
       register int  i, expo;

       if (g_bval == NULL)
              return(-1);
       while (len-- > 0) {
              expo = scan[0][EXP] - COLXS;
              if (expo < -MAXGSHIFT) {
                     if (expo < -MAXGSHIFT-8) {
                            scan[0][RED] =
                            scan[0][GRN] =
                            scan[0][BLU] = 0;
                     } else {
                            i = (-MAXGSHIFT-1) - expo;
                            scan[0][RED] = 
                            g_bval[MAXGSHIFT][((scan[0][RED]>>i)+1)>>1];
                            scan[0][GRN] =
                            g_bval[MAXGSHIFT][((scan[0][GRN]>>i)+1)>>1];
                            scan[0][BLU] =
                            g_bval[MAXGSHIFT][((scan[0][BLU]>>i)+1)>>1];
                     }
              } else if (expo > 0) {
                     if (expo > 8) {
                            scan[0][RED] =
                            scan[0][GRN] =
                            scan[0][BLU] = 255;
                     } else {
                            i = (scan[0][RED]<<1 | 1) << (expo-1);
                            scan[0][RED] = i > 255 ? 255 : g_bval[0][i];
                            i = (scan[0][GRN]<<1 | 1) << (expo-1);
                            scan[0][GRN] = i > 255 ? 255 : g_bval[0][i];
                            i = (scan[0][BLU]<<1 | 1) << (expo-1);
                            scan[0][BLU] = i > 255 ? 255 : g_bval[0][i];
                     }
              } else {
                     scan[0][RED] = g_bval[-expo][scan[0][RED]];
                     scan[0][GRN] = g_bval[-expo][scan[0][GRN]];
                     scan[0][BLU] = g_bval[-expo][scan[0][BLU]];
              }
              scan[0][EXP] = COLXS;
              scan++;
       }
       return(0);
}

Here is the caller graph for this function:

int comprgb2rgbmat ( COLORMAT  mat,
RGBPRIMS  pr1,
RGBPRIMS  pr2 
)

Definition at line 369 of file spec_rgb.c.

{
       COLORMAT  pr1toxyz, xyztopr2;

       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(1);
       }
       if (!comprgb2xyzmat(pr1toxyz, pr1))
              return(0);
       if (!compxyz2rgbmat(xyztopr2, pr2))
              return(0);
                            /* combine transforms */
       multcolormat(mat, pr1toxyz, xyztopr2);
       return(1);
}

Here is the call graph for this function:

int comprgb2rgbWBmat ( COLORMAT  mat,
RGBPRIMS  pr1,
RGBPRIMS  pr2 
)

Definition at line 469 of file spec_rgb.c.

{
       COLORMAT  pr1toxyz, xyztopr2, wbmat;

       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(1);
       }
       if (!comprgb2xyzmat(pr1toxyz, pr1))
              return(0);
       if (!compxyzWBmat(wbmat, pr1[WHT], pr2[WHT]))
              return(0);
       if (!compxyz2rgbmat(xyztopr2, pr2))
              return(0);
                            /* combine transforms */
       multcolormat(mat, pr1toxyz, wbmat);
       multcolormat(mat, mat, xyztopr2);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int comprgb2xyzmat ( COLORMAT  mat,
RGBPRIMS  pr 
)

Here is the caller graph for this function:

int comprgb2xyzWBmat ( COLORMAT  mat,
RGBPRIMS  pr 
)

Definition at line 451 of file spec_rgb.c.

{
       COLORMAT      wbmat;
       
       if (!comprgb2xyzmat(mat, pr))
              return(0);
       if (XYEQ(pr[WHT],xyneu))
              return(1);
       if (!compxyzWBmat(wbmat, pr[WHT], xyneu))
              return(0);
       multcolormat(mat, mat, wbmat);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int compxyz2rgbmat ( COLORMAT  mat,
RGBPRIMS  pr 
)

Here is the caller graph for this function:

int compxyz2rgbWBmat ( COLORMAT  mat,
RGBPRIMS  pr 
)

Definition at line 433 of file spec_rgb.c.

{
       COLORMAT      wbmat;

       if (!compxyz2rgbmat(mat, pr))
              return(0);
       if (XYEQ(pr[WHT],xyneu))
              return(1);
       if (!compxyzWBmat(wbmat, xyneu, pr[WHT]))
              return(0);
       multcolormat(mat, wbmat, mat);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int compxyzWBmat ( COLORMAT  mat,
float  wht1[2],
float  wht2[2] 
)

Definition at line 394 of file spec_rgb.c.

{
       COLOR  cw1, cw2;
       if (XYEQ(wht1,wht2)) {
              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(1);
       }
       if (CEQ(wht1[CIEX],0.) | CEQ(wht1[CIEY],0.))
              return(0);
       cw1[RED] = wht1[CIEX]/wht1[CIEY];
       cw1[GRN] = 1.;
       cw1[BLU] = (1. - wht1[CIEX] - wht1[CIEY])/wht1[CIEY];
       colortrans(cw1, vkmat, cw1);
       if (CEQ(wht2[CIEX],0.) | CEQ(wht2[CIEY],0.))
              return(0);
       cw2[RED] = wht2[CIEX]/wht2[CIEY];
       cw2[GRN] = 1.;
       cw2[BLU] = (1. - wht2[CIEX] - wht2[CIEY])/wht2[CIEY];
       colortrans(cw2, vkmat, cw2);
       if (CEQ(cw1[RED],0.) | CEQ(cw1[GRN],0.) | CEQ(cw1[BLU],0.))
              return(0);
       mat[0][0] = cw2[RED]/cw1[RED];
       mat[1][1] = cw2[GRN]/cw1[GRN];
       mat[2][2] = cw2[BLU]/cw1[BLU];
       mat[0][1] = mat[0][2] = mat[1][0] =
       mat[1][2] = mat[2][0] = mat[2][1] = 0.0;
       multcolormat(mat, vkmat, mat);
       multcolormat(mat, mat, ivkmat);
       return(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int freadcolrs ( COLR scanline,
int  len,
FILE *  fp 
)

Definition at line 141 of file color.c.

{
       register int  i, j;
       int  code, val;
                                   /* determine scanline type */
       if ((len < MINELEN) | (len > MAXELEN))
              return(oldreadcolrs(scanline, len, fp));
       if ((i = getc(fp)) == EOF)
              return(-1);
       if (i != 2) {
              ungetc(i, fp);
              return(oldreadcolrs(scanline, len, fp));
       }
       scanline[0][GRN] = getc(fp);
       scanline[0][BLU] = getc(fp);
       if ((i = getc(fp)) == EOF)
              return(-1);
       if (scanline[0][GRN] != 2 || scanline[0][BLU] & 128) {
              scanline[0][RED] = 2;
              scanline[0][EXP] = i;
              return(oldreadcolrs(scanline+1, len-1, fp));
       }
       if ((scanline[0][BLU]<<8 | i) != len)
              return(-1);          /* length mismatch! */
                                   /* read each component */
       for (i = 0; i < 4; i++)
           for (j = 0; j < len; ) {
              if ((code = getc(fp)) == EOF)
                  return(-1);
              if (code > 128) {    /* run */
                  code &= 127;
                  if ((val = getc(fp)) == EOF)
                     return -1;
                  if (j + code > len)
                     return -1;    /* overrun */
                  while (code--)
                     scanline[j++][i] = val;
              } else {             /* non-run */
                  if (j + code > len)
                     return -1;    /* overrun */
                  while (code--) {
                     if ((val = getc(fp)) == EOF)
                         return -1;
                     scanline[j++][i] = val;
                  }
              }
           }
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int freadscan ( COLOR scanline,
int  len,
FILE *  fp 
)

Definition at line 222 of file color.c.

{
       register COLR  *clrscan;

       if ((clrscan = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
              return(-1);
       if (freadcolrs(clrscan, len, fp) < 0)
              return(-1);
                                   /* convert scanline */
       colr_color(scanline[0], clrscan[0]);
       while (--len > 0) {
              scanline++; clrscan++;
              if (clrscan[0][RED] == clrscan[-1][RED] &&
                         clrscan[0][GRN] == clrscan[-1][GRN] &&
                         clrscan[0][BLU] == clrscan[-1][BLU] &&
                         clrscan[0][EXP] == clrscan[-1][EXP])
                     copycolor(scanline[0], scanline[-1]);
              else
                     colr_color(scanline[0], clrscan[0]);
       }
       return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fwritecolrs ( COLR scanline,
int  len,
FILE *  fp 
)

Definition at line 51 of file color.c.

{
       register int  i, j, beg, cnt = 1;
       int  c2;
       
       if ((len < MINELEN) | (len > MAXELEN))    /* OOBs, write out flat */
              return(fwrite((char *)scanline,sizeof(COLR),len,fp) - len);
                                   /* put magic header */
       putc(2, fp);
       putc(2, fp);
       putc(len>>8, fp);
       putc(len&255, fp);
                                   /* put components seperately */
       for (i = 0; i < 4; i++) {
           for (j = 0; j < len; j += cnt) {      /* find next run */
              for (beg = j; beg < len; beg += cnt) {
                  for (cnt = 1; cnt < 127 && beg+cnt < len &&
                         scanline[beg+cnt][i] == scanline[beg][i]; cnt++)
                     ;
                  if (cnt >= MINRUN)
                     break;               /* long enough */
              }
              if (beg-j > 1 && beg-j < MINRUN) {
                  c2 = j+1;
                  while (scanline[c2++][i] == scanline[j][i])
                     if (c2 == beg) {     /* short run */
                         putc(128+beg-j, fp);
                         putc(scanline[j][i], fp);
                         j = beg;
                         break;
                     }
              }
              while (j < beg) {           /* write out non-run */
                  if ((c2 = beg-j) > 128) c2 = 128;
                  putc(c2, fp);
                  while (c2--)
                     putc(scanline[j++][i], fp);
              }
              if (cnt >= MINRUN) {        /* write out run */
                  putc(128+cnt, fp);
                  putc(scanline[beg][i], fp);
              } else
                  cnt = 0;
           }
       }
       return(ferror(fp) ? -1 : 0);
}

Here is the caller graph for this function:

int fwritescan ( COLOR scanline,
int  len,
FILE *  fp 
)

Definition at line 196 of file color.c.

{
       COLR  *clrscan;
       int  n;
       register COLR  *sp;
                                   /* get scanline buffer */
       if ((sp = (COLR *)tempbuffer(len*sizeof(COLR))) == NULL)
              return(-1);
       clrscan = sp;
                                   /* convert scanline */
       n = len;
       while (n-- > 0) {
              setcolr(sp[0], scanline[0][RED],
                              scanline[0][GRN],
                              scanline[0][BLU]);
              scanline++;
              sp++;
       }
       return(fwritecolrs(clrscan, len, fp));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gambs_colrs ( COLR scan,
int  len 
)

Definition at line 133 of file colrops.c.

{
       register int  nexpo;

       if ((g_mant == NULL) | (g_nexp == NULL))
              return(-1);
       while (len-- > 0) {
              nexpo = g_nexp[scan[0][RED]];
              if (g_nexp[scan[0][GRN]] < nexpo)
                     nexpo = g_nexp[scan[0][GRN]];
              if (g_nexp[scan[0][BLU]] < nexpo)
                     nexpo = g_nexp[scan[0][BLU]];
              if (nexpo < g_nexp[scan[0][RED]])
                     scan[0][RED] = g_mant[scan[0][RED]]
                                   >> (g_nexp[scan[0][RED]]-nexpo);
              else
                     scan[0][RED] = g_mant[scan[0][RED]];
              if (nexpo < g_nexp[scan[0][GRN]])
                     scan[0][GRN] = g_mant[scan[0][GRN]]
                                   >> (g_nexp[scan[0][GRN]]-nexpo);
              else
                     scan[0][GRN] = g_mant[scan[0][GRN]];
              if (nexpo < g_nexp[scan[0][BLU]])
                     scan[0][BLU] = g_mant[scan[0][BLU]]
                                   >> (g_nexp[scan[0][BLU]]-nexpo);
              else
                     scan[0][BLU] = g_mant[scan[0][BLU]];
              scan[0][EXP] = COLXS - nexpo;
              scan++;
       }
       return(0);
}

Here is the caller graph for this function:

void multcolormat ( COLORMAT  m3,
COLORMAT  m2,
COLORMAT  m1 
)

Definition at line 221 of file spec_rgb.c.

{
       COLORMAT  mt;
       register int  i, j;

       for (i = 0; i < 3; i++)
              for (j = 0; j < 3; j++)
                     mt[i][j] =    m1[i][0]*m2[0][j] +
                                   m1[i][1]*m2[1][j] +
                                   m1[i][2]*m2[2][j] ;
       cpcolormat(m3, mt);
}

Here is the caller graph for this function:

void normcolrs ( COLR scan,
int  len,
int  adjust 
)

Definition at line 192 of file colrops.c.

{
       register int  c;
       register int  shift;

       while (len-- > 0) {
              shift = scan[0][EXP] + adjust - COLXS;
              if (shift > 0) {
                     if (shift > 8) {
                            scan[0][RED] =
                            scan[0][GRN] =
                            scan[0][BLU] = 255;
                     } else {
                            shift--;
                            c = (scan[0][RED]<<1 | 1) << shift;
                            scan[0][RED] = c > 255 ? 255 : c;
                            c = (scan[0][GRN]<<1 | 1) << shift;
                            scan[0][GRN] = c > 255 ? 255 : c;
                            c = (scan[0][BLU]<<1 | 1) << shift;
                            scan[0][BLU] = c > 255 ? 255 : c;
                     }
              } else if (shift < 0) {
                     if (shift < -8) {
                            scan[0][RED] =
                            scan[0][GRN] =
                            scan[0][BLU] = 0;
                     } else {
                            shift = -1-shift;
                            scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1;
                            scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1;
                            scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1;
                     }
              }
              scan[0][EXP] = COLXS - adjust;
              scan++;
       }
}

Here is the caller graph for this function:

void setcolr ( COLR  clr,
double  r,
double  g,
double  b 
)

Definition at line 250 of file color.c.

{
       double  d;
       int  e;
       
       d = r > g ? r : g;
       if (b > d) d = b;

       if (d <= 1e-32) {
              clr[RED] = clr[GRN] = clr[BLU] = 0;
              clr[EXP] = 0;
              return;
       }

       d = frexp(d, &e) * 255.9999 / d;

       if (r > 0.0)
              clr[RED] = r * d;
       else
              clr[RED] = 0;
       if (g > 0.0)
              clr[GRN] = g * d;
       else
              clr[GRN] = 0;
       if (b > 0.0)
              clr[BLU] = b * d;
       else
              clr[BLU] = 0;

       clr[EXP] = e + COLXS;
}

Here is the caller graph for this function:

int setcolrcor ( double(*)(double, double)  f,
double  a2 
)

Here is the caller graph for this function:

int setcolrgam ( double  g)

Definition at line 73 of file colrops.c.

{
       if (setcolrcor(pow, 1.0/g) < 0)
              return(-1);
       return(setcolrinv(pow, g));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int setcolrinv ( double(*)(double, double)  f,
double  a2 
)

Here is the caller graph for this function:

void shiftcolrs ( COLR scan,
int  len,
int  adjust 
)

Definition at line 170 of file colrops.c.

{
       int    minexp;

       if (adjust == 0)
              return;
       minexp = adjust < 0 ? -adjust : 0;
       while (len-- > 0) {
              if (scan[0][EXP] <= minexp)
                     scan[0][RED] = scan[0][GRN] = scan[0][BLU] =
                     scan[0][EXP] = 0;
              else
                     scan[0][EXP] += adjust;
              scan++;
       }
}

Here is the caller graph for this function:

void spec_cie ( COLOR  col,
int  s,
int  e 
)

Definition at line 108 of file spec_rgb.c.

{
       register int  i, d, r;
       
       s -= STARTWL;
       if (s < 0)
              s = 0;

       e -= STARTWL;
       if (e <= s) {
              col[CIEX] = col[CIEY] = col[CIEZ] = 0.0;
              return;
       }
       if (e >= INCWL*(NINC - 1))
              e = INCWL*(NINC - 1) - 1;

       d = e / INCWL;                     /* interpolate values */
       r = e % INCWL;
       for (i = 0; i < 3; i++)
              col[i] = chroma[i][d]*(INCWL - r) + chroma[i][d + 1]*r;

       d = s / INCWL;
       r = s % INCWL;
       for (i = 0; i < 3; i++)
              col[i] -= chroma[i][d]*(INCWL - r) - chroma[i][d + 1]*r;

       col[CIEX] = (col[CIEX] + 0.5) * (1./(256*INCWL));
       col[CIEY] = (col[CIEY] + 0.5) * (1./(256*INCWL));
       col[CIEZ] = (col[CIEZ] + 0.5) * (1./(256*INCWL));
}

Here is the caller graph for this function:

void spec_rgb ( COLOR  col,
int  s,
int  e 
)

Definition at line 94 of file spec_rgb.c.

{
       COLOR  ciecolor;

       spec_cie(ciecolor, s, e);
       cie_rgb(col, ciecolor);
}

Here is the call graph for this function:

char* tempbuffer ( unsigned int  len)

Definition at line 33 of file color.c.

{
       static char  *tempbuf = NULL;
       static unsigned  tempbuflen = 0;

       if (len > tempbuflen) {
              if (tempbuflen > 0)
                     tempbuf = (char *)realloc((void *)tempbuf, len);
              else
                     tempbuf = (char *)malloc(len);
              tempbuflen = tempbuf==NULL ? 0 : len;
       }
       return(tempbuf);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 26 of file spec_rgb.c.

Definition at line 27 of file spec_rgb.c.

Definition at line 72 of file spec_rgb.c.

Definition at line 24 of file spec_rgb.c.

Definition at line 60 of file spec_rgb.c.