Class Picture

java.lang.Object
  extended bySimplePicture
      extended byPicture
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.

Author:
Barbara Ericson

Constructor Summary
Picture()
          Constructor that takes no arguments
Picture(int width, int height)
          Constructor that takes the width and height
Picture(String fileName)
          Constructor that takes a file name and creates the picture
 
Method Summary
 void addHorizontalLines()
          Method to add a horizontal line every 5 pixels in the current picture
 void addLines()
          Method to add vertical and horizontal lines to the current picture
 void addVerticalLines()
          Method to add a vertical line every 5 pixels in the current picture
static Picture blendPictures()
          Method to blend pictures of Katie and Jenny
 void bluescreen(Picture target, int targetx, int targety)
          Method to do chromakey assuming blue background for background at a given point.
 void blur(int numPixels)
          Method to blur the pixels
 void blurCopy(int numPixels)
          Method to blur the pixels using a copy of the original as the source for the average
 void chromakey(Picture newBg)
          Method to do chromakey using a blue background
 void chromakey(Picture target, Color bgcolor, int threshold, int targetx, int targety)
          Method to do chromakey using an input color for background at a given point.
 void chromakeyBlue(Picture newBg)
          Method to do chromakey using a blue background
 void chromakeyRed(Picture newBg)
          Method to do chromakey using a red background
 void clearBlue()
          Method to clear the blue from the picture (set the blue to 0 for all pixels)
 void complex1()
          Complex manipulation
 void compose(Picture target, int targetx, int targety)
          Method to compose this picture onto target at a given point.
 Picture copy()
          A method create a copy of the current picture and return it
 void copy(Picture sourcePicture, int startX, int startY, int endX, int endY, int targetStartX, int targetStartY)
          Method to copy from the passed source picture to current picture object The copying will start at startX, startY, and end at endX and endY The copy will be placed starting at targetStartX, targetStartY
static Picture copyFlowerLarger()
          Method to copy a flower but scaled to 2x normal size
static Picture copyFlowerSmaller()
          Method to copy the flower but smaller (half as big)
static Picture copyKatie()
          Method to copy the picture of Katie to the canvas
static Picture copyKatieLeftRotation()
          Method to copy Katie rotated to the left 90 degrees
static Picture copyKatieMidway()
          Method to copy the picture of Katie to 100, 100 in the canvas
static Picture copyKatieRightRotation()
          Method to copy Katie rotated to the left 90 degrees
static Picture copyKatiesFace()
          Method to copy just Katie's face to the canvas
 void copyPictureTo(Picture sourcePicture, int xStart)
          Method that will copy all of the passed source picture into the current picture object starting with the left corner given by xStart
 int countWhite()
          Method to count teh number of white pixels in a picture
static Picture createCollage()
          Method to create a collage from the flower pictures.
static Picture createCollageBetter()
          Method to create a collage of flowers with a better method
static Picture createFlowerCollage()
          Method to create a flower collage
 void darken()
          Method to darken the color in the picture
 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
static Picture drawExample()
          Method to show using drawing on a picture
static Picture drawFilledRectangles()
          Method to draw a picture with a succession of filled rectangles with the top left corner the darkest and the bottom right the lightest
static Picture drawGrayEffect()
          Method to draw a gray effect picture
static Picture drawRectangles()
          Method to draw a picture with a succession of rectangles
 void fakeSunset()
          Method to fake a sunset by reducing the blue and green in a picture by 30%
 Picture flip()
          Method to flip an image left-to-right
 void grayscale()
          Method to change the picture to gray scale
 void grayscaleWithLuminance()
          Method to change the picture to gray scale with luminance
 void increaseRed()
           
 void increaseRed2()
          Method to increase the amount of red by 1.3
 void increaseRed3()
          Method to increase the amount of red by 1.3
 void lighten()
          Method to lighten the colors in the picture
 void lightenNested()
          Method to lighten the colors using a nested for loop
 void lightenWhileNested()
          Method to lighten the colors using a nested for loop
 void makeSunset()
          Method to make a picture look like it was taken at sunset by reducing the blue and green to make it look more red
static void makeSunset(String fileName)
          Method to simulate a sunset by reducing the green and blue
 void methodA()
           
 void methodB()
           
 void methodC()
           
 void mirrorHorizontal()
          Method to mirror around a horizontal line in the middle based on the height.
 void mirrorHorizontalBottomToTop()
          Method to mirror around a horiztonal line in the middle based on the height of the picture.
static Picture mirrorTemple()
          Method to mirror the piedmont of the temple
 void mirrorVertical()
          Method to mirror around a vertical line in the middle of the picture based on the width
 void myStupidMethod()
          My function that shifts r, g, b -- Mark Guzdial
 void negate()
          Method to negate the picture
static Picture pickAndShow()
          Class method to let the user pick a file name and then create the picture and show it
 void posterize()
          Method to posterize (reduce the number of colors) in the picture The number of reds, greens, and blues will be 4
 void posterize(int numLevels)
          Method to posterize (reduce the number of colors) in the picture
 void reduceBlue()
          Method to reduce the blue in the picture by 30%
static Picture reduceBlue(String fileName)
          Method to create a picture and reduce the blue in it
 void reduceBlueIncreaseGreen()
          Method to reduce blue by 25% and increase green by 50%
 void reduceGreen()
          Method to reduce the green in the picture by 30%
static Picture reduceGreen(String fileName)
          Method to create a picture from the passed file name and reduce the green in it
 void removeRedEye(int startX, int startY, int endX, int endY, Color newColor)
          Method to remove red eye from the current picture object in the rectange define by startX, startY, endX, endY.
 Picture scale(double factor)
          Method to scale the picture by a factor, and return the result
 Picture scale2x()
          A method to scale the current picture object 2 x regular size
 void sepiaTint()
          Method to change the current picture to a sepia tint (modify the middle colors to a light brown and the light colors to a light yellow and make the shadows darker
static Picture showNamed(String fileName)
          Class method to create a picture object from the passed file name and then show it
 void sunsetize()
          Method to make a picture look sunset-like
 void swapBackground(Picture oldBackground, Picture newBackground)
          Method to replace the background in the current picture with the background from another picture
 void swapBackgroundForThreshold(Picture oldBackground, Picture newBackground, double threshold)
          Method to replace the background in the current picture with the background from another picture for pixels that have a color distance to the old background of under the passed threshold
 Picture topQuarter()
           
 String toString()
          Method to return a string with information about this picture.
static Picture turnKatieRedHead()
          Method to turn to turn Katie into a red head
static Picture turnKatieRedHeadInRange()
          Method to turn to turn Katie into a red head using a range
 
Methods inherited from class SimplePicture
addMessage, close, copyPicture, createGraphics, explore, getBasicPixel, getBufferedImage, getExtension, getFileName, getGraphics, getHeight, getImage, getMediaPath, getPictureFrame, getPictureWithHeight, getPixel, getPixels, getTitle, getTranslationEnclosingRectangle, getWidth, load, load, loadPictureAndShowIt, repaint, setAllPixelsToAColor, setBasicPixel, setMediaPath, setPictureFrame, setTitle, show, write
 
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
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

decreaseRed

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


increaseRed

public void increaseRed()

decreaseRed

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

Parameters:
amount - the amount to change the red by

increaseRed2

public void increaseRed2()
Method to increase the amount of red by 1.3


increaseRed3

public void increaseRed3()
Method to increase the amount of red by 1.3


clearBlue

public void clearBlue()
Method to clear the blue from the picture (set the blue to 0 for all pixels)


sunsetize

public void sunsetize()
Method to make a picture look sunset-like


lighten

public void lighten()
Method to lighten the colors in the picture


lightenNested

public void lightenNested()
Method to lighten the colors using a nested for loop


lightenWhileNested

public void lightenWhileNested()
Method to lighten the colors using a nested for loop


darken

public void darken()
Method to darken the color in the picture


negate

public void negate()
Method to negate the picture


grayscale

public void grayscale()
Method to change the picture to gray scale


grayscaleWithLuminance

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


reduceGreen

public void reduceGreen()
Method to reduce the green in the picture by 30%


reduceBlue

public void reduceBlue()
Method to reduce the blue in the picture by 30%


reduceGreen

public static Picture reduceGreen(String fileName)
Method to create a picture from the passed file name and reduce the green in it

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

reduceBlue

public static Picture reduceBlue(String fileName)
Method to create a picture and reduce the blue in it

Parameters:
fileName - the name of the file to use to create the picture
Returns:
the created picture

makeSunset

public void makeSunset()
Method to make a picture look like it was taken at sunset by reducing the blue and green to make it look more red


makeSunset

public static void makeSunset(String fileName)
Method to simulate a sunset by reducing the green and blue

Parameters:
fileName - the name of the file to use

fakeSunset

public void fakeSunset()
Method to fake a sunset by reducing the blue and green in a picture by 30%


mirrorVertical

public void mirrorVertical()
Method to mirror around a vertical line in the middle of the picture based on the width


mirrorHorizontal

public void mirrorHorizontal()
Method to mirror around a horizontal line in the middle based on the height. It copies the top mirrored to the bottom


mirrorHorizontalBottomToTop

public void mirrorHorizontalBottomToTop()
Method to mirror around a horiztonal line in the middle based on the height of the picture. It copies the bottom to the top.


mirrorTemple

public static Picture mirrorTemple()
Method to mirror the piedmont of the temple

Returns:
the corrected picture

copyKatieMidway

public static Picture copyKatieMidway()
Method to copy the picture of Katie to 100, 100 in the canvas

Returns:
the picture of Katie copied to 100,100

copyKatie

public static Picture copyKatie()
Method to copy the picture of Katie to the canvas

Returns:
the canvas after the picture of Katie has been copied

copyKatieRightRotation

public static Picture copyKatieRightRotation()
Method to copy Katie rotated to the left 90 degrees

Returns:
the picture after Katie has been copied and rotated to the left 90

copyKatieLeftRotation

public static Picture copyKatieLeftRotation()
Method to copy Katie rotated to the left 90 degrees

Returns:
the picture after Katie has been copied and rotated to the left 90

copy

public void copy(Picture sourcePicture,
                 int startX,
                 int startY,
                 int endX,
                 int endY,
                 int targetStartX,
                 int targetStartY)
Method to copy from the passed source picture to current picture object The copying will start at startX, startY, and end at endX and endY The copy will be placed starting at targetStartX, targetStartY

Parameters:
sourcePicture - the source picture to copy from
startX - the starting x value in the source picture
startY - the starting y value in the source picture
endX - the ending x value in the source picture
endY - the ending y value in the source picture
targetStartX - the starting x value in the current picture
targetStartY - the starting y value in the current picture

copyKatiesFace

public static Picture copyKatiesFace()
Method to copy just Katie's face to the canvas

Returns:
the canvas after the copying the face

createFlowerCollage

public static Picture createFlowerCollage()
Method to create a flower collage


createCollage

public static Picture createCollage()
Method to create a collage from the flower pictures. All the flower pictures will be lined up near the bottom of the canvas (5 pixels from the bottom)

Returns:
the collage as a picture object

copyPictureTo

public void copyPictureTo(Picture sourcePicture,
                          int xStart)
Method that will copy all of the passed source picture into the current picture object starting with the left corner given by xStart

Parameters:
sourcePicture - the picture object to copy
xStart - the x position to start the copy into

createCollageBetter

public static Picture createCollageBetter()
Method to create a collage of flowers with a better method

Returns:
the flower collage as a picture object

blendPictures

public static Picture blendPictures()
Method to blend pictures of Katie and Jenny

Returns:
the blended picture

copyFlowerSmaller

public static Picture copyFlowerSmaller()
Method to copy the flower but smaller (half as big)

Returns:
the smaller flower picture

scale2x

public Picture scale2x()
A method to scale the current picture object 2 x regular size

Returns:
the new scaled picture

copy

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

Returns:
the copied picture

copyFlowerLarger

public static Picture copyFlowerLarger()
Method to copy a flower but scaled to 2x normal size

Returns:
the larger flower

turnKatieRedHead

public static Picture turnKatieRedHead()
Method to turn to turn Katie into a red head


turnKatieRedHeadInRange

public static Picture turnKatieRedHeadInRange()
Method to turn to turn Katie into a red head using a range


removeRedEye

public void removeRedEye(int startX,
                         int startY,
                         int endX,
                         int endY,
                         Color newColor)
Method to remove red eye from the current picture object in the rectange define by startX, startY, endX, endY. The red will be replaced with the passed newColor

Parameters:
startX - the top left corner x value of a rectangle
startY - the top left corner y value of a rectangle
endX - the bottom right corner x value of a rectangle
endY - the bottom right corner y value of a rectangle
newColor - the new color to use

sepiaTint

public void sepiaTint()
Method to change the current picture to a sepia tint (modify the middle colors to a light brown and the light colors to a light yellow and make the shadows darker


posterize

public void posterize(int numLevels)
Method to posterize (reduce the number of colors) in the picture

Parameters:
numLevels - the number of color levels to use

posterize

public void posterize()
Method to posterize (reduce the number of colors) in the picture The number of reds, greens, and blues will be 4


blur

public void blur(int numPixels)
Method to blur the pixels

Parameters:
numPixels - the number of pixels to average in all directions so if the numPixels is 2 then we will average all pixels in the rectange defined by 2 before the current pixel to 2 after the current pixel

blurCopy

public void blurCopy(int numPixels)
Method to blur the pixels using a copy of the original as the source for the average

Parameters:
numPixels - the number of pixels to average in either direction so if the numPixels is 2 then we will average all pixels in the rectange defined by 2 before current to 2 after current

swapBackground

public void swapBackground(Picture oldBackground,
                           Picture newBackground)
Method to replace the background in the current picture with the background from another picture

Parameters:
oldBackground - a picture with the old background to replace
newBackground - a picture with the new background to use

swapBackgroundForThreshold

public void swapBackgroundForThreshold(Picture oldBackground,
                                       Picture newBackground,
                                       double threshold)
Method to replace the background in the current picture with the background from another picture for pixels that have a color distance to the old background of under the passed threshold

Parameters:
oldBackground - a picture with the old background to replace
newBackground - a picture with the new background to use
threshold - the distance from the old background color to use to figure out which pixels to swap with the new background

chromakey

public void chromakey(Picture newBg)
Method to do chromakey using a blue background

Parameters:
newBg - the new background image to use to replace the blue from the current picture

chromakeyBlue

public void chromakeyBlue(Picture newBg)
Method to do chromakey using a blue background

Parameters:
newBg - the new background image to use to replace the blue from the current picture

chromakeyRed

public void chromakeyRed(Picture newBg)
Method to do chromakey using a red background

Parameters:
newBg - the new background image to use to replace the blue from the current picture

addLines

public void addLines()
Method to add vertical and horizontal lines to the current picture


addHorizontalLines

public void addHorizontalLines()
Method to add a horizontal line every 5 pixels in the current picture


addVerticalLines

public void addVerticalLines()
Method to add a vertical line every 5 pixels in the current picture


drawExample

public static Picture drawExample()
Method to show using drawing on a picture

Returns:
the example picture

drawGrayEffect

public static Picture drawGrayEffect()
Method to draw a gray effect picture

Returns:
the picture that shows the gray effect

drawFilledRectangles

public static Picture drawFilledRectangles()
Method to draw a picture with a succession of filled rectangles with the top left corner the darkest and the bottom right the lightest

Returns:
the picture with the filled rectangles

drawRectangles

public static Picture drawRectangles()
Method to draw a picture with a succession of rectangles

Returns:
the picture with the filled rectangles

countWhite

public int countWhite()
Method to count teh number of white pixels in a picture


scale

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

Parameters:
factor - 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 background at a given point.

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 blue background for background at a given point.

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

compose

public void compose(Picture target,
                    int targetx,
                    int targety)
Method to compose this picture onto target at a given point.

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

flip

public Picture flip()
Method to flip an image left-to-right


reduceBlueIncreaseGreen

public void reduceBlueIncreaseGreen()
Method to reduce blue by 25% and increase green by 50%


methodA

public void methodA()

methodB

public void methodB()

methodC

public void methodC()

myStupidMethod

public void myStupidMethod()
My function that shifts r, g, b -- Mark Guzdial


topQuarter

public Picture topQuarter()

complex1

public void complex1()
Complex manipulation