Tool for encoding / decoding with Run-Length Encoding (RLE), a very basic data compression algorithm that consists in describing a string according to its repetitions.
RLE (Run-Length Encoding) - dCode
Tag(s) : Compression
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
Run Length Encoding (or RLE, or range encoding) is a data compression (lossless) technique based on successive repetitions of elements.
Run Length means run length , and indeed, with RLE, what matters is the length, the size of the repetitions (in a text, a message, etc.)
RLE is a generic name for this compression technique, several ways to use and implement it exist.
The text to be encoded is scanned to find sequences of identical characters, then note the character and the number of repetitions in the sequence.
Example: DDDDDCCCCOOODDE can be described as 5 times the D character followed by 4 times the C character, etc. The message can therefore be compressed D5C4C3D2E1 (10 characters instead of 15, compression rate: 33%).
This procedure only produces compression if the message consists of many repetitions.
Example: DCODE would be compressed D1C1O1D1E1 (10 characters instead of 5, compression rate: -100%). In order to avoid this kind of case, it is possible to omit the 1 in the case of non-repetitions.
It is possible to encode by reversing the characters and the counts.
Example: 5D4C3C2D1E is then equivalent to D5C4C3D2E1
In case of Binary data
If the message is composed of binary data (0 and 1), then it is possible to use RLE without indicating the character, the numbers are sufficient. The first number indicating the 0 (or the 1), then alternatively.
Example: 00011110000 is coded 3,4,5
Case of Numerical data
If the message is made up of numbers, then use a separator otherwise it will no longer be possible to distinguish the characters from their number of repetitions.
Example: 11111111111122 is coded as '12 -1,2-2 'and not' 12122 'which could be translated as' 1' repeated 2122 times, or 1 times' 2 'followed by 12' times the number '2 ', etc.
The RLE decompression consists in browsing the message formed of pairs (character, number of repetition) and writing the equivalent text by writing the character the corresponding number of times.
Example: D5C4C3D2E1 decomposes into D5, C4, O3, D2, C1 and repeats the characters the correct number of times: D5 => DDDDD > CCCC, etc. To get DDDDDCCCCOOODDE
Binary data case
Example: 3,4,5 is decoded 00011110000 (or 11100001111 depending on the convention used)
A message compressed with RLE is composed of pairs (Character-Number) or triples (Character-Separator-Number).
BMP and PCX image formats use RLE to reduce file size.