diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Geometry.h | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/Geometry.h b/src/Geometry.h index f417caae0..89c9c08fb 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -170,15 +170,19 @@ PRectangle PixelAlignOutside(const PRectangle &rc, int pixelDivisions) noexcept; /** * Holds an RGBA colour with 8 bits for each component. */ -constexpr const float componentMaximum = 255.0f; +constexpr float componentMaximum = 255.0F; +constexpr unsigned int maximumByte = 0xffU; class ColourRGBA { + static constexpr float ComponentAsFloat(unsigned int component) { + return component / componentMaximum; + } static constexpr int rgbMask = 0xffffff; int co; public: constexpr explicit ColourRGBA(int co_ = 0) noexcept : co(co_) { } - constexpr ColourRGBA(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha=0xff) noexcept : + constexpr ColourRGBA(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha= maximumByte) noexcept : ColourRGBA(red | (green << 8) | (blue << 16) | (alpha << 24)) { } @@ -187,11 +191,11 @@ public: } static constexpr ColourRGBA FromRGB(int co_) noexcept { - return ColourRGBA(co_ | (0xffu << 24)); + return ColourRGBA(co_ | (maximumByte << 24)); } static constexpr ColourRGBA FromIpRGB(intptr_t co_) noexcept { - return ColourRGBA((co_ & rgbMask) | (0xffu << 24)); + return ColourRGBA((co_ & rgbMask) | (maximumByte << 24)); } constexpr ColourRGBA WithoutAlpha() const noexcept { @@ -199,7 +203,7 @@ public: } constexpr ColourRGBA Opaque() const noexcept { - return ColourRGBA(co | (0xffu << 24)); + return ColourRGBA(co | (maximumByte << 24)); } constexpr int AsInteger() const noexcept { @@ -212,32 +216,32 @@ public: // Red, green and blue values as bytes 0..255 constexpr unsigned char GetRed() const noexcept { - return co & 0xffU; + return co & maximumByte; } constexpr unsigned char GetGreen() const noexcept { - return (co >> 8) & 0xffU; + return (co >> 8) & maximumByte; } constexpr unsigned char GetBlue() const noexcept { - return (co >> 16) & 0xffU; + return (co >> 16) & maximumByte; } constexpr unsigned char GetAlpha() const noexcept { // Use a temporary here to prevent a 'Wconversion' warning from GCC const int shifted = co >> 24; - return shifted & 0xffU; + return shifted & maximumByte; } // Red, green, blue, and alpha values as float 0..1.0 constexpr float GetRedComponent() const noexcept { - return GetRed() / componentMaximum; + return ComponentAsFloat(GetRed()); } constexpr float GetGreenComponent() const noexcept { - return GetGreen() / componentMaximum; + return ComponentAsFloat(GetGreen()); } constexpr float GetBlueComponent() const noexcept { - return GetBlue() / componentMaximum; + return ComponentAsFloat(GetBlue()); } constexpr float GetAlphaComponent() const noexcept { - return GetAlpha() / componentMaximum; + return ComponentAsFloat(GetAlpha()); } constexpr bool operator==(const ColourRGBA &other) const noexcept { @@ -245,7 +249,7 @@ public: } constexpr bool IsOpaque() const noexcept { - return GetAlpha() == 0xff; + return GetAlpha() == maximumByte; } ColourRGBA MixedWith(ColourRGBA other) const noexcept; |