pub struct Composite { /* private fields */ }Expand description
A BlendMode paired with a CompositeMode.
Constructed with Composite::new, or converted from either half when the other should be
the default:
use alpha_blend::{BlendMode, Composite, CompositeMode};
let multiply_over = Composite::new(BlendMode::Multiply, CompositeMode::SourceOver);
assert_eq!(Composite::from(BlendMode::Multiply), multiply_over);
assert_eq!(Composite::default(), Composite::NORMAL_OVER);The fields are private so that a future non-separable blend mode or color space can be added
without a breaking change; use the accessors and Composite::new.
Implementations§
Source§impl Composite
impl Composite
Sourcepub const NORMAL_OVER: Self
pub const NORMAL_OVER: Self
Plain source-over compositing with no blending. The default, and by far the common case.
Sourcepub const fn new(blend: BlendMode, op: CompositeMode) -> Self
pub const fn new(blend: BlendMode, op: CompositeMode) -> Self
Pairs a blend mode with a compositing operator.
Sourcepub const fn op(self) -> CompositeMode
pub const fn op(self) -> CompositeMode
Returns the compositing operator.
Sourcepub fn composite<C: Channel>(
self,
src: Rgba<C>,
dst: Rgba<C>,
) -> Premultiplied<Rgba<C>>
pub fn composite<C: Channel>( self, src: Rgba<C>, dst: Rgba<C>, ) -> Premultiplied<Rgba<C>>
Composites src over dst, returning a premultiplied color.
This is the primitive; RgbaBlend::apply is this followed by
Premultiplied::unpremultiply. Prefer this one when the result feeds another
composite, because for integer channels the unpremultiply is lossy.
Implements the W3C general formula. Cs, Cb, as and ab are straight-alpha inputs;
co is premultiplied by ao:
Cs' = (1 - ab) * Cs + ab * B(Cb, Cs)
co = as * Fa * Cs' + ab * Fb * Cb
ao = as * Fa + ab * Fb§Accuracy
For Composite::NORMAL_OVER with an opaque destination, the u8 result is exact and
bit-for-bit identical to U8x4Rgba::source_over.
Other combinations round at most twice for integer channels and can differ from the
exact rational result by up to 2 LSB.