BMP &File format fotoflōt | 15 Apr 2013
Can a 1-bit BMP file have colors other than black and white?
Here a quick summary of a discussion in the “Digital Printing” group on LinkedIn.
BMP files with color depths of less than 8 bits per pixel are required to have a color table. That means, it is possible to assign colors other than black and white to “on” and “off” pixels in the bitmap file. Details about the BMP file format with descriptions of the file header and color table are available on Wikipedia.
A quick example (complete list of images at the end of the post).
We started with a grayscale TIF file and used ImageMagick to create a 1-bit per pixel black-and-white BMP bitmap file:
$ convert 999.tif -resize 200x200 -type Bilevel -depth 1 input-bw.bmp
While it is possible to “patch” the file (example below), more convenient is the use of the ImageMagick convert command. In this example we replace black with the redish color 0xff1234 and white with the greenish color 0x12ff34.
$ convert input-bw.bmp +level-colors '#ff1234,#12ff34' output-color.bmp
The resulting file is still a 1-bit file, as the ImageMagick command identify shows:
$ identify output-color.bmp
output-color.bmp BMP 200x200 200x200+0+0 1-bit PseudoClass
Some programs may not properly show the new colors, but Windows generates correctly colored thumbnails. A quick check shows that these programs generate the correct colors for the resulting image:
- Apple Safari
- FastPictureViewer
- Google Chrome
- ImageMagick display
- IrfanView
- Microsoft InternetExplorer
- …
A few programs are fine with the color table, but got the ‘white’ and ‘black’ colors somehow reversed:
- Mozilla Firefox
- Opera
- …
And then there will be programs that simply assume “on” is white and “off” is black.
A complete list f all images: