PageRenderTime 24ms CodeModel.GetById 2ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/v4coloru.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 120 lines | 40 code | 19 blank | 61 comment | 9 complexity | b82f217aaa2e00aa7c7e3dacd831e49e MD5 | raw file
  1/** 
  2 * @file v4coloru.cpp
  3 * @brief LLColor4U class implementation.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29//#include "v3coloru.h"
 30#include "v4coloru.h"
 31#include "v4color.h"
 32//#include "vmath.h"
 33#include "llmath.h"
 34
 35// LLColor4U
 36LLColor4U LLColor4U::white(255, 255, 255, 255);
 37LLColor4U LLColor4U::black(  0,   0,   0, 255);
 38LLColor4U LLColor4U::red  (255,   0,   0, 255);
 39LLColor4U LLColor4U::green(  0, 255,   0, 255);
 40LLColor4U LLColor4U::blue (  0,   0, 255, 255);
 41
 42// conversion
 43/* inlined to fix gcc compile link error
 44LLColor4U::operator LLColor4()
 45{
 46	return(LLColor4((F32)mV[VRED]/255.f,(F32)mV[VGREEN]/255.f,(F32)mV[VBLUE]/255.f,(F32)mV[VALPHA]/255.f));
 47}
 48*/
 49
 50// Constructors
 51
 52
 53/*
 54LLColor4U::LLColor4U(const LLColor3 &vec)
 55{
 56	mV[VX] = vec.mV[VX];
 57	mV[VY] = vec.mV[VY];
 58	mV[VZ] = vec.mV[VZ];
 59	mV[VW] = 255;
 60}
 61*/
 62
 63
 64// Clear and Assignment Functions
 65
 66
 67
 68// LLColor4U Operators
 69
 70/*
 71LLColor4U LLColor4U::operator=(const LLColor3 &a)
 72{
 73	mV[VX] = a.mV[VX];
 74	mV[VY] = a.mV[VY];
 75	mV[VZ] = a.mV[VZ];
 76
 77// converting from an rgb sets a=1 (opaque)
 78	mV[VW] = 255;
 79	return (*this);
 80}
 81*/
 82
 83
 84std::ostream& operator<<(std::ostream& s, const LLColor4U &a) 
 85{
 86	s << "{ " << (S32)a.mV[VX] << ", " << (S32)a.mV[VY] << ", " << (S32)a.mV[VZ] << ", " << (S32)a.mV[VW] << " }";
 87	return s;
 88}
 89
 90// static
 91BOOL LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
 92{
 93	if( buf.empty() || value == NULL)
 94	{
 95		return FALSE;
 96	}
 97
 98	U32 v[4];
 99	S32 count = sscanf( buf.c_str(), "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3 );
100	if (1 == count )
101	{
102		// try this format
103		count = sscanf( buf.c_str(), "%u %u %u %u", v + 0, v + 1, v + 2, v + 3 );
104	}
105	if( 4 != count )
106	{
107		return FALSE;
108	}
109
110	for( S32 i = 0; i < 4; i++ )
111	{
112		if( v[i] > U8_MAX )
113		{
114			return FALSE;
115		}
116	}
117
118	value->set( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) );
119	return TRUE;
120}