v4coloru.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 //#include "v3coloru.h"
00035 #include "v4coloru.h"
00036 #include "v4color.h"
00037 //#include "vmath.h"
00038 #include "llmath.h"
00039 
00040 // LLColor4U
00041 LLColor4U LLColor4U::white(255, 255, 255, 255);
00042 LLColor4U LLColor4U::black(  0,   0,   0, 255);
00043 LLColor4U LLColor4U::red  (255,   0,   0, 255);
00044 LLColor4U LLColor4U::green(  0, 255,   0, 255);
00045 LLColor4U LLColor4U::blue (  0,   0, 255, 255);
00046 
00047 // conversion
00048 /* inlined to fix gcc compile link error
00049 LLColor4U::operator LLColor4()
00050 {
00051         return(LLColor4((F32)mV[VRED]/255.f,(F32)mV[VGREEN]/255.f,(F32)mV[VBLUE]/255.f,(F32)mV[VALPHA]/255.f));
00052 }
00053 */
00054 
00055 // Constructors
00056 
00057 
00058 /*
00059 LLColor4U::LLColor4U(const LLColor3 &vec)
00060 {
00061         mV[VX] = vec.mV[VX];
00062         mV[VY] = vec.mV[VY];
00063         mV[VZ] = vec.mV[VZ];
00064         mV[VW] = 255;
00065 }
00066 */
00067 
00068 
00069 // Clear and Assignment Functions
00070 
00071 
00072 
00073 // LLColor4U Operators
00074 
00075 /*
00076 LLColor4U LLColor4U::operator=(const LLColor3 &a)
00077 {
00078         mV[VX] = a.mV[VX];
00079         mV[VY] = a.mV[VY];
00080         mV[VZ] = a.mV[VZ];
00081 
00082 // converting from an rgb sets a=1 (opaque)
00083         mV[VW] = 255;
00084         return (*this);
00085 }
00086 */
00087 
00088 
00089 std::ostream& operator<<(std::ostream& s, const LLColor4U &a) 
00090 {
00091         s << "{ " << (S32)a.mV[VX] << ", " << (S32)a.mV[VY] << ", " << (S32)a.mV[VZ] << ", " << (S32)a.mV[VW] << " }";
00092         return s;
00093 }
00094 
00095 // static
00096 BOOL LLColor4U::parseColor4U(const char* buf, LLColor4U* value)
00097 {
00098         if( buf == NULL || buf[0] == '\0' || value == NULL)
00099         {
00100                 return FALSE;
00101         }
00102 
00103         U32 v[4];
00104         S32 count = sscanf( buf, "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3 );
00105         if (1 == count )
00106         {
00107                 // try this format
00108                 count = sscanf( buf, "%u %u %u %u", v + 0, v + 1, v + 2, v + 3 );
00109         }
00110         if( 4 != count )
00111         {
00112                 return FALSE;
00113         }
00114 
00115         for( S32 i = 0; i < 4; i++ )
00116         {
00117                 if( v[i] > U8_MAX )
00118                 {
00119                         return FALSE;
00120                 }
00121         }
00122 
00123         value->setVec( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) );
00124         return TRUE;
00125 }

Generated on Thu Jul 1 06:10:01 2010 for Second Life Viewer by  doxygen 1.4.7