texturesynthesis.wangtilesynthesizer
Class EditableImage

java.lang.Object
  extended by texturesynthesis.wangtilesynthesizer.EditableImage

public class EditableImage
extends java.lang.Object

An easily editable image class. This image class supports simple image manipulation procedures such as setting and getting the pixel values and copying parts of images to other images. The pixel values are stored in the ARGB format with 8 bits of precision.

Author:
Aki Koskinen

Field Summary
private  int height
          The height of this image.
private  int[] pixels
          An array to store the pixel values of this image.
private  int width
          The width of this image.
 
Constructor Summary
EditableImage(int width, int height)
          The constructor.
 
Method Summary
 void copyFromImage(EditableImage source, int x, int y)
          Copies the whole source image to this image to position x, y.
 int get(int x, int y)
          Gets the pixel at x, y.
 java.awt.image.BufferedImage getBufferedImage()
          Returns this image as a BufferedImage.
 int getHeight()
          Gets the height of this image.
 EditableImage getPart(java.awt.Rectangle rect)
          Returns a sub-image of this image as a new EditableImage.
 int getWidth()
          Gets the width of this image.
 void set(EditableImage source, java.awt.Rectangle rect, int x, int y)
          Copies pixels from another image.
 void set(int x, int y, int value)
          Sets the pixel at x, y to value
 void set(int x, int y, int w, int h, int[] values)
          Copies a rectangular area of pixels from the array to this image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pixels

private int[] pixels
An array to store the pixel values of this image.


width

private int width
The width of this image.


height

private int height
The height of this image.

Constructor Detail

EditableImage

public EditableImage(int width,
                     int height)
The constructor. Constructs a new image with given dimensions.

Parameters:
width - the width of this image.
height - the height of this image.
Method Detail

get

public int get(int x,
               int y)
Gets the pixel at x, y.

Parameters:
x - x-coordinate
y - y-coordinate
Returns:
the pixel value

set

public void set(int x,
                int y,
                int value)
Sets the pixel at x, y to value

Parameters:
x - x-coordinate
y - y-coordinate
value - the pixel value

set

public void set(int x,
                int y,
                int w,
                int h,
                int[] values)
Copies a rectangular area of pixels from the array to this image. The target area's top left corner is at x, y and the width is w and the height is h. The values in the source array should be in order: left to right and top to bottom.

Parameters:
x - the x-coordinate of the top left corner of the target area
y - the y-coordinate of the top left corner of the target area
w - the width of the target area
h - the height of the target area
values - the array of values

set

public void set(EditableImage source,
                java.awt.Rectangle rect,
                int x,
                int y)
Copies pixels from another image. The pixels shown by the given rectangle from the source image are copied to this image to location x, y.

Parameters:
source - the source image
rect - the area of the source image to be copied
x - the target x-coordinate
y - the target y-coordinate

getWidth

public int getWidth()
Gets the width of this image.

Returns:
the width in pixels.

getHeight

public int getHeight()
Gets the height of this image.

Returns:
the height in pixels.

copyFromImage

public void copyFromImage(EditableImage source,
                          int x,
                          int y)
Copies the whole source image to this image to position x, y. Portions of the source image not within this image's boundaries are not copied to anywhere.

Parameters:
source - the source image
x - start position x-coordinate
y - start position y-coordinate

getPart

public EditableImage getPart(java.awt.Rectangle rect)
Returns a sub-image of this image as a new EditableImage.

Parameters:
rect - the rectangel representing the sub-image's area
Returns:
a new EditableImage

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Returns this image as a BufferedImage.

Returns:
a BufferedImage