Fundamentals of data representation - AQAData compression

All data is represented as binary digits, whether it is numbers, text, images or sound. Calculations are also made in binary.

Part ofComputer ScienceComputational thinking and problem solving

Data compression

Modern computers often generate files of very large sizes. For example, audio files often run to , while high definition video can be 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 .

Types of compression

There are two types of compression that can be applied to files:

  • compression
  • compression

An explanation of lossy and lossless compression

Lossy compression

With lossy compression, some 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 . 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 affected by it re-coloured with the darker shade. If done carefully, this is not likely to significantly damage the quality of the image.

A high resolution image next to a compressed version of the same image

For sound, lossy compression may remove sounds outside the human range of hearing that were nevertheless picked up during recording. This would produce no noticeable loss of quality, but would reduce the file size.

Similarly, an audio file can be compressed by reducing the of the samples. MP3 is a lossy audio file format.

Various lossy standards exist:

  • the file format works on this principle, which is why JPEG files tend to be smaller in size
  • the file format compresses audio and video, making it more suitable for streaming media
  • 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:

  • allows lossless compression of text documents
  • 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:

Bitmap image showing ten data values with two characters each

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.

For example:

00000011111111000000 becomes:

60 81 60 (six 0s, eight 1s, six 0s)

In large files, this can result in significant space savings.