Xj3D 2.0 VRML/X3D Code API

org.web3d.x3d.sai
Interface SFImage

All Superinterfaces:
X3DField

public interface SFImage
extends X3DField

Representation of a SFImage field.

Images are represented as arrays of integers as per the VRML IS specification Section 5.5 SFImage. Pixel values are between 0 and 256 and represented as integers to maintain consistency with java's ImageConsumer interface and PixelGrabber class.

Version:
1.0 30 April 1998

Method Summary
 int getComponents()
          Get the number of color components in the image.
 int getHeight()
          Get the height of the image.
 java.awt.image.WritableRenderedImage getImage()
          Fetch the Java representation of the underlying image from these pixels.
 void getPixels(int[] pixels)
          Get the image pixel value in the given eventOut.
 int getWidth()
          Get the width of the image.
 void setImage(java.awt.image.RenderedImage img)
          Set the image value in the given writable field to the new image defined by a set of pixels.
 void setSubImage(java.awt.image.RenderedImage img, int srcWidth, int srcHeight, int srcXOffset, int srcYOffset, int destXOffset, int destYOffset)
          Copy a region of the argument RenderedImage to replace a portion of the current SFimage.
 void setValue(int width, int height, int components, int[] pixels)
          Set the image value in the given writable field.
 
Methods inherited from interface org.web3d.x3d.sai.X3DField
addX3DEventListener, getDefinition, getUserData, isReadable, isWritable, removeX3DEventListener, setUserData
 

Method Detail

getWidth

int getWidth()
Get the width of the image.

Returns:
The width of the image in pixels

getHeight

int getHeight()
Get the height of the image.

Returns:
The height of the image in pixels

getComponents

int getComponents()
Get the number of color components in the image. The value will always be between 1 and 4 indicating the number of components of the color specification to be read from the image pixel data.

Returns:
The number of components

getPixels

void getPixels(int[] pixels)
Get the image pixel value in the given eventOut.

The number of items in the pixels array will be width * height. If there are less items than this an ArrayIndexOutOfBoundsException will be generated. The integer values are represented according to the number of components.

1 Component Images
The integer has the intensity value stored in the lowest byte and can be obtained:

    intensity = (pixel[i]     ) & 0xFF;
 

2 Component Images
The integer has the transparency value stored in the lowest byte and the intensity in the next byte:

    intensity = (pixel[i] >> 8) & 0xFF;
    alpha     = (pixel[i]     ) & 0xFF;
 

3 Component Images
The three color components are stored in the integer array as follows:

    red   = (pixel[i] >> 16) & 0xFF;
    green = (pixel[i] >>  8) & 0xFF;
    blue  = (pixel[i]      ) & 0xFF;
 

4 Component Images
The integer has the value stored in the array as follows:

    red   = (pixel[i] >> 24) & 0xFF;
    green = (pixel[i] >> 16) & 0xFF;
    blue  = (pixel[i] >>  8) & 0xFF;
    alpha = (pixel[i]      ) & 0xFF;
 

The width and height values must be greater than or equal to zero. The number of components is between 1 and 4. Any value outside of these bounds will generate an IllegalArgumentException.

Parameters:
pixels - The array to copy pixel values into

getImage

java.awt.image.WritableRenderedImage getImage()
Fetch the Java representation of the underlying image from these pixels. This is the same copy that the browser uses to generate texture information from.

Returns:
The image reference representing the current state

setImage

void setImage(java.awt.image.RenderedImage img)
              throws InvalidOperationTimingException,
                     InvalidFieldValueException,
                     InvalidWritableFieldException,
                     InvalidFieldException
Set the image value in the given writable field to the new image defined by a set of pixels.

Parameters:
img - The new image to use as the source
Throws:
InvalidOperationTimingException
InvalidFieldValueException
InvalidWritableFieldException
InvalidFieldException

setSubImage

void setSubImage(java.awt.image.RenderedImage img,
                 int srcWidth,
                 int srcHeight,
                 int srcXOffset,
                 int srcYOffset,
                 int destXOffset,
                 int destYOffset)
                 throws InvalidOperationTimingException,
                        InvalidFieldValueException,
                        InvalidWritableFieldException,
                        InvalidFieldException
Copy a region of the argument RenderedImage to replace a portion of the current SFimage.

The sub image set shall not resize the base image representation and therefore performs an intersection clip of the provided image. The user provided image shall be of the same format (pixel depth, pixel representation) as the original image obtained through the getImage() method.

RenderedImages are row order from top to bottom. A 4x8 RenderImage is indexed as follows:


 X >01234567
   ----------
 0 |********|
 1 |********|
 2 |********|
 3 |********|
 ^ ----------
 Y

 
SFImages are row order from bottom to top. A 4x8 RenderImage is indexed as follows:

 X >01234567
   ----------
 3 |********|
 2 |********|
 1 |********|
 0 |********|
 ^ ----------
 Y

 

Note: The parameter srcYOffset is referenced to the RenderedImage object (indexed top to bottom).
The parameter destYOffset is referenced to the SFImage object (indexed bottom to top).

Parameters:
img - The new image to use as the source
srcWidth - The width of the argument sub-image region to copy
srcHeight - The height of the argument sub-image region to copy
srcXOffset - The initial x dimension (width) offset into the argument sub-image that begins the region to copy
srcYOffset - The initial y dimension (height) offset into the argument sub-image that begins the region to copy
destXOffset - The initial x dimension (width) offset in the SFimage object that begins the region to receive the copy
destYOffset - The initial y dimension (height) offset in the SFimage object that begins the region to receive the copy
Throws:
InvalidOperationTimingException
InvalidFieldValueException
InvalidWritableFieldException
InvalidFieldException

setValue

void setValue(int width,
              int height,
              int components,
              int[] pixels)
Set the image value in the given writable field.

Image values are specified using a width, height and the number of components. The number of items in the pixels array must be at least width * height. If there are less items than this an ArrayIndexOutOfBoundsException will be generated. The integer values are represented according to the number of components. If the integer contains values in bytes that are not used by the number of components for that image, the values are ignored.

1 Component Images
The integer has the intensity value stored in the lowest byte and can be obtained:

    intensity = (pixel[i]     ) & 0xFF;
 

2 Component Images
The integer has the transparency value stored in the lowest byte and the intensity in the next byte:

    intensity = (pixel[i] >> 8) & 0xFF;
    alpha     = (pixel[i]     ) & 0xFF;
 

3 Component Images
The three color components are stored in the integer array as follows:

    red   = (pixel[i] >> 16) & 0xFF;
    green = (pixel[i] >>  8) & 0xFF;
    blue  = (pixel[i]      ) & 0xFF;
 

4 Component Images
The integer has the value stored in the array as follows:

    red   = (pixel[i] >> 24) & 0xFF;
    green = (pixel[i] >> 16) & 0xFF;
    blue  = (pixel[i] >>  8) & 0xFF;
    alpha = (pixel[i]      ) & 0xFF;
 

The width and height values must be greater than or equal to zero. The number of components is between 1 and 4. Any value outside of these bounds will generate an IllegalArgumentException.

Parameters:
width - The width of the image in pixels
height - The height of the image in pixels
components - The number of color components [1-4]
pixels - The array of pixel values as specified above.
Throws:
java.lang.IllegalArgumentException - The number of components or width/ height are illegal values.
java.lang.ArrayIndexOutOfBoundsException - The number of pixels provided by the caller is not enough for the width * height.

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium