org.dvb.ui
Class DVBBufferedImage

java.lang.Object
  extended by java.awt.Image
      extended by org.dvb.ui.DVBBufferedImage

public class DVBBufferedImage
extends java.awt.Image

The DVBBufferedImage subclass describes an Image with an accessible buffer of image data. The DVBBufferedImage is an adapter class for java.awt.image.BufferedImage. It supports two different platform dependent sample models TYPE_BASE and TYPE_ADVANCED. Buffered images with the TYPE_BASE have the same sample model as the on screen graphics buffer, thus TYPE_BASE could be CLUT based. TYPE_ADVANCED has a direct color model but it is not specified how many bits are used to store the different color components. By default, a new DVBBufferedImage is transparent. All alpha values are set to 0; Instances of DVBBufferedImage shall be considered to be off-screen images for the purpose of the inherited method Image.getGraphics.

Since:
MHP 1.0

Field Summary
static int TYPE_ADVANCED
          Represents an image stored in a best possible SampleModel (platform dependent) The image has a DirectColorModel with alpha.
static int TYPE_BASE
          Represents an image stored in a platform dependent Sample Model.
 
Fields inherited from class java.awt.Image
SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
 
Constructor Summary
DVBBufferedImage(int width, int height)
          Constructs a DVBBufferedImage with the specified width and height.
DVBBufferedImage(int width, int height, int type)
          Constructs a new DVBBufferedImage with the specified width and height in the Sample Model specified by type.
 
Method Summary
 DVBGraphics createGraphics()
          Creates a DVBGraphics, which can be used to draw into this DVBBufferedImage.
 void dispose()
          Disposes of this buffered image.
 void flush()
          Flushes all resources being used to cache optimization information.
 java.awt.Graphics getGraphics()
          This method returns a Graphics, it is here for backwards compatibility.
 int getHeight()
          Returns the height of the DVBBufferedImage.
 int getHeight(java.awt.image.ImageObserver observer)
          Returns the height of the image.
 java.awt.Image getImage()
          Returns a java.awt.Image representing this buffered image.
 java.lang.Object getProperty(java.lang.String name, java.awt.image.ImageObserver observer)
          Returns a property of the image by name.
 int getRGB(int x, int y)
          Returns the specified integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.
 int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
          Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a rectangular region of the image data.
 java.awt.Image getScaledInstance(int width, int height, int hints)
          Creates a scaled version of this image.
 java.awt.image.ImageProducer getSource()
          Returns the object that produces the pixels for the image.
 DVBBufferedImage getSubimage(int x, int y, int w, int h)
          Returns a subimage defined by a specified rectangular region.
 int getWidth()
          Returns the width of the DVBBufferedImage.
 int getWidth(java.awt.image.ImageObserver observer)
          Returns the width of the image.
 void setRGB(int x, int y, int rgb)
          Sets a pixel in this DVBBufferedImage to the specified ARGB value.
 void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
          Sets an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, into a rectangular portion of the image data.
 java.lang.String toString()
          Returns a String representation of this DVBBufferedImage object and its values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_ADVANCED

public static final int TYPE_ADVANCED
Represents an image stored in a best possible SampleModel (platform dependent) The image has a DirectColorModel with alpha. The color data in this image is considered not to be pre-multiplied with alpha. The data returned by getRGB() will be in the TYPE_INT_ARGB color model that is alpha component in bits 24 to 31, the red component in bits 16 to 23, the green component in bits 8 to 15, and the blue component in bits 0 to 7. The data for setRGB() shall be in the TYPE_INT_ARGB color model as well.

Since:
MHP 1.0
See Also:
Constant Field Values

TYPE_BASE

public static final int TYPE_BASE
Represents an image stored in a platform dependent Sample Model. This color model is not visible to applications. The data returned by getRGB() will be in the TYPE_INT_ARGB color model that is alpha component in bits 24 to 31, the red component in bits 16 to 23, the green component in bits 8 to 15, and the blue component in bits 0 to 7. The data for setRGB() shall be in the TYPE_INT_ARGB color model as well.

Since:
MHP 1.0
See Also:
Constant Field Values
Constructor Detail

DVBBufferedImage

public DVBBufferedImage(int width,
                        int height)
Constructs a DVBBufferedImage with the specified width and height. The Sample Model used the image is the native Sample Model (TYPE_BASE) of the implementation. Note that a request can lead to an java.lang.OutOfMemoryError. Applications should be aware of this.

Parameters:
width - the width of the created image
height - the height of the created image
Since:
MHP 1.0

DVBBufferedImage

public DVBBufferedImage(int width,
                        int height,
                        int type)
Constructs a new DVBBufferedImage with the specified width and height in the Sample Model specified by type. Note that a request can lead to an java.lang.OutOfMemoryError. Applications should be aware of this.

Parameters:
width - the width of the DVBBufferedImage
height - the height of the DVBBufferedImage
type - the ColorSpace of the DVBBufferedImage
Since:
MHP 1.0
Method Detail

createGraphics

public DVBGraphics createGraphics()
Creates a DVBGraphics, which can be used to draw into this DVBBufferedImage. Calls to this method after calls to the dispose method on the same instance shall return null.

Returns:
a DVBGraphics, used for drawing into this image.
Since:
MHP 1.0

flush

public void flush()
Flushes all resources being used to cache optimization information. The underlying pixel data is unaffected. Calls to this method after calls to the dispose method on the same instance shall fail silently.

Specified by:
flush in class java.awt.Image

getGraphics

public java.awt.Graphics getGraphics()
This method returns a Graphics, it is here for backwards compatibility. createGraphics is more convenient, since it is declared to return a DVBGraphics. Calls to this method after calls to the dispose method on the same instance shall return null.

Specified by:
getGraphics in class java.awt.Image
Returns:
a Graphics, which can be used to draw into this image.

getHeight

public int getHeight()
Returns the height of the DVBBufferedImage.

Returns:
the height of this DVBBufferedImage.
Since:
MHP 1.0

getHeight

public int getHeight(java.awt.image.ImageObserver observer)
Returns the height of the image.

Specified by:
getHeight in class java.awt.Image
Parameters:
observer - the ImageObserver that receives information about the image
Returns:
the height of the image or -1 if the height is not yet known.
See Also:
Image.getWidth(ImageObserver), ImageObserver

getImage

public java.awt.Image getImage()
Returns a java.awt.Image representing this buffered image. In implementations which implement java.awt.image.BufferedImage this returns a java.awt.image.BufferedImage cast to a java.awt.Image. Otherwise it is implementation dependent whether it returns this image or whether it returns an instance of an underlying platform specific sub-class of java.awt.Image. Calls to this method after calls to the dispose method on the same instance shall return null.

Returns:
a java.awt.image representing this buffered image
Since:
MHP 1.0

dispose

public void dispose()
Disposes of this buffered image. This method releases the resources (e.g. pixel memory) underlying this buffered image. After calling this method ;

Since:
MHP 1.0.1

getProperty

public java.lang.Object getProperty(java.lang.String name,
                                    java.awt.image.ImageObserver observer)
Returns a property of the image by name. Individual property names are defined by the various image formats. If a property is not defined for a particular image, this method returns the UndefinedProperty field. If the properties for this image are not yet known, then this method returns null and the ImageObserver object is notified later. The property name "comment" should be used to store an optional comment that can be presented to the user as a description of the image, its source, or its author. Calls to this method after calls to the dispose method on the same instance shall return null.

Specified by:
getProperty in class java.awt.Image
Parameters:
name - the property name
observer - the ImageObserver that receives notification regarding image information
Returns:
an Object that is the property referred to by the specified name or null if the properties of this image are not yet known.
See Also:
ImageObserver, Image.UndefinedProperty

getRGB

public int getRGB(int x,
                  int y)
Returns the specified integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace. Color conversion takes place if the used Sample Model is not 8-bit for each color component There are only 8-bits of precision for each color component in the returned data when using this method. Note that when a lower precision is used in this buffered image getRGB may return different values than those used in setRGB()

Parameters:
x - the x-coordinate of the pixel
y - the y-coordinate of the pixel
Returns:
an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if x or y is out of bounds or if the dispose method has been called on this instance
Since:
MHP 1.0

getRGB

public int[] getRGB(int startX,
                    int startY,
                    int w,
                    int h,
                    int[] rgbArray,
                    int offset,
                    int scansize)
Returns an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, from a rectangular region of the image data. There are only 8-bits of precision for each color component in the returned data when using this method. With a specified coordinate (x, y) in the image, the ARGB pixel can be accessed in this way:
    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
 

Parameters:
startX - the x-coordinate of the upper-left corner of the specified rectangular region
startY - the y-coordinate of the upper-left corner of the specified rectangular region
w - the width of the specified rectangular region
h - the height of the specified rectangular region
rgbArray - if not null, the rgb pixels are written here
offset - offset into the rgbArray
scansize - scanline stride for the rgbArray
Returns:
array of ARGB pixels.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the specified portion of the image data is out of bounds or if the dispose method has been called on this instance
Since:
MHP 1.0

getSource

public java.awt.image.ImageProducer getSource()
Returns the object that produces the pixels for the image.

Specified by:
getSource in class java.awt.Image
Returns:
the ImageProducer that is used to produce the pixels for this image.

If the dispose method has been called on this instance then null shall be returned. The source returned by this method is platform generated to provide access to the current contents of the DVBBufferedImage buffer.

See Also:
ImageProducer

getSubimage

public DVBBufferedImage getSubimage(int x,
                                    int y,
                                    int w,
                                    int h)
                             throws DVBRasterFormatException
Returns a subimage defined by a specified rectangular region. The returned DVBBufferedImage shares the same data array as the original image. If the dispose method has been called on this instance then null shall be returned.

Parameters:
x - the x-coordinate of the upper-left corner of the specified rectangular region
y - the y-coordinate of the upper-left corner of the specified rectangular region
w - the width of the specified rectangular region
h - the height of the specified rectangular region
Returns:
a DVBBufferedImage that is the subimage of this DVBBufferedImage.
Throws:
DVBRasterFormatException - if the specified area is not contained within this DVBBufferedImage.
Since:
MHP 1.0

getWidth

public int getWidth()
Returns the width of the DVBBufferedImage.

Returns:
the width of this DVBBufferedImage.
Since:
MHP 1.0

getWidth

public int getWidth(java.awt.image.ImageObserver observer)
Returns the width of the image. If the width is not known yet then the ImageObserver is notified later and -1 is returned.

Specified by:
getWidth in class java.awt.Image
Parameters:
observer - the ImageObserver that receives information about the image
Returns:
the width of the image or -1 if the width is not yet known.
See Also:
Image.getHeight(ImageObserver), ImageObserver

setRGB

public void setRGB(int x,
                   int y,
                   int rgb)
Sets a pixel in this DVBBufferedImage to the specified ARGB value. The pixel is assumed to be in the default RGB color model, TYPE_INT_ARGB, and default sRGB color space. Calls to this method after calls to the dispose method on the same instance shall throw an ArrayIndexOutOfBoundsException.

Parameters:
x - the x-coordinate of the pixel to set
y - the y-coordinate of the pixel to set
rgb - the ARGB value
Since:
MHP 1.0

setRGB

public void setRGB(int startX,
                   int startY,
                   int w,
                   int h,
                   int[] rgbArray,
                   int offset,
                   int scansize)
Sets an array of integer pixels in the default RGB color model (TYPE_INT_ARGB) and default sRGB color space, into a rectangular portion of the image data. There are only 8-bits of precision for each color component in the returned data when using this method. With a specified coordinate (x, y) in the this image, the ARGB pixel can be accessed in this way:
    pixel   = rgbArray[offset + (y-startY)*scansize + (x-startX)];
 
WARNING: No dithering takes place.

Calls to this method after calls to the dispose method on the same instance shall throw an ArrayIndexOutOfBoundsException.

Parameters:
startX - the x-coordinate of the upper-left corner of the specified rectangular region
startY - the y-coordinate of the upper-left corner of the specified rectangular region
w - the width of the specified rectangular region
h - the height of the specified rectangular region
rgbArray - the ARGB pixels
offset - offset into the rgbArray
scansize - scanline stride for the rgbArray
Since:
MHP 1.0

toString

public java.lang.String toString()
Returns a String representation of this DVBBufferedImage object and its values.

Overrides:
toString in class java.lang.Object
Returns:
a String representing this DVBBufferedImage.

getScaledInstance

public java.awt.Image getScaledInstance(int width,
                                        int height,
                                        int hints)
Creates a scaled version of this image. A new Image object is returned which will render the image at the specified width and height by default. The new Image object may be loaded asynchronously even if the original source image has already been loaded completely. If either the width or height is a negative number then a value is substituted to maintain the aspect ratio of the original image dimensions. If the dispose method has been called on this instance then null shall be returned.

Overrides:
getScaledInstance in class java.awt.Image
Parameters:
width - the width to which to scale the image.
height - the height to which to scale the image.
hints - flags to indicate the type of algorithm to use for image resampling.
Returns:
a scaled version of the image.