macro_rules! impl_premultiply { ($ty: ident {$($component: ident),+} $(phantom: $phantom: ident)? $(where $($where: tt)+)?) => { impl_premultiply!($ty<> {$($component),+} $(phantom: $phantom)? $(where $($where)+)?); }; ($ty: ident <$($ty_param: ident),*> {$($component: ident),+} $(phantom: $phantom: ident)? $(where $($where: tt)+)?) => { impl<$($ty_param,)* T> crate::blend::Premultiply for $ty<$($ty_param,)* T> where T: crate::num::Real + crate::stimulus::Stimulus + crate::num::Zero + crate::num::IsValidDivisor + core::ops::Mul + core::ops::Div + Clone, T::Mask: crate::bool_mask::LazySelect + Clone, $($($where)+)? { type Scalar = T; #[inline] fn premultiply(self, alpha: T) -> crate::blend::PreAlpha { crate::blend::PreAlpha { color: self * alpha.clone(), alpha } } #[inline] fn unpremultiply(premultiplied: crate::blend::PreAlpha) -> (Self, T) { let crate::blend::PreAlpha { color: $ty { $($component,)+ .. }, alpha, } = premultiplied; let is_valid_divisor = alpha.is_valid_divisor(); let color = Self { $( $component: lazy_select! { if is_valid_divisor.clone() => $component / alpha.clone(), else => T::zero() }, )+ $($phantom: core::marker::PhantomData,)? }; (color, alpha) } } impl<$($ty_param,)* T> From> for $ty<$($ty_param,)* T> where Self: crate::blend::Premultiply, { fn from(premultiplied: crate::blend::PreAlpha) -> Self { use crate::blend::Premultiply; Self::unpremultiply(premultiplied).0 } } }; }