ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/ccolor.h
Revision: 3.8
Committed: Sat Jan 23 18:58:35 2016 UTC (8 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad5R1, rad5R3
Changes since 3.7: +2 -1 lines
Log Message:
Added randomization to chroma encoding

File Contents

# User Rev Content
1 greg 3.8 /* RCSid $Id: ccolor.h,v 3.7 2015/03/26 15:57:19 greg Exp $ */
2 greg 3.1 /*
3     * Header file for spectral colors.
4     *
5     */
6    
7     #ifndef _MGF_COLOR_H_
8     #define _MGF_COLOR_H_
9     #ifdef __cplusplus
10     extern "C" {
11     #endif
12    
13     #define C_CMINWL 380 /* minimum wavelength */
14     #define C_CMAXWL 780 /* maximum wavelength */
15     #define C_CNSS 41 /* number of spectral samples */
16     #define C_CWLI ((C_CMAXWL-C_CMINWL)/(C_CNSS-1))
17     #define C_CMAXV 10000 /* nominal maximum sample value */
18     #define C_CLPWM (683./C_CMAXV) /* peak lumens/watt multiplier */
19    
20     #define C_CSSPEC 01 /* flag if spectrum is set */
21     #define C_CDSPEC 02 /* flag if defined w/ spectrum */
22     #define C_CSXY 04 /* flag if xy is set */
23     #define C_CDXY 010 /* flag if defined w/ xy */
24     #define C_CSEFF 020 /* flag if efficacy set */
25    
26     typedef struct {
27     int clock; /* incremented each change */
28     void *client_data; /* pointer to private client-owned data */
29     short flags; /* what's been set and how */
30     short ssamp[C_CNSS]; /* spectral samples, min wl to max */
31     long ssum; /* straight sum of spectral values */
32     float cx, cy; /* xy chromaticity value */
33     float eff; /* efficacy (lumens/watt) */
34     } C_COLOR;
35    
36 greg 3.7 typedef unsigned short C_CHROMA; /* encoded (x,y) chromaticity */
37    
38 greg 3.1 #define C_DEFCOLOR { 1, NULL, C_CDXY|C_CSXY|C_CSSPEC|C_CSEFF,\
39     {C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,\
40     C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,\
41     C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,\
42     C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,\
43     C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,\
44     C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,\
45     C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV,C_CMAXV},\
46     (long)C_CNSS*C_CMAXV, 1./3., 1./3., 178.006 }
47    
48 greg 3.4 #define c_cval(c,l) ((c)->ssamp[((l)+(C_CWLI/2.-C_MINWL))/C_CWLI] \
49     / (double)(c)->ssum)
50 greg 3.1
51 greg 3.6 extern const C_COLOR c_dfcolor; /* default color */
52 greg 3.8 extern const C_CHROMA c_dfchroma; /* c_encodeChroma(&c_dfcolor) */
53 greg 3.6
54     extern const C_COLOR c_x31, c_y31, c_z31; /* 1931 standard observer */
55 greg 3.1
56 greg 3.4 /* set CIE (x,y) chromaticity */
57     #define c_cset(c,x,y) ((c)->cx=(x),(c)->cy=(y),(c)->flags=C_CDXY|C_CSXY)
58    
59     /* set black body spectrum */
60     extern int c_bbtemp(C_COLOR *clr, double tk);
61 greg 3.3 /* assign arbitrary spectrum */
62     extern double c_sset(C_COLOR *clr, double wlmin, double wlmax,
63     const float spec[], int nwl);
64     extern void c_ccvt(C_COLOR *clr, int fl); /* fix color representation */
65     extern int c_isgrey(C_COLOR *clr); /* check if color is grey */
66 greg 3.1 /* mix two colors */
67     extern void c_cmix(C_COLOR *cres, double w1, C_COLOR *c1,
68     double w2, C_COLOR *c2);
69 greg 3.2 /* multiply two colors */
70     extern double c_cmult(C_COLOR *cres, C_COLOR *c1, double y1,
71     C_COLOR *c2, double y2);
72 greg 3.5 /* convert to sharpened RGB */
73     extern void c_toSharpRGB(C_COLOR *cin, double cieY, float cout[3]);
74     /* convert from sharpened RGB */
75     extern double c_fromSharpRGB(float cin[3], C_COLOR *cout);
76 greg 3.7 /* encode (x,y) chromaticity */
77     extern C_CHROMA c_encodeChroma(C_COLOR *clr);
78     /* decode (x,y) chromaticity */
79     extern void c_decodeChroma(C_COLOR *cres, C_CHROMA ccode);
80 greg 3.5
81     /* The following two routines are not defined in ccolor.c */
82 greg 3.1 /* convert to RGB color */
83     extern void ccy2rgb(C_COLOR *cin, double cieY, float cout[3]);
84     /* convert from RGB color */
85     extern double rgb2ccy(float cin[3], C_COLOR *cout);
86    
87     #ifdef __cplusplus
88     }
89     #endif
90     #endif /* _MGF_COLOR_H_ */