[fpc-pascal] Does FCL Image support transparency?
Reimar Grabowski
reimgrab at web.de
Tue Sep 20 03:50:31 CEST 2016
On Mon, 19 Sep 2016 20:00:54 +0200 (CEST)
Michael Van Canneyt <michael at freepascal.org> wrote:
> Maybe you can share your code, so we can improve the base class ?
It's just a trivial change to the Draw function and IMO there is little gain implementing it like this for TFPCustomCanvas, but here you go:
-add variables: NewColor, DstColor: TFPColor; alpha: double;
-replace: colors [r,t] := image.colors[xx,t-y] with
begin
DstColor:=colors[r,t];
NewColor:=image.colors[xx,t-y];
alpha:=0;
if NewColor.alpha>0 then alpha:=NewColor.alpha/65535;
NewColor.red:=round((NewColor.red*alpha)+DstColor.red*(1-alpha));
NewColor.green:=round((NewColor.green*alpha)+DstColor.green*(1-alpha));
NewColor.blue:=round((NewColor.blue*alpha)+DstColor.blue*(1-alpha));
colors[r,t]:=NewColor;
end;
As you can see this is (SrcColor*ScrAlpha)+DstColor*(1-SrcAlpha) and since I blend RGBA on RGB images there is no need to care about destination alpha.
FPCustomCanvas should IMHO allow many different blending equations (think Photoshop/Gimp blending of layers).
How about something like:
begin
if assigned(BlendFunc) then begin
DstColor:=colors[r,t];
SrcColor:=image.colors[xx,t-y];
colors[r,t]:=BlendFunc(SrcColor, DstColor);
end else
colors [r,t] := image.colors[xx,t-y];
end;
hih
R.
More information about the fpc-pascal
mailing list