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

Colors and things. More...

Namespaces

namespace  ghassanpl::colors
 Contains the basic colors as variables and functions.

Typedefs

using ghassanpl::color_rgba_t
 Represents a color in RGBA color space, with 0.0-1.0 float elements.
using ghassanpl::color_hsva_t
 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
 Default color_t type is RGBA.
using ghassanpl::color_rgba_u32_t
 Represent a packed RGBA color with 8 bits per pixel.
using ghassanpl::color_abgr_u32_t
 Represent a packed ABGR color with 8 bits per pixel.

Enumerations

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...

Functions

constexpr color_t ghassanpl::premultiplied (color_t const &color)
 Returns the color multiplied by its own alpha.
constexpr color_t ghassanpl::with_alpha (color_t const &color, float a)
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 color_t ghassanpl::from_u8_rgb (uint8_t r, uint8_t g, uint8_t b)
constexpr color_t ghassanpl::from_u8_rgba (uint8_t r, uint8_t g, uint8_t b, uint8_t a)
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>
constexpr TO ghassanpl::color_cast (FROM const &from)
constexpr glm::tvec4< uint8_t > ghassanpl::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

Represent a packed ABGR color with 8 bits per pixel.

Definition at line 44 of file colors.h.

◆ color_hsva_t

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 37 of file colors.h.

◆ color_rgba_t

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

Definition at line 35 of file colors.h.

◆ color_rgba_u32_t

Represent a packed RGBA color with 8 bits per pixel.

Definition at line 42 of file colors.h.

◆ color_t

Default color_t type is RGBA.

Definition at line 39 of file colors.h.

Enumeration Type Documentation

◆ color_space

enum class ghassanpl::color_space
strong

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

Definition at line 25 of file colors.h.

Function Documentation

◆ color_cast()

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

Definition at line 217 of file colors.h.

◆ contrast()

color_t ghassanpl::contrast ( color_t const & color,
float contrast )
nodiscardconstexpr

Returns a color with its contrast changed.

Note
contrast here is between 0.0 and 1.0
See also
contrast2

Definition at line 110 of file colors.h.

◆ contrast2()

color_t ghassanpl::contrast2 ( color_t const & color,
float contrast )
nodiscardconstexpr

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 120 of file colors.h.

◆ contrasting()

color_t ghassanpl::contrasting ( color_t const & color)
nodiscardconstexpr

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

Definition at line 141 of file colors.h.

◆ desaturated()

color_t ghassanpl::desaturated ( color_t const & color,
float desaturation )
nodiscardconstexpr

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

Definition at line 155 of file colors.h.

◆ from_html() [1/2]

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

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

Definition at line 278 of file colors.h.

◆ from_html() [2/2]

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

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

Definition at line 321 of file colors.h.

◆ from_u32_abgr()

color_t ghassanpl::from_u32_abgr ( uint32_t rgb)
nodiscardconstexpr

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

Definition at line 184 of file colors.h.

◆ from_u32_argb()

color_t ghassanpl::from_u32_argb ( uint32_t rgb)
nodiscardconstexpr

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

Definition at line 182 of file colors.h.

◆ from_u32_bgr()

color_t ghassanpl::from_u32_bgr ( uint32_t rgb)
nodiscardconstexpr

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

Definition at line 176 of file colors.h.

◆ from_u32_bgra()

color_t ghassanpl::from_u32_bgra ( uint32_t rgb)
nodiscardconstexpr

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

Definition at line 180 of file colors.h.

◆ from_u32_rgb()

color_t ghassanpl::from_u32_rgb ( uint32_t rgb)
nodiscardconstexpr

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

Definition at line 174 of file colors.h.

◆ from_u32_rgba()

color_t ghassanpl::from_u32_rgba ( uint32_t rgb)
nodiscardconstexpr

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

Definition at line 178 of file colors.h.

◆ from_u8_rgb()

color_t ghassanpl::from_u8_rgb ( uint8_t r,
uint8_t g,
uint8_t b )
nodiscardconstexpr

Definition at line 187 of file colors.h.

◆ from_u8_rgba()

color_t ghassanpl::from_u8_rgba ( uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a )
nodiscardconstexpr

Definition at line 189 of file colors.h.

◆ gamma_correct()

color_t ghassanpl::gamma_correct ( color_t const & color,
const float gamma )
nodiscardconstexpr

Returns a gamma corrected color.

Definition at line 128 of file colors.h.

◆ inverted()

color_t ghassanpl::inverted ( color_t const & color)
nodiscardconstexpr

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

Definition at line 135 of file colors.h.

◆ lighten()

color_t ghassanpl::lighten ( color_t const & color,
float coef )
nodiscardconstexpr

Returns a color lightened by a coefficient.

Definition at line 99 of file colors.h.

◆ luminance()

float ghassanpl::luminance ( color_t const & color)
nodiscardconstexpr

Get brightness of color.

Definition at line 149 of file colors.h.

◆ named_cast()

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

Definition at line 205 of file colors.h.

◆ operator""_rgb()

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

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

Definition at line 315 of file colors.h.

◆ premultiplied()

color_t ghassanpl::premultiplied ( color_t const & color)
nodiscardconstexpr

Returns the color multiplied by its own alpha.

Definition at line 81 of file colors.h.

◆ saturated()

color_t ghassanpl::saturated ( color_t const & color)
nodiscardconstexpr

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

Definition at line 93 of file colors.h.

◆ to_hsv()

color_hsva_t ghassanpl::to_hsv ( color_t const & rgba)
nodiscardconstexpr

Converts an RGBA color to HSVA space.

Definition at line 251 of file colors.h.

◆ to_rgb()

color_t ghassanpl::to_rgb ( color_hsva_t const & hsva)
nodiscardconstexpr

Converts a HSVA color to RGBA space.

Definition at line 226 of file colors.h.

◆ to_u32_abgr()

uint32_t ghassanpl::to_u32_abgr ( color_t const & rgba)
nodiscardconstexpr

Creates an 8bpp ABGR integer from a color.

Definition at line 194 of file colors.h.

◆ to_u32_argb()

uint32_t ghassanpl::to_u32_argb ( color_t const & rgba)
nodiscardconstexpr

Creates an 8bpp ARGB integer from a color.

Definition at line 192 of file colors.h.

◆ to_u32_bgr()

uint32_t ghassanpl::to_u32_bgr ( color_t const & rgba)
nodiscardconstexpr

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

Definition at line 202 of file colors.h.

◆ to_u32_bgra()

uint32_t ghassanpl::to_u32_bgra ( color_t const & rgba)
nodiscardconstexpr

Creates an 8bpp BGRA integer from a color.

Definition at line 198 of file colors.h.

◆ to_u32_rgb()

uint32_t ghassanpl::to_u32_rgb ( color_t const & rgba)
nodiscardconstexpr

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

Definition at line 200 of file colors.h.

◆ to_u32_rgba()

uint32_t ghassanpl::to_u32_rgba ( color_t const & rgba)
nodiscardconstexpr

Creates an 8bpp RGBA integer from a color.

Definition at line 196 of file colors.h.

◆ to_u8()

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

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

Definition at line 223 of file colors.h.

◆ with_alpha()

color_t ghassanpl::with_alpha ( color_t const & color,
float a )
nodiscardconstexpr

Definition at line 87 of file colors.h.