Skip to main content

Composite

Struct Composite 

Source
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

Source

pub const NORMAL_OVER: Self

Plain source-over compositing with no blending. The default, and by far the common case.

Source

pub const fn new(blend: BlendMode, op: CompositeMode) -> Self

Pairs a blend mode with a compositing operator.

Source

pub const fn blend(self) -> BlendMode

Returns the blend mode.

Source

pub const fn op(self) -> CompositeMode

Returns the compositing operator.

Source

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.

Trait Implementations§

Source§

impl Clone for Composite

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Composite

Source§

impl Debug for Composite

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Composite

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Composite

Source§

impl From<BlendMode> for Composite

Source§

fn from(blend: BlendMode) -> Self

Converts to this type from the input type.
Source§

impl From<CompositeMode> for Composite

Source§

fn from(op: CompositeMode) -> Self

Converts to this type from the input type.
Source§

impl Hash for Composite

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Composite

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<C: Channel> RgbaBlend<C> for Composite

Source§

fn apply(&self, src: Rgba<C>, dst: Rgba<C>) -> Rgba<C>

Blends two colors together, returning a straight-alpha result. Read more
Source§

fn apply_slice(&self, src: &[Rgba<C>], dst: &mut [Rgba<C>])

Blend src over dst in place, pixel by pixel. Read more
Source§

impl StructuralPartialEq for Composite

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.