Professional Documents
Culture Documents
INTRODUCTION RLE stands for Run Length Encoding. It is a lossless algorithm that only offers decent compression ratios in specific types of data. Run-length encoding (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. This is most useful on data that contains many such runs: for example, simple graphic images such as icons, line drawings, and animations. It is not useful with files that don't have many runs as it could greatly increase the file size.
Als you can see, RLE encoding is only effective if there are sequences of 4 or more repeating characters because three characters are used to conduct RLE so coding two repeating characters would even lead to an increase in file size. It is important to know that there are many different run-length encoding schemes. The above example has just been used to demonstrate the basic principle of RLE encoding. Sometimes the implementation of RLE is adapted to the type of data that are being compressed.
Encoding Strings
Step 1. Set the previous symbol equal to an unmatchable value. Step 2. Read the next symbol from the input stream. Step 3. If the symbol is an EOF exit. Step 4. Write out the current symbol. Step 5. If the symbol is an does not match the previous symbol, set the previous symbol to the current symbol, and go to step 2. Step 6. Read and count additional symbols until a non-matching symbol is found. This is the run length. Step 7. Write out the run length. Step 8. Write out the non-matching symbol. Step 9. Set the previous symbol to the non-matching symbol, and go to step 2. When actually implementing traditional RLE, a little attention to detail is required in Step 6. The run length is stored in a finite number of bits (I used an unsigned char). Runs longer than the amount that can be counted need to be broken up into to smaller runs. When the maximum count is reached, just write the count value and start the process of looking for a run all over again. You
also need to handle the case where a run is ended by an EOF. When a run is ended by anEOF, write out the run length and exit.
Decoding Strings
Decoding traditionally encoded strings is even easier than encoding. Not only are there less steps, but there are no caveats. To decode a traditionally encoded stream: Step 1. Set the previous symbol equal to an unmatchable value. Step 2. Read the next symbol from the input stream. Step 3. If the symbol is an EOF exit. Step 4. Write out the current symbol. Step 5. If the symbol is an does not match the previous symbol, set the previous symbol to the current symbol, and go to step 2. Step 6. Read the run length. Step 7. Write out a run of the current symbol as long as indicated by the run length. Step 8. Go to step 1.
Computer generated colour images (e.g. architectural drawings) can also give fair compression ratios.
RLE also refers to a little-used image format in Windows 3.x, with the extension .rle, which is a Run Length Encoded Bitmap, used to compress the Windows 3.x startup screen.