CS 45500 - Programming Assignment 2

This assignment makes use of the files contained in this zip file. This assignment is due Thursday, September 13.

This assignment is once again about what comes out of the graphics pipeline, the FrameBuffer data structure. Assignment 3 will be about what goes into the rendering pipeline, the Scene data structure.

For this assignment, you will write a program that modifies the contents of a framebuffer after the contents of a PPM file have been written into the framebuffer. In the zip file there is a file Hw2.java that you need to complete. Your program should draw a black border around the image in a PPM file. Run the demo program demo_program\Hw2_demo.cmd to see how your program should modify the images in cow.ppm, horse.ppm, and starfish.ppm.

You need to come up with an algorithm that detects which pixels are on the edge of an image and turn each of those pixels black. Your program needs to find "background pixels" in the framebuffer that are next to "image pixels" (in other words, your program needs to find the edge of the image) and turn those particular background pixels black. If you look at the three image files, cow.ppm, horse.ppm, and starfish.ppm, you will see that they have different background colors. Your program can assume that the first pixel in an image (the upper left hand corner pixel) has the background color. Your program can also assume that no pixel in the image itself has the color of the background or the color being used to draw the border.

Your program should essentially be a pair of nested loops that iterate through the whole framebuffer, looking for pixels on the edge of the image. You need to find a (somewhat complicated) boolean expression that is true when a background pixel has one of its (eight) neighbors in the image. Change any pixel that satisfies this boolean from the background color to black. That will give you a one-pixel wide black border around the image.

But a one pixel wide border is not too noticeable. The border drawn by the demo program is three pixels wide. To get a wider border, iterate your code on the result of your first pass over the framebuffer. The result of the second pass over the framebuffer should leave a two pixel wide border around the image. (A third pass should give a three pixel wide black border.) But the second time you iterate over the framebuffer, you will need to consider the border pixels (from the first iteration) as part of the image. So your border color for the second iteration needs to be slightly different from the border color in the first iteration (why?). I make the border color in each iteration one unit lighter that the previous iteration (I used border color (r,g,b)=(0,0,0) for the first iteration, border color (r,g,b)=(1,1,1) for the second iteration, and (r,g,b)=(2,2,2) for the third iteration, etc.) If you run the command,

     demo_program\Hw2_demo.cmd 50

it tells the demo program to draw a 50 pixel wide border. You can see in the resulting pictures that the border gets lighter as it gets wider.

Your program should draw a 3 pixel wide border around the image in a PPM file. (If you want, you can try to give your program an optional command line parameter that determines the width of the border, as in the demo program.)

Turn in a zip file called CS455Hw2Surname.zip (where Surname is your last name) containing your version of Hw2.java.

This assignment is due Thursday, September 13.