squint
Class SImage

java.lang.Object
  extended by squint.SImage
All Implemented Interfaces:
javax.swing.Icon

public class SImage
extends java.lang.Object
implements javax.swing.Icon

An SImage is a representation of an image. SImages can be created either using image data from a file, by providing arrays of brightness or color values that describe the image. It is also possible to obtain arrays of values that describes an SImage using methods provided by the class.


Field Summary
static int BLUE
          Value used to identify the blue component of an image
static int CHANNELS
          Number of distinct colors used in an image
static int GRAY
          Value used to identify the grayness of an image
static int GREEN
          Value used to identify the green component of an image
static int RED
          Value used to identify the red component of an image
 
Constructor Summary
SImage(java.awt.Image original)
          Construct a new SImage from a representation of the image as an object of Java's Image class.
SImage(int[][] pixArray)
          Construct a new SImage from a single array of pixel values.
SImage(int[][][] pixelArrays)
          Construct a new SImage from a three dimensional array of values describing the redness, blueness and greenness of the image's pixels.
SImage(int[][] reds, int[][] greens, int[][] blues)
          Construct a new SImage from a three arrays of values describing the redness, blueness, and greenness of the image's pixels.
SImage(int channel, int[][] pixelArray)
          Construct a new SImage from a two dimensional array of pixel values describing the brightness values for just one color channel.
SImage(int width, int height, java.awt.Color shade)
          Construct a new, monotone SImage of a given width and height.
SImage(int width, int height, int brightness)
          Construct a new, monotone, grayscale SImage of a given width and height.
SImage(java.lang.String pathName)
          Construct a new SImage given a String that identifies a file containing the data describing the image.
 
Method Summary
 int[][] getBluePixelArray()
          Get an array describing the blueness values of this SImage's pixels
 java.awt.Color getColor(int x, int y)
          Access the Color associated with a particular pixel of an SImage.
 int[][] getGreenPixelArray()
          Get an array describing the greenness values of this SImage's pixels
 int getHeight()
          Get this SImage's height.
 int getIconHeight()
          Get this SImage's height.
 int getIconWidth()
          Get this SImage's width.
 java.awt.Image getImage()
          Get a representation of this SImage as an Image object.
 int[][] getPixelArray()
          Get a pixel array describing the brightness values of this SImage's pixels.
 int[][] getPixelArray(int channel)
          Get a pixel array describing the amount of one of the three primary colors (red, green, and blue) in each of this image's pixels.
 int[][][] getPixelArrays()
          Get a three dimensional array describing the redness, greenness, and blueness values of this SImage's pixels
 int[][] getRedPixelArray()
          Get an array describing the redness values of this SImage's pixels
 int getWidth()
          Get this SImage's width.
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
          Draw this image using the specified graphics context.
 void saveAs(java.lang.String pathName)
          Save the image in a PNG format file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRAY

public static final int GRAY
Value used to identify the grayness of an image

See Also:
Constant Field Values

RED

public static final int RED
Value used to identify the red component of an image

See Also:
Constant Field Values

GREEN

public static final int GREEN
Value used to identify the green component of an image

See Also:
Constant Field Values

BLUE

public static final int BLUE
Value used to identify the blue component of an image

See Also:
Constant Field Values

CHANNELS

public static final int CHANNELS
Number of distinct colors used in an image

See Also:
Constant Field Values
Constructor Detail

SImage

public SImage(int width,
              int height,
              int brightness)
Construct a new, monotone, grayscale SImage of a given width and height.

Parameters:
width - the width of the desired SImage
height - the height of the desired SImage
brightness - the brightness of the desired SImage

SImage

public SImage(int width,
              int height,
              java.awt.Color shade)
Construct a new, monotone SImage of a given width and height.

Parameters:
width - the width of the desired SImage
height - the height of the desired SImage
shade - the color of the desired SImage

SImage

public SImage(java.awt.Image original)
Construct a new SImage from a representation of the image as an object of Java's Image class. The input image will be cloned.

Parameters:
original - the Image object whose contents describe the desired SImage

SImage

public SImage(java.lang.String pathName)
Construct a new SImage given a String that identifies a file containing the data describing the image. If the string starts with "http", then it will be interpreted as a URL. Otherwise, it will be treated as a path within the local file system.

Parameters:
pathName - a URL or file pathname describing where the image data can be found

SImage

public SImage(int[][] pixArray)
Construct a new SImage from a single array of pixel values. The values in the array will be interpreted as brightness values. The resulting SImage will be a grayscale image. The array must be two dimensional, rectangular array. The size of its first dimension will determine the width of the image. The size of its second dimension will determine the height of the image.

Parameters:
pixArray - an array describing the brightness of each of the image's pixels

SImage

public SImage(int[][] reds,
              int[][] greens,
              int[][] blues)
Construct a new SImage from a three arrays of values describing the redness, blueness, and greenness of the image's pixels. All of the arrays must be two-dimensional rectangular arrays with identical dimensions. The size of the first dimension will determine the width of the resulting image. The size of the second dimension will determine the height

Parameters:
reds - an array describing the amount of red in each of the image's pixels
greens - an array describing the amount of green in each of the image's pixels
blues - an array describing the amount of blue in each of the image's pixels

SImage

public SImage(int[][][] pixelArrays)
Construct a new SImage from a three dimensional array of values describing the redness, blueness and greenness of the image's pixels. The first dimension of the array must be of size 3. Its 0th element will determine the redness values of the image, its 1st element will determine the green values, and its 2nd element will determine the blues.

Parameters:
pixelArrays - an array describing the amount of red, green, and blue in each of the image's pixels

SImage

public SImage(int channel,
              int[][] pixelArray)
Construct a new SImage from a two dimensional array of pixel values describing the brightness values for just one color channel. (Note: This was added just for Morgan)

Parameters:
channel - the color whose brightness values are specified by the second parameter
pixelArray - an array describing the brightness values of the specified channel
Method Detail

getColor

public java.awt.Color getColor(int x,
                               int y)
Access the Color associated with a particular pixel of an SImage.

Parameters:
x - the x coordinate of the desired pixel
y - the y coordinate of the desired pixel
Returns:
the color of the pixel.

getPixelArray

public int[][] getPixelArray()
Get a pixel array describing the brightness values of this SImage's pixels.

Returns:
an pixel array describing the brightness value of this image's pixels

getPixelArray

public int[][] getPixelArray(int channel)
Get a pixel array describing the amount of one of the three primary colors (red, green, and blue) in each of this image's pixels.

Parameters:
channel - a value identifying which color values are desired. This parameter's value must be either SImage.RED (=0), SImage.GREEN (=1), or SImage.BLUE (=2).
Returns:
an array describing the brightness value of this image's pixels

getRedPixelArray

public int[][] getRedPixelArray()
Get an array describing the redness values of this SImage's pixels

Returns:
an array describing the redness value of this image's pixels

getGreenPixelArray

public int[][] getGreenPixelArray()
Get an array describing the greenness values of this SImage's pixels

Returns:
an array describing the greenness value of this image's pixels

getBluePixelArray

public int[][] getBluePixelArray()
Get an array describing the blueness values of this SImage's pixels

Returns:
an array describing the blueness value of this image's pixels

getPixelArrays

public int[][][] getPixelArrays()
Get a three dimensional array describing the redness, greenness, and blueness values of this SImage's pixels

Returns:
an array describing the color value of this image's pixels

getHeight

public int getHeight()
Get this SImage's height.

Returns:
the image's height

getIconHeight

public int getIconHeight()
Get this SImage's height.

Specified by:
getIconHeight in interface javax.swing.Icon
Returns:
the image's height

getWidth

public int getWidth()
Get this SImage's width.

Returns:
the image's width

getIconWidth

public int getIconWidth()
Get this SImage's width.

Specified by:
getIconWidth in interface javax.swing.Icon
Returns:
the image's width

getImage

public java.awt.Image getImage()
Get a representation of this SImage as an Image object.

Returns:
the image

saveAs

public void saveAs(java.lang.String pathName)
Save the image in a PNG format file

Parameters:
pathName - the pathname under which the image should be saved

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Draw this image using the specified graphics context.

Specified by:
paintIcon in interface javax.swing.Icon
Parameters:
c - the component to be used as the observer
g - the graphics context
x - coordinate where the image should be drawn
y - coordinate where the image should be drawn