tanszek:oktatas:techcomm:rle_coding
Differences
This shows you the differences between two versions of the page.
| tanszek:oktatas:techcomm:rle_coding [2024/10/07 08:00] – created knehez | tanszek:oktatas:techcomm:rle_coding [2025/11/10 14:51] (current) – knehez | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Run-length | + | ===== Run-Length |
| - | Run-Length Encoding (RLE) – simple | + | Run-Length Encoding (RLE) is one of the simplest **lossless data compression** techniques. |
| + | It works by replacing sequences of **repeated elements** (called " | ||
| - | It’s easy to understand with an example. | + | Run-Length Encoding cannot be attributed |
| - | Let’s encode the following characters using RLE encoding: | + | ---- |
| - | < | + | |
| - | Encoded: | + | ==== Basic Idea ==== |
| - | < | + | When a sequence contains the same value multiple times in a row, instead of storing it multiple times, we store only the value and the number of times it repeats. |
| - | The interpretation is: 12 W’s, 1 B, 12 W’s, 3 B’s, and so on. | + | For example: |
| + | < | ||
| + | AAAAABBBCCDAA → 5A3B2C1D2A | ||
| + | </ | ||
| - | Thus, the text encoded with run-length encoding describes the original 67 characters using 18. Of course, it is used with binary code rather than characters. | + | Here: |
| + | * ' | ||
| + | * ' | ||
| + | * ' | ||
| + | * ' | ||
| + | * ' | ||
| - | C program that implements this algorithm: | + | The original message had 12 characters, but the encoded version has only 10, so there is some compression (especially for longer runs). |
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Binary Example ==== | ||
| + | RLE is especially effective for **binary data**, such as black-and-white images. | ||
| + | |||
| + | Example (0 = white pixel, 1 = black pixel): | ||
| + | |||
| + | < | ||
| + | Original: 000000001111100000011111111000000000 | ||
| + | Encoded : 8 0s, 5 1s, 6 0s, 8 1s, 7 0s → (8, | ||
| + | </ | ||
| + | |||
| + | This binary form is what early image formats (like **PCX**, **TGA**) and **FAX machines** used. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Decoding ==== | ||
| + | To reconstruct (decode) the original message, we simply repeat each symbol as many times as its count indicates. | ||
| + | |||
| + | For example: | ||
| + | < | ||
| + | Encoded: 12W1B12W3B24W1B14W | ||
| + | Decoded: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWW | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Advantages ==== | ||
| + | * Very simple to implement | ||
| + | * Works well for data containing **long runs of identical values** (e.g., simple images, icons, masks) | ||
| + | * Low computational cost (fast encoding/ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Disadvantages ==== | ||
| + | * Inefficient when the data changes frequently (e.g., photographs, | ||
| + | * May increase file size if no long runs exist (e.g,. `ABCD` → `1A1B1C1D`, which is longer) | ||
| + | * Usually combined with other compression algorithms in practical applications | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Applications ==== | ||
| + | * Image compression (TGA, PCX, BMP with RLE) | ||
| + | * FAX transmission (CCITT Group 3/4 standard) | ||
| + | * Simple bitmap fonts | ||
| + | * Storing masks and binary patterns | ||
| + | * Used as a sub-step in complex formats (e.g., TIFF, PDF internal compression) | ||
| + | |||
| + | ---- | ||
| + | A C program that implements this algorithm: | ||
| <sxh c> | <sxh c> | ||
tanszek/oktatas/techcomm/rle_coding.txt · Last modified: 2025/11/10 14:51 by knehez
