Problem: Pixmap


Problem Statement

Images are stored by computers in a variety of formats, such as gif, jpg, tiff, and png. These formats differ in how faithfully they represent the original picture, how well they can be compressed to reduce the space each image takes up, or how well they can be copied from on type of computer to another. However, no matter what format the image is stored in, it can always be represented of as a mapping of (x, y) pixel position to a color (the range of colors may be restricted to values of grey or just black and white). Thus, for the remainder of this project, we will refer to all formats of digital images as pixmaps.

This programming project involves manipulating pixmaps by transforming each color in the original pixmap using the same algorithm. Your program will be able to read in gif, jpg, and png image formats, and perform several operations on these images including darkening, inverting, posterizing, coverting it to grey scale.

Problems

For each of the problems below, you will complete the method, transformColor, that given a Color parameter, returns a new Color whose component values have been changed based on the algorithm described. To test your solution, right-click on the file named pixmap.jar within your project and select Run -> Java Application from the menu that appears. This will cause a Java program to appear that allows you to open, transform, and save images. To test your method on every pixel in the displayed image, click on the button corresponding to the class in which you worked.

  1. Darken
    Darken the image by reducing the values of each of the three RGB components of the current color by some amount (corresponding to the darker method of Java's Color class.
     
  2. Brighten
    Brighten the image by increasing the values of each of the three RGB components of the current color by some amount (corresponding to the brighter method of Java's Color class.
     
  3. Negative
    Create a photographic negative of the image by inverting each of the three RGB components of the current color. For example, if the current color has the values (255, 0, 128) for its red, green, and blue components, respectively; then the resulting color should have the values (0, 255, 127) for its red, green, and blue components. In other words, each value is the other's opposite within the range of possible values from 0 .. 255.
     
  4. Posterize
    Create a posterized version of the image by reducing its total number of colors. To do this, you should restrict the values each of the three RGB components of the current color can be. Specifically, if the value of a component is between 0 and 63 inclusive, it should be set to 31; if the value of a component is between 64 and 127 inclusive, it should be set to 95; if the value of a component is between 128 and 191 inclusive, it should be set to 159; and if the value of a component is between 192 and 255 inclusive, it should be set to 223. In this way, the 256 possible values each component can have is resticted to just 4.
     
  5. GreyScale
    Create an image that has only shades of grey values by computing the average value of the current color's three RGB components and using that average value for all three components of the new color. For example, if the current color has the values (255, 0, 128) for its red, green, and blue components, respectively; then the resulting color should have the values (127, 127, 127) for its red, green, and blue components.
     

Comments?