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

Partition aest.colors:converter: conversions between color spaces. More...

#include <algorithm>
#include <array>
#include <concepts>
#include <cstdint>
#include <numeric>
#include <type_traits>
import aest.colors:transfer;
import aest.blas;

Go to the source code of this file.

Classes

struct  aest::colors::CommonAncestor< From, To >
 The closest common ancestor of two color spaces, as type; no type when they are in different trees. More...
struct  aest::colors::CommonAncestor< From, To >
 The common ancestor when From is itself an ancestor of To. More...
struct  aest::colors::Converter< ColorOut, ColorIn >
 Identity conversion between a color space and itself. More...
struct  aest::colors::ParentSpace< BasicRGB< Gamut, tf::Linear > >
 A linear RGB space converts through XYZ, the root of the conversion tree, with the matrix of its gamut. More...
struct  aest::colors::ParentSpace< BasicRGB< Gamut, Transfer > >
 An encoded RGB space converts through the linear space of its gamut. More...
struct  aest::colors::ParentSpace< BasicHSL< RGB > >
 HSL converts through the RGB space it is a view of. More...
struct  aest::colors::ParentSpace< BasicHSV< RGB > >
 HSV converts through the RGB space it is a view of. More...
struct  aest::colors::Converter< RGB, BasicHSL< RGB > >
 Converts HSL to its RGB space. More...
struct  aest::colors::Converter< BasicHSL< RGB >, RGB >
 Converts an RGB space to its HSL. More...
struct  aest::colors::Converter< BasicHSV< RGB >, RGB >
 Converts an RGB space to its HSV. More...
struct  aest::colors::Converter< RGB, BasicHSV< RGB > >
 Converts HSV to its RGB space. More...
struct  aest::colors::Converter< BasicHSV< RGB >, BasicHSL< RGB > >
 Converts HSL to HSV over the same RGB space, a shortcut that keeps the hue exactly. More...
struct  aest::colors::Converter< BasicHSL< RGB >, BasicHSV< RGB > >
 Converts HSV to HSL over the same RGB space, a shortcut that keeps the hue exactly. More...
struct  aest::colors::Converter< BasicRGB< Gamut, tf::Linear >, BasicRGB< Gamut, Transfer > >
 Decodes an encoded RGB space to the linear space of its gamut. More...
struct  aest::colors::Converter< BasicRGB< Gamut, Transfer >, BasicRGB< Gamut, tf::Linear > >
 Encodes the linear space of a gamut with a transfer function. More...
struct  aest::colors::Converter< XYZ, BasicRGB< Gamut, tf::Linear > >
 Converts linear RGB to XYZ with the matrix of its gamut. More...
struct  aest::colors::Converter< BasicRGB< Gamut, tf::Linear >, XYZ >
 Converts XYZ to linear RGB, clipping colors outside the gamut at 0. More...

Concepts

concept  aest::colors::HasParentSpace
 A color space with a parent in the conversion tree.
concept  aest::colors::DirectConverter
 A pair of color spaces with a Converter specialization between them.
concept  aest::colors::ConvertibleTo
 A color space that convert() can convert ColorIn to: directly through a Converter, or along the conversion tree.

Functions

constexpr float aest::colors::hue_of (const float r, const float g, const float b, const float max, const float delta)
 Hue of an sRGB color, shared by the HSL and HSV conversions.
template<BoundedRGBSpace RGB>
constexpr RGB aest::colors::rgb_from_hue (const float hue, const float chroma, const float offset, const float alpha)
 Builds an RGB color from a hue, a chroma and an offset, shared by the HSL and HSV conversions.
template<ColorType Ancestor, ColorType Space>
constexpr Ancestor aest::colors::ascend (const Space &color)
 Converts a color up the tree, parent by parent, to one of its ancestors.
template<ColorType Descendant, ColorType Space>
constexpr Descendant aest::colors::descend (const Space &color)
 Converts a color down the tree, child by child, to one of its descendants.
template<ColorType ColorOut, ColorType ColorIn>
requires ConvertibleTo<ColorOut, ColorIn>
constexpr ColorOut aest::colors::convert (const ColorIn &color)
 Convert a color from one color space to another.

Variables

template<typename Ancestor, typename Space>
constexpr bool aest::colors::IsAncestorOrSelf
 Whether Ancestor is Space or one of its ancestors in the conversion tree.

Detailed Description

Partition aest.colors:converter: conversions between color spaces.

Author
Davide Pierotti

Definition in file Converter.cppm.

Function Documentation

◆ ascend()

template<ColorType Ancestor, ColorType Space>
Ancestor aest::colors::ascend ( const Space & color)
constexpr

Converts a color up the tree, parent by parent, to one of its ancestors.

Template Parameters
AncestorThe ancestor to reach
SpaceThe color space of color
Parameters
[in]colorThe color to convert
Returns
The color in Ancestor.

Definition at line 208 of file Converter.cppm.

◆ convert()

template<ColorType ColorOut, ColorType ColorIn>
requires ConvertibleTo<ColorOut, ColorIn>
ColorOut aest::colors::convert ( const ColorIn & color)
constexprexport

Convert a color from one color space to another.

Uses the Converter specialization between the two spaces when there is one. Otherwise the color goes up the conversion tree to the closest ancestor the spaces share, and down from it to ColorOut; each step clamps to the range of its space.

Template Parameters
ColorOutThe desired color space
ColorInThe current color space
Parameters
[in]colorThe color to convert
Returns
A new color representing the input value in another color space

Definition at line 265 of file Converter.cppm.

◆ descend()

template<ColorType Descendant, ColorType Space>
Descendant aest::colors::descend ( const Space & color)
constexpr

Converts a color down the tree, child by child, to one of its descendants.

Template Parameters
DescendantThe descendant to reach
SpaceThe color space of color, an ancestor of Descendant
Parameters
[in]colorThe color to convert
Returns
The color in Descendant.

Definition at line 227 of file Converter.cppm.

◆ hue_of()

float aest::colors::hue_of ( const float r,
const float g,
const float b,
const float max,
const float delta )
constexpr

Hue of an sRGB color, shared by the HSL and HSV conversions.

Parameters
[in]rRed channel value
[in]gGreen channel value
[in]bBlue channel value
[in]maxThe largest of r, g and b
[in]deltamax minus the smallest channel value
Returns
The hue in degrees, in the [-60, 300) range; 0 when delta is 0. The color constructors wrap negative hues.

Definition at line 34 of file Converter.cppm.

◆ rgb_from_hue()

template<BoundedRGBSpace RGB>
RGB aest::colors::rgb_from_hue ( const float hue,
const float chroma,
const float offset,
const float alpha )
constexpr

Builds an RGB color from a hue, a chroma and an offset, shared by the HSL and HSV conversions.

Template Parameters
RGBThe encoded RGB space to build the color in
Parameters
[in]hueThe hue in degrees, in the [0, 360) range
[in]chromaDifference between the largest and smallest channel
[in]offsetValue of the smallest channel
[in]alphaAlpha channel value
Returns
The color in RGB.

Definition at line 57 of file Converter.cppm.

Variable Documentation

◆ IsAncestorOrSelf

template<typename Ancestor, typename Space>
bool aest::colors::IsAncestorOrSelf
constexpr
Initial value:
= [] {
if constexpr (std::is_same_v<Ancestor, Space>)
return true;
else if constexpr (HasParentSpace<Space>)
return IsAncestorOrSelf<Ancestor, typename ParentSpace<Space>::type>;
else
return false;
}()
constexpr bool IsAncestorOrSelf
Whether Ancestor is Space or one of its ancestors in the conversion tree.
A color space with a parent in the conversion tree.
Names the color space a space converts through, joining every space in one tree.

Whether Ancestor is Space or one of its ancestors in the conversion tree.

Template Parameters
AncestorThe candidate ancestor
SpaceThe color space whose ancestors are searched

Definition at line 158 of file Converter.cppm.