Skip to content
Member Filters
Show Inherited
Show Protected
Show abstract
GR32_Blend🞂MergeFunction

Merge

Associative alpha merging taking both foreground and background alpha channels into account.

Declaration ​

pascal
function MergeReg(F, B: TColor32): TColor32;
procedure MergeMem(F: TColor32; var B: TColor32);
procedure MergeMems(F: TColor32; Dst: PColor32; Count: Integer);
function MergeRegEx(F, B: TColor32; M: Cardinal): TColor32;
procedure MergeMemEx(F: TColor32; var B: TColor32; M: Cardinal);
procedure MergeLine(Src, Dst: PColor32; Count: Integer);
procedure MergeLineEx(Src, Dst: PColor32; Count: Integer; M: Cardinal);

Parameters ​

ParameterTypeDescription
FTColor32Foreground pixel color.
BTColor32Background pixel color.
MCardinalMaster alpha weight or mask value (0..255).
SrcPColor32Pointer to the first source foreground pixel in memory.
DstPColor32Pointer to the first destination background pixel in memory.
CountIntegerNumber of contiguous background pixels to blend.

Returns ​

TypeDescription
TColor32The blended 32-bit ARGB result color.

Description ​

The Merge* family of functions performs associative alpha merging based on Bruce Wallace's 1981 compositing formulation:

Ra=Fa+Ba⋅(1−Fa)Rc=Bc+FaRa⋅(Fc−Bc)

Unlike standard alpha blending (Blend), Merge handles semi-transparent background colors accurately, maintaining associativity:

(A over B) over C=A over (B over C)

Variant Summary ​

VariantSignatureDescription
MergeRegfunction(F, B: TColor32): TColor32;Merges foreground F and background B in registers.
MergeMemprocedure(F: TColor32; var B: TColor32);Merges foreground F directly into memory location B.
MergeMemsprocedure(F: TColor32; B: PColor32; Count: Integer);Merges uniform foreground F into Count background pixels starting at B.
MergeRegExfunction(F, B: TColor32; M: Cardinal): TColor32;Register merging with master alpha / mask factor M (0…255).
MergeMemExprocedure(F: TColor32; var B: TColor32; M: Cardinal);In-memory merging with master alpha / mask factor M (0…255).
MergeLineprocedure(Src, Dst: PColor32; Count: Integer);Scanline merging of Count source pixels onto destination pixels.
MergeLineExprocedure(Src, Dst: PColor32; Count: Integer; M: Cardinal);Scanline merging with master alpha factor M.

INFO

All these functions are actually delegates; At startup, Graphics32 binds them to the optimal implementation (Pure Pascal, x86/x64 assembly, or SSE2 vector instructions) supported by the host CPU.

See also ​