 |
Flutter Impeller
|
|
Go to the documentation of this file.
11 #include <type_traits>
20 #define _IMPELLER_ASSERT_BLEND_MODE(blend_mode) \
21 auto enum_##blend_mode = static_cast<std::underlying_type_t<BlendMode>>( \
22 BlendMode::k##blend_mode); \
23 if (i != enum_##blend_mode) { \
29 std::underlying_type_t<BlendMode> i = 0;
40 "IMPELLER_FOR_EACH_BLEND_MODE must match impeller::BlendMode.");
42 #define _IMPELLER_BLEND_MODE_NAME_LIST(blend_mode) #blend_mode,
73 f = (R == x) ? G - B : ((G == x) ? B - R : R - G);
74 i = (R == x) ? 3 : ((G == x) ? 5 : 1);
76 return ColorHSB(((i - f / (v - x)) / 6.0), (v - x) / v, v, rgb.
alpha);
98 i =
static_cast<int64_t
>(floor(h));
130 : red(value.x), green(value.y), blue(value.z), alpha(value.w) {}
133 return Color(std::min(c.
red, threshold), std::min(c.
green, threshold),
134 std::min(c.
blue, threshold), std::min(c.
alpha, threshold));
141 return color.
x * 0.3f + color.
y * 0.59f + color.
z * 0.11f;
146 Scalar mn = std::min(std::min(color.
x, color.
y), color.
z);
147 Scalar mx = std::max(std::max(color.
x, color.
y), color.
z);
151 color = lum + (((color - lum) * lum) / (lum - mn +
kEhCloseEnough));
155 lum + (((color - lum) * (1.0f - lum)) / (mx - lum +
kEhCloseEnough));
167 return std::max(std::max(color.
x, color.
y), color.
z) -
168 std::min(std::min(color.
x, color.
y), color.
z);
173 Scalar mn = std::min(std::min(color.
x, color.
y), color.
z);
174 Scalar mx = std::max(std::max(color.
x, color.
y), color.
z);
175 return (mn < mx) ? ((color - mn) * saturation) / (mx - mn) :
Vector3();
183 value.
y > cutoff ? b.
y : a.
y,
184 value.
z > cutoff ? b.
z : a.
z
193 return {color.
x, color.
y, color.
z, alpha};
225 switch (blend_mode) {
275 return s + d - s * d;
281 Vector3 screen_src = 2.0 * d - 1.0;
282 Vector3 screen = screen_src + s - screen_src * s;
302 return std::min(1.0f, d / (1.0f - s));
312 return 1.0f - std::min(1.0f, (1.0f - d) / s);
316 Vector3 screen_src = 2.0 * s - 1.0;
317 Vector3 screen = screen_src + d - screen_src * d;
331 d + (2.0 * s - 1.0) * (D - d),
337 return (d - s).Abs();
341 return d + s - 2.0f * d * s;
367 auto* c = color_matrix.
array;
377 static auto conversion = [](
Scalar component) {
378 if (component <= 0.0031308) {
379 return component * 12.92;
381 return 1.055 * pow(component, (1.0 / 2.4)) - 0.055;
388 static auto conversion = [](
Scalar component) {
389 if (component <= 0.04045) {
390 return component / 12.92;
392 return pow((component + 0.055) / 1.055, 2.4);
399 return SPrintF(
"R=%.1f,G=%.1f,B=%.1f,A=%.1f",
const char * BlendModeToString(BlendMode blend_mode)
std::string ColorToString(const Color &color)
static constexpr Vector3 ComponentChoose(Vector3 a, Vector3 b, Vector3 value, Scalar cutoff)
constexpr Color Unpremultiply() const
constexpr float kEhCloseEnough
static constexpr bool ValidateBlendModes()
static constexpr Color Min(Color c, float threshold)
std::string SPrintF(const char *format,...)
Color SRGBToLinear() const
Convert the color from sRGB space to linear space.
static constexpr Vector3 SetSaturation(Vector3 color, Scalar saturation)
static constexpr Vector3 SetLuminosity(Vector3 color, Scalar luminosity)
static constexpr Color DoColorBlendComponents(Color d, Color s, const std::function< Scalar(Scalar, Scalar)> &blend_func)
static constexpr Scalar Luminosity(Vector3 color)
static ColorHSB FromRGB(Color rgb)
#define IMPELLER_FOR_EACH_BLEND_MODE(V)
static constexpr Color DoColorBlend(Color d, Color s, const std::function< Vector3(Vector3, Vector3)> &blend_rgb_func)
#define _IMPELLER_ASSERT_BLEND_MODE(blend_mode)
static constexpr Vector3 ClipColor(Vector3 color)
constexpr ColorHSB(Scalar h, Scalar s, Scalar b, Scalar a)
static constexpr Color BlackTransparent()
constexpr Vector3 Min(const Vector3 &p) const
static constexpr Color FromRGB(Vector3 color, Scalar alpha)
static constexpr const char * kBlendModeNames[]
constexpr static Color Lerp(Color a, Color b, Scalar t)
Return a color that is linearly interpolated between colors a and b, according to the value of t.
Color ApplyColorMatrix(const ColorMatrix &color_matrix) const
A color filter that transforms colors through a 4x5 color matrix.
Color LinearToSRGB() const
Convert the color from linear space to sRGB space.
constexpr Color Premultiply() const
static constexpr Scalar Saturation(Vector3 color)
constexpr Vector3 Max(const Vector3 &p) const
static constexpr Vector3 ToRGB(Color color)
#define _IMPELLER_BLEND_MODE_NAME_LIST(blend_mode)
Color Blend(Color source, BlendMode blend_mode) const
Blends an unpremultiplied destination color into a given unpremultiplied source color to form a new u...