Images, sound and video files are huge, and every one of them has to be stored and sent somewhere. Compression shrinks them. Lossless methods rebuild the original exactly; lossy methods throw away data you are unlikely to miss. Learn both, apply run-length encoding, and justify the right method for a task.
Compression reduces file size so files need less storage and less bandwidth, and are transmitted faster. Lossless compression reduces the size with no loss of data: the original is rebuilt exactly. Lossy compression permanently removes data, usually detail that human senses notice least, giving much smaller files. Run-length encoding (RLE) is lossless: each run of identical values is replaced by a count and the value.
In the lab, try the lossy mode on the image and turn the amount of compression up. Notice which details disappear first, and that they never come back.
| Lossless | Lossy | |
|---|---|---|
| Data | No data is lost; the original is restored exactly | Data is permanently removed; the original cannot be restored |
| Size reduction | Smaller reduction | Much larger reduction |
| Examples | RLE, ZIP, PNG, FLAC | JPEG, MP3, most streamed video |
| Use for | Text, program code, spreadsheets, databases, medical or legal images | Photos, music and video for the web, streaming and social media |
A justification needs a reason linked to the scenario. "Lossy because it is smaller" earns less than "lossy, because the photo only needs to load quickly on a web page and the lost detail will not be noticed".
Switch the lab to RLE and encode the image row by row. The more long runs there are, the bigger the saving.
AAAAABBBCCCCCCCCD. Each character and each count is stored in 1 byte. How many bytes are saved?GGGGGGGGHHHHKKKKKKKKKKKK with RLE and give the saving if every count and character takes 1 byte.Four quick checks. Each correct answer earns XP and records this skill on your profile.
What is the main feature of lossless compression?
In the lab, when does RLE give the biggest saving?
What is WWWWWBBBWWWW after run-length encoding?
Which is a lossy technique?
The syllabus expects you to say how text, bitmaps, vectors and sound can each be compressed.
| File | How it can be compressed | Type |
|---|---|---|
| Text file | RLE for repeated characters; replacing repeated words or phrases with short codes held in a dictionary stored with the file | Lossless only: every character must be recovered |
| Bitmap image | RLE on runs of identical pixels; or reduce the resolution or colour depth, or merge similar colours into one (as JPEG does) | RLE is lossless; the others are lossy |
| Vector graphic | Remove redundant data in the drawing list and apply a lossless method such as RLE or ZIP to the object properties | Lossless: the objects must be redrawn exactly |
| Sound file | Perceptual coding: remove frequencies outside the range of human hearing and quieter sounds masked by louder ones (as MP3 does); or reduce the sampling rate or resolution | Lossy (lossless formats such as FLAC also exist) |
Never suggest lossy compression for a text file or program. Losing even one character changes the meaning, and a program would no longer run.
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
What is PPPPQQQQQQRR after run-length encoding?
A hospital stores X-ray images that doctors use for diagnosis. Which compression should be used?
Why does RLE make the data ABCDEF larger?
How is a sound file typically compressed using lossy compression?
This skill is now recorded on your profile. Keep the chain going.