header_utils
Loading...
Searching...
No Matches
Colors

Colors and things. More...

Namespaces

namespace  ghassanpl::colors
 Contains the basic colors as variables and functions.
 
enum class  ghassanpl::color_space { linear_rgba , srgb , hsva , rgbe }
 Implementation note: These functions use the .xyzw members instead of the .rgba members because accessing the latter is not constexpr. More...
 
using ghassanpl::color_rgba_t = glm::vec4
 Represents a color in RGBA color space, with 0.0-1.0 float elements.
 
using ghassanpl::color_hsva_t = named< glm::vec4, "color_hsva">
 Represents a color in HSVA color space, with H=0.0-6.0, S=0.0-1.0, V=0.0-1.0, A=0.0-1.0 float elements.
 
using ghassanpl::color_t = color_rgba_t
 Default color_t type is RGBA.
 
using ghassanpl::color_rgba_u32_t = named< uint32_t, "color_rgba_u32">
 Represent a packed RGBA color with 8 bits per pixel.
 
using ghassanpl::color_abgr_u32_t = named< uint32_t, "color_abgr_u32">
 Represent a packed ABGR color with 8 bits per pixel.
 
constexpr color_t ghassanpl::premultiplied (color_t const &color)
 Returns the color multiplied by its own alpha.
 
constexpr color_t ghassanpl::saturated (color_t const &color)
 Returns a color with all elements clamped between 0 and 1.
 
constexpr color_t ghassanpl::lighten (color_t const &color, float coef)
 Returns a color lightened by a coefficient.
 
constexpr color_t ghassanpl::contrast (color_t const &color, float contrast)
 Returns a color with its contrast changed.
 
constexpr color_t ghassanpl::contrast2 (color_t const &color, float contrast)
 Returns a color with its contrast changed This uses a differen algorithm and contrast value than contrast.
 
constexpr color_t ghassanpl::gamma_correct (color_t const &color, const float gamma)
 Returns a gamma corrected color.
 
constexpr color_t ghassanpl::inverted (color_t const &color)
 Returns an inverted color, i.e. with (1.0-x) on all of its elements, excluding its alpha.
 
constexpr color_t ghassanpl::contrasting (color_t const &color)
 Returns a color that's a good contrasting color for the original.
 
constexpr float ghassanpl::luminance (color_t const &color)
 Get brightness of color.
 
constexpr color_t ghassanpl::desaturated (color_t const &color, float desaturation)
 Returns a color sapped of desaturation percent (0-1) of its saturation.
 
constexpr color_t ghassanpl::from_u32_rgb (uint32_t rgb)
 Gets a color from an RGB 8bpp integer, with R being most significant.
 
constexpr color_t ghassanpl::from_u32_bgr (uint32_t rgb)
 Gets a color from an BGR 8bpp integer, with R being least significant.
 
constexpr color_t ghassanpl::from_u32_rgba (uint32_t rgb)
 Gets a color from an RGBA 8bpp integer, with R being most significant.
 
constexpr color_t ghassanpl::from_u32_bgra (uint32_t rgb)
 Gets a color from an BGRA 8bpp integer, with A being least significant, and B being most significant.
 
constexpr color_t ghassanpl::from_u32_argb (uint32_t rgb)
 Gets a color from an ARGB 8bpp integer, with A being most significant, and B being least significant.
 
constexpr color_t ghassanpl::from_u32_abgr (uint32_t rgb)
 Gets a color from an ABGR 8bpp integer, with A being most significant, and R being least significant.
 
constexpr uint32_t ghassanpl::to_u32_argb (color_t const &rgba)
 Creates an 8bpp ARGB integer from a color.
 
constexpr uint32_t ghassanpl::to_u32_abgr (color_t const &rgba)
 Creates an 8bpp ABGR integer from a color.
 
constexpr uint32_t ghassanpl::to_u32_rgba (color_t const &rgba)
 Creates an 8bpp RGBA integer from a color.
 
constexpr uint32_t ghassanpl::to_u32_bgra (color_t const &rgba)
 Creates an 8bpp BGRA integer from a color.
 
constexpr uint32_t ghassanpl::to_u32_rgb (color_t const &rgba)
 Creates a 32 bitbpp RGB integer from a color, with the most significant 8 bits set to 0.
 
constexpr uint32_t ghassanpl::to_u32_bgr (color_t const &rgba)
 Creates a 32 bitbpp BGR integer from a color, with the most significant 8 bits set to 0.
 
template<std::same_as< color_rgba_u32_t > TO>
constexpr TO ghassanpl::named_cast (color_rgba_t const &from)
 
template<typename TO , typename FROM >
TO ghassanpl::color_cast (FROM const &from)
 
constexpr glm::tvec4< uint8_tghassanpl::to_u8 (color_t const &rgba)
 Returns the color as a glm::vec4 of uint8_ts.
 
constexpr color_t ghassanpl::to_rgb (color_hsva_t const &hsva)
 Converts a HSVA color to RGBA space.
 
constexpr color_hsva_t ghassanpl::to_hsv (color_t const &rgba)
 Converts an RGBA color to HSVA space.
 
constexpr color_rgba_t ghassanpl::from_html (const char *str, size_t n)
 Converts a HTML color string (like #FBA or fafafa) to an RGBA color.
 
consteval color_rgba_t ghassanpl::operator""_rgb (const char *str, size_t n)
 Converts a HTML color string (like #FBA or fafafa) to an RGBA color.
 
constexpr color_rgba_t ghassanpl::from_html (std::string_view html)
 Converts a HTML color string (like #FBA or fafafa) to an RGBA color.
 

Detailed Description

Colors and things.

Typedef Documentation

◆ color_abgr_u32_t

using ghassanpl::color_abgr_u32_t = typedef named<uint32_t, "color_abgr_u32">

Represent a packed ABGR color with 8 bits per pixel.

Definition at line 43 of file colors.h.

◆ color_hsva_t

using ghassanpl::color_hsva_t = typedef named<glm::vec4, "color_hsva">

Represents a color in HSVA color space, with H=0.0-6.0, S=0.0-1.0, V=0.0-1.0, A=0.0-1.0 float elements.

Definition at line 36 of file colors.h.

◆ color_rgba_t

Represents a color in RGBA color space, with 0.0-1.0 float elements.

Definition at line 34 of file colors.h.

◆ color_rgba_u32_t

using ghassanpl::color_rgba_u32_t = typedef named<uint32_t, "color_rgba_u32">

Represent a packed RGBA color with 8 bits per pixel.

Definition at line 41 of file colors.h.

◆ color_t

Default color_t type is RGBA.

Definition at line 38 of file colors.h.

Enumeration Type Documentation

◆ color_space

Implementation note: These functions use the .xyzw members instead of the .rgba members because accessing the latter is not constexpr.

Definition at line 24 of file colors.h.

Function Documentation

◆ color_cast()

template<typename TO , typename FROM >
TO ghassanpl::color_cast ( FROM const from)

Definition at line 203 of file colors.h.

◆ contrast()

constexpr color_t ghassanpl::contrast ( color_t const color,
float  contrast 
)
constexpr

Returns a color with its contrast changed.

Note
contrast here is between 0.0 and 1.0
See also
contrast2

Definition at line 103 of file colors.h.

◆ contrast2()

constexpr color_t ghassanpl::contrast2 ( color_t const color,
float  contrast 
)
constexpr

Returns a color with its contrast changed This uses a differen algorithm and contrast value than contrast.

Note
contrast here is between -1.0 and 1.0
See also
contrast

Definition at line 113 of file colors.h.

◆ contrasting()

constexpr color_t ghassanpl::contrasting ( color_t const color)
constexpr

Returns a color that's a good contrasting color for the original.

Definition at line 134 of file colors.h.

◆ desaturated()

constexpr color_t ghassanpl::desaturated ( color_t const color,
float  desaturation 
)
constexpr

Returns a color sapped of desaturation percent (0-1) of its saturation.

Definition at line 146 of file colors.h.

◆ from_html() [1/2]

constexpr color_rgba_t ghassanpl::from_html ( const char str,
size_t  n 
)
constexpr

Converts a HTML color string (like #FBA or fafafa) to an RGBA color.

Definition at line 264 of file colors.h.

◆ from_html() [2/2]

constexpr color_rgba_t ghassanpl::from_html ( std::string_view  html)
constexpr

Converts a HTML color string (like #FBA or fafafa) to an RGBA color.

Definition at line 307 of file colors.h.

◆ from_u32_abgr()

constexpr color_t ghassanpl::from_u32_abgr ( uint32_t  rgb)
constexpr

Gets a color from an ABGR 8bpp integer, with A being most significant, and R being least significant.

Definition at line 175 of file colors.h.

◆ from_u32_argb()

constexpr color_t ghassanpl::from_u32_argb ( uint32_t  rgb)
constexpr

Gets a color from an ARGB 8bpp integer, with A being most significant, and B being least significant.

Definition at line 173 of file colors.h.

◆ from_u32_bgr()

constexpr color_t ghassanpl::from_u32_bgr ( uint32_t  rgb)
constexpr

Gets a color from an BGR 8bpp integer, with R being least significant.

Definition at line 167 of file colors.h.

◆ from_u32_bgra()

constexpr color_t ghassanpl::from_u32_bgra ( uint32_t  rgb)
constexpr

Gets a color from an BGRA 8bpp integer, with A being least significant, and B being most significant.

Definition at line 171 of file colors.h.

◆ from_u32_rgb()

constexpr color_t ghassanpl::from_u32_rgb ( uint32_t  rgb)
constexpr

Gets a color from an RGB 8bpp integer, with R being most significant.

Definition at line 165 of file colors.h.

◆ from_u32_rgba()

constexpr color_t ghassanpl::from_u32_rgba ( uint32_t  rgb)
constexpr

Gets a color from an RGBA 8bpp integer, with R being most significant.

Definition at line 169 of file colors.h.

◆ gamma_correct()

constexpr color_t ghassanpl::gamma_correct ( color_t const color,
const float  gamma 
)
constexpr

Returns a gamma corrected color.

Definition at line 121 of file colors.h.

◆ inverted()

constexpr color_t ghassanpl::inverted ( color_t const color)
constexpr

Returns an inverted color, i.e. with (1.0-x) on all of its elements, excluding its alpha.

Definition at line 128 of file colors.h.

◆ lighten()

constexpr color_t ghassanpl::lighten ( color_t const color,
float  coef 
)
constexpr

Returns a color lightened by a coefficient.

Definition at line 92 of file colors.h.

◆ luminance()

constexpr float ghassanpl::luminance ( color_t const color)
constexpr

Get brightness of color.

Definition at line 140 of file colors.h.

◆ named_cast()

template<std::same_as< color_rgba_u32_t > TO>
constexpr TO ghassanpl::named_cast ( color_rgba_t const from)
constexpr

Definition at line 191 of file colors.h.

◆ operator""_rgb()

consteval color_rgba_t ghassanpl::operator""_rgb ( const char str,
size_t  n 
)

Converts a HTML color string (like #FBA or fafafa) to an RGBA color.

Definition at line 301 of file colors.h.

◆ premultiplied()

constexpr color_t ghassanpl::premultiplied ( color_t const color)
constexpr

Returns the color multiplied by its own alpha.

Definition at line 80 of file colors.h.

◆ saturated()

constexpr color_t ghassanpl::saturated ( color_t const color)
constexpr

Returns a color with all elements clamped between 0 and 1.

Definition at line 86 of file colors.h.

◆ to_hsv()

constexpr color_hsva_t ghassanpl::to_hsv ( color_t const rgba)
constexpr

Converts an RGBA color to HSVA space.

Definition at line 237 of file colors.h.

◆ to_rgb()

constexpr color_t ghassanpl::to_rgb ( color_hsva_t const hsva)
constexpr

Converts a HSVA color to RGBA space.

Definition at line 212 of file colors.h.

◆ to_u32_abgr()

constexpr uint32_t ghassanpl::to_u32_abgr ( color_t const rgba)
constexpr

Creates an 8bpp ABGR integer from a color.

Definition at line 180 of file colors.h.

◆ to_u32_argb()

constexpr uint32_t ghassanpl::to_u32_argb ( color_t const rgba)
constexpr

Creates an 8bpp ARGB integer from a color.

Definition at line 178 of file colors.h.

◆ to_u32_bgr()

constexpr uint32_t ghassanpl::to_u32_bgr ( color_t const rgba)
constexpr

Creates a 32 bitbpp BGR integer from a color, with the most significant 8 bits set to 0.

Definition at line 188 of file colors.h.

◆ to_u32_bgra()

constexpr uint32_t ghassanpl::to_u32_bgra ( color_t const rgba)
constexpr

Creates an 8bpp BGRA integer from a color.

Definition at line 184 of file colors.h.

◆ to_u32_rgb()

constexpr uint32_t ghassanpl::to_u32_rgb ( color_t const rgba)
constexpr

Creates a 32 bitbpp RGB integer from a color, with the most significant 8 bits set to 0.

Definition at line 186 of file colors.h.

◆ to_u32_rgba()

constexpr uint32_t ghassanpl::to_u32_rgba ( color_t const rgba)
constexpr

Creates an 8bpp RGBA integer from a color.

Definition at line 182 of file colors.h.

◆ to_u8()

constexpr glm::tvec4< uint8_t > ghassanpl::to_u8 ( color_t const rgba)
constexpr

Returns the color as a glm::vec4 of uint8_ts.

Definition at line 209 of file colors.h.