| 1 |
greg |
1.15 |
/* Copyright (c) 1991 Regents of the University of California */
|
| 2 |
greg |
1.1 |
|
| 3 |
|
|
/* SCCSid "$SunId$ LBL" */
|
| 4 |
|
|
|
| 5 |
|
|
/*
|
| 6 |
|
|
* color.h - header for routines using pixel color values.
|
| 7 |
|
|
*
|
| 8 |
|
|
* 12/31/85
|
| 9 |
|
|
*
|
| 10 |
|
|
* Two color representations are used, one for calculation and
|
| 11 |
|
|
* another for storage. Calculation is done with three floats
|
| 12 |
|
|
* for speed. Stored color values use 4 bytes which contain
|
| 13 |
|
|
* three single byte mantissas and a common exponent.
|
| 14 |
|
|
*/
|
| 15 |
|
|
|
| 16 |
|
|
#define RED 0
|
| 17 |
|
|
#define GRN 1
|
| 18 |
|
|
#define BLU 2
|
| 19 |
greg |
2.10 |
#define CIEX 0 /* or, if input is XYZ... */
|
| 20 |
|
|
#define CIEY 1
|
| 21 |
|
|
#define CIEZ 2
|
| 22 |
|
|
#define EXP 3 /* exponent same for either format */
|
| 23 |
greg |
1.1 |
#define COLXS 128 /* excess used for exponent */
|
| 24 |
greg |
2.10 |
#define WHT 3 /* used for RGBPRIMS type */
|
| 25 |
greg |
1.1 |
|
| 26 |
|
|
typedef unsigned char BYTE; /* 8-bit unsigned integer */
|
| 27 |
|
|
|
| 28 |
greg |
2.10 |
typedef BYTE COLR[4]; /* red, green, blue (or X,Y,Z), exponent */
|
| 29 |
greg |
1.1 |
|
| 30 |
greg |
2.10 |
typedef float COLOR[3]; /* red, green, blue (or X,Y,Z) */
|
| 31 |
|
|
|
| 32 |
|
|
typedef float RGBPRIMS[4][2]; /* (x,y) chromaticities for RGBW */
|
| 33 |
|
|
typedef float (*RGBPRIMP)[2]; /* pointer to RGBPRIMS array */
|
| 34 |
|
|
|
| 35 |
|
|
typedef float COLORMAT[3][3]; /* color coordinate conversion matrix */
|
| 36 |
|
|
|
| 37 |
greg |
1.1 |
#define copycolr(c1,c2) (c1[0]=c2[0],c1[1]=c2[1], \
|
| 38 |
|
|
c1[2]=c2[2],c1[3]=c2[3])
|
| 39 |
|
|
|
| 40 |
|
|
#define colval(col,pri) ((col)[pri])
|
| 41 |
|
|
|
| 42 |
|
|
#define setcolor(col,r,g,b) ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
|
| 43 |
|
|
|
| 44 |
|
|
#define copycolor(c1,c2) ((c1)[0]=(c2)[0],(c1)[1]=(c2)[1],(c1)[2]=(c2)[2])
|
| 45 |
|
|
|
| 46 |
|
|
#define scalecolor(col,sf) ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf))
|
| 47 |
|
|
|
| 48 |
|
|
#define addcolor(c1,c2) ((c1)[0]+=(c2)[0],(c1)[1]+=(c2)[1],(c1)[2]+=(c2)[2])
|
| 49 |
|
|
|
| 50 |
|
|
#define multcolor(c1,c2) ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])
|
| 51 |
|
|
|
| 52 |
greg |
1.7 |
#ifdef NTSC
|
| 53 |
greg |
2.7 |
#define CIE_x_r 0.670 /* standard NTSC primaries */
|
| 54 |
|
|
#define CIE_y_r 0.330
|
| 55 |
|
|
#define CIE_x_g 0.210
|
| 56 |
|
|
#define CIE_y_g 0.710
|
| 57 |
|
|
#define CIE_x_b 0.140
|
| 58 |
|
|
#define CIE_y_b 0.080
|
| 59 |
greg |
2.8 |
#define CIE_x_w 0.3333 /* use true white */
|
| 60 |
|
|
#define CIE_y_w 0.3333
|
| 61 |
greg |
1.7 |
#else
|
| 62 |
greg |
2.7 |
#define CIE_x_r 0.640 /* nominal CRT primaries */
|
| 63 |
|
|
#define CIE_y_r 0.330
|
| 64 |
|
|
#define CIE_x_g 0.290
|
| 65 |
|
|
#define CIE_y_g 0.600
|
| 66 |
|
|
#define CIE_x_b 0.150
|
| 67 |
|
|
#define CIE_y_b 0.060
|
| 68 |
greg |
2.8 |
#define CIE_x_w 0.3333 /* use true white */
|
| 69 |
|
|
#define CIE_y_w 0.3333
|
| 70 |
greg |
1.7 |
#endif
|
| 71 |
greg |
2.7 |
|
| 72 |
greg |
2.10 |
#define STDPRIMS {CIE_x_r,CIE_y_r,CIE_x_g,CIE_y_g, \
|
| 73 |
|
|
CIE_x_b,CIE_y_b,CIE_x_w,CIE_y_w}
|
| 74 |
|
|
|
| 75 |
greg |
2.7 |
#define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \
|
| 76 |
|
|
CIE_x_g*(CIE_y_b - CIE_y_r) + \
|
| 77 |
|
|
CIE_x_b*(CIE_y_r - CIE_y_g) )
|
| 78 |
|
|
#define CIE_C_rD ( (1./CIE_y_w) * \
|
| 79 |
|
|
( CIE_x_w*(CIE_y_g - CIE_y_b) - \
|
| 80 |
|
|
CIE_y_w*(CIE_x_g - CIE_x_b) + \
|
| 81 |
|
|
CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
|
| 82 |
|
|
#define CIE_C_gD ( (1./CIE_y_w) * \
|
| 83 |
|
|
( CIE_x_w*(CIE_y_b - CIE_y_r) - \
|
| 84 |
|
|
CIE_y_w*(CIE_x_b - CIE_x_r) - \
|
| 85 |
|
|
CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
|
| 86 |
|
|
#define CIE_C_bD ( (1./CIE_y_w) * \
|
| 87 |
|
|
( CIE_x_w*(CIE_y_r - CIE_y_g) - \
|
| 88 |
|
|
CIE_y_w*(CIE_x_r - CIE_x_g) + \
|
| 89 |
|
|
CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
|
| 90 |
|
|
|
| 91 |
|
|
#define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D)
|
| 92 |
|
|
#define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D)
|
| 93 |
|
|
#define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D)
|
| 94 |
|
|
|
| 95 |
greg |
2.9 |
/* As of 9-94, CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */
|
| 96 |
|
|
|
| 97 |
greg |
2.10 |
/***** The following definitions are valid for RGB colors only... *****/
|
| 98 |
|
|
|
| 99 |
greg |
2.7 |
#define bright(col) (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
|
| 100 |
|
|
#define normbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
|
| 101 |
|
|
(long)(CIE_gf*256.+.5)*(c)[GRN] + \
|
| 102 |
|
|
(long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )
|
| 103 |
greg |
1.1 |
|
| 104 |
greg |
1.14 |
/* luminous efficacies over visible spectrum */
|
| 105 |
|
|
#define MAXEFFICACY 683. /* defined maximum at 550 nm */
|
| 106 |
|
|
#define WHTEFFICACY 179. /* uniform white light */
|
| 107 |
|
|
#define D65EFFICACY 203. /* standard illuminant D65 */
|
| 108 |
|
|
#define INCEFFICACY 160. /* illuminant A (incand.) */
|
| 109 |
|
|
#define SUNEFFICACY 208. /* illuminant B (solar dir.) */
|
| 110 |
|
|
#define SKYEFFICACY D65EFFICACY /* skylight */
|
| 111 |
|
|
#define DAYEFFICACY D65EFFICACY /* combined sky and solar */
|
| 112 |
|
|
|
| 113 |
|
|
#define luminance(col) (WHTEFFICACY * bright(col))
|
| 114 |
greg |
1.9 |
|
| 115 |
greg |
2.10 |
/***** ...end of stuff specific to RGB colors *****/
|
| 116 |
|
|
|
| 117 |
greg |
1.1 |
#define intens(col) ( (col)[0] > (col)[1] \
|
| 118 |
|
|
? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
|
| 119 |
|
|
: (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
|
| 120 |
|
|
|
| 121 |
greg |
1.3 |
#define colrval(c,p) ( (c)[EXP] ? \
|
| 122 |
|
|
ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \
|
| 123 |
|
|
0. )
|
| 124 |
|
|
|
| 125 |
greg |
1.1 |
#define WHTCOLOR {1.0,1.0,1.0}
|
| 126 |
|
|
#define BLKCOLOR {0.0,0.0,0.0}
|
| 127 |
|
|
#define WHTCOLR {128,128,128,COLXS+1}
|
| 128 |
|
|
#define BLKCOLR {0,0,0,0}
|
| 129 |
greg |
1.3 |
|
| 130 |
greg |
1.11 |
/* picture format identifier */
|
| 131 |
|
|
#define COLRFMT "32-bit_rle_rgbe"
|
| 132 |
greg |
2.10 |
#define CIEFMT "32-bit_rle_xyze"
|
| 133 |
|
|
#define PICFMT "32-bit_rle_???e" /* matches either */
|
| 134 |
|
|
#define LPICFMT 15 /* max format id len */
|
| 135 |
greg |
1.11 |
|
| 136 |
greg |
1.6 |
/* macros for exposures */
|
| 137 |
greg |
1.5 |
#define EXPOSSTR "EXPOSURE="
|
| 138 |
greg |
1.12 |
#define LEXPOSSTR 9
|
| 139 |
|
|
#define isexpos(hl) (!strncmp(hl,EXPOSSTR,LEXPOSSTR))
|
| 140 |
|
|
#define exposval(hl) atof((hl)+LEXPOSSTR)
|
| 141 |
greg |
1.5 |
#define fputexpos(ex,fp) fprintf(fp,"%s%e\n",EXPOSSTR,ex)
|
| 142 |
greg |
1.6 |
|
| 143 |
|
|
/* macros for pixel aspect ratios */
|
| 144 |
|
|
#define ASPECTSTR "PIXASPECT="
|
| 145 |
greg |
1.12 |
#define LASPECTSTR 10
|
| 146 |
|
|
#define isaspect(hl) (!strncmp(hl,ASPECTSTR,LASPECTSTR))
|
| 147 |
|
|
#define aspectval(hl) atof((hl)+LASPECTSTR)
|
| 148 |
greg |
1.6 |
#define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa)
|
| 149 |
greg |
1.5 |
|
| 150 |
greg |
2.10 |
/* macros for primary specifications */
|
| 151 |
|
|
#define PRIMARYSTR "PRIMARIES="
|
| 152 |
|
|
#define LPRIMARYSTR 10
|
| 153 |
|
|
#define isprims(hl) (!strncmp(hl,PRIMARYSTR,LPRIMARYSTR))
|
| 154 |
|
|
#define primsval(p,hl) sscanf(hl+LPRIMARYSTR, \
|
| 155 |
|
|
"%f %f %f %f %f %f %f %f", \
|
| 156 |
|
|
&(p)[RED][CIEX],&(p)[RED][CIEY], \
|
| 157 |
|
|
&(p)[GRN][CIEX],&(p)[GRN][CIEY], \
|
| 158 |
|
|
&(p)[BLU][CIEX],&(p)[BLU][CIEY], \
|
| 159 |
|
|
&(p)[WHT][CIEX],&(p)[WHT][CIEY])
|
| 160 |
|
|
#define fputprims(p,fp) fprintf(fp, \
|
| 161 |
|
|
"%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\
|
| 162 |
|
|
PRIMARYSTR, \
|
| 163 |
|
|
(p)[RED][CIEX],(p)[RED][CIEY], \
|
| 164 |
|
|
(p)[GRN][CIEX],(p)[GRN][CIEY], \
|
| 165 |
|
|
(p)[BLU][CIEX],(p)[BLU][CIEY], \
|
| 166 |
|
|
(p)[WHT][CIEX],(p)[WHT][CIEY])
|
| 167 |
|
|
|
| 168 |
greg |
1.8 |
/* macros for color correction */
|
| 169 |
|
|
#define COLCORSTR "COLORCORR="
|
| 170 |
greg |
1.12 |
#define LCOLCORSTR 10
|
| 171 |
|
|
#define iscolcor(hl) (!strncmp(hl,COLCORSTR,LCOLCORSTR))
|
| 172 |
|
|
#define colcorval(cc,hl) sscanf(hl+LCOLCORSTR,"%f %f %f", \
|
| 173 |
greg |
1.8 |
&(cc)[RED],&(cc)[GRN],&(cc)[BLU])
|
| 174 |
|
|
#define fputcolcor(cc,fp) fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
|
| 175 |
|
|
(cc)[RED],(cc)[GRN],(cc)[BLU])
|
| 176 |
greg |
2.6 |
|
| 177 |
|
|
#ifdef DCL_ATOF
|
| 178 |
|
|
extern double atof(), ldexp(), frexp();
|
| 179 |
greg |
2.10 |
#endif
|
| 180 |
|
|
|
| 181 |
|
|
/*
|
| 182 |
|
|
* Conversions to and from XYZ space generally don't apply WHTEFFICACY.
|
| 183 |
|
|
* If you need Y to be luminance (cd/m^2), this must be applied when
|
| 184 |
|
|
* converting from radiance (watts/sr/m^2).
|
| 185 |
|
|
*/
|
| 186 |
|
|
|
| 187 |
|
|
extern RGBPRIMS stdprims; /* standard primary chromaticities */
|
| 188 |
|
|
extern COLORMAT rgb2xyzmat; /* RGB to XYZ conversion matrix */
|
| 189 |
|
|
extern COLORMAT xyz2rgbmat; /* XYZ to RGB conversion matrix */
|
| 190 |
|
|
|
| 191 |
|
|
#define cie_rgb(rgb,xyz) colortrans(rgb,xyz2rgbmat,xyz)
|
| 192 |
|
|
#define rgb_cie(xyz,rgb) colortrans(xyz,rgb2xyzmat,rgb)
|
| 193 |
|
|
|
| 194 |
|
|
#ifdef BSD
|
| 195 |
|
|
#define cpcolormat(md,ms) bcopy((char *)ms,(char *)md,sizeof(COLORMAT))
|
| 196 |
|
|
#else
|
| 197 |
|
|
extern char *memcpy();
|
| 198 |
|
|
#define cpcolormat(md,ms) (void)memcpy((char *)md,(char *)ms,sizeof(COLORMAT))
|
| 199 |
greg |
2.6 |
#endif
|