In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What is BMP?
BMP is a hardware-independent image file format, which is widely used. It uses the bit mapping storage format and does not use any compression except for the optional depth of the image, so the BblP file takes up a lot of space. The image depth of BMP files can be selected from lbit, 4bit, 8bit and 24bit. When BMP files store data, images are scanned from left to right and from bottom to top.
Because BMP file format is a standard for exchanging graph-related data in Windows environment, the graphics and image software running in Windows environment supports BMP image format.
A typical BMP image file consists of three parts: the bitmap file header data structure, which contains information such as the type and display content of the BMP image file, and the bitmap information data structure, which contains the width, height, compression method and color definition of the BMP image.
Examples of specific data:
For example, at the beginning of a BMP file:
The BMP file can be divided into four parts: bitmap file header, bitmap information header, color swatch, and image data array, which are separated by * in the above image.
1. Image file header
1) 1: image file header. 424Dh = "BM", indicating that it is an BMP format supported by Windows.
2) 2-3: the entire file size. 4690 0000, 00009046h=36934.
3) 4-5: reserved, must be set to 0.
4) 6-7: the offset from the file to the bitmap data. 4600 0000, which is 00000046h=70. The header above is 35 words = 70 bytes.
5) 8-9: bitmap header length.
6) 10-11: bitmap width, in pixels. 8000 0000, 00000080h=128.
7) 12-13: bitmap height, in pixels. 9000 0000, 00000090h=144.
8) 14: the number of bitplanes of the bitmap, which is always 1. 0100, for 0001h=1.
2. Bitmap information header
9) 15: the number of bits per pixel. There are 1 (monochrome), 4 (16 colors), 8 (256 colors), 16 (64K colors, high colors), 24 (16m colors, true colors), 32 (4096m colors, enhanced true colors). 1000 is 0010h=16.
10) 16-17: compression instructions: 0 (no compression), 1 (RLE 8-bit RLE compression), 2 (RLE 4-bit RLE compression), 3 (Bitfields, bit domain storage). RLE simply uses the number of pixels + pixel value to compress. T408 uses the bit field storage mode, using two bytes to represent a pixel, and the bit field is assigned as r5b6g5. 0300 0000 in the figure is 00000003h=3.
11) 18-19: the size of bitmap data in bytes, which must be a multiple of 4, numerically equal to bitmap width × bitmap height x bits per pixel. 0090 0000 is 00009000h=80 × 90 × 2h=36864.
12) 20-21: horizontal resolution in pixels per meter. A00F 0000 is 0000 0FA0h=4000.
13) 22-23: vertical resolution in pixels per meter. A00F 0000 is 0000 0FA0h=4000.
14) 24-25: the number of color indexes used by the bitmap. If set to 0, all palette items are used.
15) 26-27: the number of color indexes that have an important impact on image display. If it's 0, it means it's all important. Third, color plate (non-essential)
16) 28-35: color plate specification. For each table item in the color palette, the value of RGB is described in the following ways:
1 byte for blue component
1 byte for green component
1 byte for red component
1 byte for filler (set to 0)
Color swatches are not used for 24-bit true color images because the RGB values in the bitmap represent the color of each pixel.
For example, the color swatch is 00F8 0000 E007 0000 1F00 0000 0000 0000, where:
00FB 0000 is FB00h=1111100000000000 (binary), which is the mask for the red component.
E007 0000 is 07E0h=0000011111100000 (binary), which is the mask for the green component.
1F00 0000 is 001Fh=0000000000011111 (binary), which is the mask for the red component.
0000 0000 is always set to 0.
The various color component values can be obtained by the "and" operation between the mask and the pixel value and then the shift operation. If you look at the mask, you can see that in fact, in the two byte 16 bits of each pixel value, 5, 6, and 5 bits from high to low are r, g, b components, respectively. After taking out the component value, multiplying the r, g and b values by 8, 4 and 8 respectively, you can make up the first component into one byte, and then combine the three bytes according to rgb and put them into memory (also in reverse order), which can be converted into 24-bit standard BMP format.
IV. Image data array
17) 17Mel.: every two bytes represents a pixel. The first byte in the array represents the pixel in the lower-left corner of the bitmap, while the last byte represents the pixel in the upper-right corner of the bitmap.
Now open a bmp file with winhex and view its hexadecimal data.
A bmp file starts with a BITMAPFILEHEADER structure, and the first attribute of BITMAPFILEHEADER is bfType (2 bytes), which is always equal to 0x4D42. Because the data in memory is arranged high on the left and low on the right, it is shown as (424D) when viewed from left to right in memory, so the first two bytes in winhex are displayed as (424D) in this way. later data are all of this characteristic and will not be repeated.
1. The second attribute of BITMAPFILEHEADER is bfSize (4 bytes), which represents the size of the entire bmp file, which is equal to 0x000004F8=1272 bytes.
2. The third and fourth attributes of BITMAPFILEHEADER are bfReserved1 and bfReserved2 (2 bytes each). Here are two reserved attributes, both of which are 0, which is equal to & H0000 and 0 × 0000.
3. The fifth attribute of BITMAPFILEHEADER is bfOffBits (4 bytes), which represents the position offset of the DIB data area in the bmp file, which is equal to 0 × 00000076x118, indicating that the data area starts from the following 118 bytes of the file.
4. This is the end of the BITMAPFILEHEADER structure. You will find that BITMAPFILEHEADER only accounts for 14 bytes at the beginning of the bmp file, but it needs to be noted that a BITMAPFILEHEADER structure variable is defined in vb, whose length accounts for 16 bytes. The reason is that the first attribute should only be allocated 2 bytes, but it is actually allocated 4 bytes, 2 more bytes, so if you want to save a bmp picture Be sure to keep this in mind when writing BITMAPFILEHEADER structures.
Next comes the BITMAPINFO structure part. The BITMAPINFO segment consists of two parts: BITMAPINFOHEADER structure and RGBQUAD structure. Among them, the RGBQUAD structure represents the color information of the picture, and sometimes it can be omitted, the general 24-bit pictures and 32-bit pictures do not have RGBQUAD structure, because the DIB data area directly shows the RGB value, generally 4-bit pictures and 8-bit pictures have RGBQUAD structure. (the number of bits of a picture is how many bits are used to represent a color information. For example, a 4-bit picture represents a color information with 4 bit.) Whether there is a RGBQUAD structure in a bmp file can be judged according to the fifth attribute bfOffBits of the previous BITMAPFILEHEADER structure, because the length of the BITMAPINFOHEADER structure is 40bit. If the offset to the DIB data area is not reached after the end of the BITMAPINFOHEADER structure, it is stated that the next data is the RGBQUAD structure part. C:\ WINDOWS\ Blue Lace 16.bmp here is a 4bit image, so it has a RGBQUAD structure.
Let's move on to the BITMAPINFOHEADER section.
1. The first attribute of BITMAPINFOHEADER is biSize (4 bytes), which represents the length of the BITMAPINFOHEADER structure. The most common length is 40 bytes. In UltraEdit, you can see that the next 4 bytes are equal to 0 × 00000028040 bytes.
2. The second attribute of BITMAPINFOHEADER is biWidth (4 bytes), which represents the width of the bmp picture, which is equal to 0 × 000030048 pixels.
3. The third attribute of BITMAPINFOHEADER is biHeight (4 bytes), which represents the height of the bmp image, which is equal to 0 × 000030048 pixels.
4. The fourth attribute of BITMAPINFOHEADER is biPlanes (2 bytes), which represents the plane of the bmp picture. Obviously, the display has only one plane, so it is always equal to 1, which is equal to 0 × 0001 here.
5. The fifth attribute of BITMAPINFOHEADER is biBitCount (2 bytes), which represents the number of color bits of the bmp picture, that is, 24-bit map, 32-bit map, and so on. This equals 0 × 0004, which means that the picture is a 4-bit map.
6. The sixth attribute of BITMAPINFOHEADER is biCompression (4 bytes), which represents the compression attribute of the picture. The bmp image is not compressed, which is equal to 0, so it is 0 × 00000000 here.
7. The seventh attribute of BITMAPINFOHEADER is biSizeImage (4 bytes), which represents the size of the bmp image data area. When the last familiar biCompression is equal to 0, the value here can be omitted, so it is equal to 0 × 00000000.
8. The eighth attribute of BITMAPINFOHEADER is biXPelsPerMeter (4 bytes), which represents the number of pixels per meter on the X axis of the picture, which can be omitted, which is equal to 0x00000EC3=3779 pixels / meter.
9. The ninth attribute of BITMAPINFOHEADER is biYPelsPerMeter (4 bytes), which represents the number of pixels per meter on the Y axis of the picture, which can be omitted, which is equal to 0x00000EC3=3779 pixels / meter.
10. The 10th attribute of BITMAPINFOHEADER is biClrUsed (4 bytes), which indicates how many color index tables are used. Generally, the biBitCount attribute is less than 16. If it is equal to 0, it means that there are 2 ^ biBitCount color index tables, so it is still equal to 0 × 00000000.
11. The 11th attribute of BITMAPINFOHEADER is biClrImportant (4 bytes), which indicates how many important colors there are. A value equal to 0 means that all colors are important, so it is equal to 0 × 00000000 here.
This is the end of the BITMAPINFOHEADER structure.
Since the image has not yet reached the offset of the DIB data area, the next part is the RGBQUAD structure. The RGBQUAD structure consists of four bytes of data, so a RGBQUAD structure takes up only 4 bytes of space, each byte from left to right (blue, green, red, unused). In this picture, for example, I counted a total of 16 RGBQUAD structures. Because the picture is a 4-bit map, 2 ^ 4 equals 16, so it enumerates all 16 colors, which is a color index table. The color index table number starts at 0 and has a total of 16 colors, so the number is 0-15. As you can see from the winhex, the 16 RGBQUAD structures are in order:
Serial number: (blue, green, red, empty)
No. 0: (000.000000000.00)
No. 1: (0000000080pr 00)
No. 2: (00508000pr 0000)
No. 3: (005080pc80pr 00)
No. 4: (800.0000000.00)
No. 5: (800.00pc0080pr 00)
No. 6: (8050,80,00,00)
No. 7: (8050,80,80,80,0,00)
No. 8: (C0, and 00)
No. 9: (0010 / 0001 / FF / penny 00)
No. 10: (00.FF.000.00)
No. 11: (00.FFjinf.f.pr. 00)
No. 12: (FF,00,00,00)
No. 13: (FF,00,FF,00)
No. 14: (FF,FF,00,00)
No. 15: (FF,00)
At this point, it just satisfies the offset of the DIB data area, so the next byte is the content of the picture. It needs to be reminded that all DIB data scan lines are upside down, that is to say, an image first draws the bottom pixels, and then draws the top pixels, so the pixels represented by these DIB data start from the lower left corner of the picture and continue to the upper right corner of the picture.
Because the picture here is a 4-bit picture, that is, 4bit represents one pixel and one byte has 8 bit, so one word saves energy means 2 pixels.
As you can see from winhex, the first byte of the DIB data area is 0 × 44, and the hexadecimal number happens to be written in a set of 2 digits, which coincides with the 4bit picture, so 0 × 44 represents two pixels, the high 4 represents the first pixel, and the low 4 represents the second pixel. The 4 here does not mean the RGB color, but the color index number is 4. Because the index number starts with 0, 4 represents the fifth color in the index table. You can see from the drawing that the index number 4 is blue. This is the first byte, indicating that the lower left corner of the picture begins with 2 pixels. If PhotoShop opens this picture, the RGB value of the color taken out of the 2 pixels in the lower left corner is exactly equal to the RGB value of the fifth color in the index table. The following DIB data, and so on.
At this point, all the bmp pictures have been parsed, and a complete bmp picture can be drawn according to this information. Of course, you can also simply repair a BMP file that is not seriously damaged by hand!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.