1 |
greg |
2.52 |
/* RCSid $Id: color.h,v 2.51 2024/10/29 00:35:06 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 |
greg |
2.52 |
#define cx2real(m,e) (((m)+.5f)*cxponent[e]) |
158 |
|
|
|
159 |
greg |
2.38 |
#define copyscolor(sc1,sc2) memcpy(sc1,sc2,sizeof(COLORV)*NCSAMP) |
160 |
|
|
|
161 |
|
|
#define scalescolor(sc,sf) {const float _f=sf; int _i=NCSAMP; \ |
162 |
|
|
while (_i--) (sc)[_i] *= _f;} |
163 |
|
|
|
164 |
|
|
/* faster, use principal colors for RGB */ |
165 |
|
|
#define pcolor_color(col,scol) setcolor(col,scolval(scol,RED),\ |
166 |
|
|
scolval(scol,GRN),scolval(scol,BLU)) |
167 |
|
|
#define pcolor_colr(clr,scol) setcolr(clr,scolval(scol,RED),\ |
168 |
|
|
scolval(scol,GRN),scolval(scol,BLU)) |
169 |
|
|
|
170 |
|
|
#define sopscolor(sc1,op,sc2) {int _i=NCSAMP; while (_i--) (sc1)[_i] op (sc2)[_i];} |
171 |
|
|
|
172 |
|
|
#define saddscolor(sc1,sc2) sopscolor(sc1,+=,sc2) |
173 |
|
|
|
174 |
|
|
#define smultscolor(sc1,sc2) sopscolor(sc1,*=,sc2) |
175 |
|
|
|
176 |
|
|
#define scolrblack(c) memset(c,0,LSCOLR) |
177 |
greg |
1.1 |
|
178 |
greg |
2.44 |
#define scolorblack(c) memset(c,0,sizeof(COLORV)*NCSAMP) |
179 |
greg |
2.38 |
|
180 |
|
|
#define scolor_color(col,scol) scolor2color(col,scol,NCSAMP,WLPART) |
181 |
|
|
#define scolor_colr(clr,scol) scolor2colr(clr,scol,NCSAMP,WLPART) |
182 |
|
|
#define scolor_scolr(sclr,scol) scolor2scolr(sclr,scol,NCSAMP) |
183 |
|
|
#define scolr_scolor(scol,sclr) scolr2scolor(scol,sclr,NCSAMP) |
184 |
|
|
#define scolr_color(col,sclr) scolr2color(col,sclr,NCSAMP,WLPART) |
185 |
|
|
|
186 |
|
|
#define sopcolor(sc1,op,c2) {SCOLOR _sct;\ |
187 |
greg |
2.42 |
setscolor(_sct,(c2)[RED],(c2)[GRN],(c2)[BLU]);\ |
188 |
greg |
2.38 |
sopscolor(sc1,op,_sct);} |
189 |
|
|
|
190 |
|
|
#define saddcolor(sc1,c2) sopcolor(sc1,+=,c2) |
191 |
|
|
|
192 |
|
|
#define smultcolor(sc1,c2) sopcolor(sc1,*=,c2) |
193 |
|
|
|
194 |
|
|
#define opscolor(c1,op,sc2) {COLOR _ct; scolor_color(_ct,sc2);\ |
195 |
|
|
opcolor(c1,op,_ct);} |
196 |
greg |
1.1 |
|
197 |
greg |
2.38 |
#define addscolor(c1,sc2) opscolor(c1,+=,sc2) |
198 |
greg |
1.1 |
|
199 |
greg |
2.38 |
#define multscolor(c1,sc2) opscolor(c1,*=,sc2) |
200 |
greg |
1.1 |
|
201 |
greg |
2.35 |
#if defined(NTSC_RGB) |
202 |
greg |
2.7 |
#define CIE_x_r 0.670 /* standard NTSC primaries */ |
203 |
|
|
#define CIE_y_r 0.330 |
204 |
|
|
#define CIE_x_g 0.210 |
205 |
|
|
#define CIE_y_g 0.710 |
206 |
|
|
#define CIE_x_b 0.140 |
207 |
|
|
#define CIE_y_b 0.080 |
208 |
greg |
2.35 |
#define CIE_x_w (1./3.) /* use EE white */ |
209 |
|
|
#define CIE_y_w (1./3.) |
210 |
|
|
#elif defined(SHARP_RGB) |
211 |
|
|
#define CIE_x_r 0.6898 /* "sharp" RGB primaries */ |
212 |
|
|
#define CIE_y_r 0.3206 |
213 |
|
|
#define CIE_x_g 0.0736 |
214 |
|
|
#define CIE_y_g 0.9003 |
215 |
|
|
#define CIE_x_b 0.1166 |
216 |
|
|
#define CIE_y_b 0.0374 |
217 |
|
|
#define CIE_x_w (1./3.) /* use EE white */ |
218 |
greg |
2.34 |
#define CIE_y_w (1./3.) |
219 |
greg |
1.7 |
#else |
220 |
greg |
2.7 |
#define CIE_x_r 0.640 /* nominal CRT primaries */ |
221 |
|
|
#define CIE_y_r 0.330 |
222 |
|
|
#define CIE_x_g 0.290 |
223 |
|
|
#define CIE_y_g 0.600 |
224 |
|
|
#define CIE_x_b 0.150 |
225 |
|
|
#define CIE_y_b 0.060 |
226 |
greg |
2.35 |
#define CIE_x_w (1./3.) /* use EE white */ |
227 |
greg |
2.34 |
#define CIE_y_w (1./3.) |
228 |
greg |
1.7 |
#endif |
229 |
greg |
2.7 |
|
230 |
greg |
2.14 |
#define STDPRIMS {{CIE_x_r,CIE_y_r},{CIE_x_g,CIE_y_g}, \ |
231 |
|
|
{CIE_x_b,CIE_y_b},{CIE_x_w,CIE_y_w}} |
232 |
greg |
2.10 |
|
233 |
greg |
2.7 |
#define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \ |
234 |
|
|
CIE_x_g*(CIE_y_b - CIE_y_r) + \ |
235 |
|
|
CIE_x_b*(CIE_y_r - CIE_y_g) ) |
236 |
|
|
#define CIE_C_rD ( (1./CIE_y_w) * \ |
237 |
|
|
( CIE_x_w*(CIE_y_g - CIE_y_b) - \ |
238 |
|
|
CIE_y_w*(CIE_x_g - CIE_x_b) + \ |
239 |
|
|
CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) ) |
240 |
|
|
#define CIE_C_gD ( (1./CIE_y_w) * \ |
241 |
|
|
( CIE_x_w*(CIE_y_b - CIE_y_r) - \ |
242 |
|
|
CIE_y_w*(CIE_x_b - CIE_x_r) - \ |
243 |
|
|
CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) ) |
244 |
|
|
#define CIE_C_bD ( (1./CIE_y_w) * \ |
245 |
|
|
( CIE_x_w*(CIE_y_r - CIE_y_g) - \ |
246 |
|
|
CIE_y_w*(CIE_x_r - CIE_x_g) + \ |
247 |
|
|
CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) ) |
248 |
|
|
|
249 |
|
|
#define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D) |
250 |
|
|
#define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D) |
251 |
|
|
#define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D) |
252 |
|
|
|
253 |
greg |
2.35 |
/* Default CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */ |
254 |
greg |
2.9 |
|
255 |
greg |
2.38 |
/***** The following definitions are not for XYZ colors *****/ |
256 |
greg |
2.10 |
|
257 |
greg |
2.7 |
#define bright(col) (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU]) |
258 |
greg |
2.38 |
#define pbright(col) (CIE_rf*scolval(col,RED) + CIE_gf*scolval(col,GRN) + \ |
259 |
|
|
CIE_bf*scolval(col,BLU)) |
260 |
greg |
2.7 |
#define normbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \ |
261 |
|
|
(long)(CIE_gf*256.+.5)*(c)[GRN] + \ |
262 |
|
|
(long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 ) |
263 |
greg |
2.38 |
#define normpbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[CNDX[RED]] + \ |
264 |
|
|
(long)(CIE_gf*256.+.5)*(c)[CNDX[GRN]] + \ |
265 |
|
|
(long)(CIE_bf*256.+.5)*(c)[CNDX[BLU]] ) >> 8 ) |
266 |
greg |
1.1 |
|
267 |
greg |
1.14 |
/* luminous efficacies over visible spectrum */ |
268 |
|
|
#define MAXEFFICACY 683. /* defined maximum at 550 nm */ |
269 |
greg |
2.38 |
#define WHTEFFICACY 179. /* equal energy white 380-780nm */ |
270 |
greg |
1.14 |
#define D65EFFICACY 203. /* standard illuminant D65 */ |
271 |
|
|
#define INCEFFICACY 160. /* illuminant A (incand.) */ |
272 |
|
|
#define SUNEFFICACY 208. /* illuminant B (solar dir.) */ |
273 |
greg |
2.27 |
#define SKYEFFICACY D65EFFICACY /* skylight (should be 110) */ |
274 |
greg |
1.14 |
#define DAYEFFICACY D65EFFICACY /* combined sky and solar */ |
275 |
greg |
2.38 |
#define WHTSCOTOPIC 412. /* scotopic EE white 380-780nm */ |
276 |
|
|
#define WHTMELANOPIC 179. /* melanopic EE white 380-780nm */ |
277 |
greg |
1.14 |
|
278 |
|
|
#define luminance(col) (WHTEFFICACY * bright(col)) |
279 |
greg |
2.38 |
#define pluminance(scol) (WHTEFFICACY * pbright(scol)) |
280 |
|
|
|
281 |
|
|
#define scolor_rgb(col,scol) scolor2rgb(col,scol,NCSAMP,WLPART) |
282 |
greg |
1.9 |
|
283 |
greg |
2.10 |
/***** ...end of stuff specific to RGB colors *****/ |
284 |
|
|
|
285 |
greg |
2.38 |
#define scolor_cie(col,scol) scolor2cie(col,scol,NCSAMP,WLPART) |
286 |
|
|
|
287 |
|
|
#define sluminance(scol) (WHTEFFICACY * scolor_photopic(scol)) |
288 |
|
|
|
289 |
greg |
1.1 |
#define intens(col) ( (col)[0] > (col)[1] \ |
290 |
|
|
? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \ |
291 |
|
|
: (col)[1] > (col)[2] ? (col)[1] : (col)[2] ) |
292 |
|
|
|
293 |
greg |
2.52 |
#define colrval(c,p) cx2real((c)[p],(c)[EXP]) |
294 |
|
|
|
295 |
|
|
#define scolrval(c,p) cx2real((c)[CNDX[p]],(c)[CNDX[EXP]]) |
296 |
greg |
2.38 |
|
297 |
greg |
1.1 |
#define WHTCOLOR {1.0,1.0,1.0} |
298 |
|
|
#define BLKCOLOR {0.0,0.0,0.0} |
299 |
|
|
#define WHTCOLR {128,128,128,COLXS+1} |
300 |
|
|
#define BLKCOLR {0,0,0,0} |
301 |
greg |
1.3 |
|
302 |
greg |
1.11 |
/* picture format identifier */ |
303 |
|
|
#define COLRFMT "32-bit_rle_rgbe" |
304 |
greg |
2.10 |
#define CIEFMT "32-bit_rle_xyze" |
305 |
|
|
#define PICFMT "32-bit_rle_???e" /* matches either */ |
306 |
greg |
2.40 |
#define SPECFMT "Radiance_spectra" /* spectral data w/ exponent */ |
307 |
greg |
2.38 |
|
308 |
|
|
/* Number of spectral components */ |
309 |
|
|
#define NCOMPSTR "NCOMP=" |
310 |
|
|
#define LNCOMPSTR 6 |
311 |
greg |
2.43 |
#define isncomp(hl) !strncmp(hl,NCOMPSTR,LNCOMPSTR) |
312 |
greg |
2.38 |
#define ncompval(hl) atoi((hl)+LNCOMPSTR) |
313 |
|
|
#define fputncomp(nc,fp) fprintf(fp,"%s%d\n",NCOMPSTR,nc) |
314 |
|
|
|
315 |
|
|
/* 4 wavelength partitions for (IR+)R,G,B(+UV) */ |
316 |
|
|
#define WLSPLTSTR "WAVELENGTH_SPLITS=" |
317 |
|
|
#define LWLSPLTSTR 18 |
318 |
greg |
2.43 |
#define iswlsplit(hl) !strncmp(hl,WLSPLTSTR,LWLSPLTSTR) |
319 |
greg |
2.38 |
#define wlsplitval(w,hl) (sscanf((hl)+LWLSPLTSTR,"%f %f %f %f",\ |
320 |
|
|
&(w)[0],&(w)[1],&(w)[2],&(w)[3]) == 4) |
321 |
greg |
2.39 |
#define fputwlsplit(w,fp) fprintf(fp,"%s %g %g %g %g\n",WLSPLTSTR,\ |
322 |
greg |
2.38 |
(w)[0],(w)[1],(w)[2],(w)[3]) |
323 |
greg |
1.11 |
|
324 |
greg |
1.6 |
/* macros for exposures */ |
325 |
greg |
1.5 |
#define EXPOSSTR "EXPOSURE=" |
326 |
greg |
1.12 |
#define LEXPOSSTR 9 |
327 |
greg |
2.43 |
#define isexpos(hl) !strncmp(hl,EXPOSSTR,LEXPOSSTR) |
328 |
greg |
1.12 |
#define exposval(hl) atof((hl)+LEXPOSSTR) |
329 |
greg |
2.37 |
#define fputexpos(ex,fp) fprintf(fp,"%s%.4e\n",EXPOSSTR,ex) |
330 |
greg |
1.6 |
|
331 |
|
|
/* macros for pixel aspect ratios */ |
332 |
|
|
#define ASPECTSTR "PIXASPECT=" |
333 |
greg |
1.12 |
#define LASPECTSTR 10 |
334 |
greg |
2.43 |
#define isaspect(hl) !strncmp(hl,ASPECTSTR,LASPECTSTR) |
335 |
greg |
1.12 |
#define aspectval(hl) atof((hl)+LASPECTSTR) |
336 |
greg |
1.6 |
#define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa) |
337 |
greg |
1.5 |
|
338 |
greg |
2.10 |
/* macros for primary specifications */ |
339 |
|
|
#define PRIMARYSTR "PRIMARIES=" |
340 |
|
|
#define LPRIMARYSTR 10 |
341 |
greg |
2.43 |
#define isprims(hl) !strncmp(hl,PRIMARYSTR,LPRIMARYSTR) |
342 |
greg |
2.32 |
#define primsval(p,hl) (sscanf((hl)+LPRIMARYSTR, \ |
343 |
greg |
2.10 |
"%f %f %f %f %f %f %f %f", \ |
344 |
|
|
&(p)[RED][CIEX],&(p)[RED][CIEY], \ |
345 |
|
|
&(p)[GRN][CIEX],&(p)[GRN][CIEY], \ |
346 |
|
|
&(p)[BLU][CIEX],&(p)[BLU][CIEY], \ |
347 |
greg |
2.32 |
&(p)[WHT][CIEX],&(p)[WHT][CIEY]) == 8) |
348 |
greg |
2.10 |
#define fputprims(p,fp) fprintf(fp, \ |
349 |
|
|
"%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\ |
350 |
|
|
PRIMARYSTR, \ |
351 |
|
|
(p)[RED][CIEX],(p)[RED][CIEY], \ |
352 |
|
|
(p)[GRN][CIEX],(p)[GRN][CIEY], \ |
353 |
|
|
(p)[BLU][CIEX],(p)[BLU][CIEY], \ |
354 |
|
|
(p)[WHT][CIEX],(p)[WHT][CIEY]) |
355 |
|
|
|
356 |
greg |
1.8 |
/* macros for color correction */ |
357 |
|
|
#define COLCORSTR "COLORCORR=" |
358 |
greg |
1.12 |
#define LCOLCORSTR 10 |
359 |
greg |
2.43 |
#define iscolcor(hl) !strncmp(hl,COLCORSTR,LCOLCORSTR) |
360 |
greg |
2.51 |
#define colcorval(cc,hl) (sscanf((hl)+LCOLCORSTR,"%f %f %f", \ |
361 |
|
|
&(cc)[RED],&(cc)[GRN],&(cc)[BLU]) == 3) |
362 |
greg |
1.8 |
#define fputcolcor(cc,fp) fprintf(fp,"%s %f %f %f\n",COLCORSTR, \ |
363 |
|
|
(cc)[RED],(cc)[GRN],(cc)[BLU]) |
364 |
greg |
2.6 |
|
365 |
greg |
2.10 |
/* |
366 |
|
|
* Conversions to and from XYZ space generally don't apply WHTEFFICACY. |
367 |
|
|
* If you need Y to be luminance (cd/m^2), this must be applied when |
368 |
|
|
* converting from radiance (watts/sr/m^2). |
369 |
|
|
*/ |
370 |
|
|
|
371 |
greg |
2.52 |
extern const float cxponent[256]; /* exponent look-up */ |
372 |
greg |
2.38 |
extern int CNDX[4]; /* RGBE indices for SCOLOR, SCOLR */ |
373 |
|
|
extern float WLPART[4]; /* RGB wavelength limits+partitions (nm) */ |
374 |
greg |
2.18 |
extern RGBPRIMS stdprims; /* standard primary chromaticities */ |
375 |
greg |
2.38 |
extern RGBPRIMS xyzprims; /* to indicate XYZ input or output */ |
376 |
greg |
2.18 |
extern COLORMAT rgb2xyzmat; /* RGB to XYZ conversion matrix */ |
377 |
|
|
extern COLORMAT xyz2rgbmat; /* XYZ to RGB conversion matrix */ |
378 |
greg |
2.49 |
extern const COLOR cblack, cwhite; /* black (0,0,0) and white (1,1,1) */ |
379 |
|
|
extern const SCOLOR scblack; /* black spectral color (all 0's) */ |
380 |
greg |
2.10 |
|
381 |
greg |
2.13 |
#define CGAMUT_LOWER 01 |
382 |
|
|
#define CGAMUT_UPPER 02 |
383 |
|
|
#define CGAMUT (CGAMUT_LOWER|CGAMUT_UPPER) |
384 |
|
|
|
385 |
|
|
#define rgb_cie(xyz,rgb) colortrans(xyz,rgb2xyzmat,rgb) |
386 |
greg |
2.10 |
|
387 |
greg |
2.20 |
#define cpcolormat(md,ms) memcpy((void *)md,(void *)ms,sizeof(COLORMAT)) |
388 |
greg |
2.18 |
|
389 |
greg |
2.52 |
#define colr_color(col,clr) ((col)[RED]=colrval(clr,RED),\ |
390 |
|
|
(col)[GRN]=colrval(clr,GRN),\ |
391 |
|
|
(col)[BLU]=colrval(clr,BLU)) |
392 |
|
|
|
393 |
greg |
2.18 |
/* defined in color.c */ |
394 |
greg |
2.38 |
extern void *tempbuffer(size_t len); |
395 |
|
|
/* in cn[3]=nsamps, wlpt[0],wlpt[3]=extrema */ |
396 |
|
|
extern int setspectrsamp(int cn[4], float wlpt[4]); |
397 |
greg |
2.18 |
extern int fwritecolrs(COLR *scanline, int len, FILE *fp); |
398 |
greg |
2.38 |
extern int fwritescan(COLOR *scanline, int len, FILE *fp); |
399 |
greg |
2.48 |
extern int fwritescolrs(const COLRV *sscanline, int nc, int len, FILE *fp); |
400 |
|
|
extern int fwritesscan(const COLORV *sscanline, int nc, int len, FILE *fp); |
401 |
greg |
2.18 |
extern int freadcolrs(COLR *scanline, int len, FILE *fp); |
402 |
|
|
extern int freadscan(COLOR *scanline, int len, FILE *fp); |
403 |
greg |
2.48 |
extern int freadscolrs(COLRV *scanline, int nc, int len, FILE *fp); |
404 |
greg |
2.38 |
extern int freadsscan(COLORV *sscanline, int nc, int len, FILE *fp); |
405 |
greg |
2.50 |
extern int fread2colrs(COLR *scanline, int len, FILE *fp, |
406 |
|
|
int nc, const float wlpt[4]); |
407 |
|
|
extern int fread2scan(COLOR *scanline, int len, FILE *fp, |
408 |
|
|
int nc, const float wlpt[4]); |
409 |
greg |
2.38 |
/* spectrum conversion, zero-fill past ends */ |
410 |
|
|
extern void convertscolor(SCOLOR dst, int dnc, double dwl0, double dwl1, |
411 |
|
|
const COLORV src[], int snc, double swl0, double swl1); |
412 |
|
|
/* the following use avg spectral ranges */ |
413 |
|
|
/* compare scolor_rgb() and scolor_cie() */ |
414 |
|
|
/* also, pcolor_color() and pcolor_colr() */ |
415 |
|
|
extern void setscolor(SCOLOR scol, double r, double g, double b); |
416 |
greg |
2.48 |
extern void scolor2color(COLOR col, const SCOLOR scol, int ncs, const float wlpt[4]); |
417 |
|
|
extern void scolor2colr(COLR clr, const SCOLOR scol, int ncs, const float wlpt[4]); |
418 |
greg |
2.50 |
extern void scolr2colr(COLR clr, const SCOLR sclr, int ncs, const float wlpt[4]); |
419 |
greg |
2.48 |
extern void scolor2scolr(SCOLR sclr, const SCOLOR scol, int ncs); |
420 |
|
|
extern void scolr2scolor(SCOLOR scol, const SCOLR sclr, int ncs); |
421 |
|
|
extern void scolr2color(COLOR col, const SCOLR sclr, int ncs, const float wlpt[4]); |
422 |
greg |
2.18 |
extern void setcolr(COLR clr, double r, double g, double b); |
423 |
greg |
2.38 |
extern void setscolr(SCOLR sclr, double r, double g, double b); |
424 |
greg |
2.48 |
extern double scolor_mean(const SCOLOR scol); |
425 |
|
|
extern double sintens(const SCOLOR scol); |
426 |
|
|
extern int bigdiff(const COLOR c1, const COLOR c2, double md); |
427 |
|
|
extern int sbigsdiff(const SCOLOR sc1, const SCOLOR sc2, double md); |
428 |
greg |
2.18 |
/* defined in spec_rgb.c */ |
429 |
greg |
2.48 |
extern void scolor_out(COLORV *cout, RGBPRIMS pr, const SCOLOR cres); |
430 |
greg |
2.38 |
extern void spec_cie(COLOR col, int s, int e); |
431 |
greg |
2.18 |
extern void spec_rgb(COLOR col, int s, int e); |
432 |
greg |
2.48 |
extern void cie_rgb(COLOR rgb, const COLOR xyz); |
433 |
greg |
2.18 |
extern int clipgamut(COLOR col, double brt, int gamut, |
434 |
greg |
2.48 |
const COLOR lower, const COLOR upper); |
435 |
|
|
extern void colortrans(COLOR c2, const COLORMAT mat, const COLOR c1); |
436 |
|
|
extern void multcolormat(COLORMAT m3, const COLORMAT m2, |
437 |
|
|
const COLORMAT m1); |
438 |
greg |
2.29 |
extern int colorprimsOK(RGBPRIMS pr); |
439 |
|
|
extern int compxyz2rgbmat(COLORMAT mat, RGBPRIMS pr); |
440 |
|
|
extern int comprgb2xyzmat(COLORMAT mat, RGBPRIMS pr); |
441 |
|
|
extern int comprgb2rgbmat(COLORMAT mat, RGBPRIMS pr1, RGBPRIMS pr2); |
442 |
greg |
2.48 |
extern int compxyzWBmat(COLORMAT mat, const float wht1[2], const float wht2[2]); |
443 |
greg |
2.29 |
extern int compxyz2rgbWBmat(COLORMAT mat, RGBPRIMS pr); |
444 |
|
|
extern int comprgb2xyzWBmat(COLORMAT mat, RGBPRIMS pr); |
445 |
|
|
extern int comprgb2rgbWBmat(COLORMAT mat, RGBPRIMS pr1, RGBPRIMS pr2); |
446 |
greg |
2.45 |
/* any uniform spectrum to working */ |
447 |
|
|
extern void convertscolorcol(SCOLOR rcol, const COLORV src[], int snc, |
448 |
|
|
double swl0, double swl1); |
449 |
greg |
2.38 |
/* most accurate spectral->tristim */ |
450 |
greg |
2.48 |
extern void scolor2cie(COLOR col, const SCOLOR scol, int ncs, const float wlpt[4]); |
451 |
|
|
extern void scolor2rgb(COLOR col, const SCOLOR scol, int ncs, const float wlpt[4]); |
452 |
|
|
extern double scolor2photopic(const SCOLOR scol, int ncs, const float wlpt[4]); |
453 |
|
|
extern double scolor2scotopic(const SCOLOR scol, int ncs, const float wlpt[4]); |
454 |
|
|
extern double scolor2melanopic(const SCOLOR scol, int ncs, const float wlpt[4]); |
455 |
|
|
extern double scolor_photopic(const SCOLOR scol); |
456 |
|
|
extern double scolor_scotopic(const SCOLOR scol); |
457 |
|
|
extern double scolor_melanopic(const SCOLOR scol); |
458 |
greg |
2.18 |
/* defined in colrops.c */ |
459 |
schorsch |
2.26 |
extern int setcolrcor(double (*f)(double, double), double a2); |
460 |
|
|
extern int setcolrinv(double (*f)(double, double), double a2); |
461 |
greg |
2.18 |
extern int setcolrgam(double g); |
462 |
|
|
extern int colrs_gambs(COLR *scan, int len); |
463 |
|
|
extern int gambs_colrs(COLR *scan, int len); |
464 |
|
|
extern void shiftcolrs(COLR *scan, int len, int adjust); |
465 |
|
|
extern void normcolrs(COLR *scan, int len, int adjust); |
466 |
|
|
|
467 |
|
|
#ifdef __cplusplus |
468 |
|
|
} |
469 |
greg |
2.6 |
#endif |
470 |
schorsch |
2.21 |
#endif /* _RAD_COLOR_H_ */ |
471 |
|
|
|