image_overlay/
blend_mode.rs

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