1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
procedure DrawAlphaMask(x, y: integer; BmpSource, BmpDest: TBitmap);
type
TLigneInt=array of Longword;
var
PtLgnSource,
PtLgnDest: Pointer;
Yd: integer;
XPtrLgnSource: integer;
XPtrLgnDest: integer;
Alpha: LongWord;
InvAlpha: LongWord;
CSource: LongWord;
CDest: LongWord;
XMin, YMin: integer;
XMax, YMax: integer;
begin
BmpDest.PixelFormat := pf32bit;
BmpSource.PixelFormat := pf32bit;
with BmpSource do
begin
XMin := Max(0, -x);
YMin := Max(0, -y);
XMax := Min(Width-1, BmpDest.Width-x-1);
YMax := Min(Height-1, BmpDest.Height-y-1);
for Yd := YMin to YMax do
begin
PtLgnSource := ScanLine[Yd];
PtLgnDest := BmpDest.ScanLine[Yd+Y];
XPtrLgnDest := X+XMin;
for XPtrLgnSource := XMin to XMax do
begin
CSource := TLigneInt(PtLgnSource)[XPtrLgnSource];
InvAlpha := CSource shr 24;
Alpha := 255-InvAlpha;
CDest := TLigneInt(PtLgnDest)[XPtrLgnDest];
TLigneInt(PtLgnDest)[XPtrLgnDest] := (((CDest and $FF0000)*Alpha+(CSource and $FF0000)*InvAlpha)div 255)and $FF0000+
(((CDest and $FF00)*Alpha+(CSource and $FF00)*InvAlpha)div 255)and $FF00+
(((CDest and $FF)*Alpha+(CSource and $FF)*InvAlpha)div 255)and $FF;
inc(XPtrLgnDest);
end;
end;
end;
BmpDest.Modified := True;
end; |
Partager