[Lazarus] Canvas cannot draw properly if has an alpha channel?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
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


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.


--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
On 25.04.2018 2:35, Anthony Walter via Lazarus 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
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
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.

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
On 25.04.2018 12:18, Anthony Walter wrote:
For years I have my own solution that works, but I am interested in LCL TCanvas someday working correctly without 3rd party add ins.

Unfortunately, I have experienced the same issues.

Ondrej


--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
On 25.04.2018 12:24, Ondrej Pokorny via Lazarus wrote:
On 25.04.2018 12:18, Anthony Walter wrote:
For years I have my own solution that works, 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

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
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?

Giuliano

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
On 25.04.2018 13:00, Giuliano Colla via Lazarus 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
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list


On Wed, 25 Apr 2018, Giuliano Colla via Lazarus 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?

packages/fcl-image

Michael.
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list

Il 25/04/2018 13:05, Michael Van Canneyt via Lazarus ha scritto:

Where are they located?

packages/fcl-image

Thanks to you and to Ondrej.

Giuliano


--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
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 changed at runtime.

GDI+ 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?

--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
On 25.04.2018 16:30, Anthony Walter via Lazarus wrote:
> 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.

>
> 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
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Canvas cannot draw properly if has an alpha channel?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On 25.04.2018 16:30, Anthony Walter via Lazarus wrote:
> 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
--
_______________________________________________
Lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus