Recent

Author Topic: Artifacts when displaying transparent png in timage  (Read 2015 times)

wp

  • Hero Member
  • *****
  • Posts: 12678
Re: Artifacts when displaying transparent png in timage
« Reply #15 on: February 05, 2025, 06:03:24 pm »
Did you try loading the image by means of the graphics classes as I showed above? This seems to work even for gtk2 and gkt3 (Manjaro Linux KDE24.1.2, Mint 21.1 Cinnamon).

Code: Pascal  [Select][+][-]
  1.     program test;
  2.      
  3.     uses
  4.       Interfaces, Classes, Graphics,
  5.       Forms, ExtCtrls;
  6.      
  7.     var
  8.       frmMain: TForm;
  9.       imgForm: TImage;
  10.      
  11.     begin
  12.       Application.Initialize;
  13.       Application.CreateForm(TForm,frmMain);
  14.       frmMain.Width := 600;
  15.       frmMain.Height := 600;
  16.       frmMain.Color := clYellow;
  17.       imgForm := TImage.Create(frmMain);
  18.       imgForm.Parent := frmMain;
  19.       imgForm.Proportional := True;
  20.       imgForm.Stretch := True;
  21.       //imgForm.Transparent := True;
  22.       imgForm.BoundsRect := frmMain.BoundsRect;
  23.       imgForm.Picture.LoadFromFile('test.png');
  24.       Application.Run;
  25.     end.


Jonny

  • Full Member
  • ***
  • Posts: 143
Re: Artifacts when displaying transparent png in timage
« Reply #16 on: February 05, 2025, 06:51:44 pm »
Quote from: wp
Did you try loading the image by means of the graphics classes as I showed above?

Yes, your method of directly loading the file into the TImage component works correctly.

But I pass the image through a TFPMemoryImage because I need to manipulate it.

Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. uses
  4.   Interfaces, Classes, Graphics,
  5.   Forms, ExtCtrls, FPImage, FPReadPNG;
  6.  
  7. var
  8.   frmMain: TForm;
  9.   imgForm: TImage;
  10.   imgLogo: TFPMemoryImage;
  11.   imgReader: TFPReaderPNG;
  12.  
  13. begin
  14.   Application.Initialize;
  15.   Application.CreateForm(TForm,frmMain);
  16.   frmMain.Width := 600;
  17.   frmMain.Height := 600;
  18.   frmMain.Color := clYellow;
  19.   imgForm := TImage.Create(frmMain);
  20.   imgForm.Parent := frmMain;
  21.   imgForm.Proportional := True;
  22.   imgForm.Stretch := True;
  23.   //imgForm.Transparent := True;
  24.   imgForm.BoundsRect := frmMain.BoundsRect;
  25.  
  26. //  imgForm.Picture.LoadFromFile('test.png');  // do not load directly
  27.   imgLogo := TFPMemoryImage.Create(0,0);  // instead load to TFPMemoryImage
  28.   imgReader := TFPReaderPNG.Create;
  29.   imgLogo.LoadFromFile('test.png',imgReader);
  30. //  Manipulate the image in my program (not necessary to show the bug here)
  31.   imgForm.Picture.Assign(imgLogo);
  32.  
  33.   Application.Run;
  34. end.
  35.  

This causes the break in GTK2 only.

lainz

  • Hero Member
  • *****
  • Posts: 4690
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Artifacts when displaying transparent png in timage
« Reply #17 on: February 05, 2025, 06:59:14 pm »
Try with BGRABitmap.

TRon

  • Hero Member
  • *****
  • Posts: 4139
Re: Artifacts when displaying transparent png in timage
« Reply #18 on: February 05, 2025, 07:04:33 pm »
Try with BGRABitmap.
Nothing personal but that answer pisses me off so badly you have no idea  :)

Ofc that works but is besides the point.
Today is tomorrow's yesterday.

Jonny

  • Full Member
  • ***
  • Posts: 143
Re: Artifacts when displaying transparent png in timage
« Reply #19 on: February 05, 2025, 07:08:12 pm »
Quote from: lainz
Try with BGRABitmap.

I am afraid that due to external factors here, I cannot use BGRABitmap or any other third party components.

(BGRABitmap may be very nice but it is a monster - something that I would avoid even if I had a choice)

Besides, if there is a bug, why ignore it, can we confirm the issue and maybe address it?

TRon

  • Hero Member
  • *****
  • Posts: 4139
Re: Artifacts when displaying transparent png in timage
« Reply #20 on: February 05, 2025, 07:46:48 pm »
So confused - is this a bug then?
It tells us that assign does not seem to handle the alpha channel properly while the standard graphic loaders seem to do it correctly.

It would probably require a pixel by pixel check (actually check the alpha channel) comparing both methods in order to try locate the difference between the two.

I consider it a bug though wp mentioned issues with transparency as well so his opinion might differ. Know that wp is better versed in that regards.
« Last Edit: February 05, 2025, 07:50:02 pm by TRon »
Today is tomorrow's yesterday.

Jonny

  • Full Member
  • ***
  • Posts: 143
Re: Artifacts when displaying transparent png in timage
« Reply #21 on: February 05, 2025, 09:08:00 pm »
Thanks. Not sure what you want me to do. Happy to perform tests if you provide simple instructions.

TRon

  • Hero Member
  • *****
  • Posts: 4139
Re: Artifacts when displaying transparent png in timage
« Reply #22 on: February 06, 2025, 12:24:49 am »
Nothing you can currently do that I am aware. I can confirm the results (both the original issue as well as the workaround) as presented by your examples.

If nobody disputes it as being a bug then by logic it becomes one (and should be reported as such).

I am trying to figure out if I am able to determine what might be the culprit tough I do hope it isn't something going as deep as being related to gtk2 because in that case I'm pretty much lost.

PS: the todo note inside the source of assign method of rasterimage when the source is a TFPCustomImage (ancestor of TFPMemoryimage) might be there for a reason.
« Last Edit: February 06, 2025, 01:14:01 am by TRon »
Today is tomorrow's yesterday.

lainz

  • Hero Member
  • *****
  • Posts: 4690
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Artifacts when displaying transparent png in timage
« Reply #23 on: February 06, 2025, 01:00:56 am »
Try with BGRABitmap.
Nothing personal but that answer pisses me off so badly you have no idea  :)

Ofc that works but is besides the point.

 :D

Quote from: lainz
Try with BGRABitmap.

I am afraid that due to external factors here, I cannot use BGRABitmap or any other third party components.

(BGRABitmap may be very nice but it is a monster - something that I would avoid even if I had a choice)

Besides, if there is a bug, why ignore it, can we confirm the issue and maybe address it?

You can use the 'lite' version, with less stuff not a big monster..

Quote
core version of BGRABitmap available: by adding the library to the project include path and setting BGRABITMAP_CORE directive (see test/testcore sample)

No packages to install, just add path relative or inside your project folder... No need to install bgracontrols, use it with a normal canvas.

Jonny

  • Full Member
  • ***
  • Posts: 143
Re: Artifacts when displaying transparent png in timage
« Reply #24 on: February 06, 2025, 01:56:07 am »
Quote from: lainz
You can use the 'lite' version, with less stuff not a big monster..

core version of BGRABitmap available: by adding the library to the project include path and setting BGRABITMAP_CORE directive (see test/testcore sample)

No packages to install, just add path relative or inside your project folder... No need to install bgracontrols, use it with a normal canvas.

OK, so I took the last snippet of working code that was posted.

- Added BGRABitmap to the uses clause.

- Add compiler options: -dBGRABITMAP_CORE

- Compiled with GTK2 widgetset

Code: [Select]
$ ls -la --time-style='+' test.gtk2
-rwxr-xr-x 1 user user 2957824  test.gtk2

$ ls -la --time-style='+' bgratest/test.gtk2
-rwxr-xr-x 1 user user 3859232  bgratest/test.gtk2

$ size -G test.gtk2
      text       data        bss      total filename
   2007720     939693     110312    3057725 test.gtk2

$ size -G bgratest/test.gtk2
      text       data        bss      total filename
   2717064    1133857     185272    4036193 bgratest/test.gtk2

The executable grows by almost 1Mb, and requires countless source files (I tried working out which ones but gave up).

As I shall be deploying to a small embedded system with very limited resources, I am trying to reduce all footprints.

BGRABitmap may be great for bigger projects, but for my current use-case it is, unfortunately a monster.

lainz

  • Hero Member
  • *****
  • Posts: 4690
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Artifacts when displaying transparent png in timage
« Reply #25 on: February 06, 2025, 03:12:49 am »
I see. Limited hardware is a thing. Hope you can fix the bug.  :)

 

TinyPortal © 2005-2018