diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-03-20 00:35:34 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-03-20 00:35:34 +0200 |
commit | 5226042ca5bce9335c39eaae1384b7131bf300a2 (patch) | |
tree | 3b53940f3d75ebf0a525277f5ff5ac2fd09c25c9 | |
parent | fd09a83ef101193f579240e0920e96f50a056388 (diff) | |
download | fpGUI-5226042ca5bce9335c39eaae1384b7131bf300a2.tar.xz |
CreateMaskFromSample() under Agg-enabled canvas uses Alpha channel to mask image.
-rw-r--r-- | src/corelib/fpg_base.pas | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas index a6f4947f..0da6cf25 100644 --- a/src/corelib/fpg_base.pas +++ b/src/corelib/fpg_base.pas @@ -19,6 +19,9 @@ unit fpg_base; {$mode objfpc}{$H+} +// To enable the AggPas powered Canvas +{.$define AGGCanvas} + interface uses @@ -2271,11 +2274,12 @@ procedure TfpgImageBase.CreateMaskFromSample(x, y: TfpgCoord); var p: ^longword; pmsk: ^byte; - c: longword; + c, n: longword; linecnt: integer; pixelcnt: integer; bit: byte; msklinelen: integer; + row, col: integer; begin if FColorDepth = 1 then Exit; //==> @@ -2283,6 +2287,32 @@ begin if (FImageData = nil) then Exit; //==> +{$ifdef AGGCanvas} + p := FImageData; + if x < 0 then + Inc(p, FWidth - 1) + else + Inc(p, x); + if y < 0 then + Inc(p, FWidth * (FHeight - 1)) + else + Inc(p, FWidth * y); + + c := p^; // the sample + + for row := 0 to FHeight-1 do + begin + for col := 0 to FWidth-1 do + begin + n := PLongWord(FImageData)[row * FWidth + col]; + if n = c then + { set Alpha value 100% transparent } + PLongWord(FImageData)[row * FWidth + col] := n and $00FFFFFF; + end; + end; + +{$else} + AllocateMask; FMaskPoint := Point(x, y); @@ -2334,6 +2364,7 @@ begin Inc(linecnt); until linecnt >= FHeight; +{$endif} end; procedure TfpgImageBase.UpdateImage; |