What is the BMP format for Gray scale Images
Aside from using a palette, you can create a grayscale BMP (8 bits per pixel) by writing a BMP with a BITMAPV4HEADER
. and set bV4RedMask
, bV4GreenMask
and bV4BlueMask
to the same value. However, the minimum bcBitCount
value for such a format is 16, so each pixel will still need to occupy two bytes. You can use the second byte for the alpha channel (transparency) though.
especially for 16 bit per pixel
It doesn't look like any BMP version supports 16 bit color depth. Even though the file format seemingly allows it (bcBitCount=16
and bV4…Mask=0xFFFF
), image editors and libraries discard the extra bits.
Some documents refer to 64-BPP BMP files, however it's unclear how that would fit with the BITMAPV4HEADER
fields, as the mask fields are all 32 bits in size (so it's not possible to specify a channel mask for 64 BPP).
Another option was to use PNG, but it compresses the data (which is not what I want) as discussed here .
You don't have to compress PNG files if you don't want to. Using a compression level of 0 will put the pixels as they are (plus a zlib header/footer).
Also note that the image may appear distorted, since most of the monitors support 256 colors and not 4096 for 16 bit.
16 bit depth would allow for 65536 distinct per-channel luminosity values, not 4096. The distortion sounds like an issue with the gamma curve, and isn't really related to the file format question.