17 #include <SDL2/SDL_pixels.h>
51 constexpr uint8_t
color_blend(uint8_t n1, uint8_t n2, uint8_t
p);
65 : SDL_Color{r_val, g_val, b_val, a_val}
69 constexpr
color_t(
const SDL_Color&
c) : SDL_Color{
c} {}
186 constexpr
bool null()
const
193 return r ==
c.r &&
g ==
c.g &&
b ==
c.b && a ==
c.a;
198 return !(*
this ==
c);
207 static_cast<uint8_t
>(r > 255 -
c.r ? 255 : r +
c.r),
208 static_cast<uint8_t
>(
g > 255 -
c.g ? 255 :
g +
c.g),
209 static_cast<uint8_t
>(
b > 255 -
c.b ? 255 :
b +
c.b),
210 static_cast<uint8_t
>(a > 255 -
c.a ? 255 : a +
c.a),
217 std::max<uint8_t>(r,
c.r),
218 std::max<uint8_t>(
g,
c.g),
219 std::max<uint8_t>(
b,
c.b),
220 std::max<uint8_t>(a,
c.a),
226 static_cast<uint8_t
>(255 - r),
227 static_cast<uint8_t
>(255 -
g),
228 static_cast<uint8_t
>(255 -
b),
259 s <<
c.to_hex_string();
270 return c.to_rgba_bytes();
282 if(
n <= 0.0)
return 0;
283 else if(
n >= 1.0)
return 255;
284 else return uint8_t(
n * 256.0);
290 if(
n <= 0.0f)
return 0;
291 else if(
n >= 1.0f)
return 255;
292 else return uint8_t(
n * 256.0f);
298 return uint8_t((uint16_t(n1) * uint16_t(n2))/255);
constexpr uint8_t ALPHA_OPAQUE
constexpr uint32_t RGBA_RED_MASK
constexpr uint32_t SDL_RED_BITSHIFT
constexpr uint32_t RGBA_BLUE_BITSHIFT
constexpr uint32_t SDL_GREEN_BITSHIFT
constexpr uint32_t SDL_GREEN_MASK
constexpr uint32_t RGBA_GREEN_MASK
constexpr uint32_t SDL_ALPHA_MASK
constexpr uint8_t color_multiply(uint8_t n1, uint8_t n2)
Multiply two 8-bit colour values as if in the range [0.0,1.0].
constexpr uint32_t SDL_BLUE_BITSHIFT
std::ostream & operator<<(std::ostream &s, const color_t &c)
constexpr uint8_t float_to_color(double n)
Convert a double in the range [0.0,1.0] to an 8-bit colour value.
constexpr uint32_t SDL_ALPHA_BITSHIFT
constexpr uint32_t RGBA_ALPHA_BITSHIFT
constexpr uint8_t color_blend(uint8_t n1, uint8_t n2, uint8_t p)
Blend 8-bit colour value with another in the given proportion.
constexpr uint32_t RGBA_GREEN_BITSHIFT
constexpr uint32_t SDL_RED_MASK
constexpr uint32_t RGBA_BLUE_MASK
constexpr uint32_t RGBA_ALPHA_MASK
constexpr uint32_t RGBA_RED_BITSHIFT
constexpr uint32_t SDL_BLUE_MASK
The basic class for representing 8-bit RGB or RGBA colour values.
static constexpr color_t from_rgba_bytes(uint32_t c)
Creates a new color_t object from a uint32_t variable.
constexpr uint32_t to_rgba_bytes() const
Returns the stored color as a uint32_t, in RGBA format.
static color_t from_hex_string(std::string_view c)
Creates a new color_t object from a string variable in hex format.
constexpr color_t smooth_blend(const color_t &c, uint8_t p) const
Blend smoothly with another color_t.
constexpr uint32_t to_argb_bytes() const
Returns the stored color as a uint32_t, an ARGB format.
constexpr bool operator!=(const color_t &c) const
std::string to_hex_string() const
Returns the stored color in rrggbb hex format.
static color_t from_rgb_string(std::string_view c)
Creates a new opaque color_t object from a string variable in "R,G,B" format.
static constexpr color_t null_color()
Definition of a 'null' color - fully transparent black.
std::string to_rgb_string() const
Returns the stored color as an "R,G,B" string.
constexpr color_t blend_lighten(const color_t &c) const
constexpr color_t(const SDL_Color &c)
This is a thin wrapper.
constexpr color_t blend_add(const color_t &c) const
constexpr color_t inverse() const
constexpr bool operator==(const color_t &c) const
static color_t from_rgba_string(std::string_view c)
Creates a new color_t object from a string variable in "R,G,B,A" format.
static constexpr color_t from_argb_bytes(uint32_t c)
Creates a new color_t object from a uint32_t variable.
std::string to_rgba_string() const
Returns the stored color as an "R,G,B,A" string.
constexpr color_t()
color_t initializes to fully opaque white by default.
constexpr color_t(uint8_t r_val, uint8_t g_val, uint8_t b_val, uint8_t a_val=ALPHA_OPAQUE)
Basic RGB or RGBA constructor.
std::size_t operator()(const color_t &c) const noexcept
static map_location::direction n
static map_location::direction s