Class SFImageObject

java.lang.Object
org.web3d.x3d.jsail.fields.X3DConcreteField
org.web3d.x3d.jsail.fields.SFImageObject
All Implemented Interfaces:
SFImage, X3DField

public class SFImageObject
extends X3DConcreteField
implements SFImage
This utility class provides a concrete implementation corresponding to SFImage X3D field type.


Package hint: This specification class is defined by the X3D Java Language Binding Specification for the Scene Authoring Interface (SAI). SFImage specifies a single uncompressed 2-dimensional pixel image. SFImage fields contain three integers representing the width, height and number of components in the image, followed by (width x height) hexadecimal or integer values representing the pixels in the image.

Related field object: MFImageObject
See Also:
X3D Tooltips: type SFImage, SAI Java Specification: B.4.11 X3DFieldTypes, SAI Abstract Specification: 5.2.15 SAIFieldType, X3D Abstract Specification: SFImageAndMFImage, X3D Tooltips, X3D Tooltips: field, X3D Tooltips: fieldValue, X3D Scene Authoring Hints
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int[] DEFAULT_VALUE
    Default value for this field type contains values of 0 0 0.
    static java.lang.String DEFAULT_VALUE_STRING
    Default string value for this field type is "0 0 0".
    static java.lang.String NAME
    String constant NAME provides name of this element: SFImage
    static java.util.regex.Pattern PATTERN
    Precompiled regular expression (regex) pattern for this field type using default REGEX value.
    static java.lang.String REGEX
    Default regular expression (regex) pattern for this field type is \s*([+]?
    static int TUPLE_SIZE
    Default tuple size for this field type is 1 (i.e. number of component values making up a single-field SF object).

    Fields inherited from class org.web3d.x3d.jsail.fields.X3DConcreteField

    validationResult
  • Constructor Summary

    Constructors 
    Constructor Description
    SFImageObject()
    Constructor for SFImageObject performs value initialization.
    SFImageObject​(int[] newValue)
    Constructor for SFImageObject using a corresponding Java primitive int[] array as new initial value.
    SFImageObject​(SFImageObject newValue)
    Constructor to copy an SFImageObject value as initial value for this new field object.
  • Method Summary

    Modifier and Type Method Description
    boolean equals​(SFImageObject comparisonSFImageObject)
    Determine whether two objects contain equal values.
    int getExpectedLength()
    Compute expected length of SFImage integer array (based on height and width values).
    int getHeight()
    Get the height of the image.
    java.awt.image.WritableRenderedImage getImage()
    Fetch the Java representation of the underlying image from these pixels.
    int getNumberComponents()
    Get the number of color components in the image.
    int getNumberOfPixelValues()
    Compute number of pixel values in SFImage integer array (not counting height, width and components values).
    static java.lang.String getPixelHexFormat​(int numberComponents)
    Utility method to get format string for proper output of hexadecimal values.
    void getPixels​(int[] destinationPixels)
    Get the image pixel value in the given eventOut.
    java.lang.String getPixelsString()
    Utility method to get String value of pixels in SFImage image field.
    int[] getPrimitiveValue()
    Provides current value of the field as a Java primitive type.
    int getWidth()
    Get the width of the image.
    void initialize()
    Initialization for SFImageObject applies default initial value.
    static boolean isArray()
    Whether or not this field type is an array (false)
    boolean isDefaultValue()
    Determine whether current value matches DEFAULT_VALUE
    boolean matches()
    Test PATTERN match via regular expression (regex) check of current object's toString() value.
    static boolean matches​(java.lang.String value)
    Test PATTERN match with regular expression (regex) of provided value.
    void setImage​(java.awt.image.RenderedImage image)
    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 image, int sourceWidth, int sourceHeight, int sourceXOffset, int sourceYOffset, int destinationXOffset, int destinationYOffset)
    Copy a region of the argument RenderedImage to replace a portion of the current SFimage.
    void setValue​(int[] sfImageArray)
    Set the image value as a primitive array.
    void setValue​(int width, int height, int components, int[] pixels)
    Set the image value in the given writable field.
    SFImageObject setValue​(SFImageObject newValue)
    Apply an SFImageObject value to this field.
    SFImageObject setValueByString​(java.lang.String newValue)
    Utility accessor for SFImageObject using String value (which must pass parsing validation checks).
    java.lang.String toString()
    Provides current value as a String.
    static java.lang.String toString​(int[] value)
    Static utility method to provide String representation of a correctly typed input value.
    java.lang.String toStringDecimal()
    Provide pixel values in decimal format.
    java.lang.String toStringHexadecimal()
    Provide pixel values in hexadecimal format.
    java.lang.String validate()
    Validate current value via get/set comparison tests
    java.lang.String validateRegex()
    Validate current value via regular expression (regex) check of current object's toString() value, reporting errors only if found.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.web3d.x3d.sai.X3DField

    addX3DEventListener, getDefinition, isReadable, isWritable, removeX3DEventListener
  • Field Details

  • Constructor Details

    • SFImageObject

      public SFImageObject()
      Constructor for SFImageObject performs value initialization.
    • SFImageObject

      public SFImageObject​(SFImageObject newValue)
      Constructor to copy an SFImageObject value as initial value for this new field object.
      Parameters:
      newValue - The newValue to apply
    • SFImageObject

      public SFImageObject​(int[] newValue)
      Constructor for SFImageObject using a corresponding Java primitive int[] array as new initial value.
      Parameters:
      newValue - is new value to assign setContainerFieldOverride(containerFieldName); // apply checksConcreteField#getTupleSize(String)
  • Method Details

    • isArray

      public static final boolean isArray()
      Whether or not this field type is an array (false)
      Returns:
      true if array type
    • initialize

      public final void initialize()
      Initialization for SFImageObject applies default initial value. Static initializer also provided to verify that the regex pattern compiles and matches that default value.
      Specified by:
      initialize in class X3DConcreteField
      See Also:
      Stack Overflow: How to check if a given Regex is valid?, DEFAULT_VALUE
    • equals

      public boolean equals​(SFImageObject comparisonSFImageObject)
      Determine whether two objects contain equal values.
      Parameters:
      comparisonSFImageObject - field type to compare
      Returns:
      true if equivalent, false otherwise
    • validate

      public final java.lang.String validate()
      Validate current value via get/set comparison tests
      Returns:
      empty string if get/set testing passes, warning otherwise
      See Also:
      validate(), validateRegex()
    • validateRegex

      public final java.lang.String validateRegex()
      Validate current value via regular expression (regex) check of current object's toString() value, reporting errors only if found.
      Returns:
      empty string if PATTERN matches, warning otherwise
      See Also:
      REGEX, PATTERN, matches(), matches(String), validate(), validate(), java.util.regex.Pattern
    • matches

      public final boolean matches()
      Test PATTERN match via regular expression (regex) check of current object's toString() value.
      Returns:
      true if PATTERN matches, false otherwise
      See Also:
      REGEX, PATTERN, matches(), matches(String), validate(), java.util.regex.Pattern
    • matches

      public static final boolean matches​(java.lang.String value)
      Test PATTERN match with regular expression (regex) of provided value.
      Parameters:
      value - String to check against regex pattern for successful match
      Returns:
      true if PATTERN matches, false otherwise
      See Also:
      REGEX, PATTERN, matches(), matches(String), validate(), java.util.regex.Pattern
    • setValueByString

      public SFImageObject setValueByString​(java.lang.String newValue) throws InvalidFieldValueException
      Utility accessor for SFImageObject using String value (which must pass parsing validation checks).

      Warning: this method is not type safe at compile time! Best practice for X3DJSAIL programmers is to use strongly typed methods instead, in order to avoid potential for run-time errors.
      Parameters:
      newValue - is new value to assign, if empty then assign DEFAULT_VALUE
      Returns:
      MFMatrix4dObject - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same node object).
      Throws:
      InvalidFieldValueException
      See Also:
      X3DLoaderDOM.toX3dObjectTree(org.w3c.dom.Node)
    • toString

      public static java.lang.String toString​(int[] value)
      Static utility method to provide String representation of a correctly typed input value.
      Parameters:
      value - The value to convert to a String
      Returns:
      String version of the provided value
      See Also:
      X3D Tooltips: type
    • getPrimitiveValue

      public int[] getPrimitiveValue()
      Provides current value of the field as a Java primitive type.
      Returns:
      current value
    • toString

      public java.lang.String toString()
      Provides current value as a String.
      Overrides:
      toString in class java.lang.Object
      Returns:
      String version of the provided value, with pixels in hexadecimal or decimal format.
      See Also:
      X3D Tooltips: type SFImage, toStringHexadecimal(), toStringDecimal(), ConfigurationProperties.SFImagePixelOutputHexadecimal_DEFAULT, ConfigurationProperties.isSFImagePixelOutputHexadecimal(), ConfigurationProperties.setSFImagePixelOutputHexadecimal(boolean)
    • toStringDecimal

      public java.lang.String toStringDecimal()
      Provide pixel values in decimal format.
      Returns:
      String version of the provided value in decimal format
      See Also:
      toStringHexadecimal(), ConfigurationProperties.SFImagePixelOutputHexadecimal_DEFAULT, ConfigurationProperties.isSFImagePixelOutputHexadecimal(), ConfigurationProperties.setSFImagePixelOutputHexadecimal(boolean), X3D Tooltips: type SFImage
    • toStringHexadecimal

      public java.lang.String toStringHexadecimal()
      Provide pixel values in hexadecimal format.
      Returns:
      String version of the provided value in hexadecimal format
      See Also:
      toStringDecimal(), ConfigurationProperties.SFImagePixelOutputHexadecimal_DEFAULT, ConfigurationProperties.isSFImagePixelOutputHexadecimal(), ConfigurationProperties.setSFImagePixelOutputHexadecimal(boolean), X3D Tooltips: type SFImage
    • getWidth

      public int getWidth()
      Get the width of the image.
      Specified by:
      getWidth in interface SFImage
      Returns:
      The width of the image in pixels
      Throws:
      InvalidFieldValueException - Invalid SFImage data found
    • getHeight

      public int getHeight()
      Get the height of the image.
      Specified by:
      getHeight in interface SFImage
      Returns:
      The height of the image in pixels
      Throws:
      InvalidFieldValueException - Invalid SFImage data found
    • getNumberComponents

      public int getNumberComponents()
      Get the number of color components in the image. The value will always be between 0 and 4 indicating the number of components of the color specification to be read from the image pixel data.
      Specified by:
      getNumberComponents in interface SFImage
      Returns:
      The number of components
      Throws:
      InvalidFieldValueException - Invalid SFImage data found
    • getExpectedLength

      public int getExpectedLength()
      Compute expected length of SFImage integer array (based on height and width values). Note that each integer pixel value must represent the full set of components for this SFImage.
      Returns:
      number of expected pixel values in SFImage integer array
      See Also:
      getWidth(), getHeight()
    • getNumberOfPixelValues

      public int getNumberOfPixelValues()
      Compute number of pixel values in SFImage integer array (not counting height, width and components values). Note that each integer pixel value must represent the full set of components for this SFImage.
      Returns:
      number of pixel values in SFImage integer array
      See Also:
      getWidth(), getHeight()
    • getPixels

      public void getPixels​(int[] destinationPixels)
      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.

      Specified by:
      getPixels in interface SFImage
      Parameters:
      destinationPixels - The array to copy pixel values into
      Throws:
      InvalidFieldValueException - Invalid SFImage data found
    • getImage

      public 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.
      Specified by:
      getImage in interface SFImage
      Returns:
      The image reference representing the current state
    • setImage

      public void setImage​(java.awt.image.RenderedImage image)
      Set the image value in the given writable field to the new image defined by a set of pixels.

      Specified by:
      setImage in interface SFImage
      Parameters:
      image - The new image to use as the source
    • setSubImage

      public void setSubImage​(java.awt.image.RenderedImage image, int sourceWidth, int sourceHeight, int sourceXOffset, int sourceYOffset, int destinationXOffset, int destinationYOffset)
      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).

      Specified by:
      setSubImage in interface SFImage
      Parameters:
      image - The new image to use as the source
      sourceWidth - The width of the argument sub-image region to copy
      sourceHeight - The height of the argument sub-image region to copy
      sourceXOffset - The initial x dimension (width) offset into the argument sub-image that begins the region to copy
      sourceYOffset - The initial y dimension (height) offset into the argument sub-image that begins the region to copy
      destinationXOffset - The initial x dimension (width) offset in the SFimage object that begins the region to receive the copy
      destinationYOffset - The initial y dimension (height) offset in the SFimage object that begins the region to receive the copy
    • setValue

      public 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.

      Specified by:
      setValue in interface SFImage
      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.
      java.lang.IllegalArgumentException - Invalid parameter(s) provided, no change was made
    • setValue

      public void setValue​(int[] sfImageArray)
      Set the image value as a primitive array.
      Parameters:
      sfImageArray - full set of SFImage values
    • getPixelHexFormat

      public static java.lang.String getPixelHexFormat​(int numberComponents)
      Utility method to get format string for proper output of hexadecimal values.
      Parameters:
      numberComponents - 1..4 for transparency, BW, RGB, RGBA texture
      Returns:
      format string for hexadecimal values
    • getPixelsString

      public java.lang.String getPixelsString()
      Utility method to get String value of pixels in SFImage image field.
      Returns:
      string value of pixels
    • setValue

      public SFImageObject setValue​(SFImageObject newValue)
      Apply an SFImageObject value to this field.
      Parameters:
      newValue - The newValue to apply
      Returns:
      SFImageObject - namely this same object to allow sequential method pipelining (i.e. consecutive method invocations on the same object).
    • isDefaultValue

      public boolean isDefaultValue()
      Determine whether current value matches DEFAULT_VALUE
      Returns:
      whether current value matches DEFAULT_VALUE
      See Also:
      DEFAULT_VALUE