Lesson 43: Squash the data
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
Smaller, with nothing lost
- Compression makes a file smaller, so it needs less storage and is sent faster.
- Lossless compression loses nothing: you can get back every bit. Lossy compression throws some data away for good.
- Run-length encoding (RLE) is lossless. It stores a run of the same value as how many and which one.
Words for this lesson
| Word | Meaning |
|---|---|
| run | the same value several times in a row |
| encode | change data into the short form |
| decode | change it back |
| lossless | nothing is lost when you decode |
English
RLE on a picture
| Pixels in one row | RLE |
|---|---|
| W W W W B B W W | 4W 2B 2W |
| B B B B B B B B | 8B |
| W B W B | 1W 1B 1W 1B |
- 8 black pixels take 2 characters instead of 8. But a row that changes all the time gets bigger.
English
A digit is a character
void setup() {
Serial.begin(9600);
String out = "";
out += String(4);
out += 'A';
Serial.println(out);
}
void loop() {
}
- The Monitor shows 4A:
String(4)turns the number 4 into the character '4'.
English
In the exam
- 0478/11/M/J/20 Q3(c): Carla uses lossless compression on photos. Describe how it reduces the file size. Mark scheme: a compression algorithm is used; no data is removed; an index or dictionary of pixels is made; the number of times a pixel is repeated in a row is stored. That last point is RLE, your first program.
Độ khó 4/5 · 280 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Run-length encoding (RLE) makes data smaller with no loss: a run of the same character is stored as how many, then the character. AAAABBBCCD becomes 4A3B2C1D. Type a text (no run is longer than 9). Print RLE: and the encoded text.
Nhấn Chạy để xem kết quả ở đây.
Độ khó 4/5 · 280 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Now decode: the text comes in pairs of a digit and a character. 4A3B becomes AAAABBB. Type an encoded text and print Text: and the full text again. Nothing is lost: you get back exactly what was encoded.
Nhấn Chạy để xem kết quả ở đây.