Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SbRasterImage Class Reference

VSG extension 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
}
 Components type. More...
 
enum  CopyPolicy {
  COPY = 0 ,
  NO_COPY = 1 ,
  NO_COPY_AND_DELETE = 2 ,
  NO_COPY_AND_FREE = 3
}
 Copy policy. More...
 

Public Member Functions

 SbRasterImage ()
 Constructor that creates an empty image.
 
 SbRasterImage (const SbVec2i32 &size, Components components, SoBufferObject *bufferObject)
 Constructor that initializes with an image.
 
virtual ~SbRasterImage ()
 Destructor.
 
void setSize (const SbVec2s &size)
 Sets the raster image size in pixels.
 
void setSize_i32 (const SbVec2i32 &size)
 Sets the raster image size in pixels.
 
SbVec2s getSize () const
 Returns the raster image size in pixels.
 
SbVec2i32 getSize_i32 () const
 Returns the raster image size in pixels for large images.
 
void setComponents (SbRasterImage::Components comp)
 Sets the number of components in each pixel of the raster image.
 
SbRasterImage::Components getComponents () const
 Returns the number of components of each pixel as an enum.
 
int getComponentsSize () const
 Returns the size in bytes of each pixel in the image.
 
int getComponentsCount () const
 Returns the number of components of each pixel.
 
void setBuffer (SoBufferObject *bufferObject)
 Sets the pixel buffer of the raster image.
 
SoBufferObjectgetBufferObject () const
 Returns the pixel buffer of the raster image.
 
int getNumMipmaps ()
 Returns the number of mipmaps contained by the buffer.
 
CopyPolicy getCopyPolicy () const
 Returns the current buffer copy policy.
 
SbBool removeAlphaChannel ()
 Removes the Alpha channel from the current raster image.
 

Deprecated

SoDEPRECATED SbRasterImage (const SbVec2s &size, Components components, const unsigned char *bytes, CopyPolicy copy=COPY)
 Constructor that initializes with an image.
 
SoDEPRECATED SbRasterImage (const SbVec2i32 &size, Components components, const unsigned char *bytes, CopyPolicy copy=COPY)
 Constructor that initializes with a large image.
 
SoDEPRECATED void setBuffer (unsigned char *buffer, CopyPolicy copy=COPY)
 Sets the pixel buffer of the raster image.
 
SoDEPRECATED unsigned char * getBuffer () const
 Returns the pixel buffer of the raster image.
 

Detailed Description

VSG extension Class encapsulating a raster image and its attributes.

This class encapsulates a raster image, including its size and number of color components.

SEE ALSO

SoRasterImageRW

Definition at line 56 of file SbRasterImage.h.

Member Enumeration Documentation

◆ Components

Components type.

Enumerator
UNKNOWN 

Unknown number of components.

LUMINANCE 

Number of components 1 (luminance).

LUMINANCE_TRANSPARENCY 

Number of components 2 (luminance + transparency).

RGB 

Number of components 3 (RGB) (default).

RGB_TRANSPARENCY 

Number of components 4 (RGB + transparency).

RGBE 

Number of components 4 (RGBE).

This is used by some HDR formats.

Definition at line 64 of file SbRasterImage.h.

◆ CopyPolicy

Copy policy.

Enumerator
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".

Definition at line 101 of file SbRasterImage.h.

Constructor & Destructor Documentation

◆ SbRasterImage() [1/4]

SbRasterImage::SbRasterImage ( )

Constructor that creates an empty image.

◆ SbRasterImage() [2/4]

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:

  • imageSize : Dimensions of image
  • imageBPP : Number of bytes per pixel (1, 2, 3, ...)
  • imageComps : Type of pixel (L, LA, RGB, RGBA, ...)
  • imageData : Pointer to image data

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() );
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class encapsulat...
SbRasterImage()
Constructor that creates an empty image.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPU buffer objec...
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
T * ptr() const
Cast to C pointer.
Definition SoRef.h:167

Case 2: Create raster image from image data, making a copy of the data.

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() );
@ SET
The target buffer contents are initially undefined (although they may be the same as the source buffe...

◆ ~SbRasterImage()

virtual SbRasterImage::~SbRasterImage ( )
virtual

Destructor.

◆ SbRasterImage() [3/4]

SoDEPRECATED SbRasterImage::SbRasterImage ( const SbVec2s size,
Components  components,
const unsigned char *  bytes,
CopyPolicy  copy = COPY 
)

Constructor that initializes with an image.

◆ SbRasterImage() [4/4]

SoDEPRECATED SbRasterImage::SbRasterImage ( const SbVec2i32 size,
Components  components,
const unsigned char *  bytes,
CopyPolicy  copy = COPY 
)

Constructor that initializes with a large image.

Member Function Documentation

◆ getBuffer()

SoDEPRECATED unsigned char * SbRasterImage::getBuffer ( ) const

Returns the pixel buffer of the raster image.

◆ getBufferObject()

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();
imageBuffer->map( cpuBuffer.ptr(), SoBufferObject::READ_ONLY);
unsigned char* imageData = (unsigned char*)cpuBuffer->map(SoBufferObject::READ_ONLY);
. . .
cpuBuffer->unmap();
imageBuffer->unmap(cpuBuffer.ptr());
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
@ READ_ONLY
The target buffer initially has the same contents as the source buffer.
virtual void * map(AccessMode accessMode, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL)
Map the buffer to a system memory address and allows the mapping of a sub part of the buffer object i...
virtual void unmap()
Unmaps the buffer from CPU address space.

◆ getComponents()

SbRasterImage::Components SbRasterImage::getComponents ( ) const

Returns the number of components of each pixel as an enum.


For example, an RGBA image returns RGB_TRANSPARENCY.

◆ getComponentsCount()

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

◆ getComponentsSize()

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.

◆ getCopyPolicy()

SbRasterImage::CopyPolicy SbRasterImage::getCopyPolicy ( ) const
inline

Returns the current buffer copy policy.

Definition at line 416 of file SbRasterImage.h.

◆ getNumMipmaps()

int SbRasterImage::getNumMipmaps ( )
inline

Returns the number of mipmaps contained by the buffer.

Definition at line 282 of file SbRasterImage.h.

◆ getSize()

SbVec2s SbRasterImage::getSize ( ) const

Returns the raster image size in pixels.

◆ getSize_i32()

SbVec2i32 SbRasterImage::getSize_i32 ( ) const

Returns the raster image size in pixels for large images.

◆ removeAlphaChannel()

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.

Returns
True if the format contains an alpha channel and it was possible to remove it.

◆ setBuffer() [1/2]

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:

  • imageSize : Dimensions of image
  • imageBPP : Number of bytes per pixel (1, 2, 3, ...)
  • imageData : Pointer to image data

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() );
virtual bool setSize(size_t size)
Sets the size in bytes of the buffer object.

◆ setBuffer() [2/2]

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.

◆ setComponents()

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.

◆ setSize()

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.

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


The documentation for this class was generated from the following file: