P1 - Image RLE (1)
P1 - Image RLE (1)
COP3504C
Run-Length Encoding
RLE is a form of lossless compression used in many industry applications, including imaging. It is intended to
take advantage of datasets where elements (such as bytes or characters) are repeated several times in a row in
certain types of data (such as pixel art in games). Black pixels often appear in long “runs” in some animation
frames; instead of representing each black pixel individually, the color is recorded once, following by the number
of instances.
For example, consider the first row of pixels from the pixel image of a gator
(shown in Figure 1). The color black is “0”, and green is “2”:
Flat (unencoded) data: 0 0 2 2 2 0 0 0 0 0 0 2 2 0 _
The encoding for the entire image in RLE (in hexadecimal) – width, height, and pixels - is:
1 E |1 6 2 0 3 2 6 0 2 2 2 0 1 2 1 F 1 0 7 2 1 A F 2 1 0 9 2 3 0 1 2 1 0 3 2 6 0 3 2 3 0 8 2 5 0
\W/ \H/ \------------------------------------------PIXELS-----------------------------------------------/
Image Formatting
The images are stored in uncompressed / unencoded format natively. In addition, there are a few other rules to
make the project more tractable:
1. Images are stored as an array of bytes, with the first two bytes holding image width and height.
2. Pixels will be represented by a number between 0 and 15 (representing 16 unique colors).
3. No run may be longer than 15 pixels; if any pixel runs longer, it should be broken into a new run.
For example, the chubby smiley image (Figure 2) would contain the data shown in Figure 3.
NOTE: Students do not need to work with the image file format itself – they only need to work with byte
sequences and encode or decode them. Information about image formatting is to provide context.
Requirements
Student programs must present a menu when run in standalone mode and must also implement several methods,
defined below, during this assignment.
There are five ways to load data into the program that should be provided and four ways the program must be
able to display data to the user.
Loading a File
Accepts a filename from the user and invokes console_gfx.load_file(filename: str):
Select a Menu Option: 1
Enter name of file to load: testfiles/uga.gfx
Module Functions
Student modules are required to provide all of the following functions with the defined behaviors. We
recommend completing them in the following order:
File: rle_program.py
Method: Submit on ZyLabs