18#define _IMPELLER_ASSERT_BLEND_MODE(blend_mode) \
19 auto enum_##blend_mode = static_cast<std::underlying_type_t<BlendMode>>( \
20 BlendMode::k##blend_mode); \
21 if (i != enum_##blend_mode) { \
27 std::underlying_type_t<BlendMode>
i = 0;
38 "IMPELLER_FOR_EACH_BLEND_MODE must match impeller::BlendMode.");
40#define _IMPELLER_BLEND_MODE_NAME_LIST(blend_mode) #blend_mode,
54 return Color(std::min(
c.red, threshold), std::min(
c.green, threshold),
55 std::min(
c.blue, threshold), std::min(
c.alpha, threshold));
62 return color.
x * 0.3f + color.
y * 0.59f + color.
z * 0.11f;
67 Scalar mn = std::min(std::min(color.
x, color.
y), color.
z);
68 Scalar mx = std::max(std::max(color.
x, color.
y), color.
z);
72 color = lum + (((color - lum) * lum) / (lum - mn +
kEhCloseEnough));
76 lum + (((color - lum) * (1.0f - lum)) / (mx - lum +
kEhCloseEnough));
88 return std::max(std::max(color.
x, color.
y), color.
z) -
89 std::min(std::min(color.
x, color.
y), color.
z);
94 Scalar mn = std::min(std::min(color.
x, color.
y), color.
z);
95 Scalar mx = std::max(std::max(color.
x, color.
y), color.
z);
96 return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) :
Vector3();
104 value.y > cutoff ? b.y : a.
y,
105 value.z > cutoff ? b.z : a.
z
114 return {color.
x, color.
y, color.
z, alpha};
134 return src + dst * (1.0f - src.
alpha);
158 switch (blend_mode) {
208 return s +
d - s *
d;
215 Vector3 screen = screen_src + s - screen_src * s;
235 return std::min(1.0f,
d / (1.0f - s));
245 return 1.0f - std::min(1.0f, (1.0f -
d) / s);
249 Vector3 screen_src = 2.0 * s - 1.0;
250 Vector3 screen = screen_src +
d - screen_src *
d;
264 d + (2.0 * s - 1.0) * (D -
d),
270 return (
d - s).Abs();
274 return d + s - 2.0f *
d * s;
300 auto*
c = color_matrix.
array;
310 static auto conversion = [](
Scalar component) {
311 if (component <= 0.0031308) {
312 return component * 12.92;
314 return 1.055 * pow(component, (1.0 / 2.4)) - 0.055;
321 static auto conversion = [](
Scalar component) {
322 if (component <= 0.04045) {
323 return component / 12.92;
325 return pow((component + 0.055) / 1.055, 2.4);
#define _IMPELLER_ASSERT_BLEND_MODE(blend_mode)
#define _IMPELLER_BLEND_MODE_NAME_LIST(blend_mode)
#define IMPELLER_FOR_EACH_BLEND_MODE(V)
static constexpr const char * kBlendModeNames[]
static constexpr Color Min(Color c, float threshold)
static constexpr bool ValidateBlendModes()
static constexpr Vector3 SetSaturation(Vector3 color, Scalar saturation)
static Color DoColorBlendComponents(Color dst, Color src, const std::function< Scalar(Scalar, Scalar)> &blend_func)
constexpr float kEhCloseEnough
static constexpr Scalar Saturation(Vector3 color)
static constexpr Vector3 ToRGB(Color color)
const char * BlendModeToString(BlendMode blend_mode)
static constexpr Color FromRGB(Vector3 color, Scalar alpha)
static constexpr Vector3 SetLuminosity(Vector3 color, Scalar luminosity)
static constexpr Color ApplyBlendedColor(Color dst, Color src, Vector3 blend_result)
static Color DoColorBlend(Color dst, Color src, const std::function< Vector3(Vector3, Vector3)> &blend_rgb_func)
static constexpr Vector3 ComponentChoose(Vector3 a, Vector3 b, Vector3 value, Scalar cutoff)
static constexpr Vector3 ClipColor(Vector3 color)
static constexpr Scalar Luminosity(Vector3 color)
static constexpr Color BlackTransparent()
Color LinearToSRGB() const
Convert the color from linear space to sRGB space.
Color ApplyColorMatrix(const ColorMatrix &color_matrix) const
A color filter that transforms colors through a 4x5 color matrix.
constexpr Color Unpremultiply() const
constexpr Color Premultiply() const
Color SRGBToLinear() const
Convert the color from sRGB space to linear space.
Color Blend(Color source, BlendMode blend_mode) const
Blends an unpremultiplied destination color into a given unpremultiplied source color to form a new u...
Vector3 Min(const Vector3 &p) const
Vector3 Max(const Vector3 &p) const