Field containing a 2D image. More...
#include <Inventor/fields/SoSFImage.h>
Public Types | |
enum | DataType { UNSIGNED_BYTE = SbDataType::UNSIGNED_BYTE, UNSIGNED_SHORT = SbDataType::UNSIGNED_SHORT, UNSIGNED_INT32 = SbDataType::UNSIGNED_INT32, SIGNED_BYTE = SbDataType::SIGNED_BYTE, SIGNED_SHORT = SbDataType::SIGNED_SHORT, SIGNED_INT32 = SbDataType::SIGNED_INT32, FLOAT = SbDataType::FLOAT } |
enum | CopyPolicy { COPY = 0, NO_COPY = 1, NO_COPY_AND_DELETE = 2, NO_COPY_AND_FREE = 3 } |
Public Member Functions | |
virtual SoType | getTypeId () const |
const SoSFImage & | operator= (const SoSFImage &f) |
SoSFImage () | |
virtual | ~SoSFImage () |
SoSFImage (const SoSFImage &obj) | |
const void * | getValue (SbVec2s &size, int &nc, DataType &dataType) const |
const void * | getValue (SbVec2i32 &size, int &nc, DataType &dataType) const |
const unsigned char * | getValue (SbVec2s &size, int &nc) const |
const unsigned char * | getValue (SbVec2i32 &size, int &nc) const |
void | setValue (const SbVec2s &size, int nc, DataType dataType, const void *data, CopyPolicy copy=COPY) |
void | setValue (const SbVec2s &size, int nc, DataType dataType, SoBufferObject *bufferObject, CopyPolicy copy=COPY) |
void | setValue (const SbVec2i32 &size, int nc, DataType dataType, const void *data, CopyPolicy copy=COPY) |
void | setValue (const SbVec2i32 &size, int nc, DataType dataType, SoBufferObject *bufferObject, CopyPolicy copy=COPY) |
void | setValue (const SbVec2s &size, int nc, const unsigned char *bytes, CopyPolicy copy=COPY) |
void | setValue (const SbVec2i32 &size, int nc, const unsigned char *bytes, CopyPolicy copy=COPY) |
void | setSubValue (const SbVec2s &subSize, const SbVec2s &offset, void *data) |
void | setSubValue (const SbVec2i32 &subSize, const SbVec2i32 &offset, void *data) |
void | setSubValue (const SbVec2s &subSize, const SbVec2s &offset, unsigned char *bytes) |
void | setSubValue (const SbVec2i32 &subSize, const SbVec2i32 &offset, unsigned char *bytes) |
void | setSubValues (const SbVec2s *subSizes, const SbVec2s *offsets, int num, void **data) |
void | setSubValues (const SbVec2i32 *subSizes, const SbVec2i32 *offsets, int num, void **data) |
void | setSubValues (const SbVec2s *subSizes, const SbVec2s *offsets, int num, unsigned char **subBytes) |
void | setSubValues (const SbVec2i32 *subSizes, const SbVec2i32 *offsets, int num, unsigned char **subBytes) |
int | operator== (const SoSFImage &f) const |
int | operator!= (const SoSFImage &f) const |
void * | startEditing (SbVec2s &size, int &nc, DataType &dataType) |
void * | startEditing (SbVec2i32 &size, int &nc, DataType &dataType) |
unsigned char * | startEditing (SbVec2s &size, int &nc) |
unsigned char * | startEditing (SbVec2i32 &size, int &nc) |
void | finishEditing () |
void * | getSubTexture (int index, SbVec2s &size, SbVec2s &offset, DataType &dataType) |
void * | getSubTexture (int index, SbVec2i32 &size, SbVec2i32 &offset, DataType &dataType) |
unsigned char * | getSubTexture (int index, SbVec2s &size, SbVec2s &offset) |
unsigned char * | getSubTexture (int index, SbVec2i32 &size, SbVec2i32 &offset) |
SbBool | hasSubTextures (int &numSubTextures) |
void | setNeverWrite (SbBool neverWrite) |
SbBool | isNeverWrite () |
SbBool | hasTransparency () const |
SbRasterImage * | toRasterImage (bool downSample=true) const |
Static Public Member Functions | |
static SoType | getClassTypeId () |
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.
SoSFImage may be manipulating some large amounts of memory.
It is therefore convienent to be able to set the memory usage policy dynamically. By default, the memory policy is COPY, which is consistent with other OIV fields. The most likely to be efficient is NO_COPY. See also setNeverWrite.
COPY |
Open Inventor will make a copy of the data (default). |
NO_COPY |
Passed buffer used , user will delete. |
NO_COPY_AND_DELETE |
Passed buffer used, SoSFImage will delete. Use this if memory is allocated with "new". |
NO_COPY_AND_FREE |
Passed buffer used, SoSFImage will free. Use this if memory is allocated with "malloc". |
enum SoSFImage::DataType |
SoSFImage::SoSFImage | ( | ) |
Default constructor.
virtual SoSFImage::~SoSFImage | ( | ) | [virtual] |
Destructor.
SoSFImage::SoSFImage | ( | const SoSFImage & | obj | ) |
Copy constructor.
void SoSFImage::finishEditing | ( | ) |
This method (along with startEditing())can be used to efficiently edit the values in an image field.
static SoType SoSFImage::getClassTypeId | ( | ) | [static] |
Returns the type identifier for this class.
Reimplemented from SoSField.
Same as above.
Convenience method for the unsigned char datatype.
void* SoSFImage::getSubTexture | ( | int | index, | |
SbVec2i32 & | size, | |||
SbVec2i32 & | offset, | |||
DataType & | dataType | |||
) |
Returns a buffer of a given subTexture set by setSubValue() or setSubValues().
These two methods append subTextures to a list. Also returns the size of the subtexture and the offset from the beginning of the image of the requested subImage.
virtual SoType SoSFImage::getTypeId | ( | ) | const [virtual] |
Returns the type identifier for this specific instance.
Implements SoTypedObject.
const unsigned char* SoSFImage::getValue | ( | SbVec2i32 & | size, | |
int & | nc | |||
) | const |
const unsigned char* SoSFImage::getValue | ( | SbVec2s & | size, | |
int & | nc | |||
) | const |
Same as above.
Convenience method for the unsigned char datatype.
Returns the pixels in the image as an array of values of type <dataType>.
The size and nc arguments are filled in with the dimensions of the image and the number of components in the image. The number of bytes in the array returned will be size[0]*sizeof(<dataType>)*size[1]*sizeof(<dataType>)*nc.
SbBool SoSFImage::hasSubTextures | ( | int & | numSubTextures | ) |
Returns TRUE if subTextures have been defined or FALSE if none have been defined.
Also returns the number of subTextures defined.
SbBool SoSFImage::hasTransparency | ( | ) | const |
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.
SbBool SoSFImage::isNeverWrite | ( | ) | [inline] |
Queries the "neverWrite" flag.
int SoSFImage::operator!= | ( | const SoSFImage & | f | ) | const [inline] |
Inequality test.
Reimplemented from SoField.
void SoSFImage::setNeverWrite | ( | SbBool | 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.
void SoSFImage::setSubValue | ( | const SbVec2i32 & | subSize, | |
const SbVec2i32 & | offset, | |||
unsigned char * | bytes | |||
) |
void SoSFImage::setSubValue | ( | const SbVec2s & | subSize, | |
const SbVec2s & | offset, | |||
unsigned char * | bytes | |||
) |
Same as above.
Convenience method for the unsigned char datatype.
This method can be used for subtexturing.
Instead of replacing the texture in texture memory, only parts of it are replaced. This is much faster and uses less memory. In any case this method affects the texture in processor memory. Note that the sub-image must have the same number of components as the one contained in this object. The texture in texture memory will not actually be modified until the next render traversal. See also startEditing(), finishEditing().
void SoSFImage::setSubValues | ( | const SbVec2i32 * | subSizes, | |
const SbVec2i32 * | offsets, | |||
int | num, | |||
unsigned char ** | subBytes | |||
) |
void SoSFImage::setSubValues | ( | const SbVec2s * | subSizes, | |
const SbVec2s * | offsets, | |||
int | num, | |||
unsigned char ** | subBytes | |||
) |
Same as above.
Convenience method for the unsigned char datatype.
void SoSFImage::setSubValues | ( | const SbVec2i32 * | subSizes, | |
const SbVec2i32 * | offsets, | |||
int | num, | |||
void ** | data | |||
) |
void SoSFImage::setSubValues | ( | const SbVec2s * | subSizes, | |
const SbVec2s * | offsets, | |||
int | num, | |||
void ** | data | |||
) |
This method can be used for subtexturing.
Instead of replacing the texture in texture memory, only parts of it are replaced. This is much faster and uses less memory. In any case this method affects the texture in processor memory. Note that the sub-images must have the same number of components as the one contained in this object. The texture in texture memory will not actually be modified until the next render traversal. See also startEditing(), finishEditing().
void SoSFImage::setValue | ( | const SbVec2i32 & | size, | |
int | nc, | |||
const unsigned char * | bytes, | |||
CopyPolicy | copy = COPY | |||
) |
void SoSFImage::setValue | ( | const SbVec2s & | size, | |
int | nc, | |||
const unsigned char * | bytes, | |||
CopyPolicy | copy = COPY | |||
) |
Same as above.
Convenience method for the unsigned char datatype.
void SoSFImage::setValue | ( | const SbVec2i32 & | size, | |
int | nc, | |||
DataType | dataType, | |||
SoBufferObject * | bufferObject, | |||
CopyPolicy | copy = COPY | |||
) |
void SoSFImage::setValue | ( | const SbVec2i32 & | size, | |
int | nc, | |||
DataType | dataType, | |||
const void * | data, | |||
CopyPolicy | copy = COPY | |||
) |
void SoSFImage::setValue | ( | const SbVec2s & | size, | |
int | nc, | |||
DataType | dataType, | |||
SoBufferObject * | bufferObject, | |||
CopyPolicy | copy = COPY | |||
) |
void SoSFImage::setValue | ( | const SbVec2s & | size, | |
int | nc, | |||
DataType | dataType, | |||
const void * | data, | |||
CopyPolicy | copy = COPY | |||
) |
Sets the value of this field to be an image of the given size, with the given number of components, and with the given pixel values.
size[0]*sizeof(<dataType>)*size[1]*sizeof(<dataType>)*nc bytes from the given array will be copied into internal storage maintained by the SoSFImage field.
At times, SoSFImage may need to manipulate large amounts of memory. Therefore, it is useful to be able to specify the memory usage policy dynamically. By default, the memory policy is COPY, which is consistent with other Open Inventor fields. The most likely to be efficient is NO_COPY. See also setNeverWrite().
unsigned char* SoSFImage::startEditing | ( | SbVec2i32 & | size, | |
int & | nc | |||
) |
unsigned char* SoSFImage::startEditing | ( | SbVec2s & | size, | |
int & | nc | |||
) |
Same as above.
Convenience method for the unsigned char datatype.
This method (along with finishEditing()) can be used to efficiently edit the values in an image field.
It returns the size of the image in the size and nc arguments; writing past the end of the array returned is a good way to cause hard-to-find core dumps.
SbRasterImage* SoSFImage::toRasterImage | ( | bool | downSample = true |
) | const |
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.