This post describes an implementation of a Run Length Encoding (RLE) based codec for binary images, implemented on Arduino
RLE is a form of lossless data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. For example an image of a fax document with text in black printed on white paper contains long runs of white pixels interspersed with short runs of black pixels.
Below we consider a hypothetical scan line and its RLE compression.
WWWWWWWWWWBBWWWWWWWBBBBBWWWBWWWWWWWWWWWBB
10W2B7W5B3W1B11W2B
The PC is connected to the Arduino via the serial port. Arduino IDE which runs on the PC is used to program the board through the serial port. A Python code runs on the PC sends bitstreams over the serial port to the Arduino. Depending on whether an image or an RLE encoding is sent, the Atmega displays the RLE encoding or the decoded image on the LCD screen.
The PC and the Arduino communicate using the following codec. The blue cells indicate header bytes, while the green cells indicate data bytes.
Code for this post can be accessed here.
LCD showing decoded image
LCD showing encoding of input image