Trying to understand how a 1-bit BMP image is drawn

As you can see from this example , each channel (R, G, B) in the BMP file accepts an input. A 24-bit BMP image has 8 bits for -R, 8 bits for G and 8 bits for B. I saved the image in MS-paint as monochrome (black and white). Its property says that the image depth is 1 bit. The question is, who gets this 1 bit: R, G or B? Isn't it necessary that all three channels get some value? I can't figure out how MS-Paint painted this BMP image using 1 bit.

Thanks in advance for your answers.

+3


source to share


3 answers


There are several ways to save a bitmap. In this case, the important difference is RGB and is indexed.

RGB : , , . "" ( ) , - 8 , 8 () -. , - - , , , . , BGR-565, 16 , 5 , 6 5 .

In an indexed bitmap, the value stored with each of the pixels is the index (hence the "indexed bitmap") in the palette (color table). A palette is usually a regular table of colors, using RGB "pixel" formats to assign a specific color to each index. For example, index 0 could mean black, 1 could mean turqouise, etc.

In this case, the bit depth does not exactly match the color quality - you are not trying to map the entire color space, instead you are focusing on a subset of possible colors. For example, if you have 256 grayscale (say black to white), a true color bitmap would need at least three bytes per pixel (and each of those three bytes will have the same value), while you can use an indexed bitmap with an all-gray palette requiring only one byte per pixel (plus a palette cost of 256 * 3 bytes). There are many benefits to using indexed bitmaps and many tricks to improve image quality without using more bits per pixel, but that is beyond the scope of this question.



This also means that you only need as many possible values ​​as you want to show. If you only need 16 different colors, you only need four bits per pixel. If you only want a monochromatic bitmap (that is, either the pixel is "on" or it is disabled), you only need one bit per pixel — and that’s your case. If you have the number of different colors you want, you can easily get the bit depth you want by taking the base-2 logarithm (e.g. log 256 = 8).

So let's say you have an image that uses only two colors - black and white. You will create a palette with two colors, black and white. And for each of the pixels in the bitmap, you either store 0 if it's black, or 1 if it's white.

Now when you want to draw a bitmap like this you just read the palette (0 -> RGB (0, 0, 0), 1 -> RGB (1, 1, 1) in this case) and then you read one pixel after another ... If the bit is zero, draw a black pixel. If there is one, draw a white pixel. Done :)

+2


source


No, it depends on the type of data you have chosen to save. Since you chose to save as monochrome, RGB mapping is not used here, and the mapping used will be one byte per pixel, white to black.

Each type has its own way of mapping, keeping as 24-bit gives you RGB rendering, keeping how 256 bytes will render for each pixel, each value represents a color (you can find a table on the internet) since for monochrome you will have the same as a 256-bit image, but the color table will only have white and black colors.



Sorry for the mistake, the way I explained for monochrome is actually using Gray Scale, monochrome uses one bit to indicate whether a pixel is black or white, depending on the value of each bit, no mapping table is used.

+1


source


Monochrome consists of only two colors. This is done with only two bits.

0 for black and 1 for white. (This is why it is called with only 1 bit)

There is virtually no color in this profile, and (BGR) has nothing to do with it.

If you choose to export it as 8 bits, the colors used will be one byte in size. This is a complete shade of gray. (255 options)

As for the rest. 16 bit BMP responds to "Hello Color Profile" where you have two bytes for each color. (red, green, blue, yellow, cyan, magnetic, white, black) * 255 default saturation. This is 65,536 colors.

24-bit BMPs are 255 (^ 3) (255 * 255 * 255) with 16,777,216 colors. True Color profile.

+1


source







All Articles