# How is the color of the pixels encoded

## Image coding

One way in which computers can save and transfer images works as follows: A rectangular grid is placed over the image and then for each sub-square it is recorded which color prevails in this part of the image. In the coded message, each sub-square is named as a colored point pixel represents. That is why pictures coded in this way are also called Raster graphics or Pixel graphics (see Wikipedia). As an example, the image of the robot bit with different grid sizes:

As with all other codes, a code table is required to code the colors. It assigns a binary code to all colors. The corresponding code table in the mobile phone of the three robots is not very large, because the mobile phone of the robot can only display images with a maximum of eight colors:

 White 0000 black 0001 red 0010 green 0011 yellow 0100 brown 0101 orange 0110 blue 0111

Thus, every four bits of the coded message correspond to one pixel in the decoded image.

### Image compression

Coding images can take up a lot of space if the grid is very large and therefore many pixels have to be coded. Here it would be very practical if the image could be compressed. The compression process of the three robots' mobile phones takes advantage of the many images that they often contain large areas of the same color. The coding of such areas is relatively monotonous: one pixel of the same color follows the next. If people had to convey such a picture to themselves, they would not say stubbornly "green, green, green, green ..." but they would probably shorten it with "now there are 5 green pixels, then 20 yellow, then ...".

This one trick can also use the three robots' mobile phones. If several pixels of the same color follow one another in an image, this can be coded accordingly. In addition to the 8 color values, there are also 8 repetition instructions in the code table:

 White 0000 2 pixels 1000 black 0001 3 pixels 1001 red 0010 4 pixels 1010 green 0010 5 pixels 1011 yellow 0100 6 pixels 1100 brown 0101 7 pixels 1101 orange 0110 8 pixels 1110 blue 0111 9 pixels 1111

Eight yellow pixels can thus be coded to save space as follows:

### example

The following example shows step-by-step how compressed images can be decoded. The compressed image looks like this:

 111000101001001010000000100100101001001010000000100100 100010110000000010001011000000001010010010100000001001 001010010010100000001001001011100010

Since the image is compressed, it is not immediately apparent how big the image is. The first step is to decompress the message:

 1110 0010 8 pixels red 1001 0010 3 pixels red 1000 0000 2 pixels white 1001 0010 3 pixels red 1001 0010 3 pixels red 1000 0000 2 pixels white 1001 0010 3 pixels red 0010 1 pixel red 1100 0000 6 pixels white 0010 1 pixel red 0010 1 pixel red 1100 0000 6 pixels white 0010 1 pixel red 1001 0010 3 pixels red 1000 0000 2 pixels white 1001 0010 3 pixels red 1001 0010 3 pixels red 1000 0000 2 pixels white 1001 0010 3 pixels red 1110 0010 8 pixels red

So the image consists of 64 pixels. Since it has to be square, the image is now recorded in a grid of 8x8 pixels:

Continue to music decoding ...

If you've already found a solution, you can check it out here:

Check solutions