1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Blend modes. Restricted to the intersection of Vello and Blend2D.
//!
//! Both backends support the full set of separable and non-separable Mix modes
//! listed here plus the Porter–Duff Compose operators. Blend2D supports a few
//! extras (LinearBurn, PinLight, HardMix, Modulate, etc.) which are
//! intentionally not exposed.
/// Composite operator (Porter–Duff).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Compose {
Clear,
Copy,
Dest,
SrcOver,
DestOver,
SrcIn,
DestIn,
SrcOut,
DestOut,
SrcAtop,
DestAtop,
Xor,
Plus,
}
/// Blend (mix) function applied before the compositor.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Mix {
Normal,
Multiply,
Screen,
Overlay,
Darken,
Lighten,
ColorDodge,
ColorBurn,
HardLight,
SoftLight,
Difference,
Exclusion,
Hue,
Saturation,
Color,
Luminosity,
}
/// A blend mode is a (mix, compose) pair.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BlendMode {
pub mix: Mix,
pub compose: Compose,
}
impl BlendMode {
/// Combine a [`Mix`] function with a [`Compose`] operator.
pub const fn new(mix: Mix, compose: Compose) -> Self {
Self { mix, compose }
}
/// `Mix::Normal` over `Compose::SrcOver` — the default "alpha blend".
pub const NORMAL: Self = Self::new(Mix::Normal, Compose::SrcOver);
}
impl Default for BlendMode {
fn default() -> Self {
Self::NORMAL
}
}