Recent

Author Topic: Solved BGRABitmapTypes.BGRA() needs parameters reordered on Linux vs Windows  (Read 1098 times)

Coxy

  • New Member
  • *
  • Posts: 45
Solved BGRABitmapTypes.BGRA() needs parameters reordered on Linux vs Windows
« Reply #15 on: October 19, 2025, 11:30:40 am »
Hi All,

Installed Lazarus on an Intel 4690K running Linux Mint 22.2 Zara to same software specs as in original post.

Created simple project,

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.BtnRedboxClick(Sender: TObject);
  2. var
  3.   Bitmap : TBGRABitmap;
  4. begin
  5.   Bitmap:=TBGRABitmap.Create(100,100,BGRA(255,0,0));
  6.   Bitmap.SaveToFile('redbox.png');
  7.   Bitmap.Free;
  8. end;
  9.  

This worked correctly, creating a red image.

Then built and ran code on my laptop that exhibited the problem. It created a red image.

Cut and pasted code in to application that had the problem. Created a red image.

Changes where I had swapped red and blue channels where now showing incorrect colors. Feeling very surreal.

Looked in /var/log/d[kg.log and found NVidia driver had been updated on the 16th.

Code: Text  [Select][+][-]
  1. 2025-10-16 21:56:29 status unpacked nvidia-driver-580-open:amd64 580.95.05-0ubuntu0.24.04.2
  2. 2025-10-16 21:56:29 status half-configured nvidia-driver-580-open:amd64 580.95.05-0ubuntu0.24.04.2
  3. 2025-10-16 21:56:29 status installed nvidia-driver-580-open:amd64 580.95.05-0ubuntu0.24.04.2
  4.  

But the machine had been rebooted since then so the install should have been completed.

I don't understand what's happened. But anyway BGRABitmap is working as expected. I've now got to revert my code changes.

Sorry for wasting everyone's time.


Coxy

  • New Member
  • *
  • Posts: 45
Hi All,

Further update. NVidia driver update had nothing to do with the problem.

Cause was wrong color format parameter passed to glTexImage2D()

Code: Text  [Select][+][-]
  1.   glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, pBitmap.Width,pBitmap.Height, 0, ColorFormat, GL_UNSIGNED_BYTE, pBitmap.DataByte);

ColorFormat now defined as,

Code: Pascal  [Select][+][-]
  1. const
  2.   {$IF Defined(UNIX)}
  3.     ColorFormat=GL_RGBA;
  4.   {$ELSEIF Defined(WINDOWS)}
  5.     ColorFormat=GL_BGRA;
  6.   {$ELSE}
  7.     Platform not supported!
  8.   {$ENDIF}

Again apologies for time wasted.


DomingoGP

  • Full Member
  • ***
  • Posts: 106
You can also use this code  that works for all platforms where BGRABitmap works.

Code: Pascal  [Select][+][-]
  1.   if TBGRAPixel_RGBAOrder then
  2.     ColorFormat := GL_RGBA
  3.   else
  4.     ColorFormat := GL_BGRA;
  5.  

circular

  • Hero Member
  • *****
  • Posts: 4450
    • Personal webpage
Hi!

Apologies for the late reply, I couldn't access the forum.

Indeed, BGRABitmap can store colors differently depending on system or framework for speed and compatibility. So when you supply the data directly to OpenGL or another library, the best way is to specify how it is encoded. As DomingoGP points out, you can check TBGRAPixel_RGBAOrder boolean.

In rare cases where you need the data to be the other way around, you can call SwapRedBlue function, however this is a bit slow, and you may need to call it again if you want to continue using the bitmap.

Regards
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018