Compression - Run Length Encoding (AQA GCSE Computer Science)

Revision Note

Test yourself

Run Length Encoding

What is run-length encoding?

  • Run-length encoding (RLE) is a form of data compression that condenses identical elements into a single value with a count

  • For a text file, "AAAABBBCCDAA" is compressed to "4A3B2C1D2A"

  • The string has four 'A's, followed by three 'B's, two 'C's, one 'D', and two 'A's

  • RLE is used in bitmap images to compress sequences of the same colour

  • For example, a line in an image with 5 red pixels followed by 3 blue pixels could be represented as "5R3B"

Represent Data in Frequency / Data Pairs

How do you represent data in frequency/data pairs?

  • Run-length encoding (RLE) uses frequency/data pairs to compress bitmap image data

  • For example, the following bitmap image with a colour depth of 1 bit would have the following binary bit pattern

Bitmap

Bit pattern

rle
rle-bits
  • Using RLE we group pixel colours and can create frequency/data pairs as follows

    • 30, 11, 20, 11, 20, 11, 50, 11, 30, 11, 10, 11, 60, 11......

rle-groups
  • 3 x 0 = 3 x white, 1 x 1 = 1 x black

  • Data pairs can carry over on to the next line, e.g. end of first line and start of second line is 5 x 0 (5 x white)

How do you represent a bitmap image from frequency/data pairs?

  • To recreate a simple bitmap from frequency/data pairs you need to know what binary code is assigned to what colour and reverse the process above

  • If we assume 0 = white and 1 = black and have the following frequency/data pairs and the image size is 5x3 pixels

    • 20, 11, 30, 31, 10, 51

  • The bitmap image would be

rle-example

Last updated:

You've read 0 of your 10 free revision notes

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.