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 2.2 by greg, Thu Dec 19 14:45:43 1991 UTC vs.
Revision 2.14 by greg, Tue Apr 15 14:12:31 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1997 Regents of the University of California */
2  
3   /* SCCSid "$SunId$ LBL" */
4  
# 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 */
27  
28 < typedef BYTE  COLR[4];          /* red, green, blue, exponent */
28 > typedef BYTE  COLR[4];          /* red, green, blue (or X,Y,Z), exponent */
29  
30 + typedef float  COLOR[3];        /* red, green, blue (or X,Y,Z) */
31 +
32 + typedef float  RGBPRIMS[4][2];  /* (x,y) chromaticities for RGBW */
33 + typedef float  (*RGBPRIMP)[2];  /* pointer to RGBPRIMS array */
34 +
35 + typedef float  COLORMAT[3][3];  /* color coordinate conversion matrix */
36 +
37   #define  copycolr(c1,c2)        (c1[0]=c2[0],c1[1]=c2[1], \
38                                  c1[2]=c2[2],c1[3]=c2[3])
39  
29 typedef float  COLOR[3];        /* red, green, blue */
30
40   #define  colval(col,pri)        ((col)[pri])
41  
42   #define  setcolor(col,r,g,b)    ((col)[RED]=(r),(col)[GRN]=(g),(col)[BLU]=(b))
# Line 41 | Line 50 | typedef float  COLOR[3];       /* red, green, blue */
50   #define  multcolor(c1,c2)       ((c1)[0]*=(c2)[0],(c1)[1]*=(c2)[1],(c1)[2]*=(c2)[2])
51  
52   #ifdef  NTSC
53 < #define  bright(col)            (.295*(col)[RED]+.636*(col)[GRN]+.070*(col)[BLU])
54 < #define  normbright(c)          (int)((74L*(c)[RED]+164L*(c)[GRN]+18L*(c)[BLU])/256)
53 > #define  CIE_x_r                0.670           /* standard NTSC primaries */
54 > #define  CIE_y_r                0.330
55 > #define  CIE_x_g                0.210
56 > #define  CIE_y_g                0.710
57 > #define  CIE_x_b                0.140
58 > #define  CIE_y_b                0.080
59 > #define  CIE_x_w                0.3333          /* use true white */
60 > #define  CIE_y_w                0.3333
61   #else
62 < #define  bright(col)            (.263*(col)[RED]+.655*(col)[GRN]+.082*(col)[BLU])
63 < #define  normbright(c)          (int)((67L*(c)[RED]+168L*(c)[GRN]+21L*(c)[BLU])/256)
62 > #define  CIE_x_r                0.640           /* nominal CRT primaries */
63 > #define  CIE_y_r                0.330
64 > #define  CIE_x_g                0.290
65 > #define  CIE_y_g                0.600
66 > #define  CIE_x_b                0.150
67 > #define  CIE_y_b                0.060
68 > #define  CIE_x_w                0.3333          /* use true white */
69 > #define  CIE_y_w                0.3333
70   #endif
71  
72 + #define  STDPRIMS       {{CIE_x_r,CIE_y_r},{CIE_x_g,CIE_y_g}, \
73 +                                {CIE_x_b,CIE_y_b},{CIE_x_w,CIE_y_w}}
74 +
75 + #define CIE_D           (       CIE_x_r*(CIE_y_g - CIE_y_b) + \
76 +                                CIE_x_g*(CIE_y_b - CIE_y_r) + \
77 +                                CIE_x_b*(CIE_y_r - CIE_y_g)     )
78 + #define CIE_C_rD        ( (1./CIE_y_w) * \
79 +                                ( CIE_x_w*(CIE_y_g - CIE_y_b) - \
80 +                                  CIE_y_w*(CIE_x_g - CIE_x_b) + \
81 +                                  CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g     ) )
82 + #define CIE_C_gD        ( (1./CIE_y_w) * \
83 +                                ( CIE_x_w*(CIE_y_b - CIE_y_r) - \
84 +                                  CIE_y_w*(CIE_x_b - CIE_x_r) - \
85 +                                  CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r     ) )
86 + #define CIE_C_bD        ( (1./CIE_y_w) * \
87 +                                ( CIE_x_w*(CIE_y_r - CIE_y_g) - \
88 +                                  CIE_y_w*(CIE_x_r - CIE_x_g) + \
89 +                                  CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r     ) )
90 +
91 + #define CIE_rf          (CIE_y_r*CIE_C_rD/CIE_D)
92 + #define CIE_gf          (CIE_y_g*CIE_C_gD/CIE_D)
93 + #define CIE_bf          (CIE_y_b*CIE_C_bD/CIE_D)
94 +
95 + /* As of 9-94, CIE_rf=.265074126, CIE_gf=.670114631 and CIE_bf=.064811243 */
96 +
97 + /***** The following definitions are valid for RGB colors only... *****/
98 +
99 + #define  bright(col)    (CIE_rf*(col)[RED]+CIE_gf*(col)[GRN]+CIE_bf*(col)[BLU])
100 + #define  normbright(c)  ( ( (long)(CIE_rf*256.+.5)*(c)[RED] + \
101 +                            (long)(CIE_gf*256.+.5)*(c)[GRN] + \
102 +                            (long)(CIE_bf*256.+.5)*(c)[BLU] ) >> 8 )
103 +
104                                  /* luminous efficacies over visible spectrum */
105   #define  MAXEFFICACY            683.            /* defined maximum at 550 nm */
106   #define  WHTEFFICACY            179.            /* uniform white light */
# Line 59 | Line 112 | typedef float  COLOR[3];       /* red, green, blue */
112  
113   #define  luminance(col)         (WHTEFFICACY * bright(col))
114  
115 + /***** ...end of stuff specific to RGB colors *****/
116 +
117   #define  intens(col)            ( (col)[0] > (col)[1] \
118                                  ? (col)[0] > (col)[2] ? (col)[0] : (col)[2] \
119                                  : (col)[1] > (col)[2] ? (col)[1] : (col)[2] )
# Line 74 | Line 129 | typedef float  COLOR[3];       /* red, green, blue */
129  
130                                  /* picture format identifier */
131   #define  COLRFMT                "32-bit_rle_rgbe"
132 + #define  CIEFMT                 "32-bit_rle_xyze"
133 + #define  PICFMT                 "32-bit_rle_???e"       /* matches either */
134 + #define  LPICFMT                15                      /* max format id len */
135  
136                                  /* macros for exposures */
137   #define  EXPOSSTR               "EXPOSURE="
# Line 89 | Line 147 | typedef float  COLOR[3];       /* red, green, blue */
147   #define  aspectval(hl)          atof((hl)+LASPECTSTR)
148   #define  fputaspect(pa,fp)      fprintf(fp,"%s%f\n",ASPECTSTR,pa)
149  
150 +                                /* macros for primary specifications */
151 + #define  PRIMARYSTR             "PRIMARIES="
152 + #define  LPRIMARYSTR            10
153 + #define  isprims(hl)            (!strncmp(hl,PRIMARYSTR,LPRIMARYSTR))
154 + #define  primsval(p,hl)         sscanf(hl+LPRIMARYSTR, \
155 +                                        "%f %f %f %f %f %f %f %f", \
156 +                                        &(p)[RED][CIEX],&(p)[RED][CIEY], \
157 +                                        &(p)[GRN][CIEX],&(p)[GRN][CIEY], \
158 +                                        &(p)[BLU][CIEX],&(p)[BLU][CIEY], \
159 +                                        &(p)[WHT][CIEX],&(p)[WHT][CIEY])
160 + #define  fputprims(p,fp)        fprintf(fp, \
161 +                                "%s %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\n",\
162 +                                        PRIMARYSTR, \
163 +                                        (p)[RED][CIEX],(p)[RED][CIEY], \
164 +                                        (p)[GRN][CIEX],(p)[GRN][CIEY], \
165 +                                        (p)[BLU][CIEX],(p)[BLU][CIEY], \
166 +                                        (p)[WHT][CIEX],(p)[WHT][CIEY])
167 +
168                                  /* macros for color correction */
169   #define  COLCORSTR              "COLORCORR="
170   #define  LCOLCORSTR             10
# Line 98 | Line 174 | typedef float  COLOR[3];       /* red, green, blue */
174   #define  fputcolcor(cc,fp)      fprintf(fp,"%s %f %f %f\n",COLCORSTR, \
175                                          (cc)[RED],(cc)[GRN],(cc)[BLU])
176  
177 < extern double  ldexp();
178 < #ifndef atof                    /* atof's a macro on some systems! */
179 < extern double  atof();
177 > #ifdef  DCL_ATOF
178 > extern double  atof(), ldexp(), frexp();
179 > #endif
180 >
181 > /*
182 > * Conversions to and from XYZ space generally don't apply WHTEFFICACY.
183 > * If you need Y to be luminance (cd/m^2), this must be applied when
184 > * converting from radiance (watts/sr/m^2).
185 > */
186 >
187 > extern RGBPRIMS  stdprims;              /* standard primary chromaticities */
188 > extern COLORMAT  rgb2xyzmat;            /* RGB to XYZ conversion matrix */
189 > extern COLORMAT  xyz2rgbmat;            /* XYZ to RGB conversion matrix */
190 > extern COLOR  cblack, cwhite;           /* black (0,0,0) and white (1,1,1) */
191 >
192 > #define  CGAMUT_LOWER           01
193 > #define  CGAMUT_UPPER           02
194 > #define  CGAMUT                 (CGAMUT_LOWER|CGAMUT_UPPER)
195 >
196 > #define  rgb_cie(xyz,rgb)       colortrans(xyz,rgb2xyzmat,rgb)
197 >
198 > #ifdef BSD
199 > #define  cpcolormat(md,ms)      bcopy((char *)ms,(char *)md,sizeof(COLORMAT))
200 > #else
201 > extern char  *memcpy();
202 > #define  cpcolormat(md,ms)      (void)memcpy((char *)md,(char *)ms,sizeof(COLORMAT))
203   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines