29export template <
typename T>
45export template <LinearSpace Space>
49 static constexpr std::string_view
TYPE_PREFIX =
"Premultiplied<";
88 return Premultiplied{lhs.ch1() + rhs.ch1(), lhs.ch2() + rhs.ch2(), lhs.ch3() + rhs.ch3(),
89 lhs.alpha() + rhs.alpha()};
100 const float scalar)
noexcept
102 return Premultiplied{color.ch1() * scalar, color.ch2() * scalar, color.ch3() * scalar,
103 color.alpha() * scalar};
116 return color * scalar;
126 return *
this = *
this + other;
137 return *
this = *
this * scalar;
155template <LinearSpace Space>
166template <LinearSpace Space>
176 const float alpha = color.alpha();
186template <LinearSpace Space>
197 const float alpha = color.
alpha();
199 return Space{0.0f, 0.0f, 0.0f, 0.0f};
201 return Space{color.
ch1() / alpha, color.
ch2() / alpha, color.
ch3() / alpha, alpha};
209template <LinearSpace Space>
237export template <
typename Space =
void, ColorType Foreground, ColorType Background>
242constexpr Background
over(
const Foreground& foreground,
243 const Background& background,
246 using Working = Premultiplied<WorkingSpace<Space, Background>>;
248 const Working front = convert<Working>(foreground);
249 return convert<Background>(front + convert<Working>(background) * (1 - front.alpha()));
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.
constexpr Background over(const Foreground &foreground, const Background &background, In< Space > space={})
Composites a color over another: Porter-Duff source-over.
A color of a linear space with premultiplied alpha: each color channel is already multiplied by alpha...
constexpr Premultiplied & operator+=(const Premultiplied &other) noexcept
Adds another color to this color in place.
friend 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(const Space &clamped)
Construct a color from channels already clamped by Space.
constexpr Premultiplied & operator*=(const float scalar) noexcept
Scales every channel of this color in place, alpha included.
static constexpr std::string_view TYPE_PREFIX
Beginning of the space name, before the name of Space.
constexpr Premultiplied()
Default constructor initializes the color to opaque black (0, 0, 0, 1).
friend constexpr Premultiplied operator*(const Premultiplied &color, const float scalar) noexcept
Scales every channel of a color, alpha included, as when fading it.
static constexpr std::string_view TYPE
Color space name, used by the std::formatter specialization.
constexpr Premultiplied(const float ch1, const float ch2, const float ch3, const float a=1.0f)
Construct a color from premultiplied channel values.
static constexpr auto TYPE_CHARS
The space name, Premultiplied< + Space::TYPE + >.
friend constexpr Premultiplied operator*(const float scalar, const Premultiplied &color) noexcept
Scales every channel of a color, alpha included, as when fading it.
Concept to check if a type is a color.
A color space that convert() can convert ColorIn to: directly through a Converter,...
A color space whose channels are proportional to light, so that adding and scaling them is physically...
constexpr float ch2() const noexcept
constexpr float ch1() const noexcept
constexpr float ch3() const noexcept
constexpr ColorBase(const float alpha, const float channel1, const float channel2, const float channel3)
constexpr float alpha() const noexcept
static constexpr Premultiplied< Space > convert(const Space &color)
Multiplies each color channel of color by its alpha.
static constexpr Space convert(const Premultiplied< Space > &color)
Divides each color channel of color by its alpha.
Converts colors from one color space to another.
Tag naming the color space an operation works in.
Space type
The linear space.
The linear space that operations in linear light, such as mix() and over(), use for a color type when...
Space type
The parent space.
Names the color space a space converts through, joining every space in one tree.