aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
Color.cppm File Reference

Partition aest.colors:color: color types, their shared base and the ColorType concept. More...

#include <algorithm>
#include <array>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <initializer_list>
#include <numbers>
#include <string_view>

Go to the source code of this file.

Classes

struct  aest::colors::ColorBase< Derived >
 Base class for color representations. More...
struct  aest::colors::ColorArithmetic< Derived >
 Mixin adding channel-wise arithmetic operators to a color type. More...
class  aest::colors::XYZ
 A color in the CIE 1931 XYZ color space, relative to the D65 white point. More...

Concepts

concept  aest::colors::ColorType
 Concept to check if a type is a color.

Functions

constexpr float aest::colors::clamp (const float value)
 Clamp a floating-point value to the 0-1 range.
constexpr float aest::colors::non_negative (const float value)
 Clamp a floating-point value to be non-negative, leaving it unbounded above.
constexpr float aest::colors::to_float (const std::uint8_t value)
 Convert an 8-bit color channel value to a float in the 0-1 range.
constexpr std::uint8_t aest::colors::to_byte (const float value)
 Convert a float in the 0-1 range to a 8-bit color channel value.
constexpr std::uint8_t aest::colors::byte_at (const std::uint32_t word, const std::uint32_t index)
 Extract one byte of a 32-bit word.
constexpr std::uint32_t aest::colors::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.
template<std::size_t Size>
constexpr std::array< char, Size > aest::colors::join_names (const std::initializer_list< std::string_view > parts)
 Concatenate names into a character array, for a color space name built at compile time.
constexpr float aest::colors::wrap_hue (const float hue)
 Wrap a hue angle to the [0, 360) range.

Variables

constexpr std::uint8_t aest::colors::BYTE_MAX = 255
 Maximum value for an 8-bit color channel.
constexpr double aest::colors::DEGREES_PER_RADIAN = 180.0 / std::numbers::pi
 Degrees in a radian.

Detailed Description

Partition aest.colors:color: color types, their shared base and the ColorType concept.

Author
Davide Pierotti

Definition in file Color.cppm.

Function Documentation

◆ byte_at()

std::uint8_t aest::colors::byte_at ( const std::uint32_t word,
const std::uint32_t index )
constexpr

Extract one byte of a 32-bit word.

Parameters
[in]wordThe word to read
[in]indexPosition of the byte, 0 being the least significant
Returns
The byte at index.

Definition at line 70 of file Color.cppm.

◆ clamp()

float aest::colors::clamp ( const float value)
constexpr

Clamp a floating-point value to the 0-1 range.

Parameters
[in]valueThe value to clamp
Returns
The clamped value

Definition at line 29 of file Color.cppm.

◆ join_names()

template<std::size_t Size>
std::array< char, Size > aest::colors::join_names ( const std::initializer_list< std::string_view > parts)
constexpr

Concatenate names into a character array, for a color space name built at compile time.

Template Parameters
SizeThe total length of parts
Parameters
[in]partsThe names to join, in order
Returns
The characters of parts, without a terminator.

Definition at line 100 of file Color.cppm.

◆ non_negative()

float aest::colors::non_negative ( const float value)
constexpr

Clamp a floating-point value to be non-negative, leaving it unbounded above.

Parameters
[in]valueThe value to clamp
Returns
The value, or 0 when it is negative

Definition at line 39 of file Color.cppm.

◆ pack()

std::uint32_t aest::colors::pack ( const std::uint8_t byte3,
const std::uint8_t byte2,
const std::uint8_t byte1,
const std::uint8_t byte0 )
constexpr

Pack four bytes into a 32-bit word, most significant first.

Parameters
[in]byte3The most significant byte
[in]byte2The second byte
[in]byte1The third byte
[in]byte0The least significant byte
Returns
The word with byte3 in the top byte and byte0 in the bottom one.

Definition at line 83 of file Color.cppm.

◆ to_byte()

std::uint8_t aest::colors::to_byte ( const float value)
constexpr

Convert a float in the 0-1 range to a 8-bit color channel value.

Parameters
[in]valueThe color value in the 0-1 range.
Returns
The nearest 8-bit representation.

Definition at line 59 of file Color.cppm.

◆ to_float()

float aest::colors::to_float ( const std::uint8_t value)
constexpr

Convert an 8-bit color channel value to a float in the 0-1 range.

Parameters
[in]valueThe 8-bit color channel value
Returns
The corresponding float value in the 0-1 range

Definition at line 49 of file Color.cppm.

◆ wrap_hue()

float aest::colors::wrap_hue ( const float hue)
constexpr

Wrap a hue angle to the [0, 360) range.

Parameters
[in]hueThe hue in degrees, any finite value whose whole turns fit a std::int64_t.
Returns
The equivalent hue in the [0, 360) range.

Definition at line 118 of file Color.cppm.

Variable Documentation

◆ BYTE_MAX

std::uint8_t aest::colors::BYTE_MAX = 255
inlineconstexpr

Maximum value for an 8-bit color channel.

Definition at line 22 of file Color.cppm.

◆ DEGREES_PER_RADIAN

double aest::colors::DEGREES_PER_RADIAN = 180.0 / std::numbers::pi
constexpr

Degrees in a radian.

Definition at line 110 of file Color.cppm.