Recent

Author Topic: TBitmap.Scanline with pf32bit broken on Linux (Debian+Mint)  (Read 962 times)

domasz

  • Hero Member
  • *****
  • Posts: 563
Lazarus 3.4 64bit GTK2
(Same problem on Lazarus 2.2.6 64bit GTK2)
FPC 3.2.2
Debian 12 Bookworm

The code below displays a bunch of weird lines instead of a fully blue image. The saved image is correct (fully blue).
Code: Pascal  [Select][+][-]
  1. TPix = packed record
  2. case Byte of
  3. 1: (R,G,B,A: Byte);
  4. 2: (RGBA: Cardinal;)
  5. end;
  6. PPixArray = ^TPixArray;
  7. TPixArray = array[0..32766] of TPix;
  8.  
  9. x,y: Integer;
  10. P: PPixArray;
  11. Result: TBitmap;
  12. begin
  13.   Result := TBitmap.Create;
  14.   Result.SetSize(500, 500);
  15.   Result.PixelFormat := pf32bit;
  16.  
  17.   for y:=0 to Result.Height-1 do begin
  18.     P := Result.Scanline[y];
  19.     for x:=0 to Result.Width-1 do begin
  20.       P^[x].R := 0;
  21.       P^[x].G := 0;
  22.       P^[x].B := 255;
  23.       P^[x].A := 255;
  24.    end;
  25.   end;
  26.  
  27.   Panel2.Canvas.Draw(0,0, Result);
  28.   Result.SaveToFile('hej.bmp');
  29.   Result.Free;
  30.  
« Last Edit: June 04, 2024, 08:47:36 pm by domasz »

wp

  • Hero Member
  • *****
  • Posts: 12676
Re: Canvas.Draw and Canvas.StretchDraw broken on Linux (Debian)
« Reply #1 on: June 04, 2024, 04:55:14 pm »
Working correctly for me on Linux Mint gtk2 and qt5, except for the color (fully red) since R and B are exchanged, and maybe the alpha channel is also at a different location. That's the problem when pixels are accessed via ScanLine...
« Last Edit: June 04, 2024, 05:33:19 pm by wp »

domasz

  • Hero Member
  • *****
  • Posts: 563
Re: Canvas.Draw and Canvas.StretchDraw broken on Linux (Debian)
« Reply #2 on: June 04, 2024, 05:04:49 pm »
What version of Lazarus do you have?
What exact version of GTK?

I have the same bug also in Linux Mint 21.3 Cinnamon, Cinnamon version 6.1.4.
« Last Edit: June 04, 2024, 05:45:58 pm by domasz »

wp

  • Hero Member
  • *****
  • Posts: 12676
Re: Canvas.Draw and Canvas.StretchDraw broken on Linux (Debian)
« Reply #3 on: June 04, 2024, 05:47:06 pm »
What version of Lazarus do you have?
At first I tried Laz/main with the result reported by me, but now I switched to Laz 3.2 and it shows the striped image that you get.

domasz

  • Hero Member
  • *****
  • Posts: 563
Re: Canvas.Draw and Canvas.StretchDraw broken on Linux (Debian)
« Reply #4 on: June 04, 2024, 08:47:03 pm »
Below works on Linux with pf32bit.

Code: Pascal  [Select][+][-]
  1.       Color := R + (G shl 8) + (B shl 16);
  2.       Result.Canvas.Pixels[x,y] := Color;
  3.  

TRon

  • Hero Member
  • *****
  • Posts: 4133
Re: Canvas.Draw and Canvas.StretchDraw broken on Linux (Debian)
« Reply #5 on: June 05, 2024, 06:03:08 am »
Below works on Linux with pf32bit.
Ofc that works !

It works for every pixelformat (that is with taking the number of colours that are possible for such format into account )

By using the pixels property the class uses the property setter that is responsible for 'setting' the actual pixels, taking away the burden for the user to understand how images are actually stored in memory (and that is a good thing because there as many users as there are (wrong) assumptions  :)

Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018