Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exporting 16bit BMP
#1
I am using GIMP 2.10 on a Macbook Pro OSX 12.3.1. When I try to export a 16 bit XCF file as a 16 bit BMP R5G6R5 file, I wind uo with an 8 bit BMP file.
Reply
#2
(04-15-2022, 09:15 PM)bilbo Wrote: I am using GIMP 2.10 on a Macbook Pro OSX 12.3.1. When I try to export a 16 bit XCF file as a 16 bit BMP R5G6R5 file, I wind uo with an 8 bit BMP file.

First of all it is a matter of definition and convention.

A Gimp 16 bit precision is 16 bits for each channel = 16 red + 16 green + 16 blue = total 48 bits

The bmp advanced option 16 bits 565 format is 5 red + 6 green + 5 blue = total 16 bits

Confusing, well that is the way it is Wink

Why does Gimp open the 565 (16 bits) bmp as 8 bit (8 red + 8 green + 8 blue = 24 bits) Gimp is a RGB editor and will edit in that format. Want to keep the 565 bmp, then export again in that format.

How can you tell if Gimp is exporting as a 565 bmp ? There is no real way, the utilities I use will identify as 8 bit same as at the top of the Gimp window. One way, since bmp is (usually) uncompressed is compare file size. For an example image:
A precision 16 bit (48 bits) uncompressed = 700 KB
A regular 8 bit (24 bits) bmp = 360 KB
A 565 (16 bits) bmp = 240 KB - Less information / smaller file size.

You might notice a difference with the 565 (16) bit bmp open in Gimp. The reduced color information can be seen in gradients where banding will occur. If you hope to improve gradients by using Gimp 16 bit precision, you are out of luck. 

Other ways of getting a 565 bmp ? There is command line ffmpeg (you can get a macos version)

Code:
ffmpeg -vcodec png -i 565.png -vcodec rawvideo -f rawvideo -pix_fmt rgb565 565.raw

You can check that in Gimp, opening as raw data. Set the size and image type. You will still edit as 8 bit RGB.

   

Is this for a Game engine ? You would have to try the raw file and see.
Reply
#3
Rich 2005: Thanks for your help. The BMP file is for a custom splash screen on a  car radio. It requires a 16 bit BMP R5G6B5. The file I generate using the advanced export option won't work. I am assuming it is in the wrong format. When I open the BMP file with GIMP, the header shows:
"[image3](imported)-1.0 (RGB color 8-bit gamma integer, GIMP built in sRGB, 1 layer) 800x480-GIMP".
The file is 770 KB. Maybe it is actually in the right format? Any help yopu can give me would be appreciated
Reply
#4
(04-16-2022, 01:37 PM)bilbo Wrote: The BMP file is for a custom splash screen on a  car radio. It requires a 16 bit BMP R5G6B5. The file I generate using the advanced export option won't work. I am assuming it is in the wrong format. When I open the BMP file with GIMP, the header shows:
"[image3](imported)-1.0 (RGB color 8-bit gamma integer, GIMP built in sRGB, 1 layer) 800x480-GIMP".

The Gimp bmp rgb565 file will be correct but obviously not the correct format for the device.

Quote:The file is 770 KB. Maybe it is actually in the right format? Any help yopu can give me would be appreciated

As a very rough check, export as a 24 bit bmp and compare file size. The rgb 565 bmp will be smaller.

The problem is confirming that it is RGB 565. When you re-open in Gimp it is converted to RGB 888 ie. an 8 bit image. Other utilities I have also classify as 8 bit RGB.

As well as ffmpeg there is another command line utility ImageMagick (IM) http://www.imagemagick.org that will convert to a RGB 565 bmp

Code:
magick rgb.png -define bmp:format=bmp4 -define bmp:subtype=rgb565  im-565.bmp

The only confirmation I have is the filesize from IM is the exactly same as from GIMP.

A search found this on-line convertor: https://lvgl.io/tools/imageconverter but it outputs a raw file, no header, similar to ffmpeg (4 bytes difference) I can open that in Gimp as a raw (data) file. So the colour information is there, other parameters also come into play, big endian / little endian will swap colours. You could give that a try.

Sorry, not much else I can suggest, especially for a Mac.
Reply
#5
(04-16-2022, 09:31 AM)rich2005 Wrote: How can you tell if Gimp is exporting as a 565 bmp ? There is no real way...

You can inspect the byte at offset 0x1C using a hex editor. The specification says that this byte is set as follows:

1 = monochrome bitmap
4 = 16 colour bitmap
8 = 256 colour bitmap
16 (0x10) = 16-bit (high colour) bitmap
24 (0x18) = 24-bit (true colour) bitmap
32 (0x20) = 32-bit (true colour) bitmap


(so in each case this byte gives the number of bits required to hold the possible colours)

The byte at offset 0x1E should be set to 0x03 (BI_BITFIELDS)

The numbers of bits per colour are then given in the following bytes:

0x36..0x39 = 0x0000F800 (5 bits for red)
0x3A..0x3D = 0x0000007E (6 bits for green)
0x3E..0x41 = 0x0000001F (5 bits for blue)

These 3 double words hold the masks for the colour bits in each 16-bit value from the image data part of the file.

I have just check a normal 24-bit (8 bits each of R, G and B) and this byte is set to 0x18. I exported the file in the R5G6B5 format and the byte then holds 0x10. Apart from that the file is roughly 2/3 the size of the 24-bit one.

(Ghex works well on Linux Mint and I'm sure that there are Windows hex editors available - I have used them in the past but can't recall off-hand which ones I used)
Reply
#6
I am beginning to believe that GIMP is exporting in the right format. The file is the right size and when I tried to install a 16bit BMP from another source, the installation failed as well. I conclude that my problem lies elsewhere from GIMP. Thank you both for your help. Sorry for putting ypu to all this trouble.
Reply
#7
(04-16-2022, 06:44 PM)bilbo Wrote: I am beginning to believe that GIMP is exporting in the right format. The file is the right size and when I tried to install a 16bit BMP from another source, the installation failed as well. I conclude that my problem lies elsewhere from GIMP. Thank you both for your help. Sorry for putting ypu to all this trouble.

No trouble, hope you get it sorted.

Have you tried selecting "Compatibility Options/Do not write colour space information"?
Reply


Forum Jump: