00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _SG_COLORS_HXX
00025 #define _SG_COLORS_HXX 1
00026
00027 #include <math.h>
00028
00029 #if defined( macintosh )
00030 const float system_gamma = 1.4;
00031
00032 #elif defined (sgi)
00033 const float system_gamma = 2.0/1.7;
00034
00035 #else // others
00036 const float system_gamma = 2.5;
00037 #endif
00038
00039
00040 inline void gamma_correct_rgb(float *color,
00041 float reff = 2.5, float system = system_gamma)
00042 {
00043 if (reff == system)
00044 return;
00045
00046 float tmp = reff/system;
00047 color[0] = pow(color[0], tmp);
00048 color[1] = pow(color[1], tmp);
00049 color[2] = pow(color[2], tmp);
00050 };
00051
00052 inline void gamma_correct_c(float *color,
00053 float reff = 2.5, float system = system_gamma)
00054 {
00055 if (reff == system)
00056 return;
00057
00058 *color = pow(*color, reff/system);
00059 };
00060
00061 inline void gamma_restore_rgb(float *color,
00062 float reff = 2.5, float system = system_gamma)
00063 {
00064 if (reff == system)
00065 return;
00066
00067 float tmp = system/reff;
00068 color[0] = pow(color[0], tmp);
00069 color[1] = pow(color[1], tmp);
00070 color[2] = pow(color[2], tmp);
00071 };
00072
00073 inline void gamma_restore_c(float *color,
00074 float reff = 2.5, float system = system_gamma)
00075 {
00076 if (reff == system)
00077 return;
00078
00079 *color = pow(*color, system/reff);
00080 };
00081
00082
00083 #endif // _SG_COLORS_HXX
00084