0

Hex editor

Address 1D indicates the image is eight bits per pixel, but it isn't, each pixel is represented by 3 bytes (24 bits).

At first, I thought photoshop did this in error, but I found that this format was used for all greyscale images.

Instead of using four bytes for pixel, why don't .bmp images use a value from 0 - FF to describe the greyscale value of each pixel?

EDIT: I was able to answer my own question about the file structure

from Wikipedia

The 8-bit per pixel (8bpp) format supports 256 distinct colors and stores 1 pixel per 1 byte.

Each byte is an index into a table of up to 256 colors. This Color Table is in 32bpp 8.8.8.0.8 RGBAX format.

The color table shown in the hex editor is four bytes per pixel.

Far below that is the actual pixel array, which is 8 bits per pixel.

the actual pixel array

I figured that out by a calculation, the image is 64 x 64, 4096 pixels.

The pixel array starts at 436, and ends at 1437. In decimal, the difference between those two numbers is 4097, so the pixel array is exactly one byte per pixel.

I am still curious as to why a color table is necessary for a greyscale image, though

Community
  • 1
  • 1
superlazyname
  • 265
  • 3
  • 7
  • 17
  • hmm... I didn't notice that the numbers were incrementing steadily, this format is more complicated than I first thought. The top third of the image is the same value of black, yet the values change... – superlazyname May 30 '11 at 14:08
  • Looking at the pattern, I'd say it uses 4 bytes per pixel. – zneak May 30 '11 at 14:11

1 Answers1

0

I am still curious as to why a color table is necessary for a greyscale image, though

It looks like bmp files have no special greyscale mode. So you cannot set in the header the format is greyscale, so you need the color table to define the colors you use. Even if all colors are greyscale.

If you look at the .png format, you can define that you are using a greyscale image, so you don't need a color table there. (but it would also be possible to use a color table to create a grayscale image).

wimh
  • 15,072
  • 6
  • 47
  • 98