Class Pixel

java.lang.Object
  extended by Pixel

public class Pixel
extends java.lang.Object

Class that references a pixel in a picture. A pixel has an x and y location in a picture. A pixel knows how to get and set the red, green, blue, and alpha values in the picture. A pixel also knows how to get and set the color using a Color object.
Copyright Georgia Institute of Technology 2004

Author:
Barb Ericson ericson@cc.gatech.edu Modified 6 July 2007 Pam Cutter Kalamazoo College Added a field to hold the pixel's color. Updated the get/set color methods to reflect this new field. Commented out original code. Kalamazoo additional methods merged by Buck Scharfnorth 22 May 2008

Constructor Summary
Pixel(DigitalPicture picture, int x, int y)
          A constructor that take the x and y location for the pixel and the picture the pixel is coming from
 
Method Summary
 double colorDistance(java.awt.Color testColor)
          Method to get the distance between this pixel's color and the passed color
static double colorDistance(java.awt.Color color1, java.awt.Color color2)
          Method to compute the color distances between two color objects
static int correctLevel(double level)
          Round and correct a color level to be within 0 and 255, according to the current wrapLevels setting.
static int correctLevel(int level)
          Correct a color level to be within 0 and 255, according to the current wrapLevels setting.
 int getAlpha()
          Method to get the amount of alpha (transparency) at this pixel.
 double getAverage()
          Method to get the average of the colors of this pixel
 int getBlue()
          Method to get the amount of blue at this pixel.
static int getBlue(int value)
          Method to get the blue value from a pixel represented as an int
 java.awt.Color getColor()
          Method to get a color object that represents the color at this pixel.
 int getGreen()
          Method to get the amount of green at this pixel.
static int getGreen(int value)
          Method to get the green value from a pixel represented as an int
 int getRed()
          Method to get the amount of red at this pixel.
static int getRed(int value)
          Method to get the red value from a pixel represented as an int
static boolean getWrapLevels()
          Indicates whether levels outside the range 0-255 are clamped or wrapped around (saturating or modular arithmetic).
 int getX()
          Method to get the x location of this pixel.
 int getY()
          Method to get the y location of this pixel.
 void setAlpha(int value)
          Method to set the alpha (transparency) to a new alpha value
 void setBlue(int value)
          Method to set the blue to a new blue value
 void setColor(java.awt.Color newColor)
          Method to set the pixel color to the passed in color object.
 void setColor(int red, int green, int blue, int alpha)
          Method to set the pixel color to the passed in RGB and alpha components.
 void setColorFrom(Pixel otherPixel)
          Sets the color of this pixel from the color value of otherPixel.
 void setGreen(int value)
          Method to set the green to a new green value
 void setRed(int value)
          Method to set the red to a new red value
static void setWrapLevels(boolean wrap)
          Changes Pixel's behavior for dealing with levels outside the range 0-255.
 java.lang.String toString()
          Method to return a string with information about this pixel
 void updatePicture(int alpha, int red, int green, int blue)
          Method to update the picture based on the passed color values for this pixel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pixel

public Pixel(DigitalPicture picture,
             int x,
             int y)
A constructor that take the x and y location for the pixel and the picture the pixel is coming from

Parameters:
picture - the picture that the pixel is in
x - the x location of the pixel in the picture
y - the y location of the pixel in the picture
Method Detail

getWrapLevels

public static boolean getWrapLevels()
Indicates whether levels outside the range 0-255 are clamped or wrapped around (saturating or modular arithmetic).

Returns:
False to clamp levels, true to modulo them.

setWrapLevels

public static void setWrapLevels(boolean wrap)
Changes Pixel's behavior for dealing with levels outside the range 0-255.

Parameters:
wrap - If true, values will be wrapped (modular arithmetic). If false, values will be clamped (saturating arithmetic).

correctLevel

public static int correctLevel(double level)
Round and correct a color level to be within 0 and 255, according to the current wrapLevels setting.

Parameters:
level - The user-provided level.
Returns:
A value within 0 and 255.

correctLevel

public static int correctLevel(int level)
Correct a color level to be within 0 and 255, according to the current wrapLevels setting.

Parameters:
level - The user-provided level.
Returns:
A value within 0 and 255.

getX

public int getX()
Method to get the x location of this pixel.

Returns:
the x location of the pixel in the picture

getY

public int getY()
Method to get the y location of this pixel.

Returns:
the y location of the pixel in the picture

getAlpha

public int getAlpha()
Method to get the amount of alpha (transparency) at this pixel. It will be from 0-255.

Returns:
the amount of alpha (transparency)

getRed

public int getRed()
Method to get the amount of red at this pixel. It will be from 0-255 with 0 being no red and 255 being as much red as you can have.

Returns:
the amount of red from 0 for none to 255 for max

getRed

public static int getRed(int value)
Method to get the red value from a pixel represented as an int

Parameters:
value - the color value as an int
Returns:
the amount of red

getGreen

public int getGreen()
Method to get the amount of green at this pixel. It will be from 0-255 with 0 being no green and 255 being as much green as you can have.

Returns:
the amount of green from 0 for none to 255 for max

getGreen

public static int getGreen(int value)
Method to get the green value from a pixel represented as an int

Parameters:
value - the color value as an int
Returns:
the amount of green

getBlue

public int getBlue()
Method to get the amount of blue at this pixel. It will be from 0-255 with 0 being no blue and 255 being as much blue as you can have.

Returns:
the amount of blue from 0 for none to 255 for max

getBlue

public static int getBlue(int value)
Method to get the blue value from a pixel represented as an int

Parameters:
value - the color value as an int
Returns:
the amount of blue

getColor

public java.awt.Color getColor()
Method to get a color object that represents the color at this pixel.

Returns:
a color object that represents the pixel color

setColor

public void setColor(java.awt.Color newColor)
Method to set the pixel color to the passed in color object.

Parameters:
newColor - the new color to use

setColor

public void setColor(int red,
                     int green,
                     int blue,
                     int alpha)
Method to set the pixel color to the passed in RGB and alpha components.

Parameters:
red - the new red component value to use
green - the new green component value to use
blue - the new blue component value to use
alpha - the new alpha component value to use

updatePicture

public void updatePicture(int alpha,
                          int red,
                          int green,
                          int blue)
Method to update the picture based on the passed color values for this pixel

Parameters:
alpha - the alpha (transparency) at this pixel
red - the red value for the color at this pixel
green - the green value for the color at this pixel
blue - the blue value for the color at this pixel

setRed

public void setRed(int value)
Method to set the red to a new red value

Parameters:
value - the new value to use

setGreen

public void setGreen(int value)
Method to set the green to a new green value

Parameters:
value - the value to use

setBlue

public void setBlue(int value)
Method to set the blue to a new blue value

Parameters:
value - the new value to use

setAlpha

public void setAlpha(int value)
Method to set the alpha (transparency) to a new alpha value

Parameters:
value - the new value to use

setColorFrom

public void setColorFrom(Pixel otherPixel)
Sets the color of this pixel from the color value of otherPixel.

Parameters:
otherPixel - a pixel that may be in the same picture or a different picture.
Added by Alyce Brady/Pam Cutter

colorDistance

public double colorDistance(java.awt.Color testColor)
Method to get the distance between this pixel's color and the passed color

Parameters:
testColor - the color to compare to
Returns:
the distance between this pixel's color and the passed color

colorDistance

public static double colorDistance(java.awt.Color color1,
                                   java.awt.Color color2)
Method to compute the color distances between two color objects

Parameters:
color1 - a color object
color2 - a color object
Returns:
the distance between the two colors

getAverage

public double getAverage()
Method to get the average of the colors of this pixel

Returns:
the average of the red, green, and blue values

toString

public java.lang.String toString()
Method to return a string with information about this pixel

Overrides:
toString in class java.lang.Object
Returns:
a string with information about this pixel