|
Project #3 |
CMSC 131 |
|
Due Wednesday, October 22 at 11:00PM |
Object-Oriented Programming I |
|
Type of project: CLOSED |
Fall 2008 |
Photograph Manipulation
Objective
To practice using a library, reading and understanding JavaDoc, writing and calling methods, and to reinforce all of the techniques you've been learning so far.
Overview
This project will involve manipulation of photographs. We have provided the images, below, for you to use with your project, but the project will work with just about any images -- in fact, you can have it manipulate any picture from the internet by typing in the URL. Here are the photos that are included with the project (all members of the original “Justice League”):
|
wonderwoman.jpg |
|
|
batman.jpg |
|
|
superman.jpg |
|
|
aquaman.jpg |
|
|
greenlatern.jpg |
|
Digital Images and Pixels
A digital photograph is made up of a rectangular grid of tiny spots of color, called "pixels". There are many different schemes for how the color in a pixel could be determined -- for this project we will use the most common one (RGB). The color of each pixel in our photos will be determined by its level of three "primary" colors: Red, Green, and Blue. By mixing various amounts of red, green and blue in a pixel, you can create what appears to the human eye as any of a wide range of colors. For each pixel, the level of each of the three primary colors (red, green, and blue) can be anywhere in the range of 0 to 255. Below is a table that illustrates how mixing various levels of Red Green and Blue results in different colors:
|
Red |
Green |
Blue |
Resulting Color |
|
153 |
102 |
255 |
|
|
89 |
183 |
105 |
|
|
214 |
73 |
214 |
|
|
255 |
255 |
111 |
|
|
0 |
0 |
0 |
|
|
255 |
255 |
255 |
|
JavaDoc
JavaDoc is a tool that Java programmers use to create automatically-generated documentation for their projects. This sort of documentation has been generated for all of the standard Java class Libraries. If you haven't already discovered it, take a look: Java 5.0 API Specifications.
We have created JavaDoc for the cmsc131PhotoLibrary that you will be using for this project. Take a look: cmsc131PhotoLibrary API Documentation. There will be some information in the JavaDoc that you won't be able to understand yet. Please don't worry about that -- by the end of the course it will all make sense! You should immediately read and become familiar with the JavaDoc for the Photograph and Pixel classes, found in the link above.
The Driver
We are providing a Driver in a class called "Driver.java", located in the package called "editing". (In Eclipse, click on the "editing" package to see what is inside.) The driver contains a main method that you should run to make this project work.
When you run the main method in the driver, you will see this dialog box:

Enter the name of a photo you would like to edit, and then click the "Get Photo" button.
After selecting a photo, you will see your photo presented in a dialog box like this:

If you select one of the twelve "radio buttons" and then click "Modify Photo", you will see the photo displayed again after the selected "effect" has been applied. For example, if you select the "Rotated" radio button and click "Modify Photo" for the picture above, you will see this:

You can continue to apply effects to the image by choosing one of the various options and selecting "Modify Photo". If at any time you want to start over with a new unaltered photo, just click the "Load New Photo" button, and you will go back to the original dialog box that asks you to enter the location of a photo.
PhotoTools Class
This is where you come in. None of the editing effects will work until you implement them! You must fill in the implementation for nine static methods of the PhotoTools class. This class is located in the "editing" package -- in Eclipse, click the editing package to access the files inside.
Below is a description of all of the static methods that you must implement in the PhotoTools class. You should implement these methods one at a time and run the Driver to test them out one-by-one as you write them!
For each method described below, you will see a screenshot that shows the resulting image when the effect is applied to the original "Superman.jpg" photo. Your results must look exactly like those pictured below. Any slight variation will cause you to fail the release tests!
·
public static Photograph
copy(Photograph photo) -- This method will return a new Photograph that
is an exact copy of the parameter. You will need to instantiate a blank
Photograph that is the same size as the parameter, and then copy all of the
pixels from the parameter to the new Photograph. (Hint: Use nested
loops!) Note: Do not return a reference to the parameter itself;
you must return a reference to a distinct copy of the parameter.

· public static Photograph rotate(Photograph photo) -- This method will return a new Photograph that is the same as the original, but turned 90 degrees clockwise.
·
public static Photograph
inverted(Photograph photo) -- Each pixel of the new photograph is
inverted in all three dimensions of color (red, green and blue) from the
original picture. If the amount of red, green and blue are each 0 in one
pixel of the original picture (that pixel is black in the original picture),
then the amount of red, green and blue should be each 255 in the corresponding
pixel of the new picture (that new pixel will be white in the new
picture). If the amount of red is 10, the amount of green is 200 and the
amount of blue is 55 in one pixel of the original picture, the corresponding
pixel in the new picture would have red at 245, green at 55 and blue at 200
(notice this is 255 minus each of the values of the original).
· public static Photograph horizontalStripes(Photograph photo) – Returns a new photo where the top 5 rows are black then the next 15 rows are the same as the original picture; the next five rows are black and then the next 15 rows are the same as the original picture; this pattern continues until the bottom of the picture.
· public static Photograph verticalStripes(Photograph photo) – Returns a new photo where the left 5 columns of the picture are black then the next 15 columns to the right are the same as the original picture; the next five columns are black and then the next 15 columns are the same as the original picture; this pattern continues until the right side of the picture.
· public static Photograph windowScreen(Photograph photo) – Returns a new photo that has both vertical and horizontal lines like you would see if you were looking at the picture through a window screen. The top five rows and the five columns to the far left are black; the next 15 rows and 15 columns are the same as the original picture; the next five rows and five columns are black; this pattern then continues until the right and bottom of the picture are reached.

·
public static Photograph allShrink(Photograph photo) -- The new picture is
half the height and half the width of the original picture. If either
dimension is odd in the original picture, the size of the small copy should be
rounded up. Only the even row numbers and even column numbers are
preserved in the new copy, the odd rows and the odd columns are discarded.

· public static Photograph isolateColor(Photograph photo, int color) – Returns a new photo where one color of the original picture is isolated. If the integer passed as the second parameter is 0, the red should be isolated; if the integer passed as the second parameter is 1, the green should be isolated; if the integer passed as the second parameter is 2, the blue should be isolated. To isolate a color means to remove all of the other two colors but to keep the amount of the color being isolated the same as the original picture. For example, if the red is being isolated, each pixel will have exactly the same amount of red as the original picture, but the amount of green and blue of each pixel will be set to 0. If any other value is passed as the type, the original picture should be displayed with no modification.
(type 0)
(type 1)
(type 2)
· public static Photograph mirror(Photograph photo) -- This corresponds to the horizontal mirror. The new picture should be created that is what would be shown if there was a mirror held against the right side of the original picture.

10. public static Photograph rotateColors(Photograph photo) -- This one is tricky. The new picture will be a concatenation of the three shrunk (1/2 size) versions of the original picture. The three pictures will individually isolate the Red, Green and Blue. Also the first picture is in the original orientation, the second is rotated 90 degrees to the right, and the third is rotated 180 degrees to the right.

Requirements
Grading
For this project, we have written one test for each of the methods you will be implementing.