Discussion:
[Lazarus] Canvas cannot draw properly if has an alpha channel?
Anthony Walter via Lazarus
2018-04-25 00:35:23 UTC
Permalink
I am going to file a bug for this, but wanted to check with other people
first to see if I'm overlooking something.

So the problem is you cannot draw properly to any canvas backed by alpha
channel.

For example, if you have 2 TPortableNetworkGraphic images with images that
contain alpha channels and try to draw from one to another using
Canvas.Draw, the destination will be filled with black. The expected result
should be the source image be copied over.

I'm not sure, but I think all TCanvas drawing operations on graphic objects
with a pf32bit pixel format don't work. Essentially that are read only
surfaces. Is this intended and a won't fix problem or is there a chance
someone is willing to fix this problem?

On Windows the fix is to use the AlphaBlend function instead of BitBlt

https://msdn.microsoft.com/en-us/library/windows/desktop/dd183351(v=vs.85).aspx

On Gtk2 the fix is to use a temporary Cairo surface with cairo_set_source,
and cairo_fill or cairo_paint_with_alpha instead of Gdk graphic commands.

I'm not sure about Qt or Carbon.
Ondrej Pokorny via Lazarus
2018-04-25 04:12:17 UTC
Permalink
Post by Anthony Walter via Lazarus
I'm not sure, but I think all TCanvas drawing operations on graphic
objects with a pf32bit pixel format don't work. Essentially that are
read only surfaces. Is this intended and a won't fix problem or is
there a chance someone is willing to fix this problem?
You have 2 options to overcome this problem:
1.) Use a decent Graphics library. E.g. Graphics32.
2.) Use FPC graphics classes/functions without the LCL overhead.

Ondrej
--
Anthony Walter via Lazarus
2018-04-25 10:18:32 UTC
Permalink
Ondrej,

For years I have my own solution that works
but I am interested in LCL
TCanvas someday working correctly without 3rd party add ins.
Ondrej Pokorny via Lazarus
2018-04-25 10:24:39 UTC
Permalink
Post by Anthony Walter via Lazarus
For years I have my own solution that works
http://youtu.be/P5MPv_GOzRk but I am interested in
LCL TCanvas someday working correctly without 3rd party add ins.
Unfortunately, I have experienced the same issues.

Ondrej
Ondrej Pokorny via Lazarus
2018-04-25 10:34:54 UTC
Permalink
Post by Ondrej Pokorny via Lazarus
Post by Anthony Walter via Lazarus
For years I have my own solution that works
http://youtu.be/P5MPv_GOzRk but I am interested in
LCL TCanvas someday working correctly without 3rd party add ins.
Unfortunately, I have experienced the same issues.
But if you don't want to use 3rd party add ins, use the FCL directly. It
supports transparency, smooth resize etc etc. Actually it supports more
than you would think at the first glance :)

The LCL graphic classes/methods are very OS-specific. The FCL graphic
classes/methods are OS-independent.

I'd love to have full transparency support in LCL TBitmap/TCanvas as
well but it all depends on the underlying OS. If you can fix it (at
least for some OS/WS), feel free to post a patch.

Ondrej
Giuliano Colla via Lazarus
2018-04-25 11:00:42 UTC
Permalink
Post by Ondrej Pokorny via Lazarus
2.) Use FPC graphics classes/functions without the LCL overhead.
Where are they located?

Giuliano

--
Ondrej Pokorny via Lazarus
2018-04-25 11:04:28 UTC
Permalink
Post by Giuliano Colla via Lazarus
Post by Ondrej Pokorny via Lazarus
2.) Use FPC graphics classes/functions without the LCL overhead.
Where are they located?
FPC\packages\fcl-image\src\

Ondrej
--
Michael Van Canneyt via Lazarus
2018-04-25 11:05:06 UTC
Permalink
Post by Giuliano Colla via Lazarus
Post by Ondrej Pokorny via Lazarus
2.) Use FPC graphics classes/functions without the LCL overhead.
Where are they located?
packages/fcl-image

Michael.
--
Giuliano Colla via Lazarus
2018-04-25 11:11:54 UTC
Permalink
Post by Michael Van Canneyt via Lazarus
Post by Giuliano Colla via Lazarus
Where are they located?
packages/fcl-image
Thanks to you and to Ondrej.

Giuliano
Anthony Walter via Lazarus
2018-04-25 14:30:55 UTC
Permalink
This post might be inappropriate. Click to display it.
zeljko via Lazarus
2018-04-25 18:01:01 UTC
Permalink
Post by Anthony Walter via Lazarus
I am trying to paint controls, so I need to eventually Canvas.Draw() to
get a graphic onto a control. I've been working on creating a fully
featured web browser for Lazarus and have been looking at the underlying
widgetset interface code.
Gtk3, which my project currently works great on, uses the now required
Cairo system for painting Gtk widgets. I've already had to patch the
Gtk3 LCL interface section quite a bit to fix errors and I'll submit
those changes when I publish my project.
That would be nice.
Post by Anthony Walter via Lazarus
However, the LCL Gtk2 widgetset is stuck using the Gdk system for
drawing, even though that was deprecated early on in the Gtk2 lifetime
and Cairo has been recommend for a decade or more. I would like to
submit a patch for Gtk2 replacing Gdk with Cairo, but using a swtich
setting that could be changed at runtime.
+1, maybe add Gtk2UseCairo as default.

.... paths are also welcome, afair win32,qt and gtk2/3 supports paths
and it can be implemented inside widgetsets.

zeljko
--
Ondrej Pokorny via Lazarus
2018-04-26 05:26:31 UTC
Permalink
Post by Anthony Walter via Lazarus
Suggestions?
You obviously know much more in this topic than I do, so it's hard to
comment for me.

Just a note about win32: AFAIK the LCL supports only Windows XP and up
officially since 1.8. So there is no problem to switch to GDI+.

I am quite sure any improvements will be highly appreciated.

Ondrej
--

Loading...