(computer science) A method of data compression that encodes strings of the same character as a single number.
| Sci-Tech Dictionary: run-length encoding |
(computer science) A method of data compression that encodes strings of the same character as a single number.
| 5min Related Video: Run-length encoding |
| Abbreviations: RLE |
| Meaning | Category |
| Bitmap graphics (Utah Run-Length Encoded image file) | Computing->File Extensions |
| Red Letter Edition | Community->Media |
| Required Local Effort | Community->Educational |
| Research Laboratory of Electronics at MIT | Academic & Science->Electronics Academic & Science->Universities |
| Right lower extremity | Medical->Physiology |
| Robert Lee Entertainment | Business->Firms |
| Run Length Encoded file | Computing->General |
| Run Length Encoding | Computing->General Computing->Networking |
| Windows or CompuServe RLE image format | Academic & Science->Electronics |
Click here to submit an acronym.
| Wikipedia: Run-length encoding |
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, relatively simple graphic images such as icons, line drawings, and animations. It is not recommended for use with files that don't have many runs as it could potentially double the file size.
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.1 startup screen.
Contents |
For example, consider a screen containing plain black text on a solid white background. There will be many long runs of white pixels in the blank space, and many short runs of black pixels within the text. Let us take a hypothetical single scan line, with B representing a black pixel and W representing white:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWIf we apply the run-length encoding (RLE) data compression algorithm to the above hypothetical scan line, we get the following:
12W1B12W3B24W1B14WInterpret this as twelve W's, one B, twelve W's, three B's, etc.
The run-length code represents the original 67 characters in only 18. Of course, the actual format used for the storage of images is generally binary rather than ASCII characters like this, but the principle remains the same. Even binary data files can be compressed with this method; file format specifications often dictate repeated bytes in files as padding space. However, newer compression methods such as DEFLATE often use LZ77-based algorithms, a generalization of run-length encoding that can take advantage of runs of strings of characters (such as BWWBWWBWWBWW).
Run-length encoding performs lossless data compression and is well suited to palette-based iconic images. It does not work well at all on continuous-tone images such as photographs, although JPEG uses it quite effectively on the coefficients that remain after transforming and quantizing image blocks.
Common formats for run-length encoded data include Truevision TGA, PackBits, PCX and ILBM.
Run-length encoding is used in fax machines (combined with other techniques into Modified Huffman coding). It is relatively efficient because most faxed documents are mostly white space, with occasional interruptions of black.
Data that have long sequential runs of bytes (such as lower-quality sound samples) can be RLE compressed after applying a predictive filter such as delta encoding.
Note: this basic code assumes that the input valid alphabet string only
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RunLengthEncoding { public String encode(String source) { StringBuffer dest = new StringBuffer(); for (int i = 0; i < source.length(); i++) { int runLength = 1; while( i+1 < source.length() && source.charAt(i) == source.charAt(i+1) ) { runLength++; i++; } dest.append(runLength); dest.append(source.charAt(i)); } return dest.toString(); } public String decode(String source) { StringBuffer dest = new StringBuffer(); Pattern pattern = Pattern.compile("[0-9]+|[a-zA-Z]"); Matcher matcher = pattern.matcher(source); while (matcher.find()) { int number = Integer.parseInt(matcher.group()); matcher.find(); while (number-- != 0) { dest.append(matcher.group()); } } return dest.toString(); } public static void main(String[] args) { RunLengthEncoding RLE = new RunLengthEncoding(); String example = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"; System.out.println(RLE.encode(example)); System.out.println(RLE.decode("1W1B1W1B1W1B1W1B1W1B1W1B1W1B")); } }
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
| Best of the Web: Run-length encoding |
Some good "Run-length encoding" pages on the web:
Math mathworld.wolfram.com |
| crunch (computer jargon) | |
| RLE | |
| Modified Huffman coding |
| One diamensional Run-length encoding? | |
| Why Run Length Encoding algorithm supports only 24 bit color depth? | |
| Can you tell me how to write code for run length encoding of Bit map images in c language? |
Copyrights:
![]() | Sci-Tech Dictionary. McGraw-Hill Dictionary of Scientific and Technical Terms. Copyright © 2003, 1994, 1989, 1984, 1978, 1976, 1974 by McGraw-Hill Companies, Inc. All rights reserved. Read more | |
![]() | Abbreviations. STANDS4.com - The source for acronyms and abbreviations. Copyright ©2006 STANDS4 LLC. All rights reserved. Read more | |
![]() | Wikipedia. This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Run-length encoding". Read more |