How to interpret pixel array in BMP file 1 bit.

I cannot find a way to explain the pixel array in the following situation: I created a 2x2 pixel BMP image with MS Paint in Windows 7. Saved it as monochrome BMP (which I think means BMP with 1 bit per pixel color depth)

This is how the image looks when zoomed in (black pixel, white pixel, white pixel, black pixel) enter image description here

Then I open bmp with a hex editor and I can see the following information:

00: 424d 4600 0000 0000 0000 3e00 0000 2800  BMF.......>...(.
10: 0000 0200 0000 0200 0000 0100 0100 0000  ................
20: 0000 0800 0000 0000 0000 0000 0000 0000  ................
30: 0000 0000 0000 0000 0000 3f3f 3f00 3f00  ..........???.?.
40: 0000 4000 0000 0a                        ..@....

      

As far as I read in the Wikipedia article on BMP format ( https://en.wikipedia.org/wiki/BMP_file_format ) this part is a pixel array:

3f00 0000 4000 0000

What is the point of values ​​in a pixel array? Does 3F have a special meaning?

+1


source to share


1 answer


This hex dump you posted does not quite match the image you posted. This is what I get:

00000000 42 4D 46 00 00 00 00 00 00 00 3E 00 00 00 28 00 BMF.......>...(.
00000010 00 00 02 00 00 00 02 00 00 00 01 00 01 00 00 00 ................
00000020 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 FF FF FF 00 80 00 ................
00000040 00 00 40 00 00 00                               ..@...

      

The color table starts at 0x36. There are two RGBQUADs in there. The first, 0x00000000, is black. The next one, 0x00FFFFFF, is white.

After that, the pixel data starts. Each pixel is represented by one bit. Even if only two bits are required for each line of your image, each line will be aligned with a four-byte border. So the first line is 0x80000000 and the second is 0x40000000. It is likely that some applications may not bother to clear the padding bits.

These strings are interpreted byte by byte, from the most significant bit to the smallest in each byte.



The high bits of 0x8 are 1 and 0 and we should see color 1 (white) followed by color 0 (black), in that order on the bottom line. The rest of the bits are ignored because they will fit pixels beyond the width of 2, since the next three bytes only exist to ensure that the subsequent line is aligned to a 4-byte boundary.

The high bits of 0x4 are 0 and 1, so we should see color 0 (black) followed by color 1 (white), in the following order from the top. As before, the rest of the bits are ignored.

In your hex dump, the color table was black (0x00000000) and gray (0x003F3F3F). Nothing wrong. The pixel data had high bits of 0 and 0 in the first (bottom) row and 0 and 1 in the second (top) row. The other bits are random garbage used for padding.

(The fact that 0x3F looks like a gray value suggests that the encoder may not have cleared a variable or register that was reused after the color table was written.)

+3


source







All Articles