40 constexpr
Color(uint8_t rr, uint8_t gg, uint8_t bb, uint8_t aa = 255) noexcept
87 constexpr uint8_t
GetRed() const noexcept
99 constexpr uint8_t
GetBlue() const noexcept
113 return (uint32_t(
mRed) << 24) + (uint32_t(
mGreen) << 16) +
124 constexpr uint32_t
GetRGB() const noexcept
126 return (uint32_t(
mRed) << 16) + (uint32_t(
mGreen) << 8) +
133 Add(lhs.mRed, rhs.mRed),
Add(lhs.mGreen, rhs.mGreen),
134 Add(lhs.mBlue, rhs.mBlue),
Add(lhs.mAlpha, rhs.mAlpha));
140 Sub(lhs.mRed, rhs.mRed),
Sub(lhs.mGreen, rhs.mGreen),
141 Sub(lhs.mBlue, rhs.mBlue),
Sub(lhs.mAlpha, rhs.mAlpha));
147 Mul(lhs.mRed, rhs.mRed),
Mul(lhs.mGreen, rhs.mGreen),
148 Mul(lhs.mBlue, rhs.mBlue),
Mul(lhs.mAlpha, rhs.mAlpha));
151 template <
typename ScaleType>
156 return *
this = *
this + rhs;
161 return *
this = *
this - rhs;
166 return *
this = *
this * rhs;
171 return mABGR == rhs.mABGR;
175 return mABGR != rhs.mABGR;
179 static constexpr uint8_t
Add(uint8_t a, uint8_t b)
noexcept
181 return uint8_t((a + b) & 0xFF);
184 static constexpr uint8_t
Sub(uint8_t a, uint8_t b)
noexcept
186 return (a > b) ? a - b : 0;
189 static constexpr uint8_t
Mul(uint8_t a, uint8_t b)
noexcept
191 return uint8_t((uint16_t(a) * uint16_t(b) / 255) & 0xFF);
194 static constexpr uint8_t
Scale(uint8_t a,
float s)
noexcept
196 return uint8_t(a * std::max(0.0f,
std::min(1.0f, s)) + 0.5f);
199 template <
typename ScaleType>
200 static constexpr uint8_t
Lerp(uint8_t a, uint8_t b, ScaleType t)
202 static_assert(std::is_floating_point<ScaleType>::value);
204 const auto lerpValue = (a + (b - a) * t);
206 const auto roundLerpValue =
207 static_cast<int16_t
>(lerpValue + ScaleType(0.5));
209 const auto ui8LerpValue =
210 static_cast<uint8_t
>(std::max<decltype(roundLerpValue)>(
211 0,
std::min<
decltype(roundLerpValue)>(255, roundLerpValue)));
216 explicit constexpr Color(uint32_t abgr) noexcept
232template <
typename ScaleType>
245 uint8_t((rgba >> 24) & 0xFF), uint8_t((rgba >> 16) & 0xFF),
246 uint8_t((rgba >> 8) & 0xFF), uint8_t((rgba >> 0) & 0xFF));
259 uint8_t((rgb >> 16) & 0xFF), uint8_t((rgb >> 8) & 0xFF),
260 uint8_t((rgb >> 0) & 0xFF), uint8_t(0xFF));
267 uint8_t((argb >> 16) & 0xFF), uint8_t((argb >> 8) & 0xFF),
268 uint8_t((argb >> 0) & 0xFF), uint8_t((argb >> 24) & 0xFF));
272GRAPHICS_API
constexpr Color
constexpr Color Transparent
Transparent black color constant.
constexpr Color Green
Green color constant.
constexpr Color Blue
Blue color constant.
constexpr Color White
Opaque white color constant.
constexpr Color Black
Opaque black color constant.
constexpr Color Red
Red color constant.
GRAPHICS_API constexpr Color ColorFromFloatRGBA(float r, float g, float b, float a) noexcept
A helper function to create a color from the floating point components.
GRAPHICS_API constexpr Color ColorFromABGR(uint32_t abgr) noexcept
A helper function to create a color from a 32-bit ABGR integer.
GRAPHICS_API constexpr Color ColorFromARGB(uint32_t argb) noexcept
A helper function to create a color from a 32-bit ARGB integer.
constexpr Color lerp(Color lhs, Color rhs, ScaleType t)
Performs linear interpolation between two colors.
GRAPHICS_API constexpr Color ColorFromRGA(uint32_t rgba) noexcept
A helper function to create a color from a 32-bit RGBA integer.
GRAPHICS_API constexpr Color ColorFromRGB(uint32_t rgb) noexcept
A helper function to create a color from a 32-bit RGB integer. Alpha is set to 255.
Class for storing color in 32-bit format.
static constexpr uint8_t Mul(uint8_t a, uint8_t b) noexcept
bool operator==(const Color &rhs) const noexcept
constexpr Color WithoutAlpha() const noexcept
Returns a copy of this color with the alpha set to the max.
friend constexpr Color operator*(Color lhs, Color rhs) noexcept
constexpr Color() noexcept
Constructs a transparent black color.
Color & operator+=(Color rhs) noexcept
Color & operator*=(Color rhs) noexcept
constexpr Color(Color &&) noexcept=default
static constexpr uint8_t Lerp(uint8_t a, uint8_t b, ScaleType t)
constexpr Color WithAlpha(uint8_t alpha) const noexcept
Returns a copy of this color with a new alpha value.
constexpr Color(uint32_t abgr) noexcept
constexpr uint8_t GetBlue() const noexcept
Returns blue component of this color.
constexpr uint8_t GetGreen() const noexcept
Returns green component of this color.
static constexpr uint8_t Scale(uint8_t a, float s) noexcept
constexpr Color(const Color &) noexcept=default
static constexpr Color FromFloatRGBA(float r, float g, float b, float a) noexcept
Constructs a color from individual floating point components. This value is clamped to [0,...
constexpr uint32_t GetRGBA() const noexcept
Returns color value as RGBA 32-bit integer.
constexpr Color WithOpacity(float opacity) const noexcept
Returns a copy of this color with alpha component scaled by opacity.
bool operator!=(const Color &rhs) const noexcept
static constexpr uint8_t Sub(uint8_t a, uint8_t b) noexcept
friend constexpr Color lerp(Color lhs, Color rhs, ScaleType t)
Performs linear interpolation between two colors.
friend constexpr Color operator+(Color lhs, Color rhs) noexcept
constexpr uint32_t GetRGB() const noexcept
Returns color value as RGB integer.
constexpr Color WithFloatAlpha(float alpha) const noexcept
Returns a copy of this color with a new alpha value. Value is clamped to [0, 1].
constexpr uint32_t GetABGR() const noexcept
Returns color value as ABGR 32-bit integer.
constexpr uint8_t GetRed() const noexcept
Returns red component of this color.
friend constexpr Color operator-(Color lhs, Color rhs) noexcept
constexpr uint8_t GetAlpha() const noexcept
Returns alpha component of this color.
static constexpr Color FromABGR(uint32_t abgr) noexcept
Constructs a color from ABGR 32-bit integer value.
Color & operator-=(Color rhs) noexcept
static constexpr uint8_t Add(uint8_t a, uint8_t b) noexcept