v3color.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "v3color.h"
00035 #include "v4color.h"
00036 
00037 LLColor3 LLColor3::white(1.0f, 1.0f, 1.0f);
00038 LLColor3 LLColor3::black(0.0f, 0.0f, 0.0f);
00039 LLColor3 LLColor3::grey (0.5f, 0.5f, 0.5f);
00040 
00041 LLColor3::LLColor3(const LLColor4 &a)
00042 {
00043         mV[0] = a.mV[0];
00044         mV[1] = a.mV[1];
00045         mV[2] = a.mV[2];
00046 }
00047 
00048 LLColor3::LLColor3(const LLSD &sd)
00049 {
00050         mV[0] = (F32) sd[0].asReal();
00051         mV[1] = (F32) sd[1].asReal();
00052         mV[2] = (F32) sd[2].asReal();
00053 }
00054 
00055 const LLColor3& LLColor3::operator=(const LLColor4 &a) 
00056 {
00057         mV[0] = a.mV[0];
00058         mV[1] = a.mV[1];
00059         mV[2] = a.mV[2];
00060         return (*this);
00061 }
00062 
00063 std::ostream& operator<<(std::ostream& s, const LLColor3 &a) 
00064 {
00065         s << "{ " << a.mV[VX] << ", " << a.mV[VY] << ", " << a.mV[VZ] << " }";
00066         return s;
00067 }
00068 
00069 void LLColor3::calcHSL(F32* hue, F32* saturation, F32* luminance) const
00070 {
00071         F32 var_R = mV[VRED];
00072         F32 var_G = mV[VGREEN];
00073         F32 var_B = mV[VBLUE];
00074 
00075         F32 var_Min = ( var_R < ( var_G < var_B ? var_G : var_B ) ? var_R : ( var_G < var_B ? var_G : var_B ) );
00076         F32 var_Max = ( var_R > ( var_G > var_B ? var_G : var_B ) ? var_R : ( var_G > var_B ? var_G : var_B ) );
00077 
00078         F32 del_Max = var_Max - var_Min;
00079 
00080         F32 L = ( var_Max + var_Min ) / 2.0f;
00081         F32 H = 0.0f;
00082         F32 S = 0.0f;
00083 
00084         if ( del_Max == 0.0f )
00085         {
00086            H = 0.0f;
00087            S = 0.0f;
00088         }
00089         else
00090         {
00091                 if ( L < 0.5 )
00092                         S = del_Max / ( var_Max + var_Min );
00093                 else
00094                         S = del_Max / ( 2.0f - var_Max - var_Min );
00095 
00096                 F32 del_R = ( ( ( var_Max - var_R ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max;
00097                 F32 del_G = ( ( ( var_Max - var_G ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max;
00098                 F32 del_B = ( ( ( var_Max - var_B ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max;
00099 
00100                 if ( var_R >= var_Max )
00101                         H = del_B - del_G;
00102                 else
00103                 if ( var_G >= var_Max )
00104                         H = ( 1.0f / 3.0f ) + del_R - del_B;
00105                 else
00106                 if ( var_B >= var_Max )
00107                         H = ( 2.0f / 3.0f ) + del_G - del_R;
00108 
00109                 if ( H < 0.0f ) H += 1.0f;
00110                 if ( H > 1.0f ) H -= 1.0f;
00111         }
00112 
00113         if (hue) *hue = H;
00114         if (saturation) *saturation = S;
00115         if (luminance) *luminance = L;
00116 }

Generated on Thu Jul 1 06:09:59 2010 for Second Life Viewer by  doxygen 1.4.7