PageRenderTime 64ms CodeModel.GetById 3ms app.highlight 55ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmath/v4color.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 738 lines | 616 code | 71 blank | 51 comment | 246 complexity | a94c6b4fdd45a712343d6d3660847a1b MD5 | raw file
  1/** 
  2 * @file v4color.cpp
  3 * @brief LLColor4 class implementation.
  4 *
  5 * $LicenseInfo:firstyear=2000&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 "llboost.h"
 30
 31#include "v4color.h"
 32#include "v4coloru.h"
 33#include "v3color.h"
 34#include "v4math.h"
 35#include "llmath.h"
 36
 37// LLColor4
 38
 39//////////////////////////////////////////////////////////////////////////////
 40
 41LLColor4 LLColor4::red(		1.f, 0.f, 0.f, 1.f);
 42LLColor4 LLColor4::green(	0.f, 1.f, 0.f, 1.f);
 43LLColor4 LLColor4::blue(	0.f, 0.f, 1.f, 1.f);
 44LLColor4 LLColor4::black(	0.f, 0.f, 0.f, 1.f);
 45LLColor4 LLColor4::yellow(	1.f, 1.f, 0.f, 1.f);
 46LLColor4 LLColor4::magenta( 1.0f, 0.0f, 1.0f, 1.0f);
 47LLColor4 LLColor4::cyan(	0.0f, 1.0f, 1.0f, 1.0f);
 48LLColor4 LLColor4::white(	1.f, 1.f, 1.f, 1.f);
 49LLColor4 LLColor4::smoke(	0.5f, 0.5f, 0.5f, 0.5f);
 50LLColor4 LLColor4::grey(	0.5f, 0.5f, 0.5f, 1.0f);
 51LLColor4 LLColor4::orange(	1.f, 0.5, 0.f, 1.f );
 52LLColor4 LLColor4::purple(	0.6f, 0.2f, 0.8f, 1.0f);
 53LLColor4 LLColor4::pink(	1.0f, 0.5f, 0.8f, 1.0f);
 54LLColor4 LLColor4::transparent(	0.f, 0.f, 0.f, 0.f );
 55
 56//////////////////////////////////////////////////////////////////////////////
 57
 58LLColor4 LLColor4::grey1(0.8f, 0.8f, 0.8f, 1.0f);
 59LLColor4 LLColor4::grey2(0.6f, 0.6f, 0.6f, 1.0f);
 60LLColor4 LLColor4::grey3(0.4f, 0.4f, 0.4f, 1.0f);
 61LLColor4 LLColor4::grey4(0.3f, 0.3f, 0.3f, 1.0f);
 62
 63LLColor4 LLColor4::red1(1.0f, 0.0f, 0.0f, 1.0f);
 64LLColor4 LLColor4::red2(0.6f, 0.0f, 0.0f, 1.0f);
 65LLColor4 LLColor4::red3(1.0f, 0.2f, 0.2f, 1.0f);
 66LLColor4 LLColor4::red4(0.5f, 0.1f, 0.1f, 1.0f);
 67LLColor4 LLColor4::red5(0.8f, 0.1f, 0.0f, 1.0f);
 68
 69LLColor4 LLColor4::green1(0.0f, 1.0f, 0.0f, 1.0f);
 70LLColor4 LLColor4::green2(0.0f, 0.6f, 0.0f, 1.0f);
 71LLColor4 LLColor4::green3(0.0f, 0.4f, 0.0f, 1.0f);
 72LLColor4 LLColor4::green4(0.0f, 1.0f, 0.4f, 1.0f);
 73LLColor4 LLColor4::green5(0.2f, 0.6f, 0.4f, 1.0f);
 74LLColor4 LLColor4::green6(0.4f, 0.6f, 0.2f, 1.0f);
 75
 76LLColor4 LLColor4::blue1(0.0f, 0.0f, 1.0f, 1.0f);
 77LLColor4 LLColor4::blue2(0.0f, 0.4f, 1.0f, 1.0f);
 78LLColor4 LLColor4::blue3(0.2f, 0.2f, 0.8f, 1.0f);
 79LLColor4 LLColor4::blue4(0.0f, 0.0f, 0.6f, 1.0f);
 80LLColor4 LLColor4::blue5(0.4f, 0.2f, 1.0f, 1.0f);
 81LLColor4 LLColor4::blue6(0.4f, 0.5f, 1.0f, 1.0f);
 82
 83LLColor4 LLColor4::yellow1(1.0f, 1.0f, 0.0f, 1.0f);
 84LLColor4 LLColor4::yellow2(0.6f, 0.6f, 0.0f, 1.0f);
 85LLColor4 LLColor4::yellow3(0.8f, 1.0f, 0.2f, 1.0f);
 86LLColor4 LLColor4::yellow4(1.0f, 1.0f, 0.4f, 1.0f);
 87LLColor4 LLColor4::yellow5(0.6f, 0.4f, 0.2f, 1.0f);
 88LLColor4 LLColor4::yellow6(1.0f, 0.8f, 0.4f, 1.0f);
 89LLColor4 LLColor4::yellow7(0.8f, 0.8f, 0.0f, 1.0f);
 90LLColor4 LLColor4::yellow8(0.8f, 0.8f, 0.2f, 1.0f);
 91LLColor4 LLColor4::yellow9(0.8f, 0.8f, 0.4f, 1.0f);
 92
 93LLColor4 LLColor4::orange1(1.0f, 0.8f, 0.0f, 1.0f);
 94LLColor4 LLColor4::orange2(1.0f, 0.6f, 0.0f, 1.0f);
 95LLColor4 LLColor4::orange3(1.0f, 0.4f, 0.2f, 1.0f);
 96LLColor4 LLColor4::orange4(0.8f, 0.4f, 0.0f, 1.0f);
 97LLColor4 LLColor4::orange5(0.9f, 0.5f, 0.0f, 1.0f);
 98LLColor4 LLColor4::orange6(1.0f, 0.8f, 0.2f, 1.0f);
 99
100LLColor4 LLColor4::magenta1(1.0f, 0.0f, 1.0f, 1.0f);
101LLColor4 LLColor4::magenta2(0.6f, 0.2f, 0.4f, 1.0f);
102LLColor4 LLColor4::magenta3(1.0f, 0.4f, 0.6f, 1.0f);
103LLColor4 LLColor4::magenta4(1.0f, 0.2f, 0.8f, 1.0f);
104
105LLColor4 LLColor4::purple1(0.6f, 0.2f, 0.8f, 1.0f);
106LLColor4 LLColor4::purple2(0.8f, 0.2f, 1.0f, 1.0f);
107LLColor4 LLColor4::purple3(0.6f, 0.0f, 1.0f, 1.0f);
108LLColor4 LLColor4::purple4(0.4f, 0.0f, 0.8f, 1.0f);
109LLColor4 LLColor4::purple5(0.6f, 0.0f, 0.8f, 1.0f);
110LLColor4 LLColor4::purple6(0.8f, 0.0f, 0.6f, 1.0f);
111
112LLColor4 LLColor4::pink1(1.0f, 0.5f, 0.8f, 1.0f);
113LLColor4 LLColor4::pink2(1.0f, 0.8f, 0.9f, 1.0f);
114
115LLColor4 LLColor4::cyan1(0.0f, 1.0f, 1.0f, 1.0f);
116LLColor4 LLColor4::cyan2(0.4f, 0.8f, 0.8f, 1.0f);
117LLColor4 LLColor4::cyan3(0.0f, 1.0f, 0.6f, 1.0f);
118LLColor4 LLColor4::cyan4(0.6f, 1.0f, 1.0f, 1.0f);
119LLColor4 LLColor4::cyan5(0.2f, 0.6f, 1.0f, 1.0f);
120LLColor4 LLColor4::cyan6(0.2f, 0.6f, 0.6f, 1.0f);
121
122//////////////////////////////////////////////////////////////////////////////
123
124// conversion
125LLColor4::operator const LLColor4U() const
126{
127	return LLColor4U(
128		(U8)llclampb(llround(mV[VRED]*255.f)),
129		(U8)llclampb(llround(mV[VGREEN]*255.f)),
130		(U8)llclampb(llround(mV[VBLUE]*255.f)),
131		(U8)llclampb(llround(mV[VALPHA]*255.f)));
132}
133
134LLColor4::LLColor4(const LLColor3 &vec, F32 a)
135{
136	mV[VX] = vec.mV[VX];
137	mV[VY] = vec.mV[VY];
138	mV[VZ] = vec.mV[VZ];
139	mV[VW] = a;
140}
141
142LLColor4::LLColor4(const LLColor4U& color4u)
143{
144	const F32 SCALE = 1.f/255.f;
145	mV[VX] = color4u.mV[VX] * SCALE;
146	mV[VY] = color4u.mV[VY] * SCALE;
147	mV[VZ] = color4u.mV[VZ] * SCALE;
148	mV[VW] = color4u.mV[VW] * SCALE;
149}
150
151LLColor4::LLColor4(const LLVector4& vector4)
152{
153	mV[VX] = vector4.mV[VX];
154	mV[VY] = vector4.mV[VY];
155	mV[VZ] = vector4.mV[VZ];
156	mV[VW] = vector4.mV[VW];
157}
158
159const LLColor4&	LLColor4::set(const LLColor4U& color4u)
160{
161	const F32 SCALE = 1.f/255.f;
162	mV[VX] = color4u.mV[VX] * SCALE;
163	mV[VY] = color4u.mV[VY] * SCALE;
164	mV[VZ] = color4u.mV[VZ] * SCALE;
165	mV[VW] = color4u.mV[VW] * SCALE;
166	return (*this);
167}
168
169const LLColor4&	LLColor4::set(const LLColor3 &vec)
170{
171	mV[VX] = vec.mV[VX];
172	mV[VY] = vec.mV[VY];
173	mV[VZ] = vec.mV[VZ];
174
175//  no change to alpha!
176//	mV[VW] = 1.f;  
177
178	return (*this);
179}
180
181const LLColor4&	LLColor4::set(const LLColor3 &vec, F32 a)
182{
183	mV[VX] = vec.mV[VX];
184	mV[VY] = vec.mV[VY];
185	mV[VZ] = vec.mV[VZ];
186	mV[VW] = a;
187	return (*this);
188}
189
190// deprecated -- use set()
191const LLColor4&	LLColor4::setVec(const LLColor4U& color4u)
192{
193	const F32 SCALE = 1.f/255.f;
194	mV[VX] = color4u.mV[VX] * SCALE;
195	mV[VY] = color4u.mV[VY] * SCALE;
196	mV[VZ] = color4u.mV[VZ] * SCALE;
197	mV[VW] = color4u.mV[VW] * SCALE;
198	return (*this);
199}
200
201// deprecated -- use set()
202const LLColor4&	LLColor4::setVec(const LLColor3 &vec)
203{
204	mV[VX] = vec.mV[VX];
205	mV[VY] = vec.mV[VY];
206	mV[VZ] = vec.mV[VZ];
207
208//  no change to alpha!
209//	mV[VW] = 1.f;  
210
211	return (*this);
212}
213
214// deprecated -- use set()
215const LLColor4&	LLColor4::setVec(const LLColor3 &vec, F32 a)
216{
217	mV[VX] = vec.mV[VX];
218	mV[VY] = vec.mV[VY];
219	mV[VZ] = vec.mV[VZ];
220	mV[VW] = a;
221	return (*this);
222}
223
224void LLColor4::setValue(const LLSD& sd)
225{
226#if 0
227	// Clamping on setValue from LLSD is inconsistent with other set behavior
228	F32 val;
229	bool out_of_range = false;
230	val = sd[0].asReal();
231	mV[0] = llclamp(val, 0.f, 1.f);
232	out_of_range = mV[0] != val;
233
234	val = sd[1].asReal();
235	mV[1] = llclamp(val, 0.f, 1.f);
236	out_of_range |= mV[1] != val;
237
238	val = sd[2].asReal();
239	mV[2] = llclamp(val, 0.f, 1.f);
240	out_of_range |= mV[2] != val;
241
242	val = sd[3].asReal();
243	mV[3] = llclamp(val, 0.f, 1.f);
244	out_of_range |= mV[3] != val;
245
246	if (out_of_range)
247	{
248		llwarns << "LLSD color value out of range!" << llendl;
249	}
250#else
251	mV[0] = (F32) sd[0].asReal();
252	mV[1] = (F32) sd[1].asReal();
253	mV[2] = (F32) sd[2].asReal();
254	mV[3] = (F32) sd[3].asReal();
255#endif
256}
257
258const LLColor4& LLColor4::operator=(const LLColor3 &a)
259{
260	mV[VX] = a.mV[VX];
261	mV[VY] = a.mV[VY];
262	mV[VZ] = a.mV[VZ];
263
264// converting from an rgb sets a=1 (opaque)
265	mV[VW] = 1.f;
266	return (*this);
267}
268
269
270std::ostream& operator<<(std::ostream& s, const LLColor4 &a) 
271{
272	s << "{ " << a.mV[VX] << ", " << a.mV[VY] << ", " << a.mV[VZ] << ", " << a.mV[VW] << " }";
273	return s;
274}
275
276bool operator==(const LLColor4 &a, const LLColor3 &b)
277{
278	return (  (a.mV[VX] == b.mV[VX])
279			&&(a.mV[VY] == b.mV[VY])
280			&&(a.mV[VZ] == b.mV[VZ]));
281}
282
283bool operator!=(const LLColor4 &a, const LLColor3 &b)
284{
285	return (  (a.mV[VX] != b.mV[VX])
286			||(a.mV[VY] != b.mV[VY])
287			||(a.mV[VZ] != b.mV[VZ]));
288}
289
290LLColor3	vec4to3(const LLColor4 &vec)
291{
292	LLColor3	temp(vec.mV[VX], vec.mV[VY], vec.mV[VZ]);
293	return temp;
294}
295
296LLColor4	vec3to4(const LLColor3 &vec)
297{
298	LLColor3	temp(vec.mV[VX], vec.mV[VY], vec.mV[VZ]);
299	return temp;
300}
301
302static F32 hueToRgb ( F32 val1In, F32 val2In, F32 valHUeIn )
303{
304	if ( valHUeIn < 0.0f ) valHUeIn += 1.0f;
305	if ( valHUeIn > 1.0f ) valHUeIn -= 1.0f;
306	if ( ( 6.0f * valHUeIn ) < 1.0f ) return ( val1In + ( val2In - val1In ) * 6.0f * valHUeIn );
307	if ( ( 2.0f * valHUeIn ) < 1.0f ) return ( val2In );
308	if ( ( 3.0f * valHUeIn ) < 2.0f ) return ( val1In + ( val2In - val1In ) * ( ( 2.0f / 3.0f ) - valHUeIn ) * 6.0f );
309	return ( val1In );
310}
311
312void LLColor4::setHSL ( F32 hValIn, F32 sValIn, F32 lValIn)
313{
314	if ( sValIn < 0.00001f )
315	{
316		mV[VRED] = lValIn;
317		mV[VGREEN] = lValIn;
318		mV[VBLUE] = lValIn;
319	}
320	else
321	{
322		F32 interVal1;
323		F32 interVal2;
324
325		if ( lValIn < 0.5f )
326			interVal2 = lValIn * ( 1.0f + sValIn );
327		else
328			interVal2 = ( lValIn + sValIn ) - ( sValIn * lValIn );
329
330		interVal1 = 2.0f * lValIn - interVal2;
331
332		mV[VRED] = hueToRgb ( interVal1, interVal2, hValIn + ( 1.f / 3.f ) );
333		mV[VGREEN] = hueToRgb ( interVal1, interVal2, hValIn );
334		mV[VBLUE] = hueToRgb ( interVal1, interVal2, hValIn - ( 1.f / 3.f ) );
335	}
336}
337
338void LLColor4::calcHSL(F32* hue, F32* saturation, F32* luminance) const
339{
340	F32 var_R = mV[VRED];
341	F32 var_G = mV[VGREEN];
342	F32 var_B = mV[VBLUE];
343
344	F32 var_Min = ( var_R < ( var_G < var_B ? var_G : var_B ) ? var_R : ( var_G < var_B ? var_G : var_B ) );
345	F32 var_Max = ( var_R > ( var_G > var_B ? var_G : var_B ) ? var_R : ( var_G > var_B ? var_G : var_B ) );
346
347	F32 del_Max = var_Max - var_Min;
348
349	F32 L = ( var_Max + var_Min ) / 2.0f;
350	F32 H = 0.0f;
351	F32 S = 0.0f;
352
353	if ( del_Max == 0.0f )
354	{
355	   H = 0.0f;
356	   S = 0.0f;
357	}
358	else
359	{
360		if ( L < 0.5 )
361			S = del_Max / ( var_Max + var_Min );
362		else
363			S = del_Max / ( 2.0f - var_Max - var_Min );
364
365		F32 del_R = ( ( ( var_Max - var_R ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max;
366		F32 del_G = ( ( ( var_Max - var_G ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max;
367		F32 del_B = ( ( ( var_Max - var_B ) / 6.0f ) + ( del_Max / 2.0f ) ) / del_Max;
368
369		if ( var_R >= var_Max )
370			H = del_B - del_G;
371		else
372		if ( var_G >= var_Max )
373			H = ( 1.0f / 3.0f ) + del_R - del_B;
374		else
375		if ( var_B >= var_Max )
376			H = ( 2.0f / 3.0f ) + del_G - del_R;
377
378		if ( H < 0.0f ) H += 1.0f;
379		if ( H > 1.0f ) H -= 1.0f;
380	}
381
382	if (hue) *hue = H;
383	if (saturation) *saturation = S;
384	if (luminance) *luminance = L;
385}
386
387// static
388BOOL LLColor4::parseColor(const std::string& buf, LLColor4* color)
389{
390	if( buf.empty() || color == NULL)
391	{
392		return FALSE;
393	}
394
395	boost_tokenizer tokens(buf, boost::char_separator<char>(", "));
396	boost_tokenizer::iterator token_iter = tokens.begin();
397	if (token_iter == tokens.end())
398	{
399		return FALSE;
400	}
401
402	// Grab the first token into a string, since we don't know
403	// if this is a float or a color name.
404	std::string color_name( (*token_iter) );
405	++token_iter;
406
407	if (token_iter != tokens.end())
408	{
409		// There are more tokens to read.  This must be a vector.
410		LLColor4 v;
411		LLStringUtil::convertToF32( color_name,  v.mV[VX] );
412		LLStringUtil::convertToF32( *token_iter, v.mV[VY] );
413		v.mV[VZ] = 0.0f;
414		v.mV[VW] = 1.0f;
415
416		++token_iter;
417		if (token_iter == tokens.end())
418		{
419			// This is a malformed vector.
420			llwarns << "LLColor4::parseColor() malformed color " << buf << llendl;
421		}
422		else
423		{
424			// There is a z-component.
425			LLStringUtil::convertToF32( *token_iter, v.mV[VZ] );
426
427			++token_iter;
428			if (token_iter != tokens.end())
429			{
430				// There is an alpha component.
431				LLStringUtil::convertToF32( *token_iter, v.mV[VW] );
432			}
433		}
434
435		//  Make sure all values are between 0 and 1.
436		if (v.mV[VX] > 1.f || v.mV[VY] > 1.f || v.mV[VZ] > 1.f || v.mV[VW] > 1.f)
437		{
438			v = v * (1.f / 255.f);
439		}
440		color->set( v );
441	}
442	else // Single value.  Read as a named color.
443	{
444		// We have a color name
445		if ( "red" == color_name )
446		{
447			color->set(LLColor4::red);
448		}
449		else if ( "red1" == color_name )
450		{
451			color->set(LLColor4::red1);
452		}
453		else if ( "red2" == color_name )
454		{
455			color->set(LLColor4::red2);
456		}
457		else if ( "red3" == color_name )
458		{
459			color->set(LLColor4::red3);
460		}
461		else if ( "red4" == color_name )
462		{
463			color->set(LLColor4::red4);
464		}
465		else if ( "red5" == color_name )
466		{
467			color->set(LLColor4::red5);
468		}
469		else if( "green" == color_name )
470		{
471			color->set(LLColor4::green);
472		}
473		else if( "green1" == color_name )
474		{
475			color->set(LLColor4::green1);
476		}
477		else if( "green2" == color_name )
478		{
479			color->set(LLColor4::green2);
480		}
481		else if( "green3" == color_name )
482		{
483			color->set(LLColor4::green3);
484		}
485		else if( "green4" == color_name )
486		{
487			color->set(LLColor4::green4);
488		}
489		else if( "green5" == color_name )
490		{
491			color->set(LLColor4::green5);
492		}
493		else if( "green6" == color_name )
494		{
495			color->set(LLColor4::green6);
496		}
497		else if( "blue" == color_name )
498		{
499			color->set(LLColor4::blue);
500		}
501		else if( "blue1" == color_name )
502		{
503			color->set(LLColor4::blue1);
504		}
505		else if( "blue2" == color_name )
506		{
507			color->set(LLColor4::blue2);
508		}
509		else if( "blue3" == color_name )
510		{
511			color->set(LLColor4::blue3);
512		}
513		else if( "blue4" == color_name )
514		{
515			color->set(LLColor4::blue4);
516		}
517		else if( "blue5" == color_name )
518		{
519			color->set(LLColor4::blue5);
520		}
521		else if( "blue6" == color_name )
522		{
523			color->set(LLColor4::blue6);
524		}
525		else if( "black" == color_name )
526		{
527			color->set(LLColor4::black);
528		}
529		else if( "white" == color_name )
530		{
531			color->set(LLColor4::white);
532		}
533		else if( "yellow" == color_name )
534		{
535			color->set(LLColor4::yellow);
536		}
537		else if( "yellow1" == color_name )
538		{
539			color->set(LLColor4::yellow1);
540		}
541		else if( "yellow2" == color_name )
542		{
543			color->set(LLColor4::yellow2);
544		}
545		else if( "yellow3" == color_name )
546		{
547			color->set(LLColor4::yellow3);
548		}
549		else if( "yellow4" == color_name )
550		{
551			color->set(LLColor4::yellow4);
552		}
553		else if( "yellow5" == color_name )
554		{
555			color->set(LLColor4::yellow5);
556		}
557		else if( "yellow6" == color_name )
558		{
559			color->set(LLColor4::yellow6);
560		}
561		else if( "magenta" == color_name )
562		{
563			color->set(LLColor4::magenta);
564		}
565		else if( "magenta1" == color_name )
566		{
567			color->set(LLColor4::magenta1);
568		}
569		else if( "magenta2" == color_name )
570		{
571			color->set(LLColor4::magenta2);
572		}
573		else if( "magenta3" == color_name )
574		{
575			color->set(LLColor4::magenta3);
576		}
577		else if( "magenta4" == color_name )
578		{
579			color->set(LLColor4::magenta4);
580		}
581		else if( "purple" == color_name )
582		{
583			color->set(LLColor4::purple);
584		}
585		else if( "purple1" == color_name )
586		{
587			color->set(LLColor4::purple1);
588		}
589		else if( "purple2" == color_name )
590		{
591			color->set(LLColor4::purple2);
592		}
593		else if( "purple3" == color_name )
594		{
595			color->set(LLColor4::purple3);
596		}
597		else if( "purple4" == color_name )
598		{
599			color->set(LLColor4::purple4);
600		}
601		else if( "purple5" == color_name )
602		{
603			color->set(LLColor4::purple5);
604		}
605		else if( "purple6" == color_name )
606		{
607			color->set(LLColor4::purple6);
608		}
609		else if( "pink" == color_name )
610		{
611			color->set(LLColor4::pink);
612		}
613		else if( "pink1" == color_name )
614		{
615			color->set(LLColor4::pink1);
616		}
617		else if( "pink2" == color_name )
618		{
619			color->set(LLColor4::pink2);
620		}
621		else if( "cyan" == color_name )
622		{
623			color->set(LLColor4::cyan);
624		}
625		else if( "cyan1" == color_name )
626		{
627			color->set(LLColor4::cyan1);
628		}
629		else if( "cyan2" == color_name )
630		{
631			color->set(LLColor4::cyan2);
632		}
633		else if( "cyan3" == color_name )
634		{
635			color->set(LLColor4::cyan3);
636		}
637		else if( "cyan4" == color_name )
638		{
639			color->set(LLColor4::cyan4);
640		}
641		else if( "cyan5" == color_name )
642		{
643			color->set(LLColor4::cyan5);
644		}
645		else if( "cyan6" == color_name )
646		{
647			color->set(LLColor4::cyan6);
648		}
649		else if( "smoke" == color_name )
650		{
651			color->set(LLColor4::smoke);
652		}
653		else if( "grey" == color_name )
654		{
655			color->set(LLColor4::grey);
656		}
657		else if( "grey1" == color_name )
658		{
659			color->set(LLColor4::grey1);
660		}
661		else if( "grey2" == color_name )
662		{
663			color->set(LLColor4::grey2);
664		}
665		else if( "grey3" == color_name )
666		{
667			color->set(LLColor4::grey3);
668		}
669		else if( "grey4" == color_name )
670		{
671			color->set(LLColor4::grey4);
672		}
673		else if( "orange" == color_name )
674		{
675			color->set(LLColor4::orange);
676		}
677		else if( "orange1" == color_name )
678		{
679			color->set(LLColor4::orange1);
680		}
681		else if( "orange2" == color_name )
682		{
683			color->set(LLColor4::orange2);
684		}
685		else if( "orange3" == color_name )
686		{
687			color->set(LLColor4::orange3);
688		}
689		else if( "orange4" == color_name )
690		{
691			color->set(LLColor4::orange4);
692		}
693		else if( "orange5" == color_name )
694		{
695			color->set(LLColor4::orange5);
696		}
697		else if( "orange6" == color_name )
698		{
699			color->set(LLColor4::orange6);
700		}
701		else if ( "clear" == color_name )
702		{
703			color->set(0.f, 0.f, 0.f, 0.f);
704		}
705		else
706		{
707			llwarns << "invalid color " << color_name << llendl;
708		}
709	}
710
711	return TRUE;
712}
713
714// static
715BOOL LLColor4::parseColor4(const std::string& buf, LLColor4* value)
716{
717	if( buf.empty() || value == NULL)
718	{
719		return FALSE;
720	}
721
722	LLColor4 v;
723	S32 count = sscanf( buf.c_str(), "%f, %f, %f, %f", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3 );
724	if (1 == count )
725	{
726		// try this format
727		count = sscanf( buf.c_str(), "%f %f %f %f", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3 );
728	}
729	if( 4 == count )
730	{
731		value->setVec( v );
732		return TRUE;
733	}
734
735	return FALSE;
736}
737
738// EOF