SDK screenshot (iii): Theoretical preparation of compressed bitmaps

Source: Internet
Author: User

Compressed bitmap We use a simple stroke length encoding method, which is referred to in "Windows programming 15" for DIB compression.

In the bitmapinfoheader structure, there are two fields related to bitmap compression, respectively, bicompression (compression is the meaning of compression) and nisizeimage.

Where bicompression can be set to 4 common sense values: Bi_rgb,bi_rle8,bi_rle4 or bi_bitfields (they are defined in WINGDI.H as 0-3). For 4-bit and 8-bit bitmaps, when their bicompression is set to Bi_rle4 and Bi_rle8, the pixels are encoded as a stroke length (run-length encoding,rle) compression.
The principle of stroke length coding: The DIB image often has a series of identical pixels in a row. The stroke length encoding saves space by recording the value of the repeating pixel and the number of times it repeats.

Decoding for the RLE8
When the first byte is not 0 o'clock, the byte data is the repetition factor of the stroke length encoding, which indicates how many times the subsequent pixel data was repeated. For example
0x05 0x27
will be decoded to
0x27 0x27 0x27 0x27 0x27
When the first byte is 0 o'clock, the subsequent pixel is not duplicated in the source file and is not compressed, so it is output directly. For example
0x45 0x32 0x77 0x34 0x59 0x99
will be decoded to
0x32 0x77 0x34 0x59 0x99
Another case is that when the second byte is odd, it indicates that there is an unused extra byte at the end of the sequence. For example
0x00 0x05 0x32 0x77 0x34 0x59 0x99 0x00
will be decoded to
0x32 0x77 0x34 0x59 0x99

When writing a decoding program, you need to maintain a pair of values starting from (0,0) (y,x), each decoding a pixel, so that x+1, each end of a line decoding, will y+1, and reset x is 0.
When a 0x00 byte is encountered, followed by a 0x02 byte, the two bytes immediately following the read-in, and their most unsigned integer appended to the current x and Y values. After encountering a 0x00 byte followed by a 0x00 byte, the decoding of this line is over. The x should be set to 0 and y plus 1. When a 0x00 byte is encountered followed by a 0x01 byte, the decoding of the entire image is declared complete.

SDK (iii): Theoretical preparation of compressed bitmaps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.