0% found this document useful (0 votes)
19 views10 pages

Computing Mike

Uploaded by

mike.saunders
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views10 pages

Computing Mike

Uploaded by

mike.saunders
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Computing

With: Mr Mike
Run-length encoding (RLE)
Run-length encoding (RLE) can be used for lossless compression of a number of
different file formats:

» it is a form of lossless/reversible file compression


» it reduces the size of a string of adjacent, identical data (e.g. repeated colours
in an image)
» a repeating string is encoded into two values:
– the first value represents the number of identical data items (e.g. characters) in
the run
– the second value represents the code of the data item (such as ASCII code if it
is a keyboard character)
» RLE is only effective where there is a long run of repeated units/bits.
Using RLE on text data
Consider the following text string: ‘aaaaabbbbccddddd’. Assuming each character
requires 1byte then this string needs 16bytes.

If we assume ASCII code is being used, then the string can be coded as follows:

This means we have five characters with ASCII code 97, four characters with
ASCII code 98, two characters with ASCII code 99 and five characters with
ASCII
code 100.

Assuming each number in the second row requires 1 byte of memory,


the RLE code will need 8 bytes. This is half the original file size.
Using RLE on text data adding a flag
One issue occurs with a string such as ‘cdcdcdcdcd’ where RLE compression
isn’t
very effective.

A flag preceding data indicates that what follows are the number of repeating
units.

When a flag is not used, the next byte(s) are taken with their face value and a run
of 1 (for example, 01 99 means one character with ASCII code 99 follows).

Consider this example:


Using RLE on text data adding a flag

The original string contains 32 characters and would occupy 32 bytes of storage.
The coded version contains 18 values and would require 18 bytes of storage.

Introducing a flag (255 in this case) produces:

This has 15 values and would, therefore, require 15 bytes of storage. This is a
reduction in file size of about 53% when compared to the original string.
Using RLE with images
Example 1: Black and white image
Using RLE with images
Example 2: Coloured images

This produces the following data: 2 0 0 0 4 0 255 0 3 0 0 0 6 255 255 255 1 0 0 0


2 0 255 0 4 255 0 0 4 0 255 0 1 255 255 255 2 255 0 0 1 255 255 255 4 0 255 0
4 255 0 0 4 0 255 0 4 255 255 255 2 0 255 0 1 0 0 0 2 255 255 255 2 255 0 0
2 255 255 255 3 0 0 0 4 0 255 0 2 0 0 0.
Using RLE with images
Example 2: Coloured images

The original image (8 × 8 square) would need 3 bytes per square (to include
all three RGB values). Therefore, the uncompressed file for this image is
8 × 8 × 3 = 192 bytes.

The RLE code has 92 values, which means the compressed file will be 92bytes in
size. This gives a file reduction of about 52%. It should be noted that the file
reductions in reality will not be as large as this due to other data which needs to
be stored with the compressed file (e.g. a file header).
Pop Quiz
1. What are the five stages of the program life cycle?
» analysis
» design
» coding
» testing

2. What do we use in the analysis stage to identify whats


» abstraction
required?
» decomposition

3. What formal documentation do we use in the design stage?


» structure charts
» flowcharts
» pseudo code
Thank you.
This concludes Data representation

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy