llcolor4.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /**
  2. * @file llcolor4.cpp
  3. * @brief LLColor4 class implementation.
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "boost/tokenizer.hpp"
  34. #include "llcolor4.h"
  35. #include "llcolor4u.h"
  36. #include "llcolor3.h"
  37. #include "llvector4.h"
  38. #include "llmath.h"
  39. LLColor4 LLColor4::red(1.f, 0.f, 0.f, 1.f);
  40. LLColor4 LLColor4::green(0.f, 1.f, 0.f, 1.f);
  41. LLColor4 LLColor4::blue(0.f, 0.f, 1.f, 1.f);
  42. LLColor4 LLColor4::black(0.f, 0.f, 0.f, 1.f);
  43. LLColor4 LLColor4::yellow(1.f, 1.f, 0.f, 1.f);
  44. LLColor4 LLColor4::magenta(1.f, 0.f, 1.f, 1.f);
  45. LLColor4 LLColor4::cyan(0.f, 1.f, 1.f, 1.f);
  46. LLColor4 LLColor4::white(1.f, 1.f, 1.f, 1.f);
  47. LLColor4 LLColor4::smoke(0.5f, 0.5f, 0.5f, 0.5f);
  48. LLColor4 LLColor4::grey(0.5f, 0.5f, 0.5f, 1.f);
  49. LLColor4 LLColor4::orange(1.f, 0.5, 0.f, 1.f);
  50. LLColor4 LLColor4::purple(0.6f, 0.2f, 0.8f, 1.f);
  51. LLColor4 LLColor4::pink(1.f, 0.5f, 0.8f, 1.f);
  52. LLColor4 LLColor4::transparent(0.f, 0.f, 0.f, 0.f);
  53. LLColor4 LLColor4::grey1(0.8f, 0.8f, 0.8f, 1.f);
  54. LLColor4 LLColor4::grey2(0.6f, 0.6f, 0.6f, 1.f);
  55. LLColor4 LLColor4::grey3(0.4f, 0.4f, 0.4f, 1.f);
  56. LLColor4 LLColor4::grey4(0.3f, 0.3f, 0.3f, 1.f);
  57. LLColor4 LLColor4::grey5(0.125f, 0.125f, 0.125f, 1.f);
  58. LLColor4 LLColor4::red0(0.5f, 0.f, 0.f, 1.f);
  59. LLColor4 LLColor4::red1(1.f, 0.f, 0.f, 1.f);
  60. LLColor4 LLColor4::red2(0.6f, 0.f, 0.f, 1.f);
  61. LLColor4 LLColor4::red3(1.f, 0.2f, 0.2f, 1.f);
  62. LLColor4 LLColor4::red4(0.5f, 0.1f, 0.1f, 1.f);
  63. LLColor4 LLColor4::red5(0.8f, 0.1f, 0.f, 1.f);
  64. LLColor4 LLColor4::green0(0.f, 0.5f, 0.f, 1.f);
  65. LLColor4 LLColor4::green1(0.f, 1.f, 0.f, 1.f);
  66. LLColor4 LLColor4::green2(0.f, 0.6f, 0.f, 1.f);
  67. LLColor4 LLColor4::green3(0.f, 0.4f, 0.f, 1.f);
  68. LLColor4 LLColor4::green4(0.f, 1.f, 0.4f, 1.f);
  69. LLColor4 LLColor4::green5(0.2f, 0.6f, 0.4f, 1.f);
  70. LLColor4 LLColor4::green6(0.4f, 0.6f, 0.2f, 1.f);
  71. LLColor4 LLColor4::green7(0.6f, 1.f, 0.4f, 1.f);
  72. LLColor4 LLColor4::green8(0.4f, 1.f, 0.6f, 1.f);
  73. LLColor4 LLColor4::green9(0.6f, 1.f, 0.6f, 1.f);
  74. LLColor4 LLColor4::blue0(0.f, 0.f, 0.5f, 1.f);
  75. LLColor4 LLColor4::blue1(0.f, 0.f, 1.f, 1.f);
  76. LLColor4 LLColor4::blue2(0.f, 0.4f, 1.f, 1.f);
  77. LLColor4 LLColor4::blue3(0.2f, 0.2f, 0.8f, 1.f);
  78. LLColor4 LLColor4::blue4(0.f, 0.f, 0.6f, 1.f);
  79. LLColor4 LLColor4::blue5(0.4f, 0.2f, 1.f, 1.f);
  80. LLColor4 LLColor4::blue6(0.4f, 0.5f, 1.f, 1.f);
  81. LLColor4 LLColor4::blue7(0.f, 0.f, 0.5f, 1.f);
  82. LLColor4 LLColor4::yellow1(1.f, 1.f, 0.f, 1.f);
  83. LLColor4 LLColor4::yellow2(0.6f, 0.6f, 0.f, 1.f);
  84. LLColor4 LLColor4::yellow3(0.8f, 1.f, 0.2f, 1.f);
  85. LLColor4 LLColor4::yellow4(1.f, 1.f, 0.4f, 1.f);
  86. LLColor4 LLColor4::yellow5(0.6f, 0.4f, 0.2f, 1.f);
  87. LLColor4 LLColor4::yellow6(1.f, 0.8f, 0.4f, 1.f);
  88. LLColor4 LLColor4::yellow7(0.8f, 0.8f, 0.f, 1.f);
  89. LLColor4 LLColor4::yellow8(0.8f, 0.8f, 0.2f, 1.f);
  90. LLColor4 LLColor4::yellow9(0.8f, 0.8f, 0.4f, 1.f);
  91. LLColor4 LLColor4::orange1(1.f, 0.8f, 0.f, 1.f);
  92. LLColor4 LLColor4::orange2(1.f, 0.6f, 0.f, 1.f);
  93. LLColor4 LLColor4::orange3(1.f, 0.4f, 0.2f, 1.f);
  94. LLColor4 LLColor4::orange4(0.8f, 0.4f, 0.f, 1.f);
  95. LLColor4 LLColor4::orange5(0.9f, 0.5f, 0.f, 1.f);
  96. LLColor4 LLColor4::orange6(1.f, 0.8f, 0.2f, 1.f);
  97. LLColor4 LLColor4::magenta1(1.f, 0.f, 1.f, 1.f);
  98. LLColor4 LLColor4::magenta2(0.6f, 0.2f, 0.4f, 1.f);
  99. LLColor4 LLColor4::magenta3(1.f, 0.4f, 0.6f, 1.f);
  100. LLColor4 LLColor4::magenta4(1.f, 0.2f, 0.8f, 1.f);
  101. LLColor4 LLColor4::purple1(0.6f, 0.2f, 0.8f, 1.f);
  102. LLColor4 LLColor4::purple2(0.8f, 0.2f, 1.f, 1.f);
  103. LLColor4 LLColor4::purple3(0.6f, 0.f, 1.f, 1.f);
  104. LLColor4 LLColor4::purple4(0.4f, 0.f, 0.8f, 1.f);
  105. LLColor4 LLColor4::purple5(0.6f, 0.f, 0.8f, 1.f);
  106. LLColor4 LLColor4::purple6(0.8f, 0.f, 0.6f, 1.f);
  107. LLColor4 LLColor4::pink1(1.f, 0.5f, 0.8f, 1.f);
  108. LLColor4 LLColor4::pink2(1.f, 0.8f, 0.9f, 1.f);
  109. LLColor4 LLColor4::cyan1(0.f, 1.f, 1.f, 1.f);
  110. LLColor4 LLColor4::cyan2(0.4f, 0.8f, 0.8f, 1.f);
  111. LLColor4 LLColor4::cyan3(0.f, 1.f, 0.6f, 1.f);
  112. LLColor4 LLColor4::cyan4(0.6f, 1.f, 1.f, 1.f);
  113. LLColor4 LLColor4::cyan5(0.2f, 0.6f, 1.f, 1.f);
  114. LLColor4 LLColor4::cyan6(0.2f, 0.6f, 0.6f, 1.f);
  115. // Conversion
  116. LLColor4::operator LLColor4U() const
  117. {
  118. return LLColor4U((U8)llmin((S32)(llmax(0.f, mV[VRED] * 255.f) + 0.5f),
  119. 255),
  120. (U8)llmin((S32)(llmax(0.f, mV[VGREEN] * 255.f) + 0.5f),
  121. 255),
  122. (U8)llmin((S32)(llmax(0.f, mV[VBLUE] * 255.f) + 0.5f),
  123. 255),
  124. (U8)llmin((S32)(llmax(0.f, mV[VALPHA] * 255.f) + 0.5f),
  125. 255));
  126. }
  127. LLColor4::LLColor4(const LLColor3& vec, F32 a) noexcept
  128. {
  129. mV[VX] = vec.mV[VX];
  130. mV[VY] = vec.mV[VY];
  131. mV[VZ] = vec.mV[VZ];
  132. mV[VW] = a;
  133. }
  134. LLColor4::LLColor4(const LLColor4U& color4u) noexcept
  135. {
  136. constexpr F32 SCALE = 1.f / 255.f;
  137. mV[VX] = color4u.mV[VX] * SCALE;
  138. mV[VY] = color4u.mV[VY] * SCALE;
  139. mV[VZ] = color4u.mV[VZ] * SCALE;
  140. mV[VW] = color4u.mV[VW] * SCALE;
  141. }
  142. LLColor4::LLColor4(const LLVector4& vector4) noexcept
  143. {
  144. mV[VX] = vector4.mV[VX];
  145. mV[VY] = vector4.mV[VY];
  146. mV[VZ] = vector4.mV[VZ];
  147. mV[VW] = vector4.mV[VW];
  148. }
  149. const LLColor4& LLColor4::set(const LLColor4U& color4u)
  150. {
  151. constexpr F32 SCALE = 1.f / 255.f;
  152. mV[VX] = color4u.mV[VX] * SCALE;
  153. mV[VY] = color4u.mV[VY] * SCALE;
  154. mV[VZ] = color4u.mV[VZ] * SCALE;
  155. mV[VW] = color4u.mV[VW] * SCALE;
  156. return *this;
  157. }
  158. const LLColor4& LLColor4::set(const LLColor3& vec)
  159. {
  160. mV[VX] = vec.mV[VX];
  161. mV[VY] = vec.mV[VY];
  162. mV[VZ] = vec.mV[VZ];
  163. #if 0 // Do not change alpha !
  164. mV[VW] = 1.f;
  165. #endif
  166. return *this;
  167. }
  168. const LLColor4& LLColor4::set(const LLColor3& vec, F32 a)
  169. {
  170. mV[VX] = vec.mV[VX];
  171. mV[VY] = vec.mV[VY];
  172. mV[VZ] = vec.mV[VZ];
  173. mV[VW] = a;
  174. return *this;
  175. }
  176. void LLColor4::setValue(const LLSD& sd)
  177. {
  178. #if 0
  179. // Clamping on setValue from LLSD is inconsistent with other set behavior
  180. F32 val;
  181. bool out_of_range = false;
  182. val = sd[0].asReal();
  183. mV[0] = llclamp(val, 0.f, 1.f);
  184. out_of_range = mV[0] != val;
  185. val = sd[1].asReal();
  186. mV[1] = llclamp(val, 0.f, 1.f);
  187. out_of_range |= mV[1] != val;
  188. val = sd[2].asReal();
  189. mV[2] = llclamp(val, 0.f, 1.f);
  190. out_of_range |= mV[2] != val;
  191. val = sd[3].asReal();
  192. mV[3] = llclamp(val, 0.f, 1.f);
  193. out_of_range |= mV[3] != val;
  194. if (out_of_range)
  195. {
  196. llwarns << "LLSD color value out of range !" << llendl;
  197. }
  198. #else
  199. mV[0] = (F32) sd[0].asReal();
  200. mV[1] = (F32) sd[1].asReal();
  201. mV[2] = (F32) sd[2].asReal();
  202. mV[3] = (F32) sd[3].asReal();
  203. #endif
  204. }
  205. const LLColor4& LLColor4::operator=(const LLColor3& a)
  206. {
  207. mV[VX] = a.mV[VX];
  208. mV[VY] = a.mV[VY];
  209. mV[VZ] = a.mV[VZ];
  210. // Converting from an rgb sets a=1 (opaque)
  211. mV[VW] = 1.f;
  212. return *this;
  213. }
  214. std::ostream& operator<<(std::ostream& s, const LLColor4& a)
  215. {
  216. s << "{ " << a.mV[VX] << ", " << a.mV[VY] << ", " << a.mV[VZ] << ", "
  217. << a.mV[VW] << " }";
  218. return s;
  219. }
  220. bool operator==(const LLColor4& a, const LLColor3& b)
  221. {
  222. return a.mV[VX] == b.mV[VX] && a.mV[VY] == b.mV[VY] &&
  223. a.mV[VZ] == b.mV[VZ];
  224. }
  225. bool operator!=(const LLColor4& a, const LLColor3& b)
  226. {
  227. return a.mV[VX] != b.mV[VX] || a.mV[VY] != b.mV[VY] ||
  228. a.mV[VZ] != b.mV[VZ];
  229. }
  230. LLColor3 vec4to3(const LLColor4& vec)
  231. {
  232. LLColor3 temp(vec.mV[VX], vec.mV[VY], vec.mV[VZ]);
  233. return temp;
  234. }
  235. LLColor4 vec3to4(const LLColor3& vec)
  236. {
  237. LLColor3 temp(vec.mV[VX], vec.mV[VY], vec.mV[VZ]);
  238. return temp;
  239. }
  240. LL_INLINE static F32 hue_to_component(F32 val1, F32 val2, F32 hue)
  241. {
  242. if (hue < 0.f)
  243. {
  244. hue += 1.f;
  245. }
  246. else if (hue > 1.f)
  247. {
  248. hue -= 1.f;
  249. }
  250. if (6.f * hue < 1.f)
  251. {
  252. return val1 + (val2 - val1) * 6.f * hue;
  253. }
  254. if (2.f * hue < 1.f)
  255. {
  256. return val2;
  257. }
  258. if (3.f * hue < 2.f)
  259. {
  260. constexpr F32 TWOTHIRD = 2.f / 3.f;
  261. return val1 + (val2 - val1) * (TWOTHIRD - hue) * 6.f;
  262. }
  263. return val1;
  264. }
  265. void LLColor4::setHSL(F32 h, F32 s, F32 l)
  266. {
  267. if (s < 0.00001f)
  268. {
  269. mV[VRED] = mV[VGREEN] = mV[VBLUE] = l;
  270. }
  271. else
  272. {
  273. F32 v2 = l < 0.5f ? l * (1.f + s) : (l + s) - (s * l);
  274. F32 v1 = 2.f * l - v2;
  275. constexpr F32 ONETHIRD = 1.f / 3.f;
  276. mV[VRED] = hue_to_component(v1, v2, h + ONETHIRD);
  277. mV[VGREEN] = hue_to_component(v1, v2, h);
  278. mV[VBLUE] = hue_to_component(v1, v2, h - ONETHIRD);
  279. }
  280. }
  281. void LLColor4::calcHSL(F32* hue, F32* saturation, F32* luminance) const
  282. {
  283. F32 var_r = mV[VRED];
  284. F32 var_g = mV[VGREEN];
  285. F32 var_b = mV[VBLUE];
  286. F32 var_min = (var_r < (var_g < var_b ? var_g : var_b) ? var_r :
  287. (var_g < var_b ? var_g : var_b));
  288. F32 var_max = (var_r > (var_g > var_b ? var_g : var_b) ? var_r :
  289. (var_g > var_b ? var_g : var_b));
  290. F32 del_max = var_max - var_min;
  291. F32 val_l = (var_max + var_min) * 0.5f;
  292. F32 val_h = 0.f;
  293. F32 val_s = 0.f;
  294. if (del_max != 0.f)
  295. {
  296. if (val_l < 0.5f)
  297. {
  298. val_s = del_max / (var_max + var_min);
  299. }
  300. else
  301. {
  302. val_s = del_max / (2.f - var_max - var_min);
  303. }
  304. F32 del_r = ((var_max - var_r) / 6.f + del_max * 0.5f) / del_max;
  305. F32 del_g = ((var_max - var_g) / 6.f + del_max * 0.5f) / del_max;
  306. F32 del_b = ((var_max - var_b) / 6.f + del_max * 0.5f) / del_max;
  307. if (var_r >= var_max)
  308. {
  309. val_h = del_b - del_g;
  310. }
  311. else if (var_g >= var_max)
  312. {
  313. constexpr F32 ONETHIRD = 1.f / 3.f;
  314. val_h = ONETHIRD + del_r - del_b;
  315. }
  316. else if (var_b >= var_max)
  317. {
  318. constexpr F32 TWOTHIRD = 2.f / 3.f;
  319. val_h = TWOTHIRD + del_g - del_r;
  320. }
  321. if (val_h < 0.f)
  322. {
  323. val_h += 1.f;
  324. }
  325. else if (val_h > 1.f)
  326. {
  327. val_h -= 1.f;
  328. }
  329. }
  330. if (hue)
  331. {
  332. *hue = val_h;
  333. }
  334. if (saturation)
  335. {
  336. *saturation = val_s;
  337. }
  338. if (luminance)
  339. {
  340. *luminance = val_l;
  341. }
  342. }
  343. //static
  344. bool LLColor4::parseColor(const std::string& buf, LLColor4* color)
  345. {
  346. if (buf.empty() || color == NULL)
  347. {
  348. return false;
  349. }
  350. typedef boost::tokenizer<boost::char_separator<char> > boost_tokenizer;
  351. boost_tokenizer tokens(buf, boost::char_separator<char>(", "));
  352. boost_tokenizer::iterator token_iter = tokens.begin();
  353. if (token_iter == tokens.end())
  354. {
  355. return false;
  356. }
  357. // Grab the first token into a string, since we do not know whether this is
  358. // a float or a color name.
  359. std::string color_name(*token_iter++);
  360. if (token_iter != tokens.end())
  361. {
  362. // There are more tokens to read; this must be a vector.
  363. LLColor4 v;
  364. LLStringUtil::convertToF32(color_name, v.mV[VX]);
  365. LLStringUtil::convertToF32(*token_iter, v.mV[VY]);
  366. v.mV[VZ] = 0.f;
  367. v.mV[VW] = 1.f;
  368. ++token_iter;
  369. if (token_iter == tokens.end())
  370. {
  371. // This is a malformed vector.
  372. llwarns << "Malformed color: " << buf << llendl;
  373. }
  374. else
  375. {
  376. // There is a z-component.
  377. LLStringUtil::convertToF32(*token_iter, v.mV[VZ]);
  378. ++token_iter;
  379. if (token_iter != tokens.end())
  380. {
  381. // There is an alpha component.
  382. LLStringUtil::convertToF32(*token_iter, v.mV[VW]);
  383. }
  384. }
  385. // Make sure all values are between 0 and 1.
  386. if (v.mV[VX] > 1.f || v.mV[VY] > 1.f || v.mV[VZ] > 1.f || v.mV[VW] > 1.f)
  387. {
  388. constexpr F32 SCALE = 1.f / 255.f;
  389. v *= SCALE; // Does not affect alpha
  390. v.mV[VW] *= SCALE; // Scale alpha as well !
  391. }
  392. color->set(v);
  393. }
  394. else // Single value. Read as a named color.
  395. {
  396. // We have a color name
  397. if ("red" == color_name)
  398. {
  399. color->set(LLColor4::red);
  400. }
  401. else if ("red0" == color_name)
  402. {
  403. color->set(LLColor4::red0);
  404. }
  405. else if ("red1" == color_name)
  406. {
  407. color->set(LLColor4::red1);
  408. }
  409. else if ("red2" == color_name)
  410. {
  411. color->set(LLColor4::red2);
  412. }
  413. else if ("red3" == color_name)
  414. {
  415. color->set(LLColor4::red3);
  416. }
  417. else if ("red4" == color_name)
  418. {
  419. color->set(LLColor4::red4);
  420. }
  421. else if ("red5" == color_name)
  422. {
  423. color->set(LLColor4::red5);
  424. }
  425. else if ("green" == color_name)
  426. {
  427. color->set(LLColor4::green);
  428. }
  429. else if ("green0" == color_name)
  430. {
  431. color->set(LLColor4::green0);
  432. }
  433. else if ("green1" == color_name)
  434. {
  435. color->set(LLColor4::green1);
  436. }
  437. else if ("green2" == color_name)
  438. {
  439. color->set(LLColor4::green2);
  440. }
  441. else if ("green3" == color_name)
  442. {
  443. color->set(LLColor4::green3);
  444. }
  445. else if ("green4" == color_name)
  446. {
  447. color->set(LLColor4::green4);
  448. }
  449. else if ("green5" == color_name)
  450. {
  451. color->set(LLColor4::green5);
  452. }
  453. else if ("green6" == color_name)
  454. {
  455. color->set(LLColor4::green6);
  456. }
  457. else if ("green7" == color_name)
  458. {
  459. color->set(LLColor4::green7);
  460. }
  461. else if ("green8" == color_name)
  462. {
  463. color->set(LLColor4::green8);
  464. }
  465. else if ("green9" == color_name)
  466. {
  467. color->set(LLColor4::green9);
  468. }
  469. else if ("blue" == color_name)
  470. {
  471. color->set(LLColor4::blue);
  472. }
  473. else if ("blue0" == color_name)
  474. {
  475. color->set(LLColor4::blue0);
  476. }
  477. else if ("blue1" == color_name)
  478. {
  479. color->set(LLColor4::blue1);
  480. }
  481. else if ("blue2" == color_name)
  482. {
  483. color->set(LLColor4::blue2);
  484. }
  485. else if ("blue3" == color_name)
  486. {
  487. color->set(LLColor4::blue3);
  488. }
  489. else if ("blue4" == color_name)
  490. {
  491. color->set(LLColor4::blue4);
  492. }
  493. else if ("blue5" == color_name)
  494. {
  495. color->set(LLColor4::blue5);
  496. }
  497. else if ("blue6" == color_name)
  498. {
  499. color->set(LLColor4::blue6);
  500. }
  501. else if ("blue7" == color_name)
  502. {
  503. color->set(LLColor4::blue7);
  504. }
  505. else if ("black" == color_name)
  506. {
  507. color->set(LLColor4::black);
  508. }
  509. else if ("white" == color_name)
  510. {
  511. color->set(LLColor4::white);
  512. }
  513. else if ("yellow" == color_name)
  514. {
  515. color->set(LLColor4::yellow);
  516. }
  517. else if ("yellow1" == color_name)
  518. {
  519. color->set(LLColor4::yellow1);
  520. }
  521. else if ("yellow2" == color_name)
  522. {
  523. color->set(LLColor4::yellow2);
  524. }
  525. else if ("yellow3" == color_name)
  526. {
  527. color->set(LLColor4::yellow3);
  528. }
  529. else if ("yellow4" == color_name)
  530. {
  531. color->set(LLColor4::yellow4);
  532. }
  533. else if ("yellow5" == color_name)
  534. {
  535. color->set(LLColor4::yellow5);
  536. }
  537. else if ("yellow6" == color_name)
  538. {
  539. color->set(LLColor4::yellow6);
  540. }
  541. else if ("yellow7" == color_name)
  542. {
  543. color->set(LLColor4::yellow7);
  544. }
  545. else if ("yellow8" == color_name)
  546. {
  547. color->set(LLColor4::yellow8);
  548. }
  549. else if ("yellow9" == color_name)
  550. {
  551. color->set(LLColor4::yellow9);
  552. }
  553. else if ("magenta" == color_name)
  554. {
  555. color->set(LLColor4::magenta);
  556. }
  557. else if ("magenta1" == color_name)
  558. {
  559. color->set(LLColor4::magenta1);
  560. }
  561. else if ("magenta2" == color_name)
  562. {
  563. color->set(LLColor4::magenta2);
  564. }
  565. else if ("magenta3" == color_name)
  566. {
  567. color->set(LLColor4::magenta3);
  568. }
  569. else if ("magenta4" == color_name)
  570. {
  571. color->set(LLColor4::magenta4);
  572. }
  573. else if ("purple" == color_name)
  574. {
  575. color->set(LLColor4::purple);
  576. }
  577. else if ("purple1" == color_name)
  578. {
  579. color->set(LLColor4::purple1);
  580. }
  581. else if ("purple2" == color_name)
  582. {
  583. color->set(LLColor4::purple2);
  584. }
  585. else if ("purple3" == color_name)
  586. {
  587. color->set(LLColor4::purple3);
  588. }
  589. else if ("purple4" == color_name)
  590. {
  591. color->set(LLColor4::purple4);
  592. }
  593. else if ("purple5" == color_name)
  594. {
  595. color->set(LLColor4::purple5);
  596. }
  597. else if ("purple6" == color_name)
  598. {
  599. color->set(LLColor4::purple6);
  600. }
  601. else if ("pink" == color_name)
  602. {
  603. color->set(LLColor4::pink);
  604. }
  605. else if ("pink1" == color_name)
  606. {
  607. color->set(LLColor4::pink1);
  608. }
  609. else if ("pink2" == color_name)
  610. {
  611. color->set(LLColor4::pink2);
  612. }
  613. else if ("cyan" == color_name)
  614. {
  615. color->set(LLColor4::cyan);
  616. }
  617. else if ("cyan1" == color_name)
  618. {
  619. color->set(LLColor4::cyan1);
  620. }
  621. else if ("cyan2" == color_name)
  622. {
  623. color->set(LLColor4::cyan2);
  624. }
  625. else if ("cyan3" == color_name)
  626. {
  627. color->set(LLColor4::cyan3);
  628. }
  629. else if ("cyan4" == color_name)
  630. {
  631. color->set(LLColor4::cyan4);
  632. }
  633. else if ("cyan5" == color_name)
  634. {
  635. color->set(LLColor4::cyan5);
  636. }
  637. else if ("cyan6" == color_name)
  638. {
  639. color->set(LLColor4::cyan6);
  640. }
  641. else if ("smoke" == color_name)
  642. {
  643. color->set(LLColor4::smoke);
  644. }
  645. else if ("grey" == color_name)
  646. {
  647. color->set(LLColor4::grey);
  648. }
  649. else if ("grey1" == color_name)
  650. {
  651. color->set(LLColor4::grey1);
  652. }
  653. else if ("grey2" == color_name)
  654. {
  655. color->set(LLColor4::grey2);
  656. }
  657. else if ("grey3" == color_name)
  658. {
  659. color->set(LLColor4::grey3);
  660. }
  661. else if ("grey4" == color_name)
  662. {
  663. color->set(LLColor4::grey4);
  664. }
  665. else if ("grey5" == color_name)
  666. {
  667. color->set(LLColor4::grey5);
  668. }
  669. else if ("orange" == color_name)
  670. {
  671. color->set(LLColor4::orange);
  672. }
  673. else if ("orange1" == color_name)
  674. {
  675. color->set(LLColor4::orange1);
  676. }
  677. else if ("orange2" == color_name)
  678. {
  679. color->set(LLColor4::orange2);
  680. }
  681. else if ("orange3" == color_name)
  682. {
  683. color->set(LLColor4::orange3);
  684. }
  685. else if ("orange4" == color_name)
  686. {
  687. color->set(LLColor4::orange4);
  688. }
  689. else if ("orange5" == color_name)
  690. {
  691. color->set(LLColor4::orange5);
  692. }
  693. else if ("orange6" == color_name)
  694. {
  695. color->set(LLColor4::orange6);
  696. }
  697. else if ("clear" == color_name)
  698. {
  699. color->set(0.f, 0.f, 0.f, 0.f);
  700. }
  701. else
  702. {
  703. llwarns << "Invalid color: " << color_name << llendl;
  704. return false;
  705. }
  706. }
  707. return true;
  708. }
  709. //static
  710. bool LLColor4::parseColor4(const std::string& buf, LLColor4* value)
  711. {
  712. if (buf.empty() || !value)
  713. {
  714. return false;
  715. }
  716. LLColor4 v;
  717. S32 count = sscanf(buf.c_str(), "%f, %f, %f, %f",
  718. v.mV, v.mV + 1, v.mV + 2, v.mV + 3);
  719. if (count == 1)
  720. {
  721. // Try this format
  722. count = sscanf(buf.c_str(), "%f %f %f %f",
  723. v.mV, v.mV + 1, v.mV + 2, v.mV + 3);
  724. }
  725. if (count == 4)
  726. {
  727. value->set(v);
  728. return true;
  729. }
  730. return false;
  731. }