| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#, AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#, Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#, Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#, DivAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/DivAssign#, Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#, MulAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/MulAssign#, Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#, SubAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#}; |
| 2 | |
| 3 | #[cfg(feature = "approx")] |
| 4 | use approxrust-analyzer cargo approx 0.5.1 crate/::{AbsDiffEqrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#, RelativeEqrust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq#, UlpsEqrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq#}; |
| 5 | |
| 6 | use craterust-analyzer cargo palette 0.7.6 crate/::{ |
| 7 | castrust-analyzer cargo palette 0.7.6 cast/::ArrayCastrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast#, |
| 8 | clamprust-analyzer cargo palette 0.7.6 clamp()., |
| 9 | numrust-analyzer cargo palette 0.7.6 num/::{selfrust-analyzer cargo palette 0.7.6 num/, Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#, Onerust-analyzer cargo palette 0.7.6 num/One#, Realrust-analyzer cargo palette 0.7.6 num/Real#, Zerorust-analyzer cargo palette 0.7.6 num/Zero#}, |
| 10 | stimulusrust-analyzer cargo palette 0.7.6 stimulus/::Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, |
| 11 | Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#, ArrayExtrust-analyzer cargo palette 0.7.6 ArrayExt#, Mixrust-analyzer cargo palette 0.7.6 Mix#, MixAssignrust-analyzer cargo palette 0.7.6 MixAssign#, NextArrayrust-analyzer cargo palette 0.7.6 NextArray#, |
| 12 | }; |
| 13 | |
| 14 | use superrust-analyzer cargo palette 0.7.6 blend/::Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#; |
| 15 | |
| 16 | /// Premultiplied alpha wrapper. |
| 17 | /// |
| 18 | /// Premultiplied, or alpha masked, or associated alpha colors have had their |
| 19 | /// component values multiplied with their alpha value. They are commonly used |
| 20 | /// in composition algorithms and as output from computer generated graphics. It |
| 21 | /// may also be preferred when interpolating between colors and in other image |
| 22 | /// manipulation operations, such as blurring or resizing images. |
| 23 | /// |
| 24 | /// ``` |
| 25 | /// use palette::{LinSrgb, LinSrgba}; |
| 26 | /// use palette::blend::{Blend, PreAlpha}; |
| 27 | /// |
| 28 | /// let a = PreAlpha::from(LinSrgba::new(0.4, 0.5, 0.5, 0.3)); |
| 29 | /// let b = PreAlpha::from(LinSrgba::new(0.3, 0.8, 0.4, 0.4)); |
| 30 | /// let c = PreAlpha::from(LinSrgba::new(0.7, 0.1, 0.8, 0.8)); |
| 31 | /// |
| 32 | /// let res: LinSrgba = a.screen(b).overlay(c).into(); |
| 33 | /// ``` |
| 34 | /// |
| 35 | /// Note that converting to and from premultiplied alpha will cause the alpha |
| 36 | /// component to be clamped to [0.0, 1.0], and fully transparent colors will |
| 37 | /// become black. |
| 38 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 39 | #[repr(C)] |
| 40 | pub struct PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#> { |
| 41 | /// The premultiplied color components (`original.color * original.alpha`). |
| 42 | pub colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color.: C, |
| 43 | |
| 44 | /// The transparency component. 0.0 is fully transparent and 1.0 is fully |
| 45 | /// opaque. |
| 46 | pub alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha.: C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#, |
| 47 | } |
| 48 | |
| 49 | impl<C> PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 50 | where |
| 51 | C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 52 | { |
| 53 | /// Alpha mask `color` with `alpha`. |
| 54 | pub fn newrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]new().(color: C, alpha: C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#) -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`] { |
| 55 | color.premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#premultiply().(alpha) |
| 56 | } |
| 57 | |
| 58 | /// Create an opaque alpha masked color. |
| 59 | pub fn new_opaquerust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]new_opaque().(color: C) -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`] |
| 60 | where |
| 61 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, |
| 62 | { |
| 63 | Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`] { |
| 64 | colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., |
| 65 | alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha.: C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().(), |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /// Alpha unmask the color. |
| 70 | pub fn unpremultiplyrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`]unpremultiply().(self) -> Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#<C, C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#> { |
| 71 | let (color, alpha) = C::unpremultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#unpremultiply().(self); |
| 72 | Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha# { colorrust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#color., alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#alpha. } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl<C> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 77 | where |
| 78 | C: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 79 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#, |
| 80 | { |
| 81 | fn eqrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`PartialEq<Self>`]) -> bool { |
| 82 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().other.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color. && self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().other.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | impl<C> Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 87 | where |
| 88 | C: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 89 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq#, |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | impl<C> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#<C, C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#>> for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 94 | where |
| 95 | C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 96 | { |
| 97 | #[inline] |
| 98 | fn fromrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`From<Alpha<C, <C as Premultiply>::Scalar>>`]from().(color: Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#<C, C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#>) -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`From<Alpha<C, <C as Premultiply>::Scalar>>`] { |
| 99 | color.colorrust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#color..premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#premultiply().(color.alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#alpha.) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | impl<C> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>> for Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#<C, C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#> |
| 104 | where |
| 105 | C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 106 | { |
| 107 | #[inline] |
| 108 | fn fromrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][`From<PreAlpha<C>>`]from().(color: PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>) -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`Alpha<C, <C as Premultiply>::Scalar>`][`From<PreAlpha<C>>`] { |
| 109 | let (color, alpha) = C::unpremultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#unpremultiply().(color); |
| 110 | Alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha# { colorrust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#color., alpharust-analyzer cargo palette 0.7.6 alpha/alpha/Alpha#alpha. } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | impl<C> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<C> for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 115 | where |
| 116 | C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 117 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, |
| 118 | { |
| 119 | fn fromrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`From<C>`]from().(color: C) -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`From<C>`] { |
| 120 | color.premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#premultiply().(C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().()) |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | impl<C, T> Mixrust-analyzer cargo palette 0.7.6 Mix# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 125 | where |
| 126 | C: Mixrust-analyzer cargo palette 0.7.6 Mix#<Scalarrust-analyzer cargo palette 0.7.6 Mix#Scalar# = T> + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#<Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar# = T>, |
| 127 | T: Realrust-analyzer cargo palette 0.7.6 num/Real# + Zerorust-analyzer cargo palette 0.7.6 num/Zero# + Onerust-analyzer cargo palette 0.7.6 num/One# + numrust-analyzer cargo palette 0.7.6 num/::Clamprust-analyzer cargo palette 0.7.6 num/Clamp# + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 128 | { |
| 129 | type Scalarrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Mix]Scalar# = T; |
| 130 | |
| 131 | #[inline] |
| 132 | fn mixrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Mix]mix().(mut self, other: Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Mix], factor: T) -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Mix] { |
| 133 | let factor = clamprust-analyzer cargo palette 0.7.6 clamp().(factor, T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), T::onerust-analyzer cargo palette 0.7.6 num/One#one().()); |
| 134 | |
| 135 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color. = self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color..mixrust-analyzer cargo palette 0.7.6 Mix#mix().(other.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., factor.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 136 | self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. = self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().factor rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().(other.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha.); |
| 137 | |
| 138 | self |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | impl<C, T> MixAssignrust-analyzer cargo palette 0.7.6 MixAssign# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 143 | where |
| 144 | C: MixAssignrust-analyzer cargo palette 0.7.6 MixAssign#<Scalarrust-analyzer cargo palette 0.7.6 MixAssign#Scalar# = T> + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#<Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar# = T>, |
| 145 | T: Realrust-analyzer cargo palette 0.7.6 num/Real# + Zerorust-analyzer cargo palette 0.7.6 num/Zero# + Onerust-analyzer cargo palette 0.7.6 num/One# + numrust-analyzer cargo palette 0.7.6 num/::Clamprust-analyzer cargo palette 0.7.6 num/Clamp# + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics# + AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 146 | { |
| 147 | type Scalarrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][MixAssign]Scalar# = T; |
| 148 | |
| 149 | #[inline] |
| 150 | fn mix_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][MixAssign]mix_assign().(&mut self, other: Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][MixAssign], factor: T) { |
| 151 | let factor = clamprust-analyzer cargo palette 0.7.6 clamp().(factor, T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), T::onerust-analyzer cargo palette 0.7.6 num/One#one().()); |
| 152 | |
| 153 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color..mix_assignrust-analyzer cargo palette 0.7.6 MixAssign#mix_assign().(other.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., factor.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 154 | self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().factor rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().(other.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | unsafe impl<C, T> ArrayCastrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 159 | where |
| 160 | C: ArrayCastrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast# + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#<Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar# = T>, |
| 161 | C::Arrayrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast#Array#: NextArrayrust-analyzer cargo palette 0.7.6 NextArray# + ArrayExtrust-analyzer cargo palette 0.7.6 ArrayExt#<Itemrust-analyzer cargo palette 0.7.6 ArrayExt#Item# = T>, |
| 162 | { |
| 163 | type Arrayrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][ArrayCast]Array# = <C::Arrayrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast#Array# as NextArrayrust-analyzer cargo palette 0.7.6 NextArray#>::Nextrust-analyzer cargo palette 0.7.6 NextArray#Next#; |
| 164 | } |
| 165 | |
| 166 | impl<C> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 167 | where |
| 168 | C: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 169 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, |
| 170 | { |
| 171 | fn defaultrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Default]default().() -> PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> { |
| 172 | PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha# { |
| 173 | colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color.: C::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(), |
| 174 | alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha.: C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().(), |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | #[cfg(feature = "approx")] |
| 180 | impl<C, T> AbsDiffEqrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 181 | where |
| 182 | C: AbsDiffEqrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#<Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon# = T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#> + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#<Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar# = T>, |
| 183 | T: AbsDiffEqrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#, |
| 184 | T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 185 | { |
| 186 | type Epsilonrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AbsDiffEq<Self>`]Epsilon# = T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#; |
| 187 | |
| 188 | fn default_epsilonrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AbsDiffEq<Self>`]default_epsilon().() -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AbsDiffEq<Self>`]::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon# { |
| 189 | T::default_epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#default_epsilon().() |
| 190 | } |
| 191 | |
| 192 | fn abs_diff_eqrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AbsDiffEq<Self>`]abs_diff_eq().(&self, other: &PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>, epsilon: Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AbsDiffEq<Self>`]::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#) -> bool { |
| 193 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color..abs_diff_eqrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#abs_diff_eq().(&other.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., epsilon.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 194 | && self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha..abs_diff_eqrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#abs_diff_eq().(&other.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha., epsilon) |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | #[cfg(feature = "approx")] |
| 199 | impl<C, T> RelativeEqrust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 200 | where |
| 201 | C: RelativeEqrust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq#<Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon# = T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#> + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#<Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar# = T>, |
| 202 | T: RelativeEqrust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq#, |
| 203 | T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 204 | { |
| 205 | fn default_max_relativerust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`RelativeEq<Self>`]default_max_relative().() -> Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`RelativeEq<Self>`]::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon# { |
| 206 | T::default_max_relativerust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq#default_max_relative().() |
| 207 | } |
| 208 | |
| 209 | fn relative_eqrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`RelativeEq<Self>`]relative_eq().( |
| 210 | &self, |
| 211 | other: &PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>, |
| 212 | epsilon: Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`RelativeEq<Self>`]::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#, |
| 213 | max_relative: Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`RelativeEq<Self>`]::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#, |
| 214 | ) -> bool { |
| 215 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color. |
| 216 | .relative_eqrust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq#relative_eq().(&other.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., epsilon.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), max_relative.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()) |
| 217 | && self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha..relative_eqrust-analyzer cargo approx 0.5.1 relative_eq/RelativeEq#relative_eq().(&other.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha., epsilon, max_relative) |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | #[cfg(feature = "approx")] |
| 222 | impl<C, T> UlpsEqrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 223 | where |
| 224 | C: UlpsEqrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq#<Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon# = T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#> + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#<Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar# = T>, |
| 225 | T: UlpsEqrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq#, |
| 226 | T::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 227 | { |
| 228 | fn default_max_ulpsrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`UlpsEq<Self>`]default_max_ulps().() -> u32 { |
| 229 | T::default_max_ulpsrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq#default_max_ulps().() |
| 230 | } |
| 231 | |
| 232 | fn ulps_eqrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`UlpsEq<Self>`]ulps_eq().(&self, other: &PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>, epsilon: Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`UlpsEq<Self>`]::Epsilonrust-analyzer cargo approx 0.5.1 abs_diff_eq/AbsDiffEq#Epsilon#, max_ulps: u32) -> bool { |
| 233 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color..ulps_eqrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq#ulps_eq().(&other.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., epsilon.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), max_ulps) |
| 234 | && self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha..ulps_eqrust-analyzer cargo approx 0.5.1 ulps_eq/UlpsEq#ulps_eq().(&other.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha., epsilon, max_ulps) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | macro_rules! impl_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_binop! { |
| 239 | ( |
| 240 | $op_trait:ident::$op_trait_fn:ident, |
| 241 | $op_assign_trait:ident::$op_assign_trait_fn:ident |
| 242 | ) => { |
| 243 | impl<C> $op_trait for PreAlpha<C> |
| 244 | where |
| 245 | C: $op_trait<Output = C> + Premultiply, |
| 246 | C::Scalar: $op_trait<Output = C::Scalar>, |
| 247 | { |
| 248 | type Output = PreAlpha<C>; |
| 249 | |
| 250 | fn $op_trait_fn(self, other: PreAlpha<C>) -> Self::Output { |
| 251 | PreAlpha { |
| 252 | color: self.color.$op_trait_fn(other.color), |
| 253 | alpha: self.alpha.$op_trait_fn(other.alpha), |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | impl<C> $op_assign_trait for PreAlpha<C> |
| 259 | where |
| 260 | C: $op_assign_trait + Premultiply, |
| 261 | C::Scalar: $op_assign_trait + Real, |
| 262 | { |
| 263 | fn $op_assign_trait_fn(&mut self, other: PreAlpha<C>) { |
| 264 | self.color.$op_assign_trait_fn(other.color); |
| 265 | self.alpha.$op_assign_trait_fn(other.alpha); |
| 266 | } |
| 267 | } |
| 268 | }; |
| 269 | } |
| 270 | |
| 271 | impl_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_binop!!(Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#::addrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Add<Self>`]add()., AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#::add_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AddAssign<Self>`]add_assign().); |
| 272 | impl_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_binop!!(Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#::subrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Sub<Self>`]sub()., SubAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#::sub_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`SubAssign<Self>`]sub_assign().); |
| 273 | impl_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_binop!!(Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#::mulrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Mul<Self>`]mul()., MulAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/MulAssign#::mul_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`MulAssign<Self>`]mul_assign().); |
| 274 | impl_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_binop!!(Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#::divrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Div<Self>`]div()., DivAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/DivAssign#::div_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`DivAssign<Self>`]div_assign().); |
| 275 | |
| 276 | macro_rules! impl_scalar_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_scalar_binop! { |
| 277 | ( |
| 278 | $op_trait:ident::$op_trait_fn:ident, |
| 279 | $op_assign_trait:ident::$op_assign_trait_fn:ident, |
| 280 | [$($ty:ident),+] |
| 281 | ) => { |
| 282 | $( |
| 283 | impl<C> $op_trait<$ty> for PreAlpha<C> |
| 284 | where |
| 285 | C: $op_trait<$ty, Output = C> + Premultiply<Scalar = $ty>, |
| 286 | { |
| 287 | type Output = PreAlpha<C>; |
| 288 | |
| 289 | fn $op_trait_fn(self, c: $ty) -> Self::Output { |
| 290 | PreAlpha { |
| 291 | color: self.color.$op_trait_fn(c), |
| 292 | alpha: self.alpha.$op_trait_fn(c), |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // // Disabled as work-around for https://github.com/Ogeon/palette/issues/283 |
| 298 | // // Blocked by https://github.com/rust-lang/rust/issues/80542 |
| 299 | // impl<C> $op_trait<PreAlpha<C>> for $ty |
| 300 | // where |
| 301 | // C: Premultiply<Scalar = $ty>, |
| 302 | // $ty: $op_trait<$ty, Output = $ty> + $op_trait<C, Output = C>, |
| 303 | // { |
| 304 | // type Output = PreAlpha<C>; |
| 305 | // |
| 306 | // fn $op_trait_fn(self, color: PreAlpha<C>) -> Self::Output { |
| 307 | // PreAlpha { |
| 308 | // color: $op_trait::<C>::$op_trait_fn(self, color.color), |
| 309 | // alpha: $op_trait::<$ty>::$op_trait_fn(self, color.alpha), |
| 310 | // } |
| 311 | // } |
| 312 | // } |
| 313 | |
| 314 | impl<C> $op_assign_trait<$ty> for PreAlpha<C> |
| 315 | where |
| 316 | C: $op_assign_trait<$ty> + Premultiply<Scalar = $ty>, |
| 317 | { |
| 318 | fn $op_assign_trait_fn(&mut self, c: $ty) { |
| 319 | self.color.$op_assign_trait_fn(c); |
| 320 | self.alpha.$op_assign_trait_fn(c); |
| 321 | } |
| 322 | } |
| 323 | )+ |
| 324 | }; |
| 325 | } |
| 326 | |
| 327 | impl_scalar_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_scalar_binop!!(Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#::addrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Add<f32>`]add()., AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#::add_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`AddAssign<f32>`]add_assign()., [f32, f64]); |
| 328 | impl_scalar_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_scalar_binop!!(Subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#::subrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Sub<f32>`]sub()., SubAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/SubAssign#::sub_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`SubAssign<f32>`]sub_assign()., [f32, f64]); |
| 329 | impl_scalar_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_scalar_binop!!(Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#::mulrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Mul<f32>`]mul()., MulAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/MulAssign#::mul_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`MulAssign<f32>`]mul_assign()., [f32, f64]); |
| 330 | impl_scalar_binoprust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl_scalar_binop!!(Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#::divrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Div<f32>`]div()., DivAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/DivAssign#::div_assignrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`DivAssign<f32>`]div_assign()., [f32, f64]); |
| 331 | |
| 332 | impl_array_castsrust-analyzer cargo palette 0.7.6 macros/casting/impl_array_casts!!([C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, const N: usize] PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>, [C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#; N], where PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C>: ArrayCastrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast#<Arrayrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast#Array# = [C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#; N]>); |
| 333 | |
| 334 | impl<C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> { |
| 335 | type Targetrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Deref]Target# = C; |
| 336 | |
| 337 | fn derefrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Deref]deref().(&self) -> &C { |
| 338 | &self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color. |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | impl<C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#> DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> { |
| 343 | fn deref_mutrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][DerefMut]deref_mut().(&mut self) -> &mut C { |
| 344 | &mut self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color. |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | #[cfg(feature = "serializing")] |
| 349 | impl<C> serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 350 | where |
| 351 | C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply# + serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 352 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: serderust-analyzer cargo serde 1.0.229 crate/::Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 353 | { |
| 354 | fn serializerust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][Serialize]serialize().<S>(&self, serializer: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<S::Okrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Ok#, S::Errorrust-analyzer cargo serde_core 1.0.229 ser/Serializer#Error#> |
| 355 | where |
| 356 | S: serderust-analyzer cargo serde 1.0.229 crate/::Serializerrust-analyzer cargo serde_core 1.0.229 ser/Serializer#, |
| 357 | { |
| 358 | self.colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color..serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#serialize().(craterust-analyzer cargo palette 0.7.6 crate/::serderust-analyzer cargo palette 0.7.6 serde/::AlphaSerializerrust-analyzer cargo palette 0.7.6 serde/alpha_serializer/AlphaSerializer# { |
| 359 | innerrust-analyzer cargo palette 0.7.6 serde/alpha_serializer/AlphaSerializer#inner.: serializer, |
| 360 | alpharust-analyzer cargo palette 0.7.6 serde/alpha_serializer/AlphaSerializer#alpha.: &self.alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha., |
| 361 | }) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | #[cfg(feature = "serializing")] |
| 366 | impl<'de, C> serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de> for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 367 | where |
| 368 | C: Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply# + serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de>, |
| 369 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#<'de>, |
| 370 | { |
| 371 | fn deserializerust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Deserialize<'de>`]deserialize().<D>(deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Deserialize<'de>`], D::Errorrust-analyzer cargo serde_core 1.0.229 de/Deserializer#Error#> |
| 372 | where |
| 373 | D: serderust-analyzer cargo serde 1.0.229 crate/::Deserializerrust-analyzer cargo serde_core 1.0.229 de/Deserializer#<'de>, |
| 374 | { |
| 375 | let mut alpha: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 376 | |
| 377 | let color = C::deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#deserialize().(craterust-analyzer cargo palette 0.7.6 crate/::serderust-analyzer cargo palette 0.7.6 serde/::AlphaDeserializerrust-analyzer cargo palette 0.7.6 serde/alpha_deserializer/AlphaDeserializer# { |
| 378 | innerrust-analyzer cargo palette 0.7.6 serde/alpha_deserializer/AlphaDeserializer#inner.: deserializer, |
| 379 | alpharust-analyzer cargo palette 0.7.6 serde/alpha_deserializer/AlphaDeserializer#alpha.: &mut alpha, |
| 380 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 381 | |
| 382 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(alpha) = alpha { |
| 383 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo palette 0.7.6 blend/pre_alpha/impl#[`PreAlpha<C>`][`Deserialize<'de>`] { colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color., alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha. }) |
| 384 | } else { |
| 385 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(serderust-analyzer cargo serde 1.0.229 crate/::derust-analyzer cargo serde_core 1.0.229 de/::Errorrust-analyzer cargo serde_core 1.0.229 de/Error#::missing_fieldrust-analyzer cargo serde_core 1.0.229 de/Error#missing_field().("alpha")) |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | #[cfg(feature = "bytemuck")] |
| 391 | unsafe impl<C> bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Zeroablerust-analyzer cargo bytemuck 1.25.2 zeroable/Zeroable# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 392 | where |
| 393 | C: bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Zeroablerust-analyzer cargo bytemuck 1.25.2 zeroable/Zeroable# + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 394 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Zeroablerust-analyzer cargo bytemuck 1.25.2 zeroable/Zeroable#, |
| 395 | { |
| 396 | } |
| 397 | |
| 398 | // Safety: |
| 399 | // |
| 400 | // See `Alpha<C, T>`'s implementation of `Pod`. |
| 401 | #[cfg(feature = "bytemuck")] |
| 402 | unsafe impl<C> bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Podrust-analyzer cargo bytemuck 1.25.2 pod/Pod# for PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<C> |
| 403 | where |
| 404 | C: bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Podrust-analyzer cargo bytemuck 1.25.2 pod/Pod# + ArrayCastrust-analyzer cargo palette 0.7.6 cast/array/ArrayCast# + Premultiplyrust-analyzer cargo palette 0.7.6 blend/Premultiply#, |
| 405 | C::Scalarrust-analyzer cargo palette 0.7.6 blend/Premultiply#Scalar#: bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Podrust-analyzer cargo bytemuck 1.25.2 pod/Pod#, |
| 406 | { |
| 407 | } |
| 408 | |
| 409 | #[cfg(test)] |
| 410 | #[cfg(feature = "serializing")] |
| 411 | mod testrust-analyzer cargo palette 0.7.6 blend/pre_alpha/test/ { |
| 412 | use superrust-analyzer cargo palette 0.7.6 blend/pre_alpha/::PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#; |
| 413 | use craterust-analyzer cargo palette 0.7.6 crate/::LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#; |
| 414 | |
| 415 | #[cfg(feature = "serializing")] |
| 416 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 417 | fn serializerust-analyzer cargo palette 0.7.6 blend/pre_alpha/test/serialize().() { |
| 418 | let color = PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha# { |
| 419 | colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color.: LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.3, 0.8, 0.1), |
| 420 | alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha.: 0.5, |
| 421 | }; |
| 422 | |
| 423 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 424 | serde_jsonrust-analyzer cargo serde_json 1.0.116 crate/::to_stringrust-analyzer cargo serde_json 1.0.116 ser/to_string().(&color).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 425 | r#"{"red":0.3,"green":0.8,"blue":0.1,"alpha":0.5}"# |
| 426 | ); |
| 427 | |
| 428 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 429 | ronrust-analyzer cargo ron 0.12.2 crate/::to_stringrust-analyzer cargo ron 0.12.2 ser/to_string().(&color).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 430 | r#"(red:0.3,green:0.8,blue:0.1,alpha:0.5)"# |
| 431 | ); |
| 432 | } |
| 433 | |
| 434 | #[cfg(feature = "serializing")] |
| 435 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 436 | fn deserializerust-analyzer cargo palette 0.7.6 blend/pre_alpha/test/deserialize().() { |
| 437 | let color = PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha# { |
| 438 | colorrust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#color.: LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.3, 0.8, 0.1), |
| 439 | alpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#alpha.: 0.5, |
| 440 | }; |
| 441 | |
| 442 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 443 | serde_jsonrust-analyzer cargo serde_json 1.0.116 crate/::from_strrust-analyzer cargo serde_json 1.0.116 de/from_str().::<PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#>>( |
| 444 | r#"{"alpha":0.5,"red":0.3,"green":0.8,"blue":0.1}"# |
| 445 | ) |
| 446 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 447 | color |
| 448 | ); |
| 449 | |
| 450 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 451 | ronrust-analyzer cargo ron 0.12.2 crate/::from_strrust-analyzer cargo ron 0.12.2 de/from_str().::<PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#>>(r#"(alpha:0.5,red:0.3,green:0.8,blue:0.1)"#) |
| 452 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 453 | color |
| 454 | ); |
| 455 | |
| 456 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 457 | ronrust-analyzer cargo ron 0.12.2 crate/::from_strrust-analyzer cargo ron 0.12.2 de/from_str().::<PreAlpharust-analyzer cargo palette 0.7.6 blend/pre_alpha/PreAlpha#<LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#>>(r#"Rgb(alpha:0.5,red:0.3,green:0.8,blue:0.1)"#) |
| 458 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 459 | color |
| 460 | ); |
| 461 | } |
| 462 | } |