Recent

Author Topic: Bitmaps look different in BGRABitmap vs. Other imaging software  (Read 1652 times)

indydev

  • Full Member
  • ***
  • Posts: 127
I finally decided to try and use BGRABitmaps in my code, and was messing around with it and noticed something rather strange. Some bitmaps display differently. 

I thought that I was doing something wrong, but even LazPaint does not display these bitmaps well.

I am not an expert (by any means) with graphical image types, but I present two photos to show what I mean.

The first is LazPaint. The second is just the folder view of the same files in Linux Mint 22.  But every other imaging software I use, displays these bitmaps the way I would expect.

Is there a formatting flag that needs to be set?

circular

  • Hero Member
  • *****
  • Posts: 4441
    • Personal webpage
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #1 on: April 06, 2025, 01:28:52 am »
Hi Indydev,

Even though the BMP format can give some unexpected results, I am surprised by what you get. Can you share some of those images, so that we can try to see what happens on our side?

Warm regards
Conscience is the debugger of the mind

indydev

  • Full Member
  • ***
  • Posts: 127
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #2 on: April 07, 2025, 03:40:52 am »
Sure:

I have uploaded some of the bitmaps.

Thanks for looking into this.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12262
  • FPC developer.
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #3 on: April 07, 2025, 11:27:23 am »
Looks like those images are somehow changes to monochrome. (1 bpp even?)

indydev

  • Full Member
  • ***
  • Posts: 127
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #4 on: April 07, 2025, 06:02:07 pm »
Except user.bmp is not converted the same way. I should note that when I draw on TCanvas with TBitmap, this does not happen.  I use these in a client application already. You can see the picture attached. They work fine.

DomingoGP

  • Jr. Member
  • **
  • Posts: 89
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #5 on: April 07, 2025, 10:54:03 pm »


I think I found the problem in the bgrabitmap code.

The barely tested patch attached solves the issue for me.

Maybe @circular would like to take a look at it.


Regards
Domingo

indydev

  • Full Member
  • ***
  • Posts: 127
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #6 on: April 07, 2025, 11:08:22 pm »
So the order of the colors RGBA vs BGRA looks to be the problem then. Nice work.

circular

  • Hero Member
  • *****
  • Posts: 4441
    • Personal webpage
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #7 on: April 12, 2025, 11:45:22 am »
Thanks Domingo for looking at it. Indeed, there is something about the byte order.

After digging into it, the line loading the pixel was correct, but the bit fields were incorrectly read outside of the header, which is not the case with the newer version of BMP format.

While checking test files, I noted that it would be better for the thumbnails to use the automatic opaque option for 32-bit BMP.

I've applied a fix on the dev branch.
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4441
    • Personal webpage
Re: Bitmaps look different in BGRABitmap vs. Other imaging software
« Reply #8 on: April 12, 2025, 01:29:21 pm »
While testing, I noted that OS/2 v2 format was not handled. So I've added basic support for this format as well.

The reader has been tested the sample images from ffmpeg.org website.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018