Class Picture

java.lang.Object
  extended by SimplePicture
      extended by Picture
All Implemented Interfaces:
DigitalPicture

public class Picture
extends SimplePicture

A class that represents a picture. This class inherits from SimplePicture and allows the student to add functionality to the Picture class. This version modified by Scot Drysdale to demonstrate arraylists. (used in reduceTo8). See end of listing. Copyright Georgia Institute of Technology 2004-2008

Author:
Barbara Ericson ericson@cc.gatech.edu Modified by Scot Drysdale to eliminate some warnings.

Constructor Summary
Picture()
          Constructor that takes no arguments
Picture(BufferedImage image)
          Constructor that takes a buffered image
Picture(int width, int height)
          Constructor that takes the width and height
Picture(Picture copyPicture)
          Constructor that takes a picture and creates a copy of that picture
Picture(String fileName)
          Constructor that takes a file name and creates the picture
 
Method Summary
static float averageColors(ArrayList<Pixel> pixels, int colorNum)
          Averages the chosen color for all the pixels in an ArrayList.
 void blueScreen(Picture target, int targetX, int targetY)
          Method to do chromakey assuming a blue background
 void chromakey(Picture target, Color bgColor, int threshold, int targetX, int targetY)
          Method to do chromakey using an input color for the background and a point for the upper left corner of where to copy
 void compose(Picture target, int targetX, int targetY)
          Method to compose (copy) this picture onto a target picture at a given point.
 Picture copy()
          A method create a copy of the current picture and return it
 void decreaseRed()
          Method to decrease the red by half in the current picture
 void decreaseRed(double amount)
          Method to decrease the red by an amount
 Picture flip()
          Method to flip a picture
static int getColor(Pixel pixel, int colorNum)
          Gets the value of the color corresponding to colorNum.
 void grayscaleWithLuminance()
          Method to change the picture to gray scale with luminance
 void increaseRed()
          Method to increase the red in a picture.
static void main(String[] args)
           
 void negate()
          Method to negate a picture
 Picture oilPaint(int dist)
          Method to do an oil paint effect on a picture
static Picture pickAndShow()
          Class method to let the user pick a file name and then create the picture and show it
 void reduceTo8()
          Reduces the number of colors to 8 by picking two values for red, two for green, and two for blue.
 Picture scale(double factor)
          Method to scale the picture by a factor, and return the result
static void setColor(Pixel pixel, int newValue, int colorNum)
          Sets the value of the color corresponding to colorNum to newValue.
static Picture showNamed(String fileName)
          Class method to create a picture object from the passed file name and then show it
 String toString()
          Method to return a string with information about this picture.
 
Methods inherited from class SimplePicture
addMessage, copyPicture, createGraphics, drawString, explore, getBasicPixel, getBufferedImage, getExtension, getFileName, getGraphics, getHeight, getImage, getMediaPath, getPictureFrame, getPictureWithHeight, getPictureWithWidth, getPixel, getPixels, getTitle, getTransformEnclosingRect, getWidth, hide, load, load, loadImage, loadOrFail, loadPictureAndShowIt, repaint, scale, setAllPixelsToAColor, setBasicPixel, setFileName, setMediaPath, setPictureFrame, setTitle, setVisible, show, write, writeOrFail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Picture

public Picture()
Constructor that takes no arguments


Picture

public Picture(String fileName)
Constructor that takes a file name and creates the picture

Parameters:
fileName - the name of the file to create the picture from

Picture

public Picture(int width,
               int height)
Constructor that takes the width and height

Parameters:
width - the width of the desired picture
height - the height of the desired picture

Picture

public Picture(Picture copyPicture)
Constructor that takes a picture and creates a copy of that picture


Picture

public Picture(BufferedImage image)
Constructor that takes a buffered image

Parameters:
image - the buffered image to use
Method Detail

toString

public String toString()
Method to return a string with information about this picture.

Overrides:
toString in class SimplePicture
Returns:
a string with information about the picture such as fileName, height and width.

pickAndShow

public static Picture pickAndShow()
Class method to let the user pick a file name and then create the picture and show it

Returns:
the picture object

showNamed

public static Picture showNamed(String fileName)
Class method to create a picture object from the passed file name and then show it

Parameters:
fileName - the name of the file that has a picture in it
Returns:
the picture object

copy

public Picture copy()
A method create a copy of the current picture and return it

Returns:
the copied picture

increaseRed

public void increaseRed()
Method to increase the red in a picture.


negate

public void negate()
Method to negate a picture


flip

public Picture flip()
Method to flip a picture


decreaseRed

public void decreaseRed()
Method to decrease the red by half in the current picture


decreaseRed

public void decreaseRed(double amount)
Method to decrease the red by an amount

Parameters:
amount - the amount to change the red by

compose

public void compose(Picture target,
                    int targetX,
                    int targetY)
Method to compose (copy) this picture onto a target picture at a given point.

Parameters:
target - the picture onto which we copy this picture
targetX - target X position to start at
targetY - target Y position to start at

scale

public Picture scale(double factor)
Method to scale the picture by a factor, and return the result

Parameters:
factor - the factor to scale by (1.0 stays the same, 0.5 decreases each side by 0.5, 2.0 doubles each side)
Returns:
the scaled picture

chromakey

public void chromakey(Picture target,
                      Color bgColor,
                      int threshold,
                      int targetX,
                      int targetY)
Method to do chromakey using an input color for the background and a point for the upper left corner of where to copy

Parameters:
target - the picture onto which we chromakey this picture
bgColor - the color to make transparent
threshold - within this distance from bgColor, make transparent
targetX - target X position to start at
targetY - target Y position to start at

blueScreen

public void blueScreen(Picture target,
                       int targetX,
                       int targetY)
Method to do chromakey assuming a blue background

Parameters:
target - the picture onto which we chromakey this picture
targetX - target X position to start at
targetY - target Y position to start at

grayscaleWithLuminance

public void grayscaleWithLuminance()
Method to change the picture to gray scale with luminance


oilPaint

public Picture oilPaint(int dist)
Method to do an oil paint effect on a picture

Parameters:
dist - the distance from the current pixel to use in the range
Returns:
the new picture

reduceTo8

public void reduceTo8()
Reduces the number of colors to 8 by picking two values for red, two for green, and two for blue. The two red values chosen are the average of the pixel red value that are greater than a threshold and the average of the pixel red values less than or equal to the threshold. The same is done for green and blue


getColor

public static int getColor(Pixel pixel,
                           int colorNum)
Gets the value of the color corresponding to colorNum. In an ideal world this would be added to the Pixel class Precondition - colorNum is 1, 2, or 3. (We will learn to throw exceptions later.)

Parameters:
pixel - the pixel whose color is returned
colorNum - the color to choose: 1 = red, 2 = green, 3 = blue

setColor

public static void setColor(Pixel pixel,
                            int newValue,
                            int colorNum)
Sets the value of the color corresponding to colorNum to newValue. In an ideal world this would be added to the Pixel class Precondition - colorNum is 1, 2, or 3. (We will learn to throw exceptions later.)

Parameters:
pixel - the pixel whose color is set
newValue - the new value for the color
colorNum - the color to choose: 1 = red, 2 = green, 3 = blue

averageColors

public static float averageColors(ArrayList<Pixel> pixels,
                                  int colorNum)
Averages the chosen color for all the pixels in an ArrayList. Returns 0 if ArrayList is empty. Precondition - colorNum is 1, 2, or 3. (We will learn to throw exceptions later.)

Parameters:
pixels - the list of pixels to be averaged
colorNum - the color to average: 1 = red, 2 = green, 3 = blue
Returns:
the average of the chosen color value

main

public static void main(String[] args)