The principle of Run-length encoding (RLE) stroke length is to replace adjacent pixels with the same color values in a scan row with a Count value and the color values 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 is used for the bytes ch that appears once in a row, if ch> 0xc0, 0xc1 is added before the byte during compression; otherwise, CH is output directly. For the byte ch that appears n times in a row, it is compressed into 0xc0 + N, Ch, therefore, n can only be FF-C0 = 3fh (63 in decimal format) at the maximum. When n is greater than 63, it needs to be compressed multiple times.
2. bi_rle8 compression method: This compression method is used in Windows bitmap files. 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 indicates the end of the graph; 2 escapes the next two bytes, these two bytes indicate the horizontal and vertical displacement of the next pixel relative to the current position. 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 Windows bitmap files. It is similar to bi_rle8 encoding. The only difference is that one byte of bi_rle4 contains two pixel colors. 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 TIFF specifications, this compression method is similar to the bi_rle8 compression method. For example, 1c1c1c2132325648 is compressed to 83 1C 21 81 32 56 48. Obviously, this compression method is best suited to the same size for every 128 bytes in a row, the 128 bytes can be compressed into a value of 7f. This method is very effective.
From: http://blog.csdn.net/lynningame/article/details/1373694