ff_filter/blend.rs
1//! Blend mode definitions for video compositing operations.
2
3// BlendMode
4
5/// Specifies how two video layers are combined during compositing.
6///
7/// Each variant corresponds **1:1** to a mode of `FFmpeg`'s `blend` filter
8/// `all_mode` option (40 modes total, matching `vf_blend.c`). [`BlendMode::Normal`]
9/// is the standard alpha-over composite, built via the `overlay` filter; every
10/// other variant is built via `blend all_mode=<token>`. The canonical token for
11/// each variant is provided by `FfmpegToken` (all variants map to a valid token).
12///
13/// For **Porter-Duff alpha compositing** (over / under / in / out / atop / xor)
14/// use [`CompositeOp`](crate::CompositeOp) instead — that is a separate concept
15/// (alpha channel operators, not pixel-value blend modes). Note `BlendMode::Xor`
16/// is the *arithmetic* `xor` blend, distinct from `CompositeOp::Xor`.
17// Open catalog: mirrors `FFmpeg`'s `blend all_mode` set, which can grow.
18#[non_exhaustive]
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21pub enum BlendMode {
22 // Standard modes
23 /// Standard alpha-over composite (`top * opacity + bottom * (1 − opacity)`).
24 /// Built via `overlay=format=auto:shortest=1` (token: `normal`).
25 Normal,
26 /// Multiply per-channel pixel values; darkens. `blend all_mode=multiply`.
27 Multiply,
28 /// Inverse of multiply; lightens. `blend all_mode=screen`.
29 Screen,
30 /// Multiply/Screen by base luminance. `blend all_mode=overlay`.
31 Overlay,
32 /// Gentle contrast enhancement. `blend all_mode=softlight`.
33 SoftLight,
34 /// Harsher Overlay driven by the top layer. `blend all_mode=hardlight`.
35 HardLight,
36 /// Brightens the base. `blend all_mode=dodge`.
37 ColorDodge,
38 /// Darkens the base. `blend all_mode=burn`.
39 ColorBurn,
40 /// Keeps the darker pixel per channel. `blend all_mode=darken`.
41 Darken,
42 /// Keeps the lighter pixel per channel. `blend all_mode=lighten`.
43 Lighten,
44 /// Per-channel absolute difference. `blend all_mode=difference`.
45 Difference,
46 /// Lower-contrast Difference. `blend all_mode=exclusion`.
47 Exclusion,
48 /// Linear addition, clamped. `blend all_mode=addition`.
49 Add,
50 /// Linear subtraction, clamped. `blend all_mode=subtract`.
51 Subtract,
52
53 // Additional FFmpeg blend modes
54 /// Bitwise AND of the two pixels. `blend all_mode=and`.
55 And,
56 /// Arithmetic mean of the two pixels. `blend all_mode=average`.
57 Average,
58 /// Bleach-bypass look. `blend all_mode=bleach`.
59 Bleach,
60 /// Per-channel division. `blend all_mode=divide`.
61 Divide,
62 /// Extremity (distance from mid-grey). `blend all_mode=extremity`.
63 Extremity,
64 /// Freeze. `blend all_mode=freeze`.
65 Freeze,
66 /// Geometric mean. `blend all_mode=geometric`.
67 Geometric,
68 /// Glow. `blend all_mode=glow`.
69 Glow,
70 /// Grain extract (alias of `difference128`). `blend all_mode=grainextract`.
71 GrainExtract,
72 /// Grain merge (alias of `addition128`). `blend all_mode=grainmerge`.
73 GrainMerge,
74 /// Hard mix. `blend all_mode=hardmix`.
75 HardMix,
76 /// Hard overlay. `blend all_mode=hardoverlay`.
77 HardOverlay,
78 /// Harmonic mean. `blend all_mode=harmonic`.
79 Harmonic,
80 /// Heat. `blend all_mode=heat`.
81 Heat,
82 /// Linear interpolation. `blend all_mode=interpolate`.
83 Interpolate,
84 /// Linear light. `blend all_mode=linearlight`.
85 LinearLight,
86 /// Multiply scaled by 128. `blend all_mode=multiply128`.
87 Multiply128,
88 /// Negation. `blend all_mode=negation`.
89 Negation,
90 /// Bitwise OR of the two pixels. `blend all_mode=or`.
91 Or,
92 /// Phoenix. `blend all_mode=phoenix`.
93 Phoenix,
94 /// Pin light. `blend all_mode=pinlight`.
95 PinLight,
96 /// Reflect. `blend all_mode=reflect`.
97 Reflect,
98 /// Soft difference. `blend all_mode=softdifference`.
99 SoftDifference,
100 /// Stain. `blend all_mode=stain`.
101 Stain,
102 /// Vivid light. `blend all_mode=vividlight`.
103 VividLight,
104 /// Arithmetic XOR of the two pixels. `blend all_mode=xor`.
105 /// Distinct from the Porter-Duff [`CompositeOp::Xor`](crate::CompositeOp).
106 Xor,
107}