A graphic image can be represented by a two dimensional array of information about the colors of various picture elements (or pixels). At high resolution the image may be composed of 1000 rows and 1000 columns of information, leading to the need to store information on 1,000,000 pixels per image. Needless to say this creates serious problems for storing and transmitting these images. However most images tend to have contiguous groups of pixels, each of which are the same color. We can take advantage of this by trying to encode information about the entire block in a relatively efficient manner.
The basic idea of our encoding will be to represent a block of pixels with the same color by simply recording the first place where we encounter the new color and only recording information when we see a new color. For instance suppose we have the following table of information (where we will imagine each number represents a color):
2 | 2 | 2 | 3 | 3 |
2 | 3 | 3 | 3 | 3 |
3 | 1 | 1 | 1 | 3 |
If we imagine tracing through the table from left to right starting with the top row and going through successive rows, then we notice that we only need to record the following entries:
2 | - | - | 3 | - |
2 | 3 | - | - | - |
- | 1 | - | - | 3 |
Rather than recording this in a two-dimensional table, it will now generally be more efficient to keep this information in a linear list:
(0,0);2 | (0,3);3 | (1,0);2 | (1,1);3 | (2,1);1 | (2,4);3 |
How might this list be implemented? Perhaps as a vector or some sort of linked list. Before we make a decision, let's consider one more thing. So far, you've probably been thinking that you are given a static image that needs to be represented in compressed form. That's part of the story. But consider also the possibility that someone might want to edit the image, thereby changing its pixels. As pixels change, we need to be sure our representation of the compressed image changes as well. Therefore, we need a form of list that will allow us to move freely backwards and forwards through it without always having to begin at the head or the tail.
In the Assignments folder on Cider Press, you will find the folder "Color Matrix Demo". The demo program will display a 12x12 matrix of "pixels" that you may edit. The color of a "pixel" may be changed by clicking on it. The currently active color (selected by clicking on one of the three color choices on the right of the screen), will be assigned to that "pixel". As you edit the 12x12 grid, you will see the corresponding list entries in the lower part of the screen.
For this assignment, you are to build the data structure that will allow us to represent such compressed tables. You will do the assignment in two stages:
I have provided you with a lot of code here, but you will find that much of the omitted code is quite tricky. This project will require you to be very careful in developing the code for the methods.
This lab will be due on Sunday, March 5 at 11:59 pm for those in a Wednesday lab and on Monday, March 6 for those in the Thursday lab. For this lab, you should turn in a folder containing your CurDoublyLinkedList class, including your test code. As usual, drop it off in the CSCI 136 drop-off folder.