Recent

Author Topic: Big issue with Timage/TBitmap, PNG under Linux  (Read 588 times)

BeanzMaster

  • Full Member
  • ***
  • Posts: 239
Big issue with Timage/TBitmap, PNG under Linux
« on: May 11, 2020, 05:20:08 pm »
Hi to all, i've made a little freecell clone with Lazarus 2.0.8 , it work like a charm under Windows 10 64 bit. But under Linux the image are black.

So why a little simple project like this, don't work properly under Linux ?  >:( >:D
How to do for fixing Bitmap drawing with linux in a simply way?

You can download full source for testing here :  https://my.pcloud.com/publink/show?code=XZMgRdkZLuwYrHbIbfQLcG9WH8zvWumgVgnX


Thanks in advance

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: Big issue with Timage/TBitmap, PNG under Linux
« Reply #1 on: May 11, 2020, 07:07:53 pm »
Hi there

PixelFormat is buggy. Do not modify it.

When accessing pixels, read the RawImage description to know where the channels are:
Code: Delphi  [Select][+][-]
  1.  function NegateBitmap(SrcBmp : TBitmap) : TBitmap;
  2.  Var
  3.   bytesPerPixel, redOffset, greenOffset, blueOffset: byte;
  4.   DstPtr : PByte;
  5.   x,y : Integer;
  6.  begin
  7.    Result := TBitmap.Create;
  8.    Result.Assign(srcBmp);
  9.    Result.BeginUpdate;
  10.    bytesPerPixel := Result.RawImage.Description.BitsPerPixel div 8;
  11.    redOffset := Result.RawImage.Description.RedShift div 8;
  12.    greenOffset := Result.RawImage.Description.GreenShift div 8;
  13.    blueOffset := Result.RawImage.Description.BlueShift div 8;
  14.    {$IFNDEF ENDIAN_LITTLE}
  15.    redOffset := bytesPerPixel - 1 - redOffset;
  16.    greenOffset := bytesPerPixel - 1 - greenOffset;
  17.    blueOffset := bytesPerPixel - 1 - blueOffset;
  18.    {$ENDIF}
  19.    for y :=  0 to Result.Height - 1 do
  20.    begin
  21.      DstPtr := Result.RawImage.GetLineStart(y);
  22.      for x := 0 to Result.Width - 1 do
  23.      begin;
  24.        (DstPtr+blueOffset)^ := not (DstPtr+blueOffset)^;
  25.        (DstPtr+greenOffset)^ := not (DstPtr+greenOffset)^;
  26.        (DstPtr+redOffset)^ := not (DstPtr+redOffset)^;
  27.        inc(DstPtr, bytesPerPixel);
  28.      end;
  29.    end;
  30.    Result.EndUpdate;
  31.  end;  
Conscience is the debugger of the mind

BeanzMaster

  • Full Member
  • ***
  • Posts: 239
Re: Big issue with Timage/TBitmap, PNG under Linux
« Reply #2 on: May 11, 2020, 08:34:57 pm »
Hi, thanks for the tips but the problem is not wiht the negate functions ;)

So if pixelformat is buggy with Linux how to display transparent bitmap correctly ?

I hope this bug will solve in next version 2.2 of Lazarus.

Thanks

circular

  • Hero Member
  • *****
  • Posts: 3359
    • Personal webpage
Re: Big issue with Timage/TBitmap, PNG under Linux
« Reply #3 on: May 11, 2020, 10:21:23 pm »
Hi, thanks for the tips but the problem is not wiht the negate functions ;)
Well it is with the Negate function as well because it relies on the pixel format.

Quote
So if pixelformat is buggy with Linux how to display transparent bitmap correctly ?
With BGRABitmap?
Conscience is the debugger of the mind

wp

  • Hero Member
  • *****
  • Posts: 7353
Re: Big issue with Timage/TBitmap, PNG under Linux
« Reply #4 on: May 11, 2020, 11:06:50 pm »
Great game! You should put it on the Application Gallery

In Linux I get rid of the black images when I set all PixelFormats to pf24bit or do not set it at all. For the NegateBitmap procedure I use an intermedate LazIntfImage for safety.
« Last Edit: May 11, 2020, 11:17:52 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

BeanzMaster

  • Full Member
  • ***
  • Posts: 239
Re: Big issue with Timage/TBitmap, PNG under Linux
« Reply #5 on: May 12, 2020, 05:46:56 pm »
Great game! You should put it on the Application Gallery

In Linux I get rid of the black images when I set all PixelFormats to pf24bit or do not set it at all. For the NegateBitmap procedure I use an intermedate LazIntfImage for safety.

Thanks wp, yes by uses pf24bit it work, and the copymode to. But on Windows copymode don't work. I'll make test with pf24bit. And yes why not tu put it in the Application Gallery. I've also made the possibility to select and move more than one card

 

TinyPortal © 2005-2018