Class encapsulating a raster image and its attributes. More...
#include <Inventor/image/SbRasterImage.h>
Public Types | |
enum | Components { UNKNOWN = -1, LUMINANCE = 1, LUMINANCE_TRANSPARENCY = 2, RGB = 3, RGB_TRANSPARENCY = 4, RGBE = 5 } |
enum | CopyPolicy { COPY = 0, NO_COPY = 1, NO_COPY_AND_DELETE = 2, NO_COPY_AND_FREE = 3 } |
Public Member Functions | |
SbRasterImage () | |
SbRasterImage (const SbVec2i32 &size, Components components, SoBufferObject *bufferObject) | |
virtual | ~SbRasterImage () |
void | setSize (const SbVec2s &size) |
void | setSize_i32 (const SbVec2i32 &size) |
SbVec2s | getSize () const |
SbVec2i32 | getSize_i32 () const |
void | setComponents (SbRasterImage::Components comp) |
SbRasterImage::Components | getComponents () const |
int | getComponentsSize () const |
int | getComponentsCount () const |
void | setBuffer (SoBufferObject *bufferObject) |
SoBufferObject * | getBufferObject () const |
int | getNumMipmaps () |
CopyPolicy | getCopyPolicy () const |
SbBool | removeAlphaChannel () |
Deprecated | |
| |
SoDEPRECATED | SbRasterImage (const SbVec2s &size, Components components, const unsigned char *bytes, CopyPolicy copy=COPY) |
SoDEPRECATED | SbRasterImage (const SbVec2i32 &size, Components components, const unsigned char *bytes, CopyPolicy copy=COPY) |
SoDEPRECATED void | setBuffer (unsigned char *buffer, CopyPolicy copy=COPY) |
SoDEPRECATED unsigned char * | getBuffer () const |
This class encapsulates a raster image, including its size and number of color components.
Components type.
Copy policy.
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, SbRasterImage will delete. Use this if memory is allocated with "new". |
NO_COPY_AND_FREE |
Passed buffer used, SbRasterImage will free. Use this if memory is allocated with "malloc". |
SbRasterImage::SbRasterImage | ( | ) |
Constructor that creates an empty image.
SbRasterImage::SbRasterImage | ( | const SbVec2i32 & | size, | |
Components | components, | |||
SoBufferObject * | bufferObject | |||
) |
Constructor that initializes with an image.
Image data is assumed to be packed (no padding between pixels or rows) and pixel components are assumed to be in RGBA order.
Given some image data for which we have:
Case 1: Create raster image from image data, retaining ownership of memory.
size_t numBytes = imageSize[0] * imageSize[1] * imageBPP; SoRef<SoCpuBufferObject> buffer = new SoCpuBufferObject( (void*)imageData, numBytes ); SbRasterImage* rasterImage = new SbRasterImage( imageSize, imageComps, buffer.ptr() );
Case 2: Create raster image from image data, making a copy of the data.
SoRef<SoCpuBufferObject> buffer = new SoCpuBufferObject(); size_t numBytes = imageSize[0] * imageSize[1] * imageBPP; buffer->setSize( numBytes ); // Allocates memory owned by buffer object memcpy( buffer->map( SoBufferObject::SET ), imageData, numBytes ); buffer->unmap(); SbRasterImage* rasterImage = new SbRasterImage( imageSize, imageComps, buffer.ptr() );
virtual SbRasterImage::~SbRasterImage | ( | ) | [virtual] |
Destructor.
SoDEPRECATED SbRasterImage::SbRasterImage | ( | const SbVec2s & | size, | |
Components | components, | |||
const unsigned char * | bytes, | |||
CopyPolicy | copy = COPY | |||
) |
Constructor that initializes with an image.
SoDEPRECATED SbRasterImage::SbRasterImage | ( | const SbVec2i32 & | size, | |
Components | components, | |||
const unsigned char * | bytes, | |||
CopyPolicy | copy = COPY | |||
) |
Constructor that initializes with a large image.
SoDEPRECATED unsigned char* SbRasterImage::getBuffer | ( | ) | const |
Returns the pixel buffer of the raster image.
SoBufferObject* SbRasterImage::getBufferObject | ( | ) | const |
Returns the pixel buffer of the raster image.
To get a pointer to the raw image data:
SbRasterImage* rasterImage . . . SoBufferObject* imageBuffer = rasterImage->getBufferObject(); SoRef<SoCpuBufferObject> cpuBuffer = new SoCpuBufferObject(); imageBuffer->map( cpuBuffer.ptr(), SoBufferObject::READ_ONLY); unsigned char* imageData = (unsigned char*)cpuBuffer->map(SoBufferObject::READ_ONLY); . . . cpuBuffer->unmap(); imageBuffer->unmap(cpuBuffer.ptr());
SbRasterImage::Components SbRasterImage::getComponents | ( | ) | const |
Returns the number of components of each pixel as an enum.
For example, an RGBA image returns RGB_TRANSPARENCY.
int SbRasterImage::getComponentsCount | ( | ) | const |
Returns the number of components of each pixel.
Returns -1 in case of invalid or unknown components type.
E.g: For an RGB image it returns 3 (R, G and B).
int SbRasterImage::getComponentsSize | ( | ) | const |
Returns the size in bytes of each pixel in the image.
Returns -1 in case of invalid or unknown components type.
E.g: For an RGB image containing byte data, the pixel size is 3 bytes.
SbRasterImage::CopyPolicy SbRasterImage::getCopyPolicy | ( | ) | const [inline] |
Returns the current buffer copy policy.
int SbRasterImage::getNumMipmaps | ( | ) | [inline] |
Returns the number of mipmaps contained by the buffer.
SbVec2s SbRasterImage::getSize | ( | ) | const |
Returns the raster image size in pixels.
SbVec2i32 SbRasterImage::getSize_i32 | ( | ) | const |
Returns the raster image size in pixels for large images.
SbBool SbRasterImage::removeAlphaChannel | ( | ) |
Removes the Alpha channel from the current raster image.
If the copy policy is COPY (Open Inventor owns the memory) then the buffer is reallocated with the correct size. Otherwise the content of the buffer is just modified.
SoDEPRECATED void SbRasterImage::setBuffer | ( | unsigned char * | buffer, | |
CopyPolicy | copy = COPY | |||
) |
Sets the pixel buffer of the raster image.
By default, the memory policy is COPY. One of the NO_COPY options is the most likely to be efficient. For interoperability with other classes, pixel buffer must be packed and must respect the RGB ordering.
void SbRasterImage::setBuffer | ( | SoBufferObject * | bufferObject | ) |
Sets the pixel buffer of the raster image.
Image data is assumed to be packed (no padding between pixels or rows) and pixel components are assumed to be in RGBA order.
Given some image data for which we have:
Case 1: Set image data, retaining ownership of memory.
SbRasterImage* rasterImage . . . size_t numBytes = imageSize[0] * imageSize[1] * imageBPP; SoRef<SoCpuBufferObject> buffer = new SoCpuBufferObject( (void*)imageData, numBytes ); rasterImage->setBuffer( buffer.ptr() );
Case 2: Set image data, making a copy of image data.
SbRasterImage* rasterImage . . . SoRef<SoCpuBufferObject> buffer = new SoCpuBufferObject(); size_t numBytes = imageSize[0] * imageSize[1] * imageBPP; buffer->setSize( numBytes ); // Allocates memory owned by buffer object memcpy( buffer->map( SoBufferObject::SET ), (void*)imageData, numBytes ); buffer->unmap(); rasterImage->setBuffer( buffer.ptr() );
void SbRasterImage::setComponents | ( | SbRasterImage::Components | comp | ) |
Sets the number of components in each pixel of the raster image.
For example, an RGB image has 3 components.
void SbRasterImage::setSize | ( | const SbVec2s & | size | ) |
Sets the raster image size in pixels.
The parameter is the size of the whole raster image. The maximum size that can be specified using this method is 32767 by 32767 (because the parameter is an SbVec2s). To specify a larger image size use the method setSize_i32.
void SbRasterImage::setSize_i32 | ( | const SbVec2i32 & | size | ) |
Sets the raster image size in pixels.
The parameter is the size of the whole raster image to be saved. Use for sizes with at least one side greater than 32767.