Skip to content

Commit c2f2d33

Browse files
committed
add doc for BlendMode
1 parent 5d173c7 commit c2f2d33

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

src/color/model.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,85 @@ extern crate alloc;
1313

1414
use crate::color::ColorFloat;
1515

16+
/// An enum naming the supported color blending modes.
17+
/// Most descriptions and implementations of these blend modes
18+
/// come from the W3C: https://www.w3.org/TR/compositing-1/.
19+
///
20+
/// # Variants
21+
///
22+
/// - `Normal` - No blending. The blending formula simply selects the source color.
23+
///
24+
/// - `Multiply` - The source color is multiplied by the destination color and replaces
25+
/// the destination.
26+
/// The resultant color is always at least as dark as either the
27+
/// source or destination color.
28+
/// Multiplying any color with black results in black;
29+
/// multiplying any color with white preserves the original color.
30+
///
31+
/// - `Screen` - Multiplies the complements of the backdrop and source color values,
32+
/// then complements the result.
33+
/// The result color is always at least as light as
34+
/// either of the two constituent colors.
35+
/// Screening any color with white produces white;
36+
/// screening with black leaves the original color unchanged.
37+
/// The effect is similar to projecting multiple photographic slides simultaneously
38+
/// onto a single screen.
39+
///
40+
/// - `Overlay` - Multiplies or screens the colors, depending on the backdrop color
41+
/// value.
42+
/// Source colors overlay the backdrop while preserving its highlights and shadows.
43+
/// The backdrop color is not replaced but is mixed with the source color to reflect
44+
/// the lightness or darkness of the backdrop.
45+
/// Overlay is the inverse of the HardLight blend mode.
46+
///
47+
/// - `Darken` - Selects the darker of the backdrop and source colors.
48+
/// The backdrop is replaced with the source where the source is darker;
49+
/// otherwise, it is left unchanged.
50+
///
51+
/// - `Lighten` - Selects the lighter of the backdrop and source colors.
52+
/// The backdrop is replaced with the source where the source is lighter;
53+
/// otherwise, it is left unchanged.
54+
/// The result must be rounded down if it exceeds the range.
55+
///
56+
/// - `ColorDodge` - Brightens the backdrop color to reflect the source color.
57+
/// Painting with black produces no changes.
58+
///
59+
/// - `ColorBurn` - Darkens the backdrop color to reflect the source color.
60+
/// Painting with white produces no change.
61+
///
62+
/// - `HardLight` - Multiplies or screens the colors, depending on the source color
63+
/// value.
64+
/// The effect is similar to shining a harsh spotlight on the backdrop.
65+
///
66+
/// - `SoftLight` - Darkens or lightens the colors, depending on the source color value.
67+
/// The effect is similar to shining a diffused spotlight on the backdrop.
68+
///
69+
/// - `Difference` - Subtracts the darker of the two constituent colors from the lighter
70+
/// color.
71+
/// Painting with white inverts the backdrop color;
72+
/// painting with black produces no change.
73+
///
74+
/// - `Exclusion` - Produces an effect similar to that of the Difference mode but lower
75+
/// in contrast.
76+
/// Painting with white inverts the backdrop color;
77+
/// painting with black produces no change.
78+
///
79+
/// - `Hue` - Creates a color with the hue of the source color and the saturation and
80+
/// luminosity of the backdrop color.
81+
///
82+
/// - `Saturation` - Creates a color with the saturation of the source color and the hue
83+
/// and luminosity of the backdrop color.
84+
/// Painting with this mode in an area of the backdrop that is a pure gray
85+
/// (no saturation) produces no change.
86+
///
87+
/// - `Color` - Creates a color with the hue and saturation of the source color and the
88+
/// luminosity of the backdrop color.
89+
/// This preserves the gray levels of the backdrop and is useful for coloring
90+
/// monochrome images or tinting color images.
91+
///
92+
/// - `Luminosity` - Creates a color with the luminosity of the source color and the hue
93+
/// and saturation of the backdrop color.
94+
/// This produces an inverse effect to that of the Color mode.
1695
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1796
pub enum BlendMode {
1897
// separable blend modes

0 commit comments

Comments
 (0)