19export namespace aest::colors
35template <ColorType Color = SRGB>
51template <ColorType Color = SRGB>
52 requires ConvertibleTo<Color, SRGB>
64template <ColorType Color = SRGB>
65 requires ConvertibleTo<Color, SRGB>
79template <ColorType Color = SRGB>
80 requires ConvertibleTo<Color, SRGB>
81constexpr Color
from_hex(
const std::uint32_t hex)
100template <ColorType Color>
101 requires ConvertibleTo<SRGB, Color>
102[[nodiscard]]
constexpr std::uint32_t
to_rgba(
const Color& color)
121template <ColorType Color>
122 requires ConvertibleTo<SRGB, Color>
123[[nodiscard]]
constexpr std::uint32_t
to_argb(
const Color& color)
126 return std::rotr(
to_rgba(color), 8);
139template <ColorType Color>
140 requires ConvertibleTo<SRGB, Color>
143 return std::format(
"#{:06X}",
to_rgba(color) >> 8);
constexpr std::uint32_t pack(const std::uint8_t byte3, const std::uint8_t byte2, const std::uint8_t byte1, const std::uint8_t byte0)
Pack four bytes into a 32-bit word, most significant first.
constexpr std::uint8_t to_byte(const float value)
Convert a float in the 0-1 range to a 8-bit color channel value.
constexpr std::uint8_t byte_at(const std::uint32_t word, const std::uint32_t index)
Extract one byte of a 32-bit word.
constexpr std::uint8_t BYTE_MAX
Maximum value for an 8-bit color channel.
constexpr float to_float(const std::uint8_t value)
Convert an 8-bit color channel value to a float in the 0-1 range.
constexpr ColorOut convert(const ColorIn &color)
Convert a color from one color space to another.
BasicRGB< gamut::SRGB, tf::SRGB > SRGB
sRGB with gamma-encoded channels: the encoding of hex codes, 8-bit channels and CSS colors.
constexpr Color from_rgba(const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a=BYTE_MAX)
Build a color from 8-bit SRGB channels.
constexpr Color from_hex(const std::uint32_t hex)
Build a color from an SRGB hex code, a 32-bit integer in 0xRRGGBB format, as in from_hex(0xFF7F50).
constexpr Color from_argb(const std::uint32_t argb)
Build a color from a 32-bit SRGB integer in 0xAARRGGBB format.
constexpr std::uint32_t to_argb(const Color &color)
Convert a color to SRGB and pack it into a 32-bit integer in 0xAARRGGBB format.
constexpr std::uint32_t to_rgba(const Color &color)
Convert a color to SRGB and pack it into a 32-bit integer in 0xRRGGBBAA format.
std::string hex_string(const Color &color)
Convert a color to SRGB and write it as a hex code in #RRGGBB format, without alpha.
constexpr float green() const noexcept
Get the green channel value.
constexpr float red() const noexcept
Get the red channel value.
constexpr float blue() const noexcept
Get the blue channel value.
A color space that convert() can convert ColorIn to: directly through a Converter,...
constexpr float alpha() const noexcept
Get the alpha channel value in the 0-1 range.