ApplyBitmask

Graphics32

ApplyBitmask

procedure ApplyBitmask(
  Dst: TBitmap32;
  DstX: Integer;
  DstY: Integer;
  Src: TBitmap32;
  SrcRect: TRect;
  Bitmask: TColor32;
  LogicalOperator: TLogicalOperator;
);

procedure ApplyBitmask(
  ABitmap: TBitmap32;
  ARect: TRect;
  Bitmask: TColor32;
  LogicalOperator: TLogicalOperator;
);

Description

ApplyBitmask performs a logical (bitwise) operation on a bitmap fragment specified by SrcRect into location (DstX, DstY) or directly in-place on ABitmap. The operation is carried out in the following manner: "Source Pixel [Logical Operation] Bitmask" regardless of present destination or in-place operation. The logical operation is defined by the provided Logical Operator.

Each byte in the bitmask will be used as component corresponding operand. The following combinations illustrates different applications:

Description Parameter Values Source Result
Zero out Red and Blue components, leave the rest untouched LogicalOperator = loAND
Bitmask = $FF00FF00
Invertion of Blue component, leave the rest untouched LogicalOperator = loXOR
Bitmask = $000000FF
Full power to Red component, leave the rest untouched LogicalOperator = loOR
Bitmask = $00FF0000
Weird filter LogicalOperator = loOR
Bitmask = $BABEC0DE

As seen above, the bitmask does not necessarily have to contain 0 or $FF in each component segment - intermediate values can also be used however with limited realistic applications (read: weird filters).
You may use auxiliary function CreateBitmask to create bitmasks.

See Also

Color Types, CopyComponents, CreateBitmask, Invert, TBitmap32, TLogicalOperator, TRect