7#ifndef SEEN_COLORS_UTILS_H
8#define SEEN_COLORS_UTILS_H
25 return (
unsigned int)(std::clamp(v, 0.0, 1.0) * 255. + .5);
29 return (v >> 24) & 0xff;
33 return (v >> 16) & 0xff;
37 return (v >> 8) & 0xff;
62 return ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8) | (a & 0xff);
87std::string
rgba_to_hex(uint32_t value,
bool alpha =
false);
88std::string
color_to_id(std::optional<Color>
const &color);
89std::string
desc_to_id(std::string
const &desc);
constexpr double SP_RGBA32_G_F(uint32_t v)
constexpr uint32_t SP_COLOR_F_TO_U(double v)
constexpr uint32_t SP_RGBA32_R_U(uint32_t v)
constexpr double SP_RGBA32_R_F(uint32_t v)
constexpr uint32_t SP_RGBA32_G_U(uint32_t v)
constexpr double SP_COLOR_U_TO_F(uint32_t v)
constexpr uint32_t SP_RGBA32_U_COMPOSE(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
constexpr uint32_t SP_RGBA32_A_U(uint32_t v)
constexpr uint32_t SP_RGBA32_B_U(uint32_t v)
constexpr double SP_RGBA32_A_F(uint32_t v)
constexpr uint32_t SP_RGBA32_F_COMPOSE(double r, double g, double b, double a)
constexpr double SP_RGBA32_B_F(uint32_t v)
constexpr uint32_t SP_RGBA32_C_COMPOSE(uint32_t c, double o)
constexpr uint32_t compose_argb32(double a, double r, double g, double b)
A set of useful color modifying functions which do not fit as generic methods on the color class itse...
std::vector< double > rgba_to_values(uint32_t rgba, bool opacity)
Convert a 32bit unsigned int into a set of 3 or 4 double values for rgba.
std::pair< double, double > get_contrasting_color(double l)
uint32_t hex_to_rgba(std::string const &value)
Parse a color directly without any CSS or CMS support.
double perceptual_lightness(double l)
double get_perceptual_lightness(Color const &color)
Return a value for how the light the color appears to be using HSLUV.
Color make_contrasted_color(Color const &orig, double amount)
Make a darker or lighter version of the color, useful for making checkerboards.
double lightness(Color color)
std::string color_to_id(std::optional< Color > const &color)
Create a somewhat unique id for the given color used for palette identification.
Color make_theme_color(Color const &orig, bool dark)
Make a themed dark or light color based on a previous shade, returns RGB color.
std::string desc_to_id(std::string const &desc)
Transform a color name or description into an id used for palette identification.
std::string rgba_to_hex(uint32_t value, bool alpha)
Output the RGBA value as a #RRGGBB hex color, if alpha is true then the output will be #RRGGBBAA inst...