Color.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #ifndef COLOR_H_
  3. #define COLOR_H_
  4. #include <cinttypes>
  5. struct RGBColor;
  6. struct RGBColorf;
  7. ///
  8. /// \brief Represents a color in RGB color space with 8-bit channels
  9. ///
  10. struct RGBColor
  11. {
  12. uint8_t r, g, b;
  13. inline RGBColor(void) :
  14. r{ 0 }, g{ 0 }, b{ 0 }
  15. {
  16. }
  17. inline RGBColor(uint8_t r, uint8_t g, uint8_t b) :
  18. r{ r }, g{ g }, b{ b }
  19. {
  20. }
  21. RGBColor(const RGBColorf& rgb);
  22. };
  23. ///
  24. /// \brief Represents a color in a RGB color space with 32-bit floating
  25. /// point numbers as channels.
  26. ///
  27. struct RGBColorf
  28. {
  29. float r, g, b;
  30. inline RGBColorf(void) :
  31. r{ 0.0f }, g{ 0.0f }, b{ 0.0f}
  32. {
  33. }
  34. inline RGBColorf(float r, float g, float b) :
  35. r{ r }, g{ g }, b{ b }
  36. {
  37. }
  38. RGBColorf(const RGBColor& srgb);
  39. ///
  40. /// \brief calculates the channel-wise sum of two colors
  41. ///
  42. inline RGBColorf operator + (const RGBColorf& o) const
  43. {
  44. return RGBColorf {
  45. r + o.r,
  46. g + o.g,
  47. b + o.b
  48. };
  49. }
  50. ///
  51. /// \brief calculates the channel-wise difference between two colors
  52. ///
  53. inline RGBColorf operator - (const RGBColorf& o) const
  54. {
  55. return RGBColorf {
  56. r - o.r,
  57. g - o.g,
  58. b - o.b
  59. };
  60. }
  61. ///
  62. /// \brief multiplies all channels by a factor
  63. ///
  64. inline RGBColorf operator * (float f) const
  65. {
  66. return RGBColorf {
  67. r * f,
  68. g * f,
  69. b * f
  70. };
  71. }
  72. ///
  73. /// \brief divides all channels by a factor
  74. ///
  75. inline RGBColorf operator / (float f) const
  76. {
  77. return this->operator * (1.0f / f);
  78. }
  79. };
  80. #endif // COLOR_H_