vrml.eai.field
Class EventOutSFImage

java.lang.Object
  extended by vrml.eai.field.BaseField
      extended by vrml.eai.field.EventOut
          extended by vrml.eai.field.EventOutSFImage

public abstract class EventOutSFImage
extends EventOut

Reference to a SFImage event-out slot. Use this class to read values from SFImage event-out slots.

The following example gets the image field of a PixelTexture node and writes the color components of all pixels to the console:

 vrml.eai.Node pixelTexture = ...;
 vrml.eai.field.EventOutSFImage image_changed = (vrml.eai.field.EventOutSFImage)pixelTexture.getEventOut("image_changed");
 int width = image_changed.getWidth();
 System.out.println("width = " + width + " pixels");
 int height = image_changed.getHeight();
 System.out.println("height = " + height + " pixels");
 int[] pixels = image_changed.getPixels();
 int intensity, red, green, blue, alpha, i;
 switch (image_changed.getComponents())
 {
     case 1:
         System.out.println("components = 1 (intensity)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 intensity = pixels[i] & 0xff;
                 System.out.println("intensity = " + intensity);
                 ++i;
             }
         break;
     case 2:
         System.out.println("components = 2 (intensity, alpha)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 intensity = (pixels[i] >> 8) & 0xff;
                 alpha = pixels[i] & 0xff;
                 System.out.println("intensity = " + intensity + ", alpha = " + alpha);
                 ++i;
             }
         break;
     case 3:
         System.out.println("components = 3 (red, green, blue)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 red = (pixels[i] >> 16) & 0xff;
                 green = (pixels[i] >> 8) & 0xff;
                 blue = pixels[i] & 0xff;
                 System.out.println("red = " + red + ", green = " + green + ", blue = " + blue);
                 ++i;
             }
         break;
     case 4:
         System.out.println("components = 4 (red, green, blue, alpha)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 red = (pixels[i] >> 24) & 0xff;
                 green = (pixels[i] >> 16) & 0xff;
                 blue = (pixels[i] >> 8) & 0xff;
                 alpha = pixels[i] & 0xff;
                 System.out.println("red = " + red + ", green = " + green + ", blue = " + blue + ", alpha = " + alpha);
                 ++i;
             }
         break;
 }
 


Field Summary
 
Fields inherited from class vrml.eai.field.BaseField
MFColor, MFFloat, MFInt32, MFNode, MFRotation, MFString, MFTime, MFVec2f, MFVec3f, SFBool, SFColor, SFFloat, SFImage, SFInt32, SFNode, SFRotation, SFString, SFTime, SFVec2f, SFVec3f
 
Constructor Summary
protected EventOutSFImage()
          Default Constructor.
 
Method Summary
abstract  int getComponents()
          Returns the number of components of the image.
abstract  int getHeight()
          Returns the height of the image.
abstract  int[] getPixels()
          Returns the pixel values of the image.
abstract  void getPixels(int[] pixels)
          Returns the pixel values of the image.
abstract  int getWidth()
          Returns the width of the image.
 
Methods inherited from class vrml.eai.field.EventOut
addVrmlEventListener, getUserData, removeVrmlEventListener, 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

EventOutSFImage

protected EventOutSFImage()
Default Constructor. This method is protected, i.e. you cannot create new instances of this class. The only way to get instances is via the Node.getEventOut(java.lang.String) method.

Method Detail

getWidth

public abstract int getWidth()
Returns the width of the image.

The following example demonstrates how to get the width of an image:

 vrml.eai.Node pixelTexture = ...;
 vrml.eai.field.EventOutSFImage image_changed = (vrml.eai.field.EventOutSFImage)pixelTexture.getEventOut("image_changed");
 System.out.println("width = " + image_changed.getWidth() + " pixels");
 

Returns:
The width of the image, in pixels.

getHeight

public abstract int getHeight()
Returns the height of the image.

The following example demonstrates how to get the height of an image:

 vrml.eai.Node pixelTexture = ...;
 vrml.eai.field.EventOutSFImage image_changed = (vrml.eai.field.EventOutSFImage)pixelTexture.getEventOut("image_changed");
 System.out.println("height = " + image_changed.getHeight() + " pixels");
 

Returns:
The height of the image, in pixels.

getComponents

public abstract int getComponents()
Returns the number of components of the image.

The following example demonstrates how to get the number of color components of an image:

 vrml.eai.Node pixelTexture = ...;
 vrml.eai.field.EventOutSFImage image_changed = (vrml.eai.field.EventOutSFImage)pixelTexture.getEventOut("image_changed");
 switch (image_changed.getComponents())
 {
     case 1:
         System.out.println("components = 1 (intensity)");
         break;
     case 2:
         System.out.println("components = 2 (intensity, alpha)");
         break;
     case 3:
         System.out.println("components = 3 (red, green, blue)");
         break;
     case 4:
         System.out.println("components = 4 (red, green, blue, alpha)");
         break;
 }
 

Returns:
The number of components. This is a number between 1 and 4, inclusively. Greyscale images have one component (intensity). Greyscale images with an alpha channel have two components (intensity and alpha). Color images have three components (red, green and blue). Color images with an alpha channel have 4 components (red, green, blue and alpha).

getPixels

public abstract int[] getPixels()
Returns the pixel values of the image.

The following example gets the image field of a PixelTexture node and writes the color components of all pixels to the console:

 vrml.eai.Node pixelTexture = ...;
 vrml.eai.field.EventOutSFImage image_changed = (vrml.eai.field.EventOutSFImage)pixelTexture.getEventOut("image_changed");
 int width = image_changed.getWidth();
 System.out.println("width = " + width + " pixels");
 int height = image_changed.getHeight();
 System.out.println("height = " + height + " pixels");
 int[] pixels = image_changed.getPixels();
 int intensity, red, green, blue, alpha, i;
 switch (image_changed.getComponents())
 {
     case 1:
         System.out.println("components = 1 (intensity)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 intensity = pixels[i] & 0xff;
                 System.out.println("intensity = " + intensity);
                 ++i;
             }
         break;
     case 2:
         System.out.println("components = 2 (intensity, alpha)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 intensity = (pixels[i] >> 8) & 0xff;
                 alpha = pixels[i] & 0xff;
                 System.out.println("intensity = " + intensity + ", alpha = " + alpha);
                 ++i;
             }
         break;
     case 3:
         System.out.println("components = 3 (red, green, blue)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 red = (pixels[i] >> 16) & 0xff;
                 green = (pixels[i] >> 8) & 0xff;
                 blue = pixels[i] & 0xff;
                 System.out.println("red = " + red + ", green = " + green + ", blue = " + blue);
                 ++i;
             }
         break;
     case 4:
         System.out.println("components = 4 (red, green, blue, alpha)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 red = (pixels[i] >> 24) & 0xff;
                 green = (pixels[i] >> 16) & 0xff;
                 blue = (pixels[i] >> 8) & 0xff;
                 alpha = pixels[i] & 0xff;
                 System.out.println("red = " + red + ", green = " + green + ", blue = " + blue + ", alpha = " + alpha);
                 ++i;
             }
         break;
 }
 

Returns:
The actual pixel values. This is an array of width x height integer values. The pixels are defined left to right, bottom to top, i.e. the first pixel is in the lower left corner, and the last pixel is in the upper right corner of the image. The value of each color component is between 0 (no intensity resp. completely transparent) and 255 (full intensity resp. completely opaque), inclusively. For one-component images, pixels simply consist of a single intensity value, e.g. 0x00 in hexadecimal (0 in decimal) for no intensity or 0xff in hexadecimal (256 in decimal) for full intensity. For two-component images, pixels consist of an intensity value in the upper byte, followed by an alpha value in the lower byte, e.g. 0xff80 is semi-transparent full intensity. When you have a pixel value, you can get the intensity and the alpha value like this: intensity = (pixel >> 8) & 0xff; alpha = pixel & 0xff. For three-component images, pixels consist of the red component in the highest byte, followed by green and finally blue in the lowest byte, e.g. 0xFF0000 is red, 0x00FF00 is green, and 0x0000FF is blue. When you have a pixel value, you can get the red, green and blue components like this: red = (pixel >> 16) & 0xff; green = (pixel >> 8) & 0xff; blue = pixel & 0xff. For four-component images, pixels consist of the red component in the highest byte, followed by green, blue and finally alpha in the lowest byte, e.g. 0xff000080 is semi-transparent red. When you have a pixel value, you can get the red, green, blue and alpha components like this: red = (pixel >> 24) & 0xff; green = (pixel >> 16) & 0xff; blue = (pixel >> 8) & 0xff; alpha = pixel & 0xff.

getPixels

public abstract void getPixels(int[] pixels)
                        throws java.lang.ArrayIndexOutOfBoundsException
Returns the pixel values of the image.

The following example gets the image field of a PixelTexture node and writes the color components of all pixels to the console:

 vrml.eai.Node pixelTexture = ...;
 vrml.eai.field.EventOutSFImage image_changed = (vrml.eai.field.EventOutSFImage)pixelTexture.getEventOut("image_changed");
 int width = image_changed.getWidth();
 System.out.println("width = " + width + " pixels");
 int height = image_changed.getHeight();
 System.out.println("height = " + height + " pixels");
 int[] pixels = new int[width * height];
 image_changed.getPixels(pixels);
 int intensity, red, green, blue, alpha, i;
 switch (image_changed.getComponents())
 {
     case 1:
         System.out.println("components = 1 (intensity)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 intensity = pixels[i] & 0xff;
                 System.out.println("intensity = " + intensity);
                 ++i;
             }
         break;
     case 2:
         System.out.println("components = 2 (intensity, alpha)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 intensity = (pixels[i] >> 8) & 0xff;
                 alpha = pixels[i] & 0xff;
                 System.out.println("intensity = " + intensity + ", alpha = " + alpha);
                 ++i;
             }
         break;
     case 3:
         System.out.println("components = 3 (red, green, blue)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 red = (pixels[i] >> 16) & 0xff;
                 green = (pixels[i] >> 8) & 0xff;
                 blue = pixels[i] & 0xff;
                 System.out.println("red = " + red + ", green = " + green + ", blue = " + blue);
                 ++i;
             }
         break;
     case 4:
         System.out.println("components = 4 (red, green, blue, alpha)");
         i = 0;
         for (int y = 0; y < height; ++y)
             for (int x = 0; x < width; ++x)
             {
                 System.out.print("pixel @ x = " + x + ", y = " + y + ": ");
                 red = (pixels[i] >> 24) & 0xff;
                 green = (pixels[i] >> 16) & 0xff;
                 blue = (pixels[i] >> 8) & 0xff;
                 alpha = pixels[i] & 0xff;
                 System.out.println("red = " + red + ", green = " + green + ", blue = " + blue + ", alpha = " + alpha);
                 ++i;
             }
         break;
 }
 

Parameters:
pixels - An array of at least width x height integer values that gets filled with the pixel values. The pixels are defined left to right, bottom to top, i.e. the first pixel is in the lower left corner, and the last pixel is in the upper right corner of the image. The value of each color component is between 0 (no intensity resp. completely transparent) and 255 (full intensity resp. completely opaque), inclusively. For one-component images, pixels simply consist of a single intensity value, e.g. 0x00 in hexadecimal (0 in decimal) for no intensity or 0xff in hexadecimal (256 in decimal) for full intensity. For two-component images, pixels consist of an intensity value in the upper byte, followed by an alpha value in the lower byte, e.g. 0xff80 is semi-transparent full intensity. When you have a pixel value, you can get the intensity and the alpha value like this: intensity = (pixel >> 8) & 0xff; alpha = pixel & 0xff. For three-component images, pixels consist of the red component in the highest byte, followed by green and finally blue in the lowest byte, e.g. 0xFF0000 is red, 0x00FF00 is green, and 0x0000FF is blue. When you have a pixel value, you can get the red, green and blue components like this: red = (pixel >> 16) & 0xff; green = (pixel >> 8) & 0xff; blue = pixel & 0xff. For four-component images, pixels consist of the red component in the highest byte, followed by green, blue and finally alpha in the lowest byte, e.g. 0xff000080 is semi-transparent red. When you have a pixel value, you can get the red, green, blue and alpha components like this: red = (pixel >> 24) & 0xff; green = (pixel >> 16) & 0xff; blue = (pixel >> 8) & 0xff; alpha = pixel & 0xff.
Throws:
java.lang.ArrayIndexOutOfBoundsException - when the pixels array has less then width x height elements.