aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
aest::colors::Premultiplied< Space > Class Template Referencefinalexport

A color of a linear space with premultiplied alpha: each color channel is already multiplied by alpha. More...

Inheritance diagram for aest::colors::Premultiplied< Space >:
aest::colors::ColorBase< Premultiplied< Space > >

Public Member Functions

constexpr Premultiplied ()
 Default constructor initializes the color to opaque black (0, 0, 0, 1).
constexpr Premultiplied (const float ch1, const float ch2, const float ch3, const float a=1.0f)
 Construct a color from premultiplied channel values.
Public Member Functions inherited from aest::colors::ColorBase< Premultiplied< Space > >
constexpr float alpha () const noexcept
 Get the alpha channel value in the 0-1 range.
constexpr float ch1 () const noexcept
 Get the first channel value.
constexpr float ch2 () const noexcept
 Get the second channel value.
constexpr float ch3 () const noexcept
 Get the third channel value.
constexpr Premultiplied< Space > opacity (const float alpha) const
 Returns a new color with the same channels and the specified alpha value.

Static Public Attributes

static constexpr std::string_view TYPE {TYPE_CHARS.data(), TYPE_CHARS.size()}
 Color space name, used by the std::formatter specialization.

Private Member Functions

constexpr Premultiplied (const Space &clamped)
 Construct a color from channels already clamped by Space.

Static Private Attributes

static constexpr std::string_view TYPE_PREFIX = "Premultiplied<"
 Beginning of the space name, before the name of Space.
static constexpr auto TYPE_CHARS
 The space name, Premultiplied< + Space::TYPE + >.

Arithmetic operators

constexpr Premultiplied & operator+= (const Premultiplied &other) noexcept
 Adds another color to this color in place.
constexpr Premultiplied & operator*= (const float scalar) noexcept
 Scales every channel of this color in place, alpha included.
constexpr Premultiplied operator+ (const Premultiplied &lhs, const Premultiplied &rhs) noexcept
 Adds two colors, alpha included, as when one adds its light and coverage on top of the other.
constexpr Premultiplied operator* (const Premultiplied &color, const float scalar) noexcept
 Scales every channel of a color, alpha included, as when fading it.
constexpr Premultiplied operator* (const float scalar, const Premultiplied &color) noexcept
 Scales every channel of a color, alpha included, as when fading it.

Additional Inherited Members

Public Attributes inherited from aest::colors::ColorBase< Premultiplied< Space > >
friend Derived
 Lets the derived color reach the private constructor and channels.

Detailed Description

template<LinearSpace Space>
class aest::colors::Premultiplied< Space >

A color of a linear space with premultiplied alpha: each color channel is already multiplied by alpha.

This is the form compositing works in: a premultiplied color is the light it adds plus the fraction of the background it covers, so blending is a sum. Its channels are clamped like those of Space; alpha is clamped to the 0-1 range. Convert from and to Space with convert(): converting a color whose alpha is 0 back to Space gives transparent black.

Template Parameters
SpaceThe linear color space of the channels, such as LinSRGB
See also
Porter-Duff

Definition at line 46 of file Compositing.cppm.

Constructor & Destructor Documentation

◆ Premultiplied() [1/3]

template<LinearSpace Space>
aest::colors::Premultiplied< Space >::Premultiplied ( )
inlineconstexpr

Default constructor initializes the color to opaque black (0, 0, 0, 1).

Definition at line 60 of file Compositing.cppm.

◆ Premultiplied() [2/3]

template<LinearSpace Space>
aest::colors::Premultiplied< Space >::Premultiplied ( const float ch1,
const float ch2,
const float ch3,
const float a = 1.0f )
inlineconstexpr

Construct a color from premultiplied channel values.

Parameters
[in]ch1First channel, already multiplied by a
[in]ch2Second channel, already multiplied by a
[in]ch3Third channel, already multiplied by a
[in]aAlpha channel value (default 1.0)
Precondition
Every channel is finite: NaN and infinities are undefined behavior.

Definition at line 72 of file Compositing.cppm.

◆ Premultiplied() [3/3]

template<LinearSpace Space>
aest::colors::Premultiplied< Space >::Premultiplied ( const Space & clamped)
inlineexplicitconstexprprivate

Construct a color from channels already clamped by Space.

Parameters
[in]clampedThe premultiplied channels, held in a Space value

Definition at line 146 of file Compositing.cppm.

Member Function Documentation

◆ operator*=()

template<LinearSpace Space>
Premultiplied & aest::colors::Premultiplied< Space >::operator*= ( const float scalar)
inlineconstexprnoexcept

Scales every channel of this color in place, alpha included.

Parameters
[in]scalarThe factor applied to each channel.
Returns
Reference to this color after modification.
Precondition
scalar is finite.

Definition at line 135 of file Compositing.cppm.

◆ operator+=()

template<LinearSpace Space>
Premultiplied & aest::colors::Premultiplied< Space >::operator+= ( const Premultiplied< Space > & other)
inlineconstexprnoexcept

Adds another color to this color in place.

Parameters
[in]otherThe color to add.
Returns
Reference to this color after modification.

Definition at line 124 of file Compositing.cppm.

◆ operator* [1/2]

template<LinearSpace Space>
Premultiplied operator* ( const float scalar,
const Premultiplied< Space > & color )
friend

Scales every channel of a color, alpha included, as when fading it.

Parameters
[in]scalarThe factor applied to each channel.
[in]colorThe color to scale.
Returns
A new color with every channel scaled.
Precondition
scalar is finite.

Definition at line 113 of file Compositing.cppm.

◆ operator* [2/2]

template<LinearSpace Space>
Premultiplied operator* ( const Premultiplied< Space > & color,
const float scalar )
friend

Scales every channel of a color, alpha included, as when fading it.

Parameters
[in]colorThe color to scale.
[in]scalarThe factor applied to each channel.
Returns
A new color with every channel scaled.
Precondition
scalar is finite.

Definition at line 99 of file Compositing.cppm.

◆ operator+

template<LinearSpace Space>
Premultiplied operator+ ( const Premultiplied< Space > & lhs,
const Premultiplied< Space > & rhs )
friend

Adds two colors, alpha included, as when one adds its light and coverage on top of the other.

Parameters
[in]lhsThe left-hand color.
[in]rhsThe right-hand color.
Returns
A new color containing the component-wise sum.

Definition at line 85 of file Compositing.cppm.

Member Data Documentation

◆ TYPE

template<LinearSpace Space>
std::string_view aest::colors::Premultiplied< Space >::TYPE {TYPE_CHARS.data(), TYPE_CHARS.size()}
staticconstexpr

Color space name, used by the std::formatter specialization.

Definition at line 57 of file Compositing.cppm.

◆ TYPE_CHARS

template<LinearSpace Space>
auto aest::colors::Premultiplied< Space >::TYPE_CHARS
staticconstexprprivate
Initial value:
=
join_names<TYPE_PREFIX.size() + Space::TYPE.size() + 1>({TYPE_PREFIX, Space::TYPE, ">"})
constexpr std::array< char, Size > 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.
Definition Color.cppm:100
static constexpr std::string_view TYPE_PREFIX
Beginning of the space name, before the name of Space.

The space name, Premultiplied< + Space::TYPE + >.

Definition at line 52 of file Compositing.cppm.

◆ TYPE_PREFIX

template<LinearSpace Space>
std::string_view aest::colors::Premultiplied< Space >::TYPE_PREFIX = "Premultiplied<"
staticconstexprprivate

Beginning of the space name, before the name of Space.

Definition at line 49 of file Compositing.cppm.


The documentation for this class was generated from the following file: