1. Stroke Length Compression
The principle is to replace adjacent pixels with the same color value in a scan row with a Count value and the color value of those pixels. For example, aaabccccddeee can be replaced by 3a1b6c2d3e. RLE compression is very effective for images with a large area and the same color area. Many specific compression methods are derived from the RLE principle:
1. PCX stroke compression method:
This algorithm is actually a conversion algorithm from the bit ing format to the compression format. This algorithm adds 0xc1 before the byte when the CH> 0xc0 is compressed for the byte ch that appears once in a row, otherwise directly output CH, for the continuous occurrence of n Bytes of CH, is compressed into 0xc0 + N, CH these two bytes, so n maximum can only be ff-c0 = 3fh (decimal 63 ), when N is greater than 63, it must be compressed multiple times.
2. bi_rle8 compression method:
This compression method is used in bitmap files of Windows 3.1 and. The compression method also uses two bytes as the basic unit. The first byte specifies the number of color repetitions specified by the second byte. For example, encoding 0504 indicates that five pixels with a color value of 04 are displayed consecutively from the current position. When the second byte is zero, the second byte has a special meaning: 0 indicates the end of the row; 1
It indicates the end of the image; 2 escapes the last two bytes. These two bytes indicate the horizontal and vertical displacement of the next pixel relative to the current position, respectively. This compression method compresses the maximum number of pixels of an image to 8 bits (256 colors.
3. bi_rle compression method:
This method is also used in windows3.0/3.1 bitmap files. It is similar to bi_rle8 encoding. The only difference is that one byte of bi_rle4 contains two pixels of color. Therefore, it can only compress images of up to 16 colors. Therefore, this compression has limited application scope.
4. packbits ):
This method is used to compress bitmap data on Apple's Macintosh machine. This method is used in the tiff specification. This compression method is similar to the bi_rle8 compression method, for example, 1c1c1c1c2132325648 is compressed to 831c2181325648, obviously, this compression method is best to be the same for every 128 bytes in a row. The 128 bytes can be compressed into a value of 7f. This method is very effective.
Ii. Zip code compression:
It is also a common compression method. It was created for text files in 1952. Its basic principle is that frequently used data is replaced by short code, and rarely used data is replaced by long code, the code for each data is different. These codes are binary codes and the code length is variable. For example, if there is a sequence of raw data, abaccdaa is encoded as a (0), B (10), C (110), d111), and 010011011011100 after compression. To generate the Hoffmann encoding, You need to scan the original data twice. The first scan requires accurate statistics on the frequency of each value in the original data, and the second scan requires the establishment of the Hoffmann tree for encoding, because Binary Trees need to be built and traversed to generate codes, data compression and restoration are slow, but simple and effective, and thus widely used.
Iii. LZW Compression Method
LZW compression technology is more complex than most other compression technologies, and the compression efficiency is also high. The basic principle is to encode each character string that appears for the first time with a value. In the restoration program, the value is converted into the original string, for example, if the value 0 x is used to replace the string "abccddeee", 0x100 is used to compress the string whenever it appears. As for the ing between 0x100 and string, it is dynamically generated during the compression process, and this ing is hidden in the compressed data, with the decompression, this encoding table will be gradually restored from the compressed data, and the subsequent compressed data will generate more mappings Based on the correspondence between the preceding data. Until the compressed file ends. LZW is reversible and all information is retained.
Iv. Arithmetic Compression Method
Arithmetic compression is similar to Hoffmann encoding compression, but it is more effective than Hoffmann encoding. Arithmetic compression is suitable for files composed of the same recurring series. Arithmetic compression is close to the theoretical limit of compression. In this method, different sequences are mapped to an area between 0 and 1, which is represented as binary decimal places with variable precision (digits, the less common the data, the higher the accuracy (more digits). This method is complex and therefore not commonly used.
V. JPEG (Joint photography expert group jointphotographicexprertsgroup)
The JPEG standard is different from other standards. It defines incompatible encoding methods. In its most common mode, it is distorted, an image recovered from a jpeg file is always different from the original image, but the lossy compressed and reconstructed image is often better than the original image. Another notable feature of JPEG is that its compression ratio is quite high. Compared with the compressed image size, the original image size can range from 1% to 80 ~ 90%. This method works well and is suitable for multimedia systems.