color4.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2025, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file color4.h
  35. * @brief RGBA color structure, including operators when compiling in C++
  36. */
  37. #pragma once
  38. #ifndef AI_COLOR4D_H_INC
  39. #define AI_COLOR4D_H_INC
  40. #ifdef __GNUC__
  41. # pragma GCC system_header
  42. #endif
  43. #include <assimp/defs.h>
  44. #ifdef __cplusplus
  45. // ----------------------------------------------------------------------------------
  46. /** Represents a color in Red-Green-Blue space including an
  47. * alpha component. Color values range from 0 to 1. */
  48. // ----------------------------------------------------------------------------------
  49. template <typename TReal>
  50. class aiColor4t {
  51. public:
  52. aiColor4t() AI_NO_EXCEPT : r(), g(), b(), a() {}
  53. aiColor4t (TReal _r, TReal _g, TReal _b, TReal _a)
  54. : r(_r), g(_g), b(_b), a(_a) {}
  55. explicit aiColor4t (TReal _r) : r(_r), g(_r), b(_r), a(_r) {}
  56. aiColor4t (const aiColor4t& o) = default;
  57. // combined operators
  58. const aiColor4t& operator += (const aiColor4t& o);
  59. const aiColor4t& operator -= (const aiColor4t& o);
  60. const aiColor4t& operator *= (TReal f);
  61. const aiColor4t& operator /= (TReal f);
  62. // comparison
  63. bool operator == (const aiColor4t& other) const;
  64. bool operator != (const aiColor4t& other) const;
  65. bool operator < (const aiColor4t& other) const;
  66. // color tuple access, rgba order
  67. inline TReal operator[](unsigned int i) const;
  68. inline TReal& operator[](unsigned int i);
  69. /** check whether a color is (close to) black */
  70. inline bool IsBlack() const;
  71. // Red, green, blue and alpha color values
  72. TReal r, g, b, a;
  73. }; // !struct aiColor4D
  74. typedef aiColor4t<float> aiColor4D;
  75. #else
  76. struct aiColor4D {
  77. float r, g, b, a;
  78. };
  79. #endif // __cplusplus
  80. #endif // AI_COLOR4D_H_INC