Compression
The need for compression
Modern computers often generate files of very large sizes. For example, audio files often run to MBMegabyte (MB) - a measurement of file size or storage capacity. 1,048,576 bytes., while high definition video can be gigabytes in size. Such files require lots of storage space, and, because of their size, are difficult to transmit. These problems can be overcome by using compressionA method of reducing file sizes, particularly in digital media such as photos, audio and video..
There are two types of compression that can be applied to files:
- lossyA form of compression that reduces digital file sizes by removing data. compression
- losslessA form of compression that encodes digital files without losing detail. Files can also be restored to their uncompressed quality. compression
An explanation of lossy and lossless compression
Lossy compression
With lossy compression, some dataUnits of information. In computing there can be different data types, including integers, characters and Boolean. Data is often acted on by instructions. is removed and discarded, thereby reducing the overall amount of data and the size of the file.
An image can be compressed by reducing its colour depthThe amount of bits available for colours in an image.. This reduces the range of colours that the image contains. In practice this results in an averaging of shades of colours. For example, a very light shade of green could be averaged with a not so light shade - the very light shade might be discarded, and the pixels affected by it re-coloured with the darker shade.
Similarly, an audio file can be compressed by reducing the bit depthThe number of bits available to store an audio sample. of the samples. MP3 is a lossy audio file format.
Various lossy standards exist:
- the JPEG Joint Photographic Experts Group - JPEG is a digital image format which uses lossy compression. file format works on this principle, which is why JPEG files tend to be smaller in size
- the MPEGMoving Picture Experts Group – Layer 4 - a standard video file format using lossy compression. file format compresses audio and video, making it more suitable for streaming media
- >MP3A standard audio file format which uses lossy compression. Compatible with most media players. Designed by the Moving picture experts group - layer 3. is a lossy format for audio, including music
Lossless compression
There are some files that we would not want to lose data from. For example:
- text files
- spreadsheets
- financial records
- emails
With lossless compression, files are reduced in size without the loss of data. However, lossless compression does not usually achieve the same file size reduction as lossy compression.
Various lossless standards exist:
- PDFPortable Document Format - a file format developed by Adobe in an effort to standardise the way documents are shared. allows lossless compression of text documents
- GIFGraphics Interchange Format - an 8-bit digital image format which uses lossless compression. Also used for short animations. is a lossless image file format
One method of lossless compression is run length encoding (RLE). RLE looks at the data in a file for consecutive runs of the same data. These runs are stored as one item of data, instead of many.
Consider this row in a bitmap image:
The data for this is 00 00 00 11 11 11 11 00 00 00, which is ten data values of two characters each, giving 20 characters in total. RLE looks for the runs of each data, and records what the data is and how many times in succession it occurs. These values are stored instead of the original data.
So:
00000011111111000000 (20 characters) becomes:
608160 (6 characters)