scenic
Class ScenicImage

java.lang.Object
  extended by java.awt.Image
      extended by java.awt.image.VolatileImage
          extended by scenic.ScenicImage
All Implemented Interfaces:
java.awt.Transparency

public class ScenicImage
extends java.awt.image.VolatileImage

The ScenicImage class is used to store images that can be directly used by the Scenic library. This class extends the VolatileImage class, but it also adds several new methods for reading and writing data. The image data is stored in video memory to make hardware acceleration possible.

The format of the image data is specified by the format attribute. Different formats are defined in the Format class.


Field Summary
 
Fields inherited from class java.awt.image.VolatileImage
IMAGE_INCOMPATIBLE, IMAGE_OK, IMAGE_RESTORED
 
Fields inherited from class java.awt.Image
SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
ScenicImage()
          Constructs an empty image
ScenicImage(java.awt.image.BufferedImage image)
          Creates an image from the given BufferedImage.
ScenicImage(int width, int height, int format)
          Constructs an image with given parameters.
ScenicImage(int width, int height, int format, int options)
          Constructs an image with given parameters.
 
Method Summary
 void addObserver(ScenicImageObserver observer)
           
 boolean contentsLost()
          Checks if the contents of the image are lost.
 java.awt.image.BufferedImage convertToBufferedImage()
          Converts the image to a java.awt.image.BufferedImage object.
 java.awt.image.BufferedImage convertToBufferedImage(int type)
          Converts the image to a java.awt.image.BufferedImage object.
 void create(int width, int height, int format)
          Creates an image with the given parameters.
 void create(int width, int height, int format, int options)
          Creates an image with the given parameters.
 java.awt.Graphics2D createGraphics()
           
 void deleteObserver(ScenicImageObserver observer)
           
 void free()
          Frees the resources associated with the image.
 java.awt.ImageCapabilities getCapabilities()
           
 int getFormat()
          Gets the format of the image.
 int getHeight()
          Gets the height of the image.
 int getHeight(java.awt.image.ImageObserver observer)
           
static ScenicImage getImageFromCache(java.awt.image.BufferedImage img)
          Tries to get a cached ScenicImage that has the content of the given BufferedImage.
 java.lang.Object getProperty(java.lang.String name, java.awt.image.ImageObserver observer)
           
 java.awt.image.BufferedImage getSnapshot()
           
 int getWidth()
          Gets the width of the image.
 int getWidth(java.awt.image.ImageObserver observer)
           
 void read(int x, int y, int width, int height, byte[] data, int format)
          Reads the pixel data of the image in the given rectangle.
 void read(int x, int y, int width, int height, float[] data, int format)
          Reads the pixel data of the image in the given rectangle.
 void read(int x, int y, int width, int height, int[] data, int format)
          Reads the pixel data of the image in the given rectangle.
 int validate(java.awt.GraphicsConfiguration gc)
           
 void write(int x, int y, int width, int height, byte[] data, int format)
          Writes the pixel data of the image in the given rectangle.
 void write(int x, int y, int width, int height, float[] data, int format)
          Writes the pixel data of the image in the given rectangle.
 void write(int x, int y, int width, int height, int[] data, int format)
          Writes the pixel data of the image in the given rectangle.
 
Methods inherited from class java.awt.image.VolatileImage
flush, getGraphics, getSource, getTransparency
 
Methods inherited from class java.awt.Image
getAccelerationPriority, getCapabilities, getScaledInstance, setAccelerationPriority
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScenicImage

public ScenicImage()
Constructs an empty image


ScenicImage

public ScenicImage(int width,
                   int height,
                   int format)
Constructs an image with given parameters.

Parameters:
width - the width of the image.
height - the height of the image.
format - the format of the image (must be one of the constants defined in the Format class).

ScenicImage

public ScenicImage(int width,
                   int height,
                   int format,
                   int options)
Constructs an image with given parameters.

Parameters:
width - the width of the image.
height - the height of the image.
format - the format of the image (must be one of the constants defined in the Format class).
options - options for the image (must be a combination of the constants in ImageOptions class).

ScenicImage

public ScenicImage(java.awt.image.BufferedImage image)
Creates an image from the given BufferedImage. The buffered image must be of type TYPE_3BYTE_BGR.

Parameters:
image - the source image.
Method Detail

getImageFromCache

public static ScenicImage getImageFromCache(java.awt.image.BufferedImage img)
Tries to get a cached ScenicImage that has the content of the given BufferedImage. If the cache does not contain the desired image then a new image is created and added to the cache.

Parameters:
img - BufferedImage
Returns:
ScenicImage

convertToBufferedImage

public java.awt.image.BufferedImage convertToBufferedImage(int type)
Converts the image to a java.awt.image.BufferedImage object. The type of the buffered image must be either BufferedImage.TYPE_4BYTE_ABGR or BufferedImage.TYPE_3BYTE_BGR.

Parameters:
type - type of the image
Returns:
the BufferedImage object

convertToBufferedImage

public java.awt.image.BufferedImage convertToBufferedImage()
Converts the image to a java.awt.image.BufferedImage object. The type of the buffered image is BufferedImage.TYPE_3BYTE_BGR.

Returns:
the BufferedImage object

getWidth

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

Specified by:
getWidth in class java.awt.image.VolatileImage

getHeight

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

Specified by:
getHeight in class java.awt.image.VolatileImage

getFormat

public int getFormat()
Gets the format of the image. The format is one of the constants defined in the Format class.


create

public void create(int width,
                   int height,
                   int format,
                   int options)
Creates an image with the given parameters. The new image replaces the old image. Pixel data is not copied to the new image.

Parameters:
width - the width of the image.
height - the height of the image.
format - the format of the image (must be one of the constants defined in the Format class).
options - options for the image (must be one of the constants defined in the ImageOptions class).

create

public void create(int width,
                   int height,
                   int format)
Creates an image with the given parameters. The new image replaces the old image. Pixel data is not copied to the new image.

Parameters:
width - the width of the image.
height - the height of the image.
format - the format of the image (must be one of the constants defined in the Format class).

addObserver

public void addObserver(ScenicImageObserver observer)

deleteObserver

public void deleteObserver(ScenicImageObserver observer)

contentsLost

public boolean contentsLost()
Checks if the contents of the image are lost. Some image types are volatile, meaning that their contents can be lost. Images that are used as render targets can be lost when using DirectX. On OpenGL images are never lost. For compatibility, you should always check if the contents are lost when you are using render target images.

Specified by:
contentsLost in class java.awt.image.VolatileImage
Returns:
true if the contents of the image are lost

free

public void free()
Frees the resources associated with the image.


write

public void write(int x,
                  int y,
                  int width,
                  int height,
                  byte[] data,
                  int format)
Writes the pixel data of the image in the given rectangle.

Parameters:
x - the left side of the rectangle
y - the top of the rectangle
width - the width of the rectangle
height - the height of the rectangle
data - the pixel data
format - format of the pixel data

write

public void write(int x,
                  int y,
                  int width,
                  int height,
                  int[] data,
                  int format)
Writes the pixel data of the image in the given rectangle.

Parameters:
x - the left side of the rectangle
y - the top of the rectangle
width - the width of the rectangle
height - the height of the rectangle
data - the pixel data
format - format of the pixel data

write

public void write(int x,
                  int y,
                  int width,
                  int height,
                  float[] data,
                  int format)
Writes the pixel data of the image in the given rectangle.

Parameters:
x - the left side of the rectangle
y - the top of the rectangle
width - the width of the rectangle
height - the height of the rectangle
data - the pixel data
format - format of the pixel data

read

public void read(int x,
                 int y,
                 int width,
                 int height,
                 byte[] data,
                 int format)
Reads the pixel data of the image in the given rectangle.

Parameters:
x - the left side of the rectangle
y - the top of the rectangle
width - the width of the rectangle
height - the height of the rectangle
data - the pixel data
format - format of the pixel data

read

public void read(int x,
                 int y,
                 int width,
                 int height,
                 int[] data,
                 int format)
Reads the pixel data of the image in the given rectangle.

Parameters:
x - the left side of the rectangle
y - the top of the rectangle
width - the width of the rectangle
height - the height of the rectangle
data - the pixel data
format - format of the pixel data

read

public void read(int x,
                 int y,
                 int width,
                 int height,
                 float[] data,
                 int format)
Reads the pixel data of the image in the given rectangle.

Parameters:
x - the left side of the rectangle
y - the top of the rectangle
width - the width of the rectangle
height - the height of the rectangle
data - the pixel data
format - format of the pixel data

getSnapshot

public java.awt.image.BufferedImage getSnapshot()
Specified by:
getSnapshot in class java.awt.image.VolatileImage

createGraphics

public java.awt.Graphics2D createGraphics()
Specified by:
createGraphics in class java.awt.image.VolatileImage

validate

public int validate(java.awt.GraphicsConfiguration gc)
Specified by:
validate in class java.awt.image.VolatileImage

getCapabilities

public java.awt.ImageCapabilities getCapabilities()
Specified by:
getCapabilities in class java.awt.image.VolatileImage

getWidth

public int getWidth(java.awt.image.ImageObserver observer)
Specified by:
getWidth in class java.awt.Image

getHeight

public int getHeight(java.awt.image.ImageObserver observer)
Specified by:
getHeight in class java.awt.Image

getProperty

public java.lang.Object getProperty(java.lang.String name,
                                    java.awt.image.ImageObserver observer)
Specified by:
getProperty in class java.awt.Image