image_overlay/
blend_mode.rs

1use std::fmt;
2
3
4/// Algorithm for blending pixels.  
5/// 
6/// If you need `BlendMode::Dissolve`, please enable "blend_dissolve" feature.
7/// 
8/// If you need serde::Serialize/Deserialize, please enable "serde" feature.
9/// 
10/// # References
11/// [Adobe Photoshop Blending Modes Documentation](https://helpx.adobe.com/en/photoshop/using/blending-modes.html)  
12/// 
13/// # Disclaimer
14/// * This is NOT a faithful reproduction.
15/// * This is NOT affiliated with or endorsed by Adobe Inc.  
16/// * Adobe and Photoshop are either registered trademarks or trademarks of Adobe in the United States and/or other countries.
17#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub enum BlendMode {
20    #[default]
21    Normal,
22
23    #[cfg(feature = "blend_dissolve")]
24    Dissolve,
25    
26    Darken,
27    Multiply,
28    ColorBurn,
29    LinearBurn,
30    DarkerColor,
31    
32    Lighten,
33    Screen,
34    ColorDodge,
35    LinearDodge,
36    LighterColor,
37    
38    Overlay,
39    SoftLight,
40    HardLight,
41    VividLight,
42    LinearLight,
43    PinLight,
44    HardMix,
45    
46    Difference,
47    Exclusion,
48    Subtract,
49    Divide,
50    
51    Hue,
52    Saturation,
53    Color,
54    Luminosity,
55}
56
57impl fmt::Display for BlendMode {
58    
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        let mode_str = match self {
61            BlendMode::Normal => "Normal",
62            
63            #[cfg(feature = "blend_dissolve")]
64            BlendMode::Dissolve => "Dissolve",
65
66            BlendMode::Darken => "Darken",
67            BlendMode::Multiply => "Multiply",
68            BlendMode::ColorBurn => "ColorBurn",
69            BlendMode::LinearBurn => "LinearBurn",
70            BlendMode::DarkerColor => "DarkerColor",
71            BlendMode::Lighten => "Lighten",
72            BlendMode::Screen => "Screen",
73            BlendMode::ColorDodge => "ColorDodge",
74            BlendMode::LinearDodge => "LinearDodge",
75            BlendMode::LighterColor => "LighterColor",
76            BlendMode::Overlay => "Overlay",
77            BlendMode::SoftLight => "SoftLight",
78            BlendMode::HardLight => "HardLight",
79            BlendMode::VividLight => "VividLight",
80            BlendMode::LinearLight => "LinearLight",
81            BlendMode::PinLight => "PinLight",
82            BlendMode::HardMix => "HardMix",
83            BlendMode::Difference => "Difference",
84            BlendMode::Exclusion => "Exclusion",
85            BlendMode::Subtract => "Subtract",
86            BlendMode::Divide => "Divide",
87            BlendMode::Hue => "Hue",
88            BlendMode::Saturation => "Saturation",
89            BlendMode::Color => "Color",
90            BlendMode::Luminosity => "Luminosity",
91        };
92        write!(f, "{}", mode_str)
93    }
94}