Lab 2: Image Displayer 3001

Overview

In this assignment you will implement a Graphical User Interface (GUI) for your solution to Lab 1. Additionally, you will add functionality for two new binary file formats, .ibig, .isml, that can reduce the space taken by a great deal. Finally, you will create a custom Exception class that will be thrown when problems with the input data are encountered.

GUI

Your GUI must have separate buttons to use for saving each file format, for loading the image, and for quitting the program. You will use a FileChooser to obtain the File objects to read and write, and will have a single Canvas to draw the image onto. An example of the GUI might look like this:

GUI.png

You should, at a minimum, have the same six Buttons and use the same text as shown above for the Buttons, but the rest of the design and layout is up to you.

Integer Binary Format

This binary format stores all the image information as binary integer values.

Files in this format must use .ibig file extension.

Bit Binary Format

This binary format uses one bit for each pixel in the image.

This format is more complicated because, when writing, you will need to pack groups of eight bits into a byte, and, when reading, you will need to extract eight pixel values from a single byte.

Files in this format must use .isml file extension.

Overview of bit operators

The following operators are helpful for manipulating bits:

We can represent binary literals by prefixing the number with 0b. E.g.,

The following are all true:

0b00111100 | 0b11001100 == 0b11111100;
0b00111100 & 0b11001100 == 0b00001100;
0b00111100 ^ 0b11001100 == 0b11110000;
~0b00111100 == 0b11000011;
0b00001000 >> 2 == 0b00000010;
0b00001000 << 3 == 0b01000000;

Therefore, if we want to get the third bit from the right as an integer, we can do:

int bitValue = (byteValue >> 2) & 0b00000001;

If we want to place the value of an integer (with value of either 0 or 1) in the 8's place and not disrupt the other bit values in the other places, we can do:

byteValue = ((intValueForPixel & 0b00000001) << 3) | (byteValue & 0b11110111);

Software Design

You should use your Image and PixelCluster classes from Lab 1 as the basis for the logic for this program. In addition, you will need to create, organize, and display all of your GUI components and link them to the rest of your program. This should be done in your main driver class using helper methods to break up the work.

InvalidFormatException

You must create a custom Exception class that will be thrown in place of an IllegalArgumentException when the exception is caused not by an incorrect argument, but bad data. For example, if you are reading a block text file and the Unicode value does not match any of the PixelCluster enum values, the argument (a String) is fine, but the data formatting is not. The InvalidFormatException should have the following methods:

Main Class

Your Main class is where you will set up your GUI and kick off your program. It must extend the JavaFX Application class and have, at a minimum, the following methods:

Exception Handling

If any problems are encountered with reading the input files or writing the output file, the program should display a useful error message using Alert objects. The program should not print anything to the console, nor should it crash or display any exceptions.

Acknowledgement

This laboratory assignment, developed by Prof. Sean Jones and Dr. Chris Taylor.

See your professor's instructions for details on submission guidelines and due dates.