MSOE 3 3 #000000 #FFFFFF #000000 #FFFFFF #FFFFFF #FFFFFF #000000 #FFFFFF #000000* 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. ### Loading and Saving Images The completed program must support loading and saving `.bmp`, `.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. The [`ImageIO`](ImageIO.java) class2) 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 `.bmp`, 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. * **`readBMP(File file)`** — Reads an image file in `.bmp` format. * **`writeBMP(Image image, File file)`** — Writes an image file in `.bmp` format. You are required to use the provided `ImageIO` class [__ImageIO.java__](ImageIO.java) as a starting point. The file contains partial implementations of the `readBMP()` and `writeBMP()` methods. You may 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/javafx/2/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` files. You must complete the provided `readBMP()` and `writeBMP()` implementations to read and write `.bmp` files. The BMP format is significantly more complicated than the MSOE format [details](http://en.wikipedia.org/wiki/BMP_file_format). The [Wikipedia article](http://en.wikipedia.org/wiki/BMP_file_format) explains the considerably more complicated header format for these files. Unlike MSOE files text files, BMP files are stored as binary 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 ## Just For Fun There are many additional enhancements that could build on the required functionality. You are encouraged to enhance this application using your creativity. A number of enhancements are included below; however, you should not feel limited to these suggestions. * Add a menu to the main window to replace (or in addition to) the buttons * Apply a transform to only a selected region of the image * Display the original and transformed images side-by-side * Toggle between original and transformed images when mouse button is pressed on the image * Create a meme generator by adding styled text on the image * Tonal adjustment (e.g., adding a red hue to the image underneath the mouse) * Provide undo functionality * Implement additional transformations, e.g. * Brighten * Darken * Decrease color saturation * Increase color saturation * Apply additional filters like the **Edge** filter [see here](http://lodev.org/cgtutor/filtering.html) ## Lab Deliverables > See your professor's instructions for details on submission guidelines and due dates. > * Dr. Taylor's students: See below > * All other students should refer to Blackboard > >If you have any questions, consult your instructor. ## Acknowledgment This laboratory assignment was developed by [Dr. Chris Taylor](/taylor/) and [Dr. Walter Schilling](http://www.waltschilling.us).
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).