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

Partition aest.colors:compositing: premultiplied alpha and Porter-Duff compositing. More...

#include <array>
#include <concepts>
#include <string_view>
import aest.colors:space;

Go to the source code of this file.

Classes

class  aest::colors::Premultiplied< Space >
 A color of a linear space with premultiplied alpha: each color channel is already multiplied by alpha. More...
struct  aest::colors::ParentSpace< Premultiplied< Space > >
 A premultiplied color converts through its straight-alpha space. More...
struct  aest::colors::Converter< Premultiplied< Space >, Space >
 Converts straight alpha to premultiplied alpha. More...
struct  aest::colors::Converter< Space, Premultiplied< Space > >
 Converts premultiplied alpha to straight alpha. More...
struct  aest::colors::LinearSpaceOf< Premultiplied< Space > >
 A premultiplied color follows its straight-alpha space. More...

Concepts

concept  aest::colors::LinearSpace
 A color space whose channels are proportional to light, so that adding and scaling them is physically meaningful.

Functions

template<typename Space = void, ColorType Foreground, ColorType Background>
requires LinearSpace<WorkingSpace<Space, Background>> && ConvertibleTo<Premultiplied<WorkingSpace<Space, Background>>, Foreground> &&
ConvertibleTo<Premultiplied<WorkingSpace<Space, Background>>, Background> && ConvertibleTo<Background, Premultiplied
<WorkingSpace<Space, Background>>>
constexpr Background aest::colors::over (const Foreground &foreground, const Background &background, In< Space > space={})
 Composites a color over another: Porter-Duff source-over.

Detailed Description

Partition aest.colors:compositing: premultiplied alpha and Porter-Duff compositing.

Author
Davide Pierotti

Definition in file Compositing.cppm.

Function Documentation

◆ over()

template<typename Space = void, ColorType Foreground, ColorType Background>
requires LinearSpace<WorkingSpace<Space, Background>> && ConvertibleTo<Premultiplied<WorkingSpace<Space, Background>>, Foreground> &&
ConvertibleTo<Premultiplied<WorkingSpace<Space, Background>>, Background> && ConvertibleTo<Background, Premultiplied
<WorkingSpace<Space, Background>>>
Background aest::colors::over ( const Foreground & foreground,
const Background & background,
In< Space > space = {} )
constexprexport

Composites a color over another: Porter-Duff source-over.

Both colors are converted to the premultiplied working space, where the result is foreground + background * (1 - foreground alpha), then converted to the type of background. Alpha combines the same way, so a half-transparent color over another gives alpha 0.75. By default the working space is the LinearSpaceOf Background, linear light in the background's gamut, so P3 colors composite without clipping to sRGB.

Template Parameters
SpaceThe linear color space the colors are composited in; void, the default, follows Background
ForegroundColor type of foreground
BackgroundColor type of background and of the result
Parameters
[in]foregroundThe color on top
[in]backgroundThe color underneath
[in]spaceThe working space, e.g. in<LinSRGB>; the LinearSpaceOf Background when omitted
Returns
The composited color, in the type of background.
See also
Porter-Duff

Definition at line 242 of file Compositing.cppm.