Debian Codegraph @

src/blend/blend_with.rs

raw symbols SCIP
1 use craterust-analyzer cargo palette 0.7.6 crate/::{stimulusrust-analyzer cargo palette 0.7.6 stimulus/::Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#};
2
3 use superrust-analyzer cargo palette 0.7.6 blend/::{BlendFunctionrust-analyzer cargo palette 0.7.6 blend/BlendFunction#, PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#, Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#};
4
5 /// Blending with a custom blend function.
6 ///
7 /// This is a convenience trait that makes it possible to use [`BlendFunction`]
8 /// via a method on the source color. This makes custom blending more similar to
9 /// how the [`Compose`][super::Compose] and [`Blend`][super::Blend] are used,
10 /// including automatic pre-multiplication.
11 pub trait BlendWithrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith# {
12 /// The base color type of `Self`.
13 type Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith#Color#: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#;
14
15 /// Blend self, as the source color, with `destination`, using
16 /// `blend_function`. Anything that implements [`BlendFunction`] is
17 /// acceptable, including functions and closures.
18 ///
19 /// ```
20 /// use palette::{LinSrgb, LinSrgba};
21 /// use palette::blend::{BlendWith, PreAlpha};
22 ///
23 /// type PreRgba = PreAlpha<LinSrgb<f32>>;
24 ///
25 /// fn blend_mode(a: PreRgba, b: PreRgba) -> PreRgba {
26 /// PreAlpha {
27 /// color: LinSrgb::new(a.red * b.green, a.green * b.blue, a.blue * b.red),
28 /// alpha: a.alpha * b.alpha,
29 /// }
30 /// }
31 ///
32 /// let a = LinSrgba::new(0.2, 0.5, 0.1, 0.8);
33 /// let b = LinSrgba::new(0.6, 0.3, 0.5, 0.1);
34 /// let c = a.blend_with(b, blend_mode);
35 /// ```
36 #[must_use]
37 fn blend_withrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith#blend_with().<F>(self, destination: Self, blend_function: F) -> Self
38 where
39 F: BlendFunctionrust-analyzer cargo palette 0.7.6 blend/BlendFunction#<Self::Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith#Color#>;
40 }
41
42 impl<C> BlendWithrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>
43 where
44 C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#,
45 {
46 type Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith]Color# = C;
47
48 #[inline]
49 fn blend_withrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith]blend_with().<F>(self, other: Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith], blend_function: F) -> Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith]
50 where
51 F: BlendFunctionrust-analyzer cargo palette 0.7.6 blend/BlendFunction#<Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith]::Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith#Color#>,
52 {
53 blend_function.apply_torust-analyzer cargo palette 0.7.6 blend/BlendFunction#apply_to().(self, other)
54 }
55 }
56
57 impl<C> BlendWithrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith# for Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#<C, C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#>
58 where
59 C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#,
60 {
61 type Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][BlendWith]Color# = C;
62
63 fn blend_withrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][BlendWith]blend_with().<F>(self, destination: Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][BlendWith], blend_function: F) -> Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][BlendWith]
64 where
65 F: craterust-analyzer cargo palette 0.7.6 crate/::blendrust-analyzer cargo palette 0.7.6 blend/::BlendFunctionrust-analyzer cargo palette 0.7.6 blend/BlendFunction#<Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][BlendWith]::Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith#Color#>,
66 {
67 self.premultiplyrust-analyzer cargo palette 0.7.6 alpha/alpha/impl#[`Alpha<C, <C as Premultiply>::Scalar>`]premultiply().()
68 .blend_withrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith]blend_with().(destination.premultiplyrust-analyzer cargo palette 0.7.6 alpha/alpha/impl#[`Alpha<C, <C as Premultiply>::Scalar>`]premultiply().(), blend_function)
69 .unpremultiplyrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]unpremultiply().()
70 }
71 }
72
73 impl<C> BlendWithrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith# for C
74 where
75 C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#,
76 C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#,
77 {
78 type Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[C][BlendWith]Color# = C;
79
80 fn blend_withrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[C][BlendWith]blend_with().<F>(self, other: Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[C][BlendWith], blend_function: F) -> Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[C][BlendWith]
81 where
82 F: BlendFunctionrust-analyzer cargo palette 0.7.6 blend/BlendFunction#<Selfrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[C][BlendWith]::Colorrust-analyzer cargo palette 0.7.6 blend/blend_with/BlendWith#Color#>,
83 {
84 PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#::new_opaquerust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]new_opaque().(self)
85 .blend_withrust-analyzer cargo palette 0.7.6 blend/blend_with/impl#[`PreAlpha<C>`][BlendWith]blend_with().(PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#::new_opaquerust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]new_opaque().(other), blend_function)
86 .unpremultiplyrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]unpremultiply().()
87 .colorrust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#color.
88 }
89 }