123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #pragma once
- #ifndef COLOR_H_
- #define COLOR_H_
- #include <cinttypes>
- struct RGBColor;
- struct RGBColorf;
- ///
- /// \brief Represents a color in RGB color space with 8-bit channels
- ///
- struct RGBColor
- {
- uint8_t r, g, b;
- inline RGBColor(void) :
- r{ 0 }, g{ 0 }, b{ 0 }
- {
- }
- inline RGBColor(uint8_t r, uint8_t g, uint8_t b) :
- r{ r }, g{ g }, b{ b }
- {
- }
- RGBColor(const RGBColorf& rgb);
- };
- ///
- /// \brief Represents a color in a RGB color space with 32-bit floating
- /// point numbers as channels.
- ///
- struct RGBColorf
- {
- float r, g, b;
- inline RGBColorf(void) :
- r{ 0.0f }, g{ 0.0f }, b{ 0.0f}
- {
- }
- inline RGBColorf(float r, float g, float b) :
- r{ r }, g{ g }, b{ b }
- {
- }
- RGBColorf(const RGBColor& srgb);
- ///
- /// \brief calculates the channel-wise sum of two colors
- ///
- inline RGBColorf operator + (const RGBColorf& o) const
- {
- return RGBColorf {
- r + o.r,
- g + o.g,
- b + o.b
- };
- }
- ///
- /// \brief calculates the channel-wise difference between two colors
- ///
- inline RGBColorf operator - (const RGBColorf& o) const
- {
- return RGBColorf {
- r - o.r,
- g - o.g,
- b - o.b
- };
- }
- ///
- /// \brief multiplies all channels by a factor
- ///
- inline RGBColorf operator * (float f) const
- {
- return RGBColorf {
- r * f,
- g * f,
- b * f
- };
- }
- ///
- /// \brief divides all channels by a factor
- ///
- inline RGBColorf operator / (float f) const
- {
- return this->operator * (1.0f / f);
- }
- };
- #endif // COLOR_H_
|