Saving a BMP file with 16 bit pixel resolution (5:6:5)

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by mch »

Hi,
I have been told that IM cannot save a BMP file with a 16 bit pixel resolution ie each pixel is represented by 2 bytes with RGB stored as 5:6:5. It can however read files with this format.

See link to the thread discussing this.
viewtopic.php?f=1&t=33334&sid=6ceff1fda ... 1a38826f62

I would like to suggest a modification to IM that would support this format, obviously colour depth may possibly be lost as the most LSB's of the colour info would have to be dropped. In my case as these bits never existed as the files started out as 5:6:5 its not a problem. The reason that this is important to me is that I am using a lot of graphics files in a small embedded application and image size is very important to me.

Here is a link to a .BMP file I am using that is stored with a 16 bit pixel size.

https://www.dropbox.com/s/flhoni3vjn9ry ... 2.BMP?dl=0

Regards, Martin
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by dlemstra »

Maybe you should read your topic again?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by fmw42 »

The file you posted is 24bits. BMP3 does not support the 5:6:5 format, since it does not have fields in the header to identify it as such. Whereas, BMP (BMP4) does contain such headers. If you have an example BMP3 file in 5:6:5 format, post that so the developers can see how it can be identified as such.
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by Jason S »

I could not figure out how to download mch's example file with a web browser. What I ended up with was always either a JPEG or HTML file. I was able to download it with wget. It is BMPv3 16-bit RGB555, not RGB565.

BMPv3 supports 16-bit images with arbitrary RGB (though not RGBA) color formats. You just have to write an extra "BITFIELDS" segment after the header, for any format other than RGB555. ImageMagick can read such images, but can't write them.

If IM were to support writing BMPv3 RGB565, it ought to support RGB555 as well, since it also has the "bmp:subtype=RGB555" option.

Even if it does not support these things, I'd say it should ignore the options completely, instead of producing malformed files as it does now.

Format reference

Examples:
RGB565
RGB555 without BITFIELDS
RGB555 with BITFIELDS
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by mch »

Sorry I had assumed it was 5:6:5 as i didnt know there was an option for 5:5:5. I did know it only used 16 bits to store each pixel rather than 24.
The original post has been added to since i posted this question on the developers forum.

So am I right in thinking that IM does not support the writing of this format?

Is it likely/possible that this will be added in the future
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by mch »

Sorry, Just re-read the original post and find it is supported, just wasnt documented.

I have tried this and it works.

>magick convert cam1.bmp -define bmp:subtype=RGB565 test.bmp

Great product!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by fmw42 »

I had noted above that it was supported for BMP (BMP4), but not for BMP3. See also documentation for that at https://www.imagemagick.org/script/comm ... php#define
kuwanger
Posts: 1
Joined: 2018-08-19T07:59:47-07:00
Authentication code: 1152

Re: Saving a BMP file with 16 bit pixel resolution (5:6:5)

Post by kuwanger »

If you want an example of an image in BMP3 format that does 16-bit RGB565 (it's actually BGR565), then: here's an example. The format is popular on the GBA (and probably similar systems) because with a negative height and no compression it makes for a pretty trivial usable and most interchangeable bitmap format.

Edit: Sorry, should more carefully read the spec given.
Post Reply