44 total
By the end of this topic, you should be able to:
Compression means reducing the size of a file so that it needs less storage space and can be sent more quickly.
Files can become very large. This is especially true for sound, images and video. Large files cause problems because they take up more space on storage devices and take longer to upload, download or stream across a network.
Compression is needed for two main reasons.
First, it helps to save storage space. If files are smaller, more of them can be stored on a hard drive, SSD, memory card, phone or tablet. For example, a music player can store far more songs if the songs are compressed.
Second, it helps to reduce transfer time. Smaller files move faster across a network because there is less data to send. This is useful when sending files by email, downloading music, streaming video, or loading images on a website.
So, in simple terms, compression is used when we want files to be:
Compression is used in many everyday situations.
A music file may be compressed so that it can be stored on a phone and streamed over the internet without using too much data.
A photo may be compressed so that it takes up less storage and can be uploaded quickly to a website or sent in a message.
A video file may be compressed so it can be streamed online more smoothly.
A document may be compressed so that it uses less space and is easier to share.
A bitmap image may be compressed to reduce file size, especially when the same colour appears many times.
A vector graphic may be compressed because it is stored as text-based instructions, which can often be reduced efficiently.
There are two main types of compression: lossless and lossy.
Lossless compression reduces file size without losing any original data. After the file is decompressed, it returns to exactly the same form as before compression.
This means nothing is missing. Every character, every value and every part of the original file can be recovered.
Lossless compression is important when losing data would cause problems. For example, in text files and documents, even a tiny missing part could change the meaning of the file. That is why lossless compression is used when accuracy must stay perfect.
Lossless compression usually does not reduce file size as dramatically as lossy compression, but it keeps all the data safe.
Lossy compression reduces file size by removing some of the original data. After decompression, the file is not exactly the same as the original because some detail has been permanently lost.
This method works when a small drop in quality is acceptable. For example, in music, images and video, some missing detail may not be noticed easily by people.
Lossy compression can make files much smaller than lossless compression. However, it cannot restore the removed data.
The easiest way to remember the difference is this:
Here is the key idea:
In an exam, you may be asked to justify which method should be used. That means you must explain why one type is better for that situation.
Lossless compression should be used when the original file must be recovered perfectly.
This is suitable for:
Why? Because even one missing letter, number or symbol could make the file incorrect or harder to use.
Lossy compression should be used when reducing file size is more important than keeping every bit of original detail.
This is suitable for:
Why? Because people may not notice a small drop in quality, but the much smaller file size gives big benefits for storage and transfer.
Sound files can be very large, especially if they store high-quality audio. One common way to compress sound is by using MP3 compression.
MP3 is a lossy compression method. It reduces file size by removing sounds that people are less likely to hear.
This includes:
This method is sometimes described as perceptual music shaping. That means the compression is based on what the human ear is likely to notice and what it is unlikely to notice.
Because some sound data is removed, the original file cannot be fully recovered. That is why MP3 is lossy.
A typical music file can be reduced by about 90%. For example, a file of 80 MB may be reduced to about 8 MB. This makes it much easier to store on a device or stream over the internet.
The bit rate of a sound file affects its quality. Bit rate means the number of bits used each second. A higher bit rate usually means better quality, but also a larger file size. A lower bit rate gives a smaller file, but quality may fall.
So, sound compression is a trade-off between:
A bitmap image is made from pixels. Each pixel stores colour data. Because there can be many thousands or millions of pixels, bitmap files can become large.
One common bitmap compression format is JPEG. JPEG uses lossy compression.
JPEG works well for photographs because it reduces file size by removing some image detail that the human eye may not notice easily. For example, similar colours may be grouped together so that less data needs to be stored.
This gives a much smaller file, but the original image cannot be restored perfectly. That is why JPEG is lossy.
Lossy bitmap compression is useful when:
However, if exact image data must be kept, then a lossless method would be better.
A vector graphic is not stored as pixels. Instead, it is stored as instructions, such as lines, shapes, curves and their positions.
Many vector graphics, such as SVG files, are stored in a text-based format. Because of this, they can often be compressed efficiently.
This is closer to the way text is compressed, because repeated words, symbols or patterns in the file can be reduced.
Vector graphics can be compressed, but the success may be more limited than with some other file types. Still, since the file is based on structured text instructions, compression is possible.
For this syllabus, the important point is that vector graphics can be compressed because they are often stored as text-based data.
Text files can be compressed using lossless methods.
This is because text must stay exact. If a letter, punctuation mark or number is changed or removed, the meaning may change.
One important method you need to know is run-length encoding (RLE).
Run-length encoding (RLE) is a lossless compression method.
It works by looking for runs, which means repeated items that appear one after another.
Instead of storing every repeated item separately, RLE stores:
So if a letter appears many times in a row, RLE stores one number and one value instead of writing the same thing again and again.
RLE works best when there are long runs of repeated data. If the data changes all the time, RLE may not help much.
Suppose we have this text:
AAAABBBCCDAA
Instead of storing every character separately, RLE stores each group as a count and a character:
So the compressed version is:
4A3B2C1D2A
This is more efficient because repeated letters are grouped together.
Another example is:
aaaaabbbbccddddd
This can be represented as runs of repeated characters. The count tells us how many times a character appears in a row, and the value tells us which character it is.
In computer storage, the count may be stored in binary and the character may be stored using its ASCII code.
For example, the run 4A could be stored as:
This shows that RLE can be used at a lower machine level, not just in simple written form.
RLE is lossless because no data is removed. The repeated values are still all represented. They are just written in a shorter form.
When the file is decompressed, the computer reads the count and the value, then rebuilds the original sequence exactly.
So if the original data was:
AAAA
the computer can expand 4A back into AAAA with no change at all.
RLE works well when the file contains many repeated values in a row.
This happens in:
For example, a row of pixels such as:
0001001001000
contains repeated 0s and 1s. RLE can group these into runs, such as:
This usually needs less storage than storing each pixel separately.
RLE is not effective if the data changes often and does not contain long runs.
For example, if every character or pixel is different from the next one, then storing count-value pairs may not reduce size much. In some cases, it can even make the file larger.
So RLE is best when the data has lots of repetition.
RLE is very useful for some bitmap images, especially simple ones.
In a black-and-white bitmap image, each pixel may be represented using values such as:
If many pixels of the same colour appear in a row, RLE can store the run length and the pixel value instead of storing every single pixel.
For example, if a row begins with:
0001111000
this can be stored as:
That is more compact than writing all ten bits separately.
The same idea can be used across an image. If long runs continue from the end of one line to the start of the next, the runs can still be grouped.
This makes RLE useful for images with:
A black-and-white 8 × 8 image has 64 pixels.
If each pixel uses 1 byte, the uncompressed image needs:
64 bytes
Using RLE, the same image can be stored in fewer bytes if many neighbouring pixels are the same colour. In the example given, the image size falls to 30 bytes.
That shows how repeated pixel values can save storage space.
Colour images can also use RLE.
In a colour bitmap, each pixel may store RGB values:
If one pixel uses 3 bytes, then an 8 × 8 colour image needs:
[ 8 \times 8 \times 3 = 192 \text{ bytes} ]
If many neighbouring pixels are the same colour, RLE can store:
For example:
In the example given, the 8 × 8 colour image is reduced from 192 bytes to 92 bytes.
This works because repeated colours are grouped together.
The sources also describe some general ways of reducing file size. These are useful examples of compression in practice.
For movie or video files, file size can be reduced by:
For image files, file size can be reduced by:
These changes make the file smaller, but they often reduce quality. So they fit best with situations where some loss of quality is acceptable.
To answer compression questions well, remember these core ideas.
Compression is needed because it saves storage space and reduces the time needed to send files.
Lossless compression keeps all the original data, so it is used when accuracy matters.
Lossy compression removes some data, so it is used when smaller size matters more than perfect quality.
Text files are usually compressed with lossless methods because every character matters.
Bitmap images can be compressed using lossy methods such as JPEG, or lossless methods such as RLE when there are repeated pixel patterns.
Vector graphics can be compressed because they are often stored as text-based instructions.
Sound files such as MP3 use lossy compression by removing sounds people are less likely to notice.
RLE is a key lossless method you must know. It works by replacing repeated data with count-value pairs.
Compression — reducing the size of a file so it takes less storage space and can be sent faster.
Lossless compression — compression where the original file can be restored exactly after decompression.
Lossy compression — compression where some original data is removed permanently, so the exact original file cannot be restored.
Decompression — expanding a compressed file back into a usable form.
RLE (run-length encoding) — a lossless method that stores repeated data as a count and a value.
Run — a sequence of the same item repeated one after another.
Bitmap image — an image made from pixels.
Vector graphic — an image stored as drawing instructions, such as lines and curves, instead of pixels.
JPEG — a common lossy compression format for bitmap images, especially photographs.
MP3 — a lossy compression format for sound files.
MP4 — a compressed multimedia format that can store video, audio, images and animation.
Perceptual music shaping — removing sounds that people are unlikely to hear, in order to reduce sound file size.
Bit rate — the number of bits used or sent each second; in sound files, a higher bit rate usually means better quality and a larger file.
RGB — red, green and blue colour values used to represent colour in digital images.
Frame rate — the number of video frames shown or recorded each second.
Resolution — the amount of detail in an image, often linked to the number of pixels.
Bit depth / colour depth — the number of bits used to store the colour of each pixel.
Explain why compression is needed. Give two reasons.
Model Answer:
Describe the difference between lossy and lossless compression.
Model Answer:
A student wants to compress a text document before sending it. State which method should be used and justify your answer.
Model Answer:
Explain how run-length encoding (RLE) compresses a text file.
Model Answer:
AAAABBBCCDAA can be stored as 4A3B2C1D2A, which is shorter because repeated letters are grouped together.Explain how a sound file and a bitmap image can be compressed.
Model Answer:
Sign in to view full notes