ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/color.h
Revision: 2.3
Committed: Thu May 28 09:25:26 1992 UTC (31 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +2 -2 lines
Log Message:
changed /256 to >>8 for compilers that aren't so swift

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     #define bright(col) (.295*(col)[RED]+.636*(col)[GRN]+.070*(col)[BLU])
45 greg 2.3 #define normbright(c) (int)((74L*(c)[RED]+164L*(c)[GRN]+18L*(c)[BLU])>>8)
46 greg 1.7 #else
47     #define bright(col) (.263*(col)[RED]+.655*(col)[GRN]+.082*(col)[BLU])
48 greg 2.3 #define normbright(c) (int)((67L*(c)[RED]+168L*(c)[GRN]+21L*(c)[BLU])>>8)
49 greg 1.7 #endif
50 greg 1.1
51 greg 1.14 /* luminous efficacies over visible spectrum */
52     #define MAXEFFICACY 683. /* defined maximum at 550 nm */
53     #define WHTEFFICACY 179. /* uniform white light */
54     #define D65EFFICACY 203. /* standard illuminant D65 */
55     #define INCEFFICACY 160. /* illuminant A (incand.) */
56     #define SUNEFFICACY 208. /* illuminant B (solar dir.) */
57     #define SKYEFFICACY D65EFFICACY /* skylight */
58     #define DAYEFFICACY D65EFFICACY /* combined sky and solar */
59    
60     #define luminance(col) (WHTEFFICACY * bright(col))
61 greg 1.9
62 greg 1.1 #define intens(col) ( (col)[0] > (col)[1] \
63     ? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
64     : (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
65    
66 greg 1.3 #define colrval(c,p) ( (c)[EXP] ? \
67     ldexp((c)[p]+.5,(int)(c)[EXP]-(COLXS+8)) : \
68     0. )
69    
70 greg 1.1 #define WHTCOLOR {1.0,1.0,1.0}
71     #define BLKCOLOR {0.0,0.0,0.0}
72     #define WHTCOLR {128,128,128,COLXS+1}
73     #define BLKCOLR {0,0,0,0}
74 greg 1.3
75 greg 1.11 /* picture format identifier */
76     #define COLRFMT "32-bit_rle_rgbe"
77    
78 greg 1.6 /* macros for exposures */
79 greg 1.5 #define EXPOSSTR "EXPOSURE="
80 greg 1.12 #define LEXPOSSTR 9
81     #define isexpos(hl) (!strncmp(hl,EXPOSSTR,LEXPOSSTR))
82     #define exposval(hl) atof((hl)+LEXPOSSTR)
83 greg 1.5 #define fputexpos(ex,fp) fprintf(fp,"%s%e\n",EXPOSSTR,ex)
84 greg 1.6
85     /* macros for pixel aspect ratios */
86     #define ASPECTSTR "PIXASPECT="
87 greg 1.12 #define LASPECTSTR 10
88     #define isaspect(hl) (!strncmp(hl,ASPECTSTR,LASPECTSTR))
89     #define aspectval(hl) atof((hl)+LASPECTSTR)
90 greg 1.6 #define fputaspect(pa,fp) fprintf(fp,"%s%f\n",ASPECTSTR,pa)
91 greg 1.5
92 greg 1.8 /* macros for color correction */
93     #define COLCORSTR "COLORCORR="
94 greg 1.12 #define LCOLCORSTR 10
95     #define iscolcor(hl) (!strncmp(hl,COLCORSTR,LCOLCORSTR))
96     #define colcorval(cc,hl) sscanf(hl+LCOLCORSTR,"%f %f %f", \
97 greg 1.8 &(cc)[RED],&(cc)[GRN],&(cc)[BLU])
98     #define fputcolcor(cc,fp) fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
99     (cc)[RED],(cc)[GRN],(cc)[BLU])
100    
101 greg 2.2 extern double ldexp();
102     #ifndef atof /* atof's a macro on some systems! */
103     extern double atof();
104     #endif