Class SoSFImage


  • public class SoSFImage
    extends SoSField
    Field containing a 2D image. A field containing a two-dimensional image. Images can be grayscale (intensity), grayscale with transparency information, RGB, or RGB with transparency. Each component of the image (intensity, red, green, blue or transparency (alpha)) can have an unsigned one-byte value from 0 to 255.

    Values are returned as arrays of unsigned chars. The image is stored in this array starting at the bottom left corner of the image with the intensity or red component of that pixel, followed by either the alpha, the green and blue, or the green, blue and alpha components (depending on the number of components in the image). The next value is the first component of the next pixel to the right.

    SoSFImages are written to file as three integers representing the width, height and number of components in the image, followed by width*height hexadecimal values representing the pixels in the image, separated by whitespace. A one-component image will have one-byte hexadecimal values representing the intensity of the image. For example, 0xFF is full intensity, 0x00 is no intensity. A two-component image puts the intensity in the first (high) byte and the transparency in the second (low) byte. Pixels in a three-component image have the red component in the first (high) byte, followed by the green and blue components (so 0xFF0000 is red). Four-component images put the transparency byte after red/green/blue (so 0x0000FF80 is semi-transparent blue). Note: each pixel is actually read as a single unsigned number, so a 3-component pixel with value "0x0000FF" can also be written as "0xFF" or "255" (decimal).

    For example,

       1 2 1 0xFF 0x00
    is a 1 pixel wide by 2 pixel high grayscale image, with the bottom pixel white and the top pixel black. And:

       2 4 3 0xFF0000 0xFF00 0 0 0 0 0xFFFFFF 0xFFFF00
    is a 2 pixel wide by 4 pixel high RGB image, with the bottom left pixel red, the bottom right pixel green, the two middle rows of pixels black, the top left pixel white, and the top right pixel yellow.

    See Also:
    SoField, SoSField
    • Method Detail

      • toRasterImage

        public SbRasterImage toRasterImage()
        Calls toRasterImage((boolean)true).
      • setValue

        public void setValue​(SbVec2i32 size,
                             int nc,
                             SoSFImage.DataTypes dataType,
                             SoBufferObject bufferObject)
        Calls setValue(size, nc, dataType, bufferObject, SoSFImage.CopyPolicies.valueOf( SoSFImage.CopyPolicies.COPY.getValue() )).
      • setValue

        public void setValue​(SbVec2s size,
                             int nc,
                             SoSFImage.DataTypes dataType,
                             SoBufferObject bufferObject)
        Calls setValue(size, nc, dataType, bufferObject, SoSFImage.CopyPolicies.valueOf( SoSFImage.CopyPolicies.COPY.getValue() )).
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class SoField
      • setNeverWrite

        public void setNeverWrite​(boolean neverWrite)
        Sets the "neverWrite" flag. As this field may have to handle large amounts of data and its representation in an .iv file is not very efficient, it is often a good idea not to allow that data to be written out when required by a write action. By default, the "neverWrite" condition is false.
      • getNumSubTextures

        public int getNumSubTextures()
        Returns true if subTextures have been defined or false if none have been defined. Also returns the number of subTextures defined.
      • setValue

        public void setValue​(SbVec2i32 size,
                             int nc,
                             byte[] bytes)
      • setValue

        public void setValue​(SbVec2s size,
                             int nc,
                             byte[] bytes)
        Same as above. Convenience method for the unsigned char datatype.
      • toRasterImage

        public SbRasterImage toRasterImage​(boolean downSample)
        Returns an instance of SbRasterImage filled with the content of this field. It is useful to save the result of an SoRenderToTexture operation in feedback mode. The caller is responsible of the release of the returned raster image.

        When the content is not of type UNSIGNED_BYTE the data is downsampled to UNSIGNED_BYTE unless the downSample parameter is set to false.

        Returns NULL if the content cannot be converted to an SbRasterImage.

      • hasTransparency

        public boolean hasTransparency()
        Returns true if the image contains any transparent pixels. Specifically if the image has 2 or 4 components and at least one pixel has an alpha value less then 255.
      • isNeverWrite

        public boolean isNeverWrite()
        Queries the "neverWrite" flag.
      • getNumComponents

        public int getNumComponents()
        Returns image's number of components.