ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/color.h
Revision: 2.9
Committed: Fri Sep 2 12:02:17 1994 UTC (29 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.8: +2 -0 lines
Log Message:
added comment as to values of CIE_rf, CIE_gf and CIE_bf

File Contents

# User Rev Content
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     #define EXP 3
20     #define COLXS 128 /* excess used for exponent */
21    
22     typedef unsigned char BYTE; /* 8-bit unsigned integer */
23    
24     typedef BYTE COLR[4]; /* red, green, blue, exponent */
25    
26     #define copycolr(c1,c2) (c1[0]=c2[0],c1[1]=c2[1], \
27     c1[2]=c2[2],c1[3]=c2[3])
28    
29     typedef float COLOR[3]; /* red, green, blue */
30    
31     #define colval(col,pri) ((col)[pri])
32    
33     #define setcolor(col,r,g,b) ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
34    
35     #define copycolor(c1,c2) ((c1)[0]=(c2)[0],(c1)[1]=(c2)[1],(c1)[2]=(c2)[2])
36    
37     #define scalecolor(col,sf) ((col)[0]*=(sf),(col)[1]*=(sf),(col)[2]*=(sf))
38    
39     #define addcolor(c1,c2) ((c1)[0]+=(c2)[0],(c1)[1]+=(c2)[1],(c1)[2]+=(c2)[2])
40    
41     #define multcolor(c1,c2) ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])
42    
43 greg 1.7 #ifdef NTSC
44 greg 2.7 #define CIE_x_r 0.670 /* standard NTSC primaries */
45     #define CIE_y_r 0.330
46     #define CIE_x_g 0.210
47     #define CIE_y_g 0.710
48     #define CIE_x_b 0.140
49     #define CIE_y_b 0.080
50 greg 2.8 #define CIE_x_w 0.3333 /* use true white */
51     #define CIE_y_w 0.3333
52 greg 1.7 #else
53 greg 2.7 #define CIE_x_r 0.640 /* nominal CRT primaries */
54     #define CIE_y_r 0.330
55     #define CIE_x_g 0.290
56     #define CIE_y_g 0.600
57     #define CIE_x_b 0.150
58     #define CIE_y_b 0.060
59 greg 2.8 #define CIE_x_w 0.3333 /* use true white */
60     #define CIE_y_w 0.3333
61 greg 1.7 #endif
62 greg 2.7
63     #define CIE_D ( CIE_x_r*(CIE_y_g - CIE_y_b) + \
64     CIE_x_g*(CIE_y_b - CIE_y_r) + \
65     CIE_x_b*(CIE_y_r - CIE_y_g) )
66     #define CIE_C_rD ( (1./CIE_y_w) * \
67     ( CIE_x_w*(CIE_y_g - CIE_y_b) - \
68     CIE_y_w*(CIE_x_g - CIE_x_b) + \
69     CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g ) )
70     #define CIE_C_gD ( (1./CIE_y_w) * \
71     ( CIE_x_w*(CIE_y_b - CIE_y_r) - \
72     CIE_y_w*(CIE_x_b - CIE_x_r) - \
73     CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r ) )
74     #define CIE_C_bD ( (1./CIE_y_w) * \
75     ( CIE_x_w*(CIE_y_r - CIE_y_g) - \
76     CIE_y_w*(CIE_x_r - CIE_x_g) + \
77     CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r ) )
78    
79     #define CIE_rf (CIE_y_r*CIE_C_rD/CIE_D)
80     #define CIE_gf (CIE_y_g*CIE_C_gD/CIE_D)
81     #define CIE_bf (CIE_y_b*CIE_C_bD/CIE_D)
82    
83 greg 2.9 /* As of 9-94, CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */
84    
85 greg 2.7 #define bright(col) (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
86     #define normbright(c) ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
87     (long)(CIE_gf*256.+.5)*(c)[GRN] + \
88     (long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )
89 greg 1.1
90 greg 1.14 /* luminous efficacies over visible spectrum */
91     #define MAXEFFICACY 683. /* defined maximum at 550 nm */
92     #define WHTEFFICACY 179. /* uniform white light */
93     #define D65EFFICACY 203. /* standard illuminant D65 */
94     #define INCEFFICACY 160. /* illuminant A (incand.) */
95     #define SUNEFFICACY 208. /* illuminant B (solar dir.) */
96     #define SKYEFFICACY D65EFFICACY /* skylight */
97     #define DAYEFFICACY D65EFFICACY /* combined sky and solar */
98    
99     #define luminance(col) (WHTEFFICACY * bright(col))
100 greg 1.9
101 greg 1.1 #define intens(col) ( (col)[0] > (col)[1] \
102     ? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
103     : (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
104    
105 greg 1.3 #define colrval(c,p) ( (c)[EXP] ? \
106     ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \
107     0. )
108    
109 greg 1.1 #define WHTCOLOR {1.0,1.0,1.0}
110     #define BLKCOLOR {0.0,0.0,0.0}
111     #define WHTCOLR {128,128,128,COLXS+1}
112     #define BLKCOLR {0,0,0,0}
113 greg 1.3
114 greg 1.11 /* picture format identifier */
115     #define COLRFMT "32-bit_rle_rgbe"
116    
117 greg 1.6 /* macros for exposures */
118 greg 1.5 #define EXPOSSTR "EXPOSURE="
119 greg 1.12 #define LEXPOSSTR 9
120     #define isexpos(hl) (!strncmp(hl,EXPOSSTR,LEXPOSSTR))
121     #define exposval(hl) atof((hl)+LEXPOSSTR)
122 greg 1.5 #define fputexpos(ex,fp) fprintf(fp,"%s%e\n",EXPOSSTR,ex)
123 greg 1.6
124     /* macros for pixel aspect ratios */
125     #define ASPECTSTR "PIXASPECT="
126 greg 1.12 #define LASPECTSTR 10
127     #define isaspect(hl) (!strncmp(hl,ASPECTSTR,LASPECTSTR))
128     #define aspectval(hl) atof((hl)+LASPECTSTR)
129 greg 1.6 #define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa)
130 greg 1.5
131 greg 1.8 /* macros for color correction */
132     #define COLCORSTR "COLORCORR="
133 greg 1.12 #define LCOLCORSTR 10
134     #define iscolcor(hl) (!strncmp(hl,COLCORSTR,LCOLCORSTR))
135     #define colcorval(cc,hl) sscanf(hl+LCOLCORSTR,"%f %f %f", \
136 greg 1.8 &(cc)[RED],&(cc)[GRN],&(cc)[BLU])
137     #define fputcolcor(cc,fp) fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
138     (cc)[RED],(cc)[GRN],(cc)[BLU])
139 greg 2.6
140     #ifdef DCL_ATOF
141     extern double atof(), ldexp(), frexp();
142     #endif