AlphaCompositor<T>

Models & Types · AiDotNet.Diffusion.MaskUtilities

Alpha compositing for layered diffusion outputs with transparency support.

For Beginners

When generating an image in layers (like background + foreground + effects), you need to combine them properly. AlphaCompositor handles the math of layering images with transparency, just like how Photoshop stacks layers together. It ensures smooth edges and correct color blending between layers.

How It Works

Implements Porter-Duff alpha compositing operations for combining multiple generated layers. Supports standard “over” compositing as well as additive and multiply blend modes. Essential for multi-layer generation pipelines where foreground, background, and effects layers are generated separately and composited into a final image.

Constructors

Constructor Summary
AlphaCompositor(bool premultipliedAlpha) Initializes a new alpha compositor.

Properties

Property Summary
bool PremultipliedAlpha { get; } Gets whether inputs are expected in premultiplied alpha format.

Methods

Method Summary
Vector<T> CompositeAdditive(Vector<T> layer1, Vector<T> layer2, double weight1, double weight2) Composites using additive blending.
Vector<T> CompositeOver(Vector<T> foreground, Vector<T> foregroundAlpha, Vector<T> background, Vector<T> backgroundAlpha) Composites foreground over background using alpha blending (Porter-Duff “over” operation).