MSOE 3 3 #000000FF #FFFFFFFF #000000FF #FFFFFFFF #FFFFFFFF #FFFFFFFF #000000FF #FFFFFFFF #000000FF* The first line specifies that the file contains an `.msoe` image. * The second line specifies, in order, the width and height of the image. * Each remain line specifies the colors of the pixels for one row of the image. * Line 3 specifies pixel colors for the first row in the image. * Line 4 specifies pixel colors for the second row in the image. * Line `k` specifies pixel colors for the `k-2` row in the image. * The pixel color is a hexidecimal number where each pair of digits represents (from left to right) the red, green, blue, and alpha/opacity * Each pair of hexidecimal digits represents an integer value in the range [0, 255] * The alpha/opacity value specifies how transparent the pixel is (`00` completely transparent, `FF` not at all transparent) ### `.bmsoe` File Format The custom `.bmsoe` file format is a binary based file format for storing images. File sizes will be smaller than `.msoe` for the same image, but the format does not do any image compression so the files will be larger than more common formats. The file consists of a number of bytes. * The file begins with the bytes having the ASCII values of the following characters: `B`, `M`, `S`, `O`, and `E`. * Next in the file are two integers containing the **width** and **height** of the image. * The remainder of the file consists of the rows, starting with the top-most row. * Each row consists of a number of bytes. The number of bytes is evenly divisible by 16. * The bytes in the row specify all of the pixels in the row and, potentially, some padding bytes (to ensure the divisible-by-16 rule). * Each pixel is specified with four bytes, one byte for each of the four pixel components: red, green, blue, alpha/opacity. ### Loading and Saving Images The completed program must support loading and saving `.bmsoe`, `.gif`, `.jpg`, `.png`, and `.msoe` image file formats. The load button will open a `FileChooser` dialog that will allow the user to select the file to be loaded (`showOpenDialog()`). The program will use the extension to determine the format of the file and load the image (provided the extension type is supported). Pressing the reload button will reload the last loaded image. The save button will open a `FileChooser` dialog box that will allow the user to select the destination folder and type in the filename and extension (`showSaveDialog()`). The program will then write the image to that file using the file format that matches the file extension. If an unsupported file extension is entered, the program will display an error message without attempting to save the image. You must create an `ImageIO` class2) that is responsible for loading and saving images. The class must have the following public class methods: * **`read(File file)`** — Reads in the specified image file and returns a `javafx.scene.image.Image` object containing the image. * **`write(Image image, File file)`** — Writes the specified image to the specified file. If the extension on the file passed to either of these methods is `.msoe` or `.bmsoe`, then the appropriate private class method below is called to do the actual work. * **`readMSOE(File file)`** — Reads an image file in `.msoe` format. * **`writeMSOE(Image image, File file)`** — Writes an image file in `.msoe` format. * **`readBMSOE(File file)`** — Reads an image file in `.bmsoe` format. * **`writeBMSOE(Image image, File file)`** — Writes an image file in `.bmsoe` format. You are encouraged to use the [`javax.imageio.ImageIO`](http://docs.oracle.com/javase/8/docs/api/javax/imageio/ImageIO.html) class to read and write files in the `.gif`, `.jpg`, and `.png` formats. The [`SwingFXUtils`](https://docs.oracle.com/javase/8/javafx/api/javafx/embed/swing/SwingFXUtils.html) class can be used to convert from `Image` to `BufferedImage`. You must implement your own code to read and write `.msoe` and `.bmsoe` files. ### Image Transformations Your program will support a number of image transformations. #### Grayscale This transformation converts the image into a grayscale image. If the image is already grayscale, the transformation has no affect. In this transformation, the RGB components of each pixel are replaced with a single value. The replacement value can be calculated as: *gray = 0.2126R + 0.7152G + 0.0722B* [more info](http://en.wikipedia.org/wiki/Grayscale).
Blur Sharpen Edge 0 1 0 0 -1 0 0 -1 0 1 5 1 -1 5 -1 -1 4 -1 0 1 0 0 -1 0 0 -1 0The **Apply** button applies the filter kernel to the image. At a minimum, the button need only apply the filter kernel if the sum of the filter kernel weights is a positive value. For example, making the **Apply** button functional for the filter kernel weights provided by the **Edge** button is optional since the sum of the weights is zero (-1-1+4-1-1). The following code applies the **Blur** filter kernel to a [`BufferedImage`](https://docs.oracle.com/javase/8/docs/api/java/awt/image/BufferedImage.html) called `original` and stores the new `BufferedImage` in `result`: ``` float[] kernel = { 0F, 1/9F, 0F, 1/9F, 5/9F, 1/9F, 0F, 1/9F, 0F}; BufferedImageOp op = new ConvolveOp(new Kernel(width, height, kernel)); BufferedImage result = op.filter(original, null); ``` You may find the [`SwingFXUtils`](https://docs.oracle.com/javafx/2/api/javafx/embed/swing/SwingFXUtils.html) class helpful for integrating the above code in your application. If the **Apply** button is pressed when an unsupported set of weights are entered in the window, an exception should occur (and be handled in a way consistent with the exception handling requirements listed below). ### Class Structure In addition to the `ImageIO` class described above, you must implement the `Transformable` interface. The `Transformable` interface is a *functional interface*. A functional interface has a single method, and can therefore be implemented with a lambda expression. The method, named `tranform`, must accept three arguments: the x and y location of the pixel and its color. The method must return the color for the pixel after the applying the transformation. You must provide implementations of the `Transformable` interface for the **grayscale**, **red**, **redGray**, and **negative** image transformations. You must implement the following method in the class that handles the button events that performs the specified transformation: ``` private static Image transformImage(Image image, Transformable transform) { // ... } ``` All of your classes should be placed in a package whose name matches your MSOE username. The rest of the class design is up to you. ### Exception Handling There are a number of situations that could cause your program to throw an exception. For example, if the file is not found, cannot be opened, or contains incorrectly formatted data, it is likely that an exception will be thrown. In these cases, the program should display an useful message and log the error. Your program should write to the log file `Lab8.txt`. ### Responding to an Event other than an `ActionEvent` You must implement a feature that responds to an event other than an `ActionEvent`. For example, you could: * allow the user to draw on the image with the mouse * display the x, y coordinates of the location of the mouse on the image * display the color of the pixel at the location of the mouse on the image * play a sound when clicking on a pixel with a particular color * flip back and forth between the image and its negative whenever the window is minimized * select a region of the image ## Creating an Executable `.jar` File
2) This [`ImageIO`](ImageIO.java) class is different than the [`javax.imageio.ImageIO`](http://docs.oracle.com/javase/8/docs/api/javax/imageio/ImageIO.html) class.
3) This is a slight simplification from the actual transformation. You may chose to implement the actual transformation, if you choose to (you'll need to look it up). Be sure to indicate with a comment if you choose to do this.
4) You may choose to make a 5 x 5, 7 x 7, or 9 x 9 grid instead.
5) For example, if **5** were entered into that field, then the filter weights should be **0.20** instead of **1** and **1** instead of **5**. If no value is entered, then the sum of all the filter weights should be used for the divisor. In the case of the example shown, the divisor should be **9** (0+1+0+1+5+1+0+1+0).