http://halicery.com/2Image Decoders/BMP/home.html

The BM-pixel format and BMP files

All my image decoders write true color output, namely 15/16/24/32 bit per pixel direct-color, in BM-format.

There were a few reasons for this decision:

BM format

BM-format is uncompressed, LSB first, packed color bytes in BGRA order. Scanlines are 4-byte aligned, with possible byte-padding (xx):

Direct color BM-format memory layout


B  G  R  A  .. .. .. .. .. .. .. ..      32-bit RGB8888
.. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. 
                        
                        
B  G  R  .. .. .. .. .. .. .. .. xx      24-bit RGB888
.. .. .. .. .. .. .. .. .. .. .. xx 
.. .. .. .. .. .. .. .. .. .. .. xx 
.. .. .. .. .. .. .. .. .. .. .. xx 
                        
                        
bg gr .. .. .. .. .. .. .. .. xx xx      16-bit RGB565
.. .. .. .. .. .. .. .. .. .. xx xx 
.. .. .. .. .. .. .. .. .. .. xx xx 
.. .. .. .. .. .. .. .. .. .. xx xx 
                        
                        
bg gr .. .. .. .. .. .. .. .. xx xx      15-bit RGB555
.. .. .. .. .. .. .. .. .. .. xx xx 
.. .. .. .. .. .. .. .. .. .. xx xx 
.. .. .. .. .. .. .. .. .. .. xx xx 

BMP format

To save the output image as a BMP file there is just a small header to add:

_____________________________ 
________ BMP HEADER _________       (68 bytes)
.. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. ..      pixel data (DWORD padded scanlines)
.. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. 

To be able to write 16- and 32-bpp BMP files I used BITMAPINFOHEADER, size=40.


Sun Jun 17 18:13:26 UTC+0200 2018 © A. Tarpai