Xj3D 2.0 VRML/X3D Code API

vrml.eai.field
Class EventInSFImage

java.lang.Object
  extended by vrml.eai.field.BaseField
      extended by vrml.eai.field.EventIn
          extended by vrml.eai.field.EventInSFImage

public abstract class EventInSFImage
extends EventIn

VRML eventIn class for SFImage.

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

Field Summary
 
Fields inherited from class vrml.eai.field.BaseField
fieldType, MFColor, MFFloat, MFInt32, MFNode, MFRotation, MFString, MFTime, MFVec2f, MFVec3f, SFBool, SFColor, SFFloat, SFImage, SFInt32, SFNode, SFRotation, SFString, SFTime, SFVec2f, SFVec3f, UNSET_FIELD
 
Constructor Summary
protected EventInSFImage()
          Construct an instance of this class.
 
Method Summary
abstract  void setValue(int width, int height, int components, int[] pixels)
          Set the image value in the given eventIn.
 
Methods inherited from class vrml.eai.field.EventIn
getUserData, setUserData
 
Methods inherited from class vrml.eai.field.BaseField
getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventInSFImage

protected EventInSFImage()
Construct an instance of this class. Calls the superclass constructor with the field type set to SFImage.

Method Detail

setValue

public abstract void setValue(int width,
                              int height,
                              int components,
                              int[] pixels)
Set the image value in the given eventIn.

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 intensity value stored in the lowest byte and the transparency in the top byte:

    intensity = pixel[i] & 0xFF;
    alpha = (pixel[i] >> 24) & 0xFF00;
 
Note that this is different to the VRML representation of the image which would store the values in the text file as alpha = pixel[i] >> 8) & 0xFF. The reason for the difference is to maintain as much compatibility with the java image model as possible. Java does not contain a separate intensity only image model, instead it sets all three colour components to the same value. This way, the user of SFImages can take a full colour image and turn it to B&W by just setting the number of components to 2 - particularly if the three colour components are the same (which they are for an intensity only image) which will result in the correct intepretation of the image.

3 Component Images
The three colour 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:

        alpha = (pixel >> 24) & 0xff;
        red   = (pixel >> 16) & 0xff;
        green = (pixel >>  8) & 0xff;
        blue  = (pixel      ) & 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 colour 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