ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/color.h
(Generate patch)

Comparing ray/src/common/color.h (file contents):
Revision 1.8 by greg, Fri Dec 14 16:28:20 1990 UTC vs.
Revision 2.17 by gwlarson, Wed Oct 21 17:48:06 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3 < /* SCCSid "$SunId$ LBL" */
3 > /* SCCSid "$SunId$ SGI" */
4  
5   /*
6   *  color.h - header for routines using pixel color values.
7   *
8 < *     12/31/85
8 > *  Must be included after X11 headers, since they declare a BYTE type.
9   *
10   *  Two color representations are used, one for calculation and
11   *  another for storage.  Calculation is done with three floats
# Line 16 | Line 16
16   #define  RED            0
17   #define  GRN            1
18   #define  BLU            2
19 < #define  EXP            3
19 > #define  CIEX           0       /* or, if input is XYZ... */
20 > #define  CIEY           1
21 > #define  CIEZ           2
22 > #define  EXP            3       /* exponent same for either format */
23   #define  COLXS          128     /* excess used for exponent */
24 + #define  WHT            3       /* used for RGBPRIMS type */
25  
26 < typedef unsigned char  BYTE;    /* 8-bit unsigned integer */
26 > #undef  BYTE
27 > #define  BYTE   unsigned char   /* 8-bit unsigned integer */
28  
29 < typedef BYTE  COLR[4];          /* red, green, blue, exponent */
29 > typedef BYTE  COLR[4];          /* red, green, blue (or X,Y,Z), exponent */
30  
31 + typedef float  COLOR[3];        /* red, green, blue (or X,Y,Z) */
32 +
33 + typedef float  RGBPRIMS[4][2];  /* (x,y) chromaticities for RGBW */
34 + typedef float  (*RGBPRIMP)[2];  /* pointer to RGBPRIMS array */
35 +
36 + typedef float  COLORMAT[3][3];  /* color coordinate conversion matrix */
37 +
38   #define  copycolr(c1,c2)        (c1[0]=c2[0],c1[1]=c2[1], \
39                                  c1[2]=c2[2],c1[3]=c2[3])
40  
29 typedef float  COLOR[3];        /* red, green, blue */
30
41   #define  colval(col,pri)        ((col)[pri])
42  
43   #define  setcolor(col,r,g,b)    ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
# Line 41 | Line 51 | typedef float  COLOR[3];       /* red, green, blue */
51   #define  multcolor(c1,c2)       ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])
52  
53   #ifdef  NTSC
54 < #define  bright(col)            (.295*(col)[RED]+.636*(col)[GRN]+.070*(col)[BLU])
55 < #define  normbright(c)          (int)((74L*(c)[RED]+164L*(c)[GRN]+18L*(c)[BLU])/256)
54 > #define  CIE_x_r                0.670           /* standard NTSC primaries */
55 > #define  CIE_y_r                0.330
56 > #define  CIE_x_g                0.210
57 > #define  CIE_y_g                0.710
58 > #define  CIE_x_b                0.140
59 > #define  CIE_y_b                0.080
60 > #define  CIE_x_w                0.3333          /* use true white */
61 > #define  CIE_y_w                0.3333
62   #else
63 < #define  bright(col)            (.263*(col)[RED]+.655*(col)[GRN]+.082*(col)[BLU])
64 < #define  normbright(c)          (int)((67L*(c)[RED]+168L*(c)[GRN]+21L*(c)[BLU])/256)
63 > #define  CIE_x_r                0.640           /* nominal CRT primaries */
64 > #define  CIE_y_r                0.330
65 > #define  CIE_x_g                0.290
66 > #define  CIE_y_g                0.600
67 > #define  CIE_x_b                0.150
68 > #define  CIE_y_b                0.060
69 > #define  CIE_x_w                0.3333          /* use true white */
70 > #define  CIE_y_w                0.3333
71   #endif
72  
73 + #define  STDPRIMS       {{CIE_x_r,CIE_y_r},{CIE_x_g,CIE_y_g}, \
74 +                                {CIE_x_b,CIE_y_b},{CIE_x_w,CIE_y_w}}
75 +
76 + #define CIE_D           (       CIE_x_r*(CIE_y_g - CIE_y_b) + \
77 +                                CIE_x_g*(CIE_y_b - CIE_y_r) + \
78 +                                CIE_x_b*(CIE_y_r - CIE_y_g)     )
79 + #define CIE_C_rD        ( (1./CIE_y_w) * \
80 +                                ( CIE_x_w*(CIE_y_g - CIE_y_b) - \
81 +                                  CIE_y_w*(CIE_x_g - CIE_x_b) + \
82 +                                  CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g     ) )
83 + #define CIE_C_gD        ( (1./CIE_y_w) * \
84 +                                ( CIE_x_w*(CIE_y_b - CIE_y_r) - \
85 +                                  CIE_y_w*(CIE_x_b - CIE_x_r) - \
86 +                                  CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r     ) )
87 + #define CIE_C_bD        ( (1./CIE_y_w) * \
88 +                                ( CIE_x_w*(CIE_y_r - CIE_y_g) - \
89 +                                  CIE_y_w*(CIE_x_r - CIE_x_g) + \
90 +                                  CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r     ) )
91 +
92 + #define CIE_rf          (CIE_y_r*CIE_C_rD/CIE_D)
93 + #define CIE_gf          (CIE_y_g*CIE_C_gD/CIE_D)
94 + #define CIE_bf          (CIE_y_b*CIE_C_bD/CIE_D)
95 +
96 + /* As of 9-94, CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */
97 +
98 + /***** The following definitions are valid for RGB colors only... *****/
99 +
100 + #define  bright(col)    (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
101 + #define  normbright(c)  ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
102 +                            (long)(CIE_gf*256.+.5)*(c)[GRN] + \
103 +                            (long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )
104 +
105 +                                /* luminous efficacies over visible spectrum */
106 + #define  MAXEFFICACY            683.            /* defined maximum at 550 nm */
107 + #define  WHTEFFICACY            179.            /* uniform white light */
108 + #define  D65EFFICACY            203.            /* standard illuminant D65 */
109 + #define  INCEFFICACY            160.            /* illuminant A (incand.) */
110 + #define  SUNEFFICACY            208.            /* illuminant B (solar dir.) */
111 + #define  SKYEFFICACY            D65EFFICACY     /* skylight */
112 + #define  DAYEFFICACY            D65EFFICACY     /* combined sky and solar */
113 +
114 + #define  luminance(col)         (WHTEFFICACY * bright(col))
115 +
116 + /***** ...end of stuff specific to RGB colors *****/
117 +
118   #define  intens(col)            ( (col)[0] > (col)[1] \
119                                  ? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
120                                  : (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
# Line 61 | Line 128 | typedef float  COLOR[3];       /* red, green, blue */
128   #define  WHTCOLR                {128,128,128,COLXS+1}
129   #define  BLKCOLR                {0,0,0,0}
130  
131 <                                /* definitions for resolution header */
132 < #define  XDECR                  1
133 < #define  YDECR                  2
134 < #define  YMAJOR                 4
131 >                                /* picture format identifier */
132 > #define  COLRFMT                "32-bit_rle_rgbe"
133 > #define  CIEFMT                 "32-bit_rle_xyze"
134 > #define  PICFMT                 "32-bit_rle_???e"       /* matches either */
135 > #define  LPICFMT                15                      /* max format id len */
136  
137                                  /* macros for exposures */
138   #define  EXPOSSTR               "EXPOSURE="
139 < #define  EXPOSSTRL              9
140 < #define  isexpos(hl)            (!strncmp(hl,EXPOSSTR,EXPOSSTRL))
141 < #define  exposval(hl)           atof((hl)+EXPOSSTRL)
139 > #define  LEXPOSSTR              9
140 > #define  isexpos(hl)            (!strncmp(hl,EXPOSSTR,LEXPOSSTR))
141 > #define  exposval(hl)           atof((hl)+LEXPOSSTR)
142   #define  fputexpos(ex,fp)       fprintf(fp,"%s%e\n",EXPOSSTR,ex)
143  
144                                  /* macros for pixel aspect ratios */
145   #define  ASPECTSTR              "PIXASPECT="
146 < #define  ASPECTSTRL             10
147 < #define  isaspect(hl)           (!strncmp(hl,ASPECTSTR,ASPECTSTRL))
148 < #define  aspectval(hl)          atof((hl)+ASPECTSTRL)
146 > #define  LASPECTSTR             10
147 > #define  isaspect(hl)           (!strncmp(hl,ASPECTSTR,LASPECTSTR))
148 > #define  aspectval(hl)          atof((hl)+LASPECTSTR)
149   #define  fputaspect(pa,fp)      fprintf(fp,"%s%f\n",ASPECTSTR,pa)
150  
151 +                                /* macros for primary specifications */
152 + #define  PRIMARYSTR             "PRIMARIES="
153 + #define  LPRIMARYSTR            10
154 + #define  isprims(hl)            (!strncmp(hl,PRIMARYSTR,LPRIMARYSTR))
155 + #define  primsval(p,hl)         sscanf(hl+LPRIMARYSTR, \
156 +                                        "%f %f %f %f %f %f %f %f", \
157 +                                        &(p)[RED][CIEX],&(p)[RED][CIEY], \
158 +                                        &(p)[GRN][CIEX],&(p)[GRN][CIEY], \
159 +                                        &(p)[BLU][CIEX],&(p)[BLU][CIEY], \
160 +                                        &(p)[WHT][CIEX],&(p)[WHT][CIEY])
161 + #define  fputprims(p,fp)        fprintf(fp, \
162 +                                "%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\
163 +                                        PRIMARYSTR, \
164 +                                        (p)[RED][CIEX],(p)[RED][CIEY], \
165 +                                        (p)[GRN][CIEX],(p)[GRN][CIEY], \
166 +                                        (p)[BLU][CIEX],(p)[BLU][CIEY], \
167 +                                        (p)[WHT][CIEX],(p)[WHT][CIEY])
168 +
169                                  /* macros for color correction */
170   #define  COLCORSTR              "COLORCORR="
171 < #define  COLCORSTRL             10
172 < #define  iscolcor(hl)           (!strncmp(hl,COLCORSTR,COLCORSTRL))
173 < #define  colcorval(cc,hl)       sscanf(hl+COLCORSTRL,"%f %f %f", \
171 > #define  LCOLCORSTR             10
172 > #define  iscolcor(hl)           (!strncmp(hl,COLCORSTR,LCOLCORSTR))
173 > #define  colcorval(cc,hl)       sscanf(hl+LCOLCORSTR,"%f %f %f", \
174                                          &(cc)[RED],&(cc)[GRN],&(cc)[BLU])
175   #define  fputcolcor(cc,fp)      fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
176                                          (cc)[RED],(cc)[GRN],(cc)[BLU])
177  
178 < extern double  ldexp(), atof();
178 > #ifdef  DCL_ATOF
179 > extern double  atof(), ldexp(), frexp();
180 > #endif
181 >
182 > /*
183 > * Conversions to and from XYZ space generally don't apply WHTEFFICACY.
184 > * If you need Y to be luminance (cd/m^2), this must be applied when
185 > * converting from radiance (watts/sr/m^2).
186 > */
187 >
188 > extern RGBPRIMS  stdprims;              /* standard primary chromaticities */
189 > extern COLORMAT  rgb2xyzmat;            /* RGB to XYZ conversion matrix */
190 > extern COLORMAT  xyz2rgbmat;            /* XYZ to RGB conversion matrix */
191 > extern COLOR  cblack, cwhite;           /* black (0,0,0) and white (1,1,1) */
192 >
193 > #define  CGAMUT_LOWER           01
194 > #define  CGAMUT_UPPER           02
195 > #define  CGAMUT                 (CGAMUT_LOWER|CGAMUT_UPPER)
196 >
197 > #define  rgb_cie(xyz,rgb)       colortrans(xyz,rgb2xyzmat,rgb)
198 >
199 > #ifdef BSD
200 > #define  cpcolormat(md,ms)      bcopy((char *)ms,(char *)md,sizeof(COLORMAT))
201 > #else
202 > #define  cpcolormat(md,ms)      memcpy((char *)md,(char *)ms,sizeof(COLORMAT))
203 > #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines