Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-04

Canvas cannot draw properly if has an alpha channel?

12 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Anthony Walter

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180424/6d720191/attachment-0001.html>

Reply by email

Ondrej Pokorny
to Anthony Walter
Anthony Walter wrote
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

Reply by email

Ondrej Pokorny
to Ondrej Pokorny
Ondrej Pokorny wrote 7 lines
On 25.04.2018 12:18, Anthony Walter wrote: > For years I have my own solution that works > <https://www.youtube.com/watch?v=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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180425/5b11d728/attachment.html>

Reply by email

Ondrej Pokorny
to Giuliano Colla
Giuliano Colla wrote
Il 25/04/2018 06:12, Ondrej Pokorny via Lazarus ha scritto: > 2.) Use FPC graphics classes/functions without the LCL overhead. Where are they located?

FPC\packages\fcl-image\src\

Ondrej

Reply by email

Anthony Walter
to Giuliano Colla

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.

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
+ has been available for Windows since XP was released in 2001, and Direct2D since Windows 7 in 2009. I think it's about time we upgrade the Windows graphics from GDI to at least GDI+.

I am willing to contribute to these changes, but I would want assurances that we would accept a common interface for the advanced features all these improved graphics back-ends include. They all include alpha blending, gradient brushes, matrix transforms, vector shaped clipping paths, and more.

My recommend approach to adding these features to the core LCL Canvas class would be to:

A) Change the underlying widgetset to operate with these new graphic backends and operate the same as before, but fixing a few problems like allowing Canavs.Draw to work between 32 bits per pixel surfaces correctly.

B) Add an advanced canvas interface for new features like gradient brushes, vector clipping paths and such. Widgetsets can implement the advanced interface and use it in conjunction with the original TCanvas class.

Examples:

Canvas.Matrix.Rotate(PI / 6);
Canvas.AddPath(Polygon);
Canvas.Clip;
Canvas.Fill(Gradient);
  TPolygon = array of TPointF;
  IAdvancedCanvas = interface
    ...
    procedure AddPath(Polygon: TPolygon);
    procedure Clip;
    procedure Fill(Brush: IBrush);
    property Matrix: IMatrix read GetMatrix write SetMatrix;
    ....
  end;

Suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180425/a82e6ae0/attachment.html>

Reply by email

zeljko
to Anthony Walter
Anthony Walter wrote 9 lines
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.

Show quoted text 6 lines
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

Reply by email