PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  27. //#include "v3coloru.h"
  28. #include "v4coloru.h"
  29. #include "v4color.h"
  30. //#include "vmath.h"
  31. #include "llmath.h"
  32. // LLColor4U
  33. LLColor4U LLColor4U::white(255, 255, 255, 255);
  34. LLColor4U LLColor4U::black( 0, 0, 0, 255);
  35. LLColor4U LLColor4U::red (255, 0, 0, 255);
  36. LLColor4U LLColor4U::green( 0, 255, 0, 255);
  37. LLColor4U LLColor4U::blue ( 0, 0, 255, 255);
  38. // conversion
  39. /* inlined to fix gcc compile link error
  40. LLColor4U::operator LLColor4()
  41. {
  42. return(LLColor4((F32)mV[VRED]/255.f,(F32)mV[VGREEN]/255.f,(F32)mV[VBLUE]/255.f,(F32)mV[VALPHA]/255.f));
  43. }
  44. */
  45. // Constructors
  46. /*
  47. LLColor4U::LLColor4U(const LLColor3 &vec)
  48. {
  49. mV[VX] = vec.mV[VX];
  50. mV[VY] = vec.mV[VY];
  51. mV[VZ] = vec.mV[VZ];
  52. mV[VW] = 255;
  53. }
  54. */
  55. // Clear and Assignment Functions
  56. // LLColor4U Operators
  57. /*
  58. LLColor4U LLColor4U::operator=(const LLColor3 &a)
  59. {
  60. mV[VX] = a.mV[VX];
  61. mV[VY] = a.mV[VY];
  62. mV[VZ] = a.mV[VZ];
  63. // converting from an rgb sets a=1 (opaque)
  64. mV[VW] = 255;
  65. return (*this);
  66. }
  67. */
  68. std::ostream& operator<<(std::ostream& s, const LLColor4U &a)
  69. {
  70. s << "{ " << (S32)a.mV[VX] << ", " << (S32)a.mV[VY] << ", " << (S32)a.mV[VZ] << ", " << (S32)a.mV[VW] << " }";
  71. return s;
  72. }
  73. // static
  74. BOOL LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
  75. {
  76. if( buf.empty() || value == NULL)
  77. {
  78. return FALSE;
  79. }
  80. U32 v[4];
  81. S32 count = sscanf( buf.c_str(), "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3 );
  82. if (1 == count )
  83. {
  84. // try this format
  85. count = sscanf( buf.c_str(), "%u %u %u %u", v + 0, v + 1, v + 2, v + 3 );
  86. }
  87. if( 4 != count )
  88. {
  89. return FALSE;
  90. }
  91. for( S32 i = 0; i < 4; i++ )
  92. {
  93. if( v[i] > U8_MAX )
  94. {
  95. return FALSE;
  96. }
  97. }
  98. value->set( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) );
  99. return TRUE;
  100. }