| 1 |
greg |
2.49 |
/* RCSid $Id: color.h,v 2.48 2024/08/14 20:05:23 greg Exp $ */
|
| 2 |
greg |
1.1 |
/*
|
| 3 |
greg |
2.38 |
* color.h - header for routines using pixel color and spectral values
|
| 4 |
greg |
2.46 |
* (Notes by Randolph Fritz)
|
| 5 |
greg |
1.1 |
*
|
| 6 |
greg |
2.46 |
* COLOR REPRESENTATION OVERVIEW
|
| 7 |
|
|
* =============================
|
| 8 |
|
|
* Internally, Radiance represents light in multiple spectral
|
| 9 |
|
|
* bands. Four spectral models are used: monochrome, RGB, XYZ,
|
| 10 |
|
|
* and multiband.
|
| 11 |
|
|
*
|
| 12 |
|
|
* Units
|
| 13 |
|
|
* -----
|
| 14 |
|
|
* Radiance -- W/sr/m2
|
| 15 |
|
|
* Irradiance -- W/m2
|
| 16 |
|
|
* Luminance -- lm/sr/m2
|
| 17 |
|
|
* Illuminance -- lm/m2
|
| 18 |
|
|
*
|
| 19 |
|
|
* Colors
|
| 20 |
|
|
* ------
|
| 21 |
|
|
* In the monochrome, RGB, and multiband formats, units of
|
| 22 |
|
|
* radiance and irradiance are used. In the XYZ format, units
|
| 23 |
|
|
* of luminance and illuminance are used, or sometimes an
|
| 24 |
|
|
* intermediate form, where the units are multiplied by the
|
| 25 |
|
|
* constant WHTEFFICACY, the scotopic luminous efficacy of
|
| 26 |
|
|
* white light. WHTEFFICACY is 179, an approximation of the
|
| 27 |
|
|
* luminous efficacy of the equal energy spectrum.
|
| 28 |
|
|
*
|
| 29 |
|
|
* In the multiband format, up to MAXCSAMP (by default 24)
|
| 30 |
|
|
* spectral bands may be used. 24 was chosen after testing,
|
| 31 |
|
|
* which found virtually no benefit for more than 18 bands. 24
|
| 32 |
|
|
* was chosen to allow for additional infrared or ultraviolet
|
| 33 |
|
|
* bands. If even that is not enough, MAXCSAMP can be increased
|
| 34 |
|
|
* at compile time.
|
| 35 |
|
|
*
|
| 36 |
|
|
* Numbers
|
| 37 |
|
|
* -------
|
| 38 |
|
|
* Calculations are done using 32-bit floating point numbers.
|
| 39 |
|
|
* Values are stored in the compressed real pixels[1] format,
|
| 40 |
|
|
* which allocates one byte per band, plus one for an exponent.
|
| 41 |
|
|
*
|
| 42 |
|
|
* Real Pixel Format
|
| 43 |
|
|
* -----------------
|
| 44 |
|
|
* The real pixel format gives at most eight bits of floating
|
| 45 |
|
|
* point precision to each spectral band; the brightest bands
|
| 46 |
|
|
* have full precision, darker ones less.
|
| 47 |
|
|
*
|
| 48 |
|
|
* In the real pixel format, each spectral band is allotted a
|
| 49 |
|
|
* one byte mantissa and a common single-byte exponent is used.
|
| 50 |
|
|
* The exponent has the range [-128,127] and each mantissa is
|
| 51 |
|
|
* assumed to have a binary point at the left, so they have the
|
| 52 |
|
|
* range [0,255/256]. In addition, the mantissas are
|
| 53 |
|
|
* normalized, so that at least one mantissa always is in the
|
| 54 |
|
|
* range [128/256, 255/256] -- one mantissa will always have
|
| 55 |
|
|
* its high-order bit set.
|
| 56 |
|
|
*
|
| 57 |
|
|
* References
|
| 58 |
|
|
* ----------
|
| 59 |
|
|
* [1] Ward, Greg. "Real Pixels." In Graphics Gems II, edited
|
| 60 |
|
|
* by Arvo, James, 80--83. Graphics Gems Series. Boston:
|
| 61 |
|
|
* Academic Press, 1991.
|
| 62 |
|
|
*
|
| 63 |
|
|
*
|
| 64 |
|
|
* IMPLEMENTATION DETAILS
|
| 65 |
|
|
* ======================
|
| 66 |
greg |
1.1 |
* Two color representations are used, one for calculation and
|
| 67 |
greg |
2.46 |
* another for storage. Calculation is done with an array of 32-bit
|
| 68 |
|
|
* floats for speed. Stored color values use single byte mantissas
|
| 69 |
|
|
* and a common exponent. By convention, types containing 32-bit
|
| 70 |
|
|
* floats are denoted by COLOR and compressed types are denoted by
|
| 71 |
|
|
* COLR. Tristimulus -- RGB or XYZ -- values can be stored in a
|
| 72 |
|
|
* single 32-bit word.
|
| 73 |
greg |
2.38 |
*
|
| 74 |
|
|
* Spectral colors have between 3 and MAXCSAMP samples, and cover
|
| 75 |
|
|
* wavelengths from WLPART[0] to WLPART[3] (max to min nanometers).
|
| 76 |
|
|
* Wavelengths WLPART[1] and WLPART[2] mark the separation
|
| 77 |
|
|
* of red/green and green/blue intervals, respectively.
|
| 78 |
|
|
* The wavelength range may go well beyond visible in either
|
| 79 |
|
|
* direction, but some routines will average over each interval
|
| 80 |
|
|
* and designate the means as R, G, and B, regardless.
|
| 81 |
|
|
* The number of samples is set in CNDX[3], and CNDX[0,1,2]
|
| 82 |
|
|
* give peak wavelength indices corresponding to stdprims.
|
| 83 |
|
|
* For best accuracy, internal calculations are promoted to
|
| 84 |
|
|
* the current number of samples and final conversions
|
| 85 |
|
|
* to tristimulus should use scolor_rgb() or scolor_cie().
|
| 86 |
|
|
*
|
| 87 |
greg |
2.46 |
* A Radiance file format is provided for spectral pictures, and
|
| 88 |
|
|
* spectral colors must be converted by caller if the sampling
|
| 89 |
|
|
* doesn't match.
|
| 90 |
greg |
1.1 |
*/
|
| 91 |
schorsch |
2.21 |
#ifndef _RAD_COLOR_H_
|
| 92 |
|
|
#define _RAD_COLOR_H_
|
| 93 |
schorsch |
2.25 |
|
| 94 |
greg |
2.33 |
#include <stdio.h>
|
| 95 |
schorsch |
2.25 |
#include <stdlib.h>
|
| 96 |
greg |
2.38 |
#include <string.h>
|
| 97 |
schorsch |
2.25 |
|
| 98 |
schorsch |
2.21 |
#ifdef __cplusplus
|
| 99 |
|
|
extern "C" {
|
| 100 |
|
|
#endif
|
| 101 |
greg |
2.18 |
|
| 102 |
greg |
2.38 |
#ifndef MAXCSAMP
|
| 103 |
|
|
#define MAXCSAMP 24 /* maximum # spectral samples */
|
| 104 |
|
|
#endif
|
| 105 |
|
|
|
| 106 |
greg |
2.46 |
/* Subscripts for tristimulus colors */
|
| 107 |
greg |
1.1 |
#define RED 0
|
| 108 |
|
|
#define GRN 1
|
| 109 |
|
|
#define BLU 2
|
| 110 |
greg |
2.10 |
#define CIEX 0 /* or, if input is XYZ... */
|
| 111 |
|
|
#define CIEY 1
|
| 112 |
|
|
#define CIEZ 2
|
| 113 |
|
|
#define EXP 3 /* exponent same for either format */
|
| 114 |
greg |
1.1 |
#define COLXS 128 /* excess used for exponent */
|
| 115 |
greg |
2.10 |
#define WHT 3 /* used for RGBPRIMS type */
|
| 116 |
greg |
1.1 |
|
| 117 |
greg |
2.31 |
#undef uby8
|
| 118 |
|
|
#define uby8 unsigned char /* 8-bit unsigned integer */
|
| 119 |
greg |
1.1 |
|
| 120 |
greg |
2.48 |
typedef uby8 COLRV;
|
| 121 |
|
|
typedef COLRV COLR[4]; /* red, green, blue (or X,Y,Z), exponent */
|
| 122 |
|
|
typedef COLRV SCOLR[MAXCSAMP+1]; /* spectral color, common exponent */
|
| 123 |
greg |
1.1 |
|
| 124 |
schorsch |
2.28 |
typedef float COLORV;
|
| 125 |
|
|
typedef COLORV COLOR[3]; /* red, green, blue (or X,Y,Z) */
|
| 126 |
greg |
2.38 |
typedef COLORV SCOLOR[MAXCSAMP]; /* spectral color */
|
| 127 |
greg |
2.10 |
|
| 128 |
|
|
typedef float RGBPRIMS[4][2]; /* (x,y) chromaticities for RGBW */
|
| 129 |
|
|
typedef float (*RGBPRIMP)[2]; /* pointer to RGBPRIMS array */
|
| 130 |
|
|
|
| 131 |
|
|
typedef float COLORMAT[3][3]; /* color coordinate conversion matrix */
|
| 132 |
|
|
|
| 133 |
greg |
1.1 |
#define copycolr(c1,c2) (c1[0]=c2[0],c1[1]=c2[1], \
|
| 134 |
|
|
c1[2]=c2[2],c1[3]=c2[3])
|
| 135 |
|
|
|
| 136 |
greg |
2.38 |
#define colval(col,pri) (col)[pri]
|
| 137 |
greg |
1.1 |
|
| 138 |
|
|
#define setcolor(col,r,g,b) ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
|
| 139 |
|
|
|
| 140 |
greg |
2.38 |
#define scalecolor(col,sf) ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf))
|
| 141 |
|
|
|
| 142 |
|
|
#define opcolor(c1,op,c2) ((c1)[0]op(c2)[0],(c1)[1]op(c2)[1],(c1)[2]op(c2)[2])
|
| 143 |
|
|
|
| 144 |
|
|
#define copycolor(c1,c2) opcolor(c1,=,c2)
|
| 145 |
|
|
|
| 146 |
|
|
#define addcolor(c1,c2) opcolor(c1,+=,c2)
|
| 147 |
|
|
|
| 148 |
|
|
#define multcolor(c1,c2) opcolor(c1,*=,c2)
|
| 149 |
|
|
|
| 150 |
|
|
#define NCSAMP CNDX[EXP] /* current number of spectral samples */
|
| 151 |
|
|
#define LSCOLR (NCSAMP+1)
|
| 152 |
|
|
|
| 153 |
|
|
#define copyscolr(sc1,sc2) memcpy(sc1,sc2,LSCOLR)
|
| 154 |
|
|
|
| 155 |
|
|
#define scolval(sc,pri) (sc)[CNDX[pri]]
|
| 156 |
|
|
|
| 157 |
|
|
#define copyscolor(sc1,sc2) memcpy(sc1,sc2,sizeof(COLORV)*NCSAMP)
|
| 158 |
|
|
|
| 159 |
|
|
#define scalescolor(sc,sf) {const float _f=sf; int _i=NCSAMP; \
|
| 160 |
|
|
while (_i--) (sc)[_i] *= _f;}
|
| 161 |
|
|
|
| 162 |
|
|
/* faster, use principal colors for RGB */
|
| 163 |
|
|
#define pcolor_color(col,scol) setcolor(col,scolval(scol,RED),\
|
| 164 |
|
|
scolval(scol,GRN),scolval(scol,BLU))
|
| 165 |
|
|
#define pcolor_colr(clr,scol) setcolr(clr,scolval(scol,RED),\
|
| 166 |
|
|
scolval(scol,GRN),scolval(scol,BLU))
|
| 167 |
|
|
|
| 168 |
|
|
#define sopscolor(sc1,op,sc2) {int _i=NCSAMP; while (_i--) (sc1)[_i] op (sc2)[_i];}
|
| 169 |
|
|
|
| 170 |
|
|
#define saddscolor(sc1,sc2) sopscolor(sc1,+=,sc2)
|
| 171 |
|
|
|
| 172 |
|
|
#define smultscolor(sc1,sc2) sopscolor(sc1,*=,sc2)
|
| 173 |
|
|
|
| 174 |
|
|
#define scolrblack(c) memset(c,0,LSCOLR)
|
| 175 |
greg |
1.1 |
|
| 176 |
greg |
2.44 |
#define scolorblack(c) memset(c,0,sizeof(COLORV)*NCSAMP)
|
| 177 |
greg |
2.38 |
|
| 178 |
|
|
#define scolor_color(col,scol) scolor2color(col,scol,NCSAMP,WLPART)
|
| 179 |
|
|
#define scolor_colr(clr,scol) scolor2colr(clr,scol,NCSAMP,WLPART)
|
| 180 |
|
|
#define scolor_scolr(sclr,scol) scolor2scolr(sclr,scol,NCSAMP)
|
| 181 |
|
|
#define scolr_scolor(scol,sclr) scolr2scolor(scol,sclr,NCSAMP)
|
| 182 |
|
|
#define scolr_color(col,sclr) scolr2color(col,sclr,NCSAMP,WLPART)
|
| 183 |
|
|
|
| 184 |
|
|
#define sopcolor(sc1,op,c2) {SCOLOR _sct;\
|
| 185 |
greg |
2.42 |
setscolor(_sct,(c2)[RED],(c2)[GRN],(c2)[BLU]);\
|
| 186 |
greg |
2.38 |
sopscolor(sc1,op,_sct);}
|
| 187 |
|
|
|
| 188 |
|
|
#define saddcolor(sc1,c2) sopcolor(sc1,+=,c2)
|
| 189 |
|
|
|
| 190 |
|
|
#define smultcolor(sc1,c2) sopcolor(sc1,*=,c2)
|
| 191 |
|
|
|
| 192 |
|
|
#define opscolor(c1,op,sc2) {COLOR _ct; scolor_color(_ct,sc2);\
|
| 193 |
|
|
opcolor(c1,op,_ct);}
|
| 194 |
greg |
1.1 |
|
| 195 |
greg |
2.38 |
#define addscolor(c1,sc2) opscolor(c1,+=,sc2)
|
| 196 |
greg |
1.1 |
|
| 197 |
greg |
2.38 |
#define multscolor(c1,sc2) opscolor(c1,*=,sc2)
|
| 198 |
greg |
1.1 |
|
| 199 |
greg |
2.35 |
#if defined(NTSC_RGB)
|
| 200 |
greg |
2.7 |
#define CIE_x_r 0.670 /* standard NTSC primaries */
|
| 201 |
|
|
#define CIE_y_r 0.330
|
| 202 |
|
|
#define CIE_x_g 0.210
|
| 203 |
|
|
#define CIE_y_g 0.710
|
| 204 |
|
|
#define CIE_x_b 0.140
|
| 205 |
|
|
#define CIE_y_b 0.080
|
| 206 |
greg |
2.35 |
#define CIE_x_w (1./3.) /* use EE white */
|
| 207 |
|
|
#define CIE_y_w (1./3.)
|
| 208 |
|
|
#elif defined(SHARP_RGB)
|
| 209 |
|
|
#define CIE_x_r 0.6898 /* "sharp" RGB primaries */
|
| 210 |
|
|
#define CIE_y_r 0.3206
|
| 211 |
|
|
#define CIE_x_g 0.0736
|
| 212 |
|
|
#define CIE_y_g 0.9003
|
| 213 |
|
|
#define CIE_x_b 0.1166
|
| 214 |
|
|
#define CIE_y_b 0.0374
|
| 215 |
|
|
#define CIE_x_w (1./3.) /* use EE white */
|
| 216 |
greg |
2.34 |
#define CIE_y_w (1./3.)
|
| 217 |
greg |
1.7 |
#else
|
| 218 |
greg |
2.7 |
#define CIE_x_r 0.640 /* nominal CRT primaries */
|
| 219 |
|
|
#define CIE_y_r 0.330
|
| 220 |
|
|
#define CIE_x_g 0.290
|
| 221 |
|
|
#define CIE_y_g 0.600
|
| 222 |
|
|
#define CIE_x_b 0.150
|
| 223 |
|
|
#define CIE_y_b 0.060
|
| 224 |
greg |
2.35 |
#define CIE_x_w (1./3.) /* use EE white */
|
| 225 |
greg |
2.34 |
#define CIE_y_w (1./3.)
|
| 226 |
greg |
1.7 |
#endif
|
| 227 |
greg |
2.7 |
|
| 228 |
greg |
2.14 |
#define STDPRIMS {{CIE_x_r,CIE_y_r},{CIE_x_g,CIE_y_g}, \
|
| 229 |
|
|
{CIE_x_b,CIE_y_b},{CIE_x_w,CIE_y_w}}
|
| 230 |
greg |
2.10 |
|
| 231 |
greg |
2.7 |
#define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \
|
| 232 |
|
|
CIE_x_g*(CIE_y_b - CIE_y_r) + \
|
| 233 |
|
|
CIE_x_b*(CIE_y_r - CIE_y_g) )
|
| 234 |
|
|
#define CIE_C_rD ( (1./CIE_y_w) * \
|
| 235 |
|
|
( CIE_x_w*(CIE_y_g - CIE_y_b) - \
|
| 236 |
|
|
CIE_y_w*(CIE_x_g - CIE_x_b) + \
|
| 237 |
|
|
CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
|
| 238 |
|
|
#define CIE_C_gD ( (1./CIE_y_w) * \
|
| 239 |
|
|
( CIE_x_w*(CIE_y_b - CIE_y_r) - \
|
| 240 |
|
|
CIE_y_w*(CIE_x_b - CIE_x_r) - \
|
| 241 |
|
|
CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
|
| 242 |
|
|
#define CIE_C_bD ( (1./CIE_y_w) * \
|
| 243 |
|
|
( CIE_x_w*(CIE_y_r - CIE_y_g) - \
|
| 244 |
|
|
CIE_y_w*(CIE_x_r - CIE_x_g) + \
|
| 245 |
|
|
CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
|
| 246 |
|
|
|
| 247 |
|
|
#define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D)
|
| 248 |
|
|
#define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D)
|
| 249 |
|
|
#define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D)
|
| 250 |
|
|
|
| 251 |
greg |
2.35 |
/* Default CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */
|
| 252 |
greg |
2.9 |
|
| 253 |
greg |
2.38 |
/***** The following definitions are not for XYZ colors *****/
|
| 254 |
greg |
2.10 |
|
| 255 |
greg |
2.7 |
#define bright(col) (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
|
| 256 |
greg |
2.38 |
#define pbright(col) (CIE_rf*scolval(col,RED) + CIE_gf*scolval(col,GRN) + \
|
| 257 |
|
|
CIE_bf*scolval(col,BLU))
|
| 258 |
greg |
2.7 |
#define normbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
|
| 259 |
|
|
(long)(CIE_gf*256.+.5)*(c)[GRN] + \
|
| 260 |
|
|
(long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )
|
| 261 |
greg |
2.38 |
#define normpbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[CNDX[RED]] + \
|
| 262 |
|
|
(long)(CIE_gf*256.+.5)*(c)[CNDX[GRN]] + \
|
| 263 |
|
|
(long)(CIE_bf*256.+.5)*(c)[CNDX[BLU]] ) >> 8 )
|
| 264 |
greg |
1.1 |
|
| 265 |
greg |
1.14 |
/* luminous efficacies over visible spectrum */
|
| 266 |
|
|
#define MAXEFFICACY 683. /* defined maximum at 550 nm */
|
| 267 |
greg |
2.38 |
#define WHTEFFICACY 179. /* equal energy white 380-780nm */
|
| 268 |
greg |
1.14 |
#define D65EFFICACY 203. /* standard illuminant D65 */
|
| 269 |
|
|
#define INCEFFICACY 160. /* illuminant A (incand.) */
|
| 270 |
|
|
#define SUNEFFICACY 208. /* illuminant B (solar dir.) */
|
| 271 |
greg |
2.27 |
#define SKYEFFICACY D65EFFICACY /* skylight (should be 110) */
|
| 272 |
greg |
1.14 |
#define DAYEFFICACY D65EFFICACY /* combined sky and solar */
|
| 273 |
greg |
2.38 |
#define WHTSCOTOPIC 412. /* scotopic EE white 380-780nm */
|
| 274 |
|
|
#define WHTMELANOPIC 179. /* melanopic EE white 380-780nm */
|
| 275 |
greg |
1.14 |
|
| 276 |
|
|
#define luminance(col) (WHTEFFICACY * bright(col))
|
| 277 |
greg |
2.38 |
#define pluminance(scol) (WHTEFFICACY * pbright(scol))
|
| 278 |
|
|
|
| 279 |
|
|
#define scolor_rgb(col,scol) scolor2rgb(col,scol,NCSAMP,WLPART)
|
| 280 |
greg |
1.9 |
|
| 281 |
greg |
2.10 |
/***** ...end of stuff specific to RGB colors *****/
|
| 282 |
|
|
|
| 283 |
greg |
2.38 |
#define scolor_cie(col,scol) scolor2cie(col,scol,NCSAMP,WLPART)
|
| 284 |
|
|
|
| 285 |
|
|
#define sluminance(scol) (WHTEFFICACY * scolor_photopic(scol))
|
| 286 |
|
|
|
| 287 |
greg |
1.1 |
#define intens(col) ( (col)[0] > (col)[1] \
|
| 288 |
|
|
? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
|
| 289 |
|
|
: (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
|
| 290 |
|
|
|
| 291 |
greg |
1.3 |
#define colrval(c,p) ( (c)[EXP] ? \
|
| 292 |
|
|
ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \
|
| 293 |
|
|
0. )
|
| 294 |
|
|
|
| 295 |
greg |
2.38 |
#define scolrval(c,p) ( (c)[CNDX[EXP]] ? \
|
| 296 |
|
|
ldexp((c)[CNDX[p]]+.5,(int)(c)[CNDX[EXP]]-(COLXS+8)) : \
|
| 297 |
|
|
0. )
|
| 298 |
|
|
|
| 299 |
greg |
1.1 |
#define WHTCOLOR {1.0,1.0,1.0}
|
| 300 |
|
|
#define BLKCOLOR {0.0,0.0,0.0}
|
| 301 |
|
|
#define WHTCOLR {128,128,128,COLXS+1}
|
| 302 |
|
|
#define BLKCOLR {0,0,0,0}
|
| 303 |
greg |
1.3 |
|
| 304 |
greg |
1.11 |
/* picture format identifier */
|
| 305 |
|
|
#define COLRFMT "32-bit_rle_rgbe"
|
| 306 |
greg |
2.10 |
#define CIEFMT "32-bit_rle_xyze"
|
| 307 |
|
|
#define PICFMT "32-bit_rle_???e" /* matches either */
|
| 308 |
greg |
2.40 |
#define SPECFMT "Radiance_spectra" /* spectral data w/ exponent */
|
| 309 |
greg |
2.38 |
|
| 310 |
|
|
/* Number of spectral components */
|
| 311 |
|
|
#define NCOMPSTR "NCOMP="
|
| 312 |
|
|
#define LNCOMPSTR 6
|
| 313 |
greg |
2.43 |
#define isncomp(hl) !strncmp(hl,NCOMPSTR,LNCOMPSTR)
|
| 314 |
greg |
2.38 |
#define ncompval(hl) atoi((hl)+LNCOMPSTR)
|
| 315 |
|
|
#define fputncomp(nc,fp) fprintf(fp,"%s%d\n",NCOMPSTR,nc)
|
| 316 |
|
|
|
| 317 |
|
|
/* 4 wavelength partitions for (IR+)R,G,B(+UV) */
|
| 318 |
|
|
#define WLSPLTSTR "WAVELENGTH_SPLITS="
|
| 319 |
|
|
#define LWLSPLTSTR 18
|
| 320 |
greg |
2.43 |
#define iswlsplit(hl) !strncmp(hl,WLSPLTSTR,LWLSPLTSTR)
|
| 321 |
greg |
2.38 |
#define wlsplitval(w,hl) (sscanf((hl)+LWLSPLTSTR,"%f %f %f %f",\
|
| 322 |
|
|
&(w)[0],&(w)[1],&(w)[2],&(w)[3]) == 4)
|
| 323 |
greg |
2.39 |
#define fputwlsplit(w,fp) fprintf(fp,"%s %g %g %g %g\n",WLSPLTSTR,\
|
| 324 |
greg |
2.38 |
(w)[0],(w)[1],(w)[2],(w)[3])
|
| 325 |
greg |
1.11 |
|
| 326 |
greg |
1.6 |
/* macros for exposures */
|
| 327 |
greg |
1.5 |
#define EXPOSSTR "EXPOSURE="
|
| 328 |
greg |
1.12 |
#define LEXPOSSTR 9
|
| 329 |
greg |
2.43 |
#define isexpos(hl) !strncmp(hl,EXPOSSTR,LEXPOSSTR)
|
| 330 |
greg |
1.12 |
#define exposval(hl) atof((hl)+LEXPOSSTR)
|
| 331 |
greg |
2.37 |
#define fputexpos(ex,fp) fprintf(fp,"%s%.4e\n",EXPOSSTR,ex)
|
| 332 |
greg |
1.6 |
|
| 333 |
|
|
/* macros for pixel aspect ratios */
|
| 334 |
|
|
#define ASPECTSTR "PIXASPECT="
|
| 335 |
greg |
1.12 |
#define LASPECTSTR 10
|
| 336 |
greg |
2.43 |
#define isaspect(hl) !strncmp(hl,ASPECTSTR,LASPECTSTR)
|
| 337 |
greg |
1.12 |
#define aspectval(hl) atof((hl)+LASPECTSTR)
|
| 338 |
greg |
1.6 |
#define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa)
|
| 339 |
greg |
1.5 |
|
| 340 |
greg |
2.10 |
/* macros for primary specifications */
|
| 341 |
|
|
#define PRIMARYSTR "PRIMARIES="
|
| 342 |
|
|
#define LPRIMARYSTR 10
|
| 343 |
greg |
2.43 |
#define isprims(hl) !strncmp(hl,PRIMARYSTR,LPRIMARYSTR)
|
| 344 |
greg |
2.32 |
#define primsval(p,hl) (sscanf((hl)+LPRIMARYSTR, \
|
| 345 |
greg |
2.10 |
"%f %f %f %f %f %f %f %f", \
|
| 346 |
|
|
&(p)[RED][CIEX],&(p)[RED][CIEY], \
|
| 347 |
|
|
&(p)[GRN][CIEX],&(p)[GRN][CIEY], \
|
| 348 |
|
|
&(p)[BLU][CIEX],&(p)[BLU][CIEY], \
|
| 349 |
greg |
2.32 |
&(p)[WHT][CIEX],&(p)[WHT][CIEY]) == 8)
|
| 350 |
greg |
2.10 |
#define fputprims(p,fp) fprintf(fp, \
|
| 351 |
|
|
"%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\
|
| 352 |
|
|
PRIMARYSTR, \
|
| 353 |
|
|
(p)[RED][CIEX],(p)[RED][CIEY], \
|
| 354 |
|
|
(p)[GRN][CIEX],(p)[GRN][CIEY], \
|
| 355 |
|
|
(p)[BLU][CIEX],(p)[BLU][CIEY], \
|
| 356 |
|
|
(p)[WHT][CIEX],(p)[WHT][CIEY])
|
| 357 |
|
|
|
| 358 |
greg |
1.8 |
/* macros for color correction */
|
| 359 |
|
|
#define COLCORSTR "COLORCORR="
|
| 360 |
greg |
1.12 |
#define LCOLCORSTR 10
|
| 361 |
greg |
2.43 |
#define iscolcor(hl) !strncmp(hl,COLCORSTR,LCOLCORSTR)
|
| 362 |
greg |
2.30 |
#define colcorval(cc,hl) sscanf((hl)+LCOLCORSTR,"%f %f %f", \
|
| 363 |
greg |
1.8 |
&(cc)[RED],&(cc)[GRN],&(cc)[BLU])
|
| 364 |
|
|
#define fputcolcor(cc,fp) fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
|
| 365 |
|
|
(cc)[RED],(cc)[GRN],(cc)[BLU])
|
| 366 |
greg |
2.6 |
|
| 367 |
greg |
2.10 |
/*
|
| 368 |
|
|
* Conversions to and from XYZ space generally don't apply WHTEFFICACY.
|
| 369 |
|
|
* If you need Y to be luminance (cd/m^2), this must be applied when
|
| 370 |
|
|
* converting from radiance (watts/sr/m^2).
|
| 371 |
|
|
*/
|
| 372 |
|
|
|
| 373 |
greg |
2.38 |
extern int CNDX[4]; /* RGBE indices for SCOLOR, SCOLR */
|
| 374 |
|
|
extern float WLPART[4]; /* RGB wavelength limits+partitions (nm) */
|
| 375 |
greg |
2.18 |
extern RGBPRIMS stdprims; /* standard primary chromaticities */
|
| 376 |
greg |
2.38 |
extern RGBPRIMS xyzprims; /* to indicate XYZ input or output */
|
| 377 |
greg |
2.18 |
extern COLORMAT rgb2xyzmat; /* RGB to XYZ conversion matrix */
|
| 378 |
|
|
extern COLORMAT xyz2rgbmat; /* XYZ to RGB conversion matrix */
|
| 379 |
greg |
2.49 |
extern const COLOR cblack, cwhite; /* black (0,0,0) and white (1,1,1) */
|
| 380 |
|
|
extern const SCOLOR scblack; /* black spectral color (all 0's) */
|
| 381 |
greg |
2.10 |
|
| 382 |
greg |
2.13 |
#define CGAMUT_LOWER 01
|
| 383 |
|
|
#define CGAMUT_UPPER 02
|
| 384 |
|
|
#define CGAMUT (CGAMUT_LOWER|CGAMUT_UPPER)
|
| 385 |
|
|
|
| 386 |
|
|
#define rgb_cie(xyz,rgb) colortrans(xyz,rgb2xyzmat,rgb)
|
| 387 |
greg |
2.10 |
|
| 388 |
greg |
2.20 |
#define cpcolormat(md,ms) memcpy((void *)md,(void *)ms,sizeof(COLORMAT))
|
| 389 |
greg |
2.18 |
|
| 390 |
|
|
/* defined in color.c */
|
| 391 |
greg |
2.38 |
extern void *tempbuffer(size_t len);
|
| 392 |
|
|
/* in cn[3]=nsamps, wlpt[0],wlpt[3]=extrema */
|
| 393 |
|
|
extern int setspectrsamp(int cn[4], float wlpt[4]);
|
| 394 |
greg |
2.18 |
extern int fwritecolrs(COLR *scanline, int len, FILE *fp);
|
| 395 |
greg |
2.38 |
extern int fwritescan(COLOR *scanline, int len, FILE *fp);
|
| 396 |
greg |
2.48 |
extern int fwritescolrs(const COLRV *sscanline, int nc, int len, FILE *fp);
|
| 397 |
|
|
extern int fwritesscan(const COLORV *sscanline, int nc, int len, FILE *fp);
|
| 398 |
greg |
2.18 |
extern int freadcolrs(COLR *scanline, int len, FILE *fp);
|
| 399 |
|
|
extern int freadscan(COLOR *scanline, int len, FILE *fp);
|
| 400 |
greg |
2.48 |
extern int freadscolrs(COLRV *scanline, int nc, int len, FILE *fp);
|
| 401 |
greg |
2.38 |
extern int freadsscan(COLORV *sscanline, int nc, int len, FILE *fp);
|
| 402 |
|
|
/* spectrum conversion, zero-fill past ends */
|
| 403 |
|
|
extern void convertscolor(SCOLOR dst, int dnc, double dwl0, double dwl1,
|
| 404 |
|
|
const COLORV src[], int snc, double swl0, double swl1);
|
| 405 |
|
|
/* the following use avg spectral ranges */
|
| 406 |
|
|
/* compare scolor_rgb() and scolor_cie() */
|
| 407 |
|
|
/* also, pcolor_color() and pcolor_colr() */
|
| 408 |
|
|
extern void setscolor(SCOLOR scol, double r, double g, double b);
|
| 409 |
greg |
2.48 |
extern void scolor2color(COLOR col, const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 410 |
|
|
extern void scolor2colr(COLR clr, const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 411 |
|
|
extern void scolor2scolr(SCOLR sclr, const SCOLOR scol, int ncs);
|
| 412 |
|
|
extern void colr_color(COLOR col, const COLR clr);
|
| 413 |
|
|
extern void scolr2scolor(SCOLOR scol, const SCOLR sclr, int ncs);
|
| 414 |
|
|
extern void scolr2color(COLOR col, const SCOLR sclr, int ncs, const float wlpt[4]);
|
| 415 |
greg |
2.18 |
extern void setcolr(COLR clr, double r, double g, double b);
|
| 416 |
greg |
2.38 |
extern void setscolr(SCOLR sclr, double r, double g, double b);
|
| 417 |
greg |
2.48 |
extern double scolor_mean(const SCOLOR scol);
|
| 418 |
|
|
extern double sintens(const SCOLOR scol);
|
| 419 |
|
|
extern int bigdiff(const COLOR c1, const COLOR c2, double md);
|
| 420 |
|
|
extern int sbigsdiff(const SCOLOR sc1, const SCOLOR sc2, double md);
|
| 421 |
greg |
2.18 |
/* defined in spec_rgb.c */
|
| 422 |
greg |
2.48 |
extern void scolor_out(COLORV *cout, RGBPRIMS pr, const SCOLOR cres);
|
| 423 |
greg |
2.38 |
extern void spec_cie(COLOR col, int s, int e);
|
| 424 |
greg |
2.18 |
extern void spec_rgb(COLOR col, int s, int e);
|
| 425 |
greg |
2.48 |
extern void cie_rgb(COLOR rgb, const COLOR xyz);
|
| 426 |
greg |
2.18 |
extern int clipgamut(COLOR col, double brt, int gamut,
|
| 427 |
greg |
2.48 |
const COLOR lower, const COLOR upper);
|
| 428 |
|
|
extern void colortrans(COLOR c2, const COLORMAT mat, const COLOR c1);
|
| 429 |
|
|
extern void multcolormat(COLORMAT m3, const COLORMAT m2,
|
| 430 |
|
|
const COLORMAT m1);
|
| 431 |
greg |
2.29 |
extern int colorprimsOK(RGBPRIMS pr);
|
| 432 |
|
|
extern int compxyz2rgbmat(COLORMAT mat, RGBPRIMS pr);
|
| 433 |
|
|
extern int comprgb2xyzmat(COLORMAT mat, RGBPRIMS pr);
|
| 434 |
|
|
extern int comprgb2rgbmat(COLORMAT mat, RGBPRIMS pr1, RGBPRIMS pr2);
|
| 435 |
greg |
2.48 |
extern int compxyzWBmat(COLORMAT mat, const float wht1[2], const float wht2[2]);
|
| 436 |
greg |
2.29 |
extern int compxyz2rgbWBmat(COLORMAT mat, RGBPRIMS pr);
|
| 437 |
|
|
extern int comprgb2xyzWBmat(COLORMAT mat, RGBPRIMS pr);
|
| 438 |
|
|
extern int comprgb2rgbWBmat(COLORMAT mat, RGBPRIMS pr1, RGBPRIMS pr2);
|
| 439 |
greg |
2.45 |
/* any uniform spectrum to working */
|
| 440 |
|
|
extern void convertscolorcol(SCOLOR rcol, const COLORV src[], int snc,
|
| 441 |
|
|
double swl0, double swl1);
|
| 442 |
greg |
2.38 |
/* most accurate spectral->tristim */
|
| 443 |
greg |
2.48 |
extern void scolor2cie(COLOR col, const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 444 |
|
|
extern void scolor2rgb(COLOR col, const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 445 |
|
|
extern double scolor2photopic(const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 446 |
|
|
extern double scolor2scotopic(const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 447 |
|
|
extern double scolor2melanopic(const SCOLOR scol, int ncs, const float wlpt[4]);
|
| 448 |
|
|
extern double scolor_photopic(const SCOLOR scol);
|
| 449 |
|
|
extern double scolor_scotopic(const SCOLOR scol);
|
| 450 |
|
|
extern double scolor_melanopic(const SCOLOR scol);
|
| 451 |
greg |
2.18 |
/* defined in colrops.c */
|
| 452 |
schorsch |
2.26 |
extern int setcolrcor(double (*f)(double, double), double a2);
|
| 453 |
|
|
extern int setcolrinv(double (*f)(double, double), double a2);
|
| 454 |
greg |
2.18 |
extern int setcolrgam(double g);
|
| 455 |
|
|
extern int colrs_gambs(COLR *scan, int len);
|
| 456 |
|
|
extern int gambs_colrs(COLR *scan, int len);
|
| 457 |
|
|
extern void shiftcolrs(COLR *scan, int len, int adjust);
|
| 458 |
|
|
extern void normcolrs(COLR *scan, int len, int adjust);
|
| 459 |
|
|
|
| 460 |
|
|
#ifdef __cplusplus
|
| 461 |
|
|
}
|
| 462 |
greg |
2.6 |
#endif
|
| 463 |
schorsch |
2.21 |
#endif /* _RAD_COLOR_H_ */
|
| 464 |
|
|
|