Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A line of an icon is stored with run-length encoding as these pairs of (count, colour code): (5, 255), (2, 0), (9, 255). Each count and each colour code takes 1 byte. Without compression each pixel takes 1 byte.
Compression reduces file size: less storage, less bandwidth and a shorter transmission time. Lossy compression removes data for good (lower resolution or colour depth, lower sample rate or resolution). Lossless compression loses nothing; run-length encoding stores each run of repeated values as a count and a value.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. Pixels. pixels: five of colour 255, two of colour 0, nine of colour 255.
Step 2. Before. One byte a pixel: 16 bytes.
Step 3. After. bytes.
Step 4. Is data lost? No. Decoding writes each colour code the number of times its count says, and gives back exactly the same 16 pixels. Run-length encoding is lossless.
Answer: (a) 16 pixels. (b) 16 bytes before and 6 bytes after. (c) No, the line is rebuilt exactly.
Log in to join the discussion.
Loading…