First, the stroke length compression
The principle is to replace the adjacent pixels of the color value in a scan line with a count value and the color value of those pixels. For example: AAABCCCCCCDEEE, you can replace 3A1B6C2D3E. For images with large area, the same color area, use the RLE compression method very effective. Many specific stroke compression methods are derived from the RLE principle:
1.PCX stroke compression method:
This algorithm is actually a conversion algorithm in the bit mapping format to compression format, which is added to the byte of the byte CH for continuous appearance, if CH> 0xc0 compresses 0xC1 before this byte, otherwise directly outputs CH, for continuous The n-byte CH appears, then compresses the two bytes of 0xc0 n, CH, so N maximum can only be ff-c0 = 3Fh (decimal 63), when N is greater than 63, then multiple compression needs.
2.bi_rle8 compression method:
This compression method is used in bitmap files in Windows3.0, 3.1. This compression method is also based on two bytes. The first byte specifies the number of colors specified with the second byte. If encoded 0504 indicates that the pixels of 5 color values 04 are continuously displayed from the current position. When the second byte is zero, the second byte has a special meaning: 0 indicates the end of the line; 1 means the end; 2 of the two bytes, the two bytes indicate the next pixel relative to the current position. Horizontal displacement and vertical displacement. This compression method can be compressed by an image pixel bit number of 8 bits (256 colors).
3.BI_RLE compression method:
The method is also used in a Windows 3.0 / 3.1 bitmap file, which is similar to BI_RLE8 encoding, and the only difference is: Bi_RLE4 contains two pixels, so it can only compress the number of colors that do not exceed 16 Image. Thus this range of compressed applications is limited.
4. Tightening bit compression method (Packbits):
The method is a bitmap data compression method for Apple's Macintosh machine. This method is used in the TIFF specification. This compression method is similar to the Bi_RLE8 compression method, such as 1C1C1C1C2132325648 compression to: 831C2181325648, which is obvious, this compression method is most A good situation is the same for each continuous 128 bytes, which can be compressed as a value 7f. This method is still very effective.
Second, Huffman coding compression:
Also a commonly used compression method. It is established in 1952 for text files. The basic principle is that frequent data is replaced with shorter code, and the data rarely used is replaced by a longer code, and the code of each data is different. These codes are binary code, and the length of code is variable. Such as: A raw data sequence, ABACCDAA is encoded as A (0), B (10), C (110), D111), and is 010011011011100 after compression. Generating Hoffman coding requires two times to the original data, the first time scan to accurately count the frequency of each value in the raw data, the second time is to establish a Huffman tree and encode, because it is necessary to establish a binary tree And travers the binary tree to generate a code, so the data compression and restore speed are slow, but it is simple and effective, and thus a wide range of applications.
Third, LZW compression method
LZW compression technology is complicated than most other compression technologies, and compression efficiency is also high. The basic principle is to encode each of the first appearance character strings, and then replace this value into the original string, such as using the value 0x100 instead of the string "abccddeee" whenever this When the string is used, it uses 0x100 instead of compression. As for the correspondence between 0x100 and strings, it is dynamically generated during the compression process, and this correspondence is implicit in compressed data, and the decompression is gradually recovered from the compressed data, The latter compressed data will produce more correspondence based on the corresponding relationship generated by the previous data. Until the compressed file ends. LZW is reversible, all information is all reserved. Fourth, arithmetic compression method
Arithmetic compression is similar to the Hoffman encoding compression method, but it is more effective than Hoffman coding. Arithmetic compression is suitable for files consisting of the same repeating sequence, arithmetic compression proximate the theoretical limit of compression. This method is to bring different sequences to the area between 0 and 1, which represents a binary fraction of a variable precision (bit), the more uncommon data, the higher the accuracy of data (more Number, this method is more complicated and is less common.
Five, JPEG (Joint Photographs Expert Group JointPhotographicExprertsgroup)
The JPEG standard is different from other standards. It defines an incompatible encoding method. In its most common mode, it is distorted, and the image recovered from the JPEG file is always different, but damage The image after compression reconstruction is often better than the original image. Another significant feature of JPEG is that its compression ratio is relatively high, the original image size is from 1% to 80 to 90% compared to the size of the image after the compressed image. This method is also suitable for multimedia systems.