HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMX_Buffer Class Reference

#include <IMX_Buffer.h>

+ Inheritance diagram for IMX_Buffer:

Public Member Functions

 IMX_Buffer ()
 Creates a new buffer. You must call setSize to make this buffer usable. More...
 
 IMX_Buffer (int width, int height, CE_Image::StorageType storage, int channels)
 Create and call setSize. More...
 
 IMX_Buffer (const IMX_Buffer &other)
 
 IMX_Buffer (IMX_Buffer &&other) noexcept
 
 IMX_Buffer (const PXL_Raster &rp)
 
 ~IMX_Buffer ()
 
void copyMetadata (const IMX_Buffer &source)
 
void copyStorageType (const IMX_Buffer &i)
 Set storesIntegers, bytes, channels. More...
 
void setStorageType (CE_Image::StorageType storage, int channels)
 Set storesIntegers, bytes, channels. More...
 
void setStorageType (CE_Image::StorageType storage)
 Set storesIntegers, bytes. More...
 
void setStorageBytes (int)
 Set number of bytes per channel, don't change storesIntegers or channels. More...
 
void setChannels (int channels)
 Set channels, don't change storesIntegers or bits. More...
 
CE_Image::StorageType getStorageType () const
 Get the data type used to store pixel data for each channel. More...
 
bool storesIntegers () const
 Does this buffer store integers? More...
 
int getChannels () const
 Get the number of channels per pixel. More...
 
int getStorageBytes () const
 Number of bytes per channel. More...
 
void setBufferSize (int width, int height)
 Sets size of this buffer. More...
 
int bufferWidth () const
 Get width (number of columns in a row) of the buffer. More...
 
int bufferHeight () const
 Get height (number of rows) of the buffer. More...
 
int64 getBufferSize () const
 Returns the number of bytes required to store the entire buffer. More...
 
void setBufferXforms (const UT_Vector2F &buffer_to_image_scale, const UT_Vector2F &buffer_to_image_xlate, const UT_Vector2F &buffer_from_image_scale, const UT_Vector2F &buffer_from_image_xlate, const UT_Vector2F &buffer_to_pixel_scale, const UT_Vector2F &buffer_to_pixel_xlate, const UT_Matrix4F &image_to_world, const UT_Matrix4F &world_to_image)
 Set transform between image and buffer space. More...
 
void setBorder (IMX_BorderType border)
 Sets the border type of this image. Constant means it is zero. More...
 
IMX_BorderType getBorderType () const
 Returns type of the border. More...
 
void setTypeInfo (IMX_TypeInfo typeinfo)
 Sets the semantic type info of this image. More...
 
IMX_TypeInfo getTypeInfo () const
 Returns type of the border. More...
 
void setDefaultColor (const UT_Vector4F &)
 
UT_Vector4F getDefaultColor () const
 
UT_Vector4I getDefaultColorI () const
 return the current integer value, which might be different More...
 
void copy (const IMX_Buffer &other)
 
IMX_Bufferoperator= (const IMX_Buffer &other)
 
void deepCopy (const IMX_Buffer &other)
 
void swap (IMX_Buffer &other)
 
IMX_Bufferoperator= (IMX_Buffer &&other)
 
bool stealable () const
 
void setStealable (bool v) const
 
bool isAligned (const IMX_Buffer &src) const
 True if the buffer pixels line up: width and the transforms from image space match. More...
 
void copyBuffer (const IMX_Buffer &other)
 Only copy the buffer pointers, the stat data is left unchanged. More...
 
void moveBuffer (IMX_Buffer &src)
 Move the buffer to this from src, src is left dirty. More...
 
void makeBufferUnique ()
 
void adoptRaster (PXL_Raster &raster, bool convert_colorspace)
 
void copyOrConvert (const IMX_Buffer &other)
 
UT_UniquePtr< TIL_RasterbuildRaster () const
 
const UT_SharedPtr
< IMX_CPU_Image > & 
CPUBufferPtr () const
 for debugging More...
 
const UT_SharedPtr< CE_Image > & GPUBufferPtr () const
 
void setPixelV4 (int x, int y, const UT_Vector4F &c)
 Sets an individual pixel. More...
 
void setPixelF (int x, int y, fpreal32 i)
 
void setPixelI (int x, int y, int i)
 
UT_Vector4F getPixelV4 (int x, int y) const
 Fetches the value of an individual pixel. More...
 
int getPixelI (int x, int y) const
 
UT_Vector4F getPixelV4 (fpreal64 x, fpreal64 y) const
 
const fpreal16getCPUBufferRF16 () const
 
fpreal16getCPUBufferWF16 ()
 
const fpreal32getCPUBufferRF32 () const
 
fpreal32getCPUBufferWF32 ()
 
const unsigned char * getCPUBufferRI8 () const
 
unsigned char * getCPUBufferWI8 ()
 
const int16getCPUBufferRI16 () const
 
int16getCPUBufferWI16 ()
 
const int32getCPUBufferRI32 () const
 
int32getCPUBufferWI32 ()
 
voidgetCPUBuffer (bool read, bool write)
 
template<CE_Image::StorageType STORAGE>
const CE_StorageTypeTraits
< STORAGE >::DataType * 
getCPUBufferR () const
 
template<CE_Image::StorageType STORAGE>
CE_StorageTypeTraits< STORAGE >
::DataType * 
getCPUBuffer (bool read, bool write)
 
CE_ImagegetGPUBuffer (bool read, bool write)
 
const CE_ImagegetGPUBufferR () const
 
CE_ImagegetGPUBufferW ()
 
bool isOnGPU () const
 Returns true if this buffer's data is currently on the GPU. More...
 
bool isOnCPU () const
 
bool isInUseGPU () const
 
void setInUseGPUFlag () const
 
void clearInUseGPUFlag () const
 
cl::Buffer getGPUStat () const
 
bool isDirty () const
 False if there are computed pixels in the CPU or GPU buffer. More...
 
void setDirty ()
 Turn on isDirty(). It is turned off by getCPU/GPUBuffer with write=true. More...
 
void freeBuffers ()
 Frees the pixel memory (also does setDirty()) More...
 
void destroy ()
 Frees all the memory used by buffer. More...
 
bool allocated () const
 True if getCPU/GPUBuffer has been done since last freeBuffers() More...
 
void setConstantV4 (const UT_Vector4F &i)
 
void setConstantV3 (const UT_Vector3F &i)
 
void setConstantF (fpreal32 i=0.0f)
 
void setConstantI (int32 i=0)
 
void setUninitialized ()
 
bool isConstant () const
 
template<typename T >
void matchAndCopyToVoxels (UT_VoxelArray< T > &dest) const
 

Friends

class IMX_Layer
 
class COP_OpenFXImage
 
class IMX_CEMemoryPool
 

Detailed Description

The per-pixel data for a single IMX_Layer

Buffer has several formats to store data in, for instance whether it is on the GPU or CPU. Buffers are converted by copying, or snippets are used to change the OpenCL code reading them. As some translators can work in-place, the format is considered a setting of the Buffer, rather than having different Buffer subclasses for each format.

This is a first working version of such a buffer, though it's missing a lot of features. There's only one supported format (32-bit float), between 1 and 4 channels. This is stored in an array, flattened over the rows first. There is also GPU storage that this buffer uses. States of these buffers (i.e. do they contain up-to-date information?) are encoded in the two boolean flags (myOnCPU and myOnGPU). When the user asks IMX_Buffer something that must access its storage, that storage is first automatically synchronized before the request is fulfilled.

Definition at line 254 of file IMX_Buffer.h.

Constructor & Destructor Documentation

IMX_Buffer::IMX_Buffer ( )

Creates a new buffer. You must call setSize to make this buffer usable.

IMX_Buffer::IMX_Buffer ( int  width,
int  height,
CE_Image::StorageType  storage,
int  channels 
)

Create and call setSize.

IMX_Buffer::IMX_Buffer ( const IMX_Buffer other)
inline

Definition at line 263 of file IMX_Buffer.h.

IMX_Buffer::IMX_Buffer ( IMX_Buffer &&  other)
inlinenoexcept

Definition at line 264 of file IMX_Buffer.h.

IMX_Buffer::IMX_Buffer ( const PXL_Raster rp)
IMX_Buffer::~IMX_Buffer ( )

Member Function Documentation

void IMX_Buffer::adoptRaster ( PXL_Raster raster,
bool  convert_colorspace 
)

Adopt a PXL_Raster into the underlying IMX_Buffer. The buffer's storage type and number of channels must be set before calling. Steals the PXL_Raster data if compatible. Does OCIO transform from raster's space to scene linear if convert is set.

bool IMX_Buffer::allocated ( ) const
inline

True if getCPU/GPUBuffer has been done since last freeBuffers()

Definition at line 511 of file IMX_Buffer.h.

int IMX_Buffer::bufferHeight ( ) const
inline

Get height (number of rows) of the buffer.

Definition at line 298 of file IMX_Buffer.h.

int IMX_Buffer::bufferWidth ( ) const
inline

Get width (number of columns in a row) of the buffer.

Definition at line 296 of file IMX_Buffer.h.

UT_UniquePtr<TIL_Raster> IMX_Buffer::buildRaster ( ) const

Constructs a TIL_Raster matching our storage/channel depth. Will be packed. TIL_Raster is subclass from PXL_Raster.

void IMX_Buffer::clearInUseGPUFlag ( ) const

Decrements the user count of our GPU data. If there are no active users of the GPU data, the memory pool will be able to unload this buffer. See setInUseGPUFlag() documentation for how these methods must be used. This method also refreshes the buffer in the eyes of the memory pool, making it less likely to get evicted.

void IMX_Buffer::copy ( const IMX_Buffer other)

Assignment operators; after executing these functions, this buffer will have the same size and data as other.

void IMX_Buffer::copyBuffer ( const IMX_Buffer other)

Only copy the buffer pointers, the stat data is left unchanged.

void IMX_Buffer::copyMetadata ( const IMX_Buffer source)

Copy everything except the buffer allocations, leaving the buffers dirty. This avoids any chance that writing pixels to this will modify the original. It also avoids shared pointer overhead and keeping buffers around longer than needed.

void IMX_Buffer::copyOrConvert ( const IMX_Buffer other)

copy the buffer, converting betwen storage types if needed and doing a shallow copy if possible

void IMX_Buffer::copyStorageType ( const IMX_Buffer i)
inline

Set storesIntegers, bytes, channels.

Definition at line 274 of file IMX_Buffer.h.

const UT_SharedPtr<IMX_CPU_Image>& IMX_Buffer::CPUBufferPtr ( ) const
inline

for debugging

Definition at line 379 of file IMX_Buffer.h.

void IMX_Buffer::deepCopy ( const IMX_Buffer other)

Deep copy operator. Unlike copy() (which shares the buffers of the source), this version allocates a new buffer and copies the data into it. This can throw CE exceptions.

void IMX_Buffer::destroy ( )

Frees all the memory used by buffer.

void IMX_Buffer::freeBuffers ( )

Frees the pixel memory (also does setDirty())

IMX_BorderType IMX_Buffer::getBorderType ( ) const

Returns type of the border.

int64 IMX_Buffer::getBufferSize ( ) const

Returns the number of bytes required to store the entire buffer.

int IMX_Buffer::getChannels ( ) const
inline

Get the number of channels per pixel.

Definition at line 289 of file IMX_Buffer.h.

void* IMX_Buffer::getCPUBuffer ( bool  read,
bool  write 
)
inline

Returns a void pointer to the CPU buffer. If a read-only buffer is requested and this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!

Definition at line 420 of file IMX_Buffer.h.

template<CE_Image::StorageType STORAGE>
CE_StorageTypeTraits<STORAGE>::DataType* IMX_Buffer::getCPUBuffer ( bool  read,
bool  write 
)
inline

Returns this buffer's data array. If read is true, isDirty must be false. If write is true then it turns off isDirty by setting isOnCPU() and turning off isOnGPU() (it is assuming caller will actually write the buffer) If a read-only buffer is requested and this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!

Definition at line 439 of file IMX_Buffer.h.

template<CE_Image::StorageType STORAGE>
const CE_StorageTypeTraits<STORAGE>::DataType* IMX_Buffer::getCPUBufferR ( ) const
inline

Returns this buffer's read-only data array. If this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!

Definition at line 426 of file IMX_Buffer.h.

const fpreal16* IMX_Buffer::getCPUBufferRF16 ( ) const
inline

Return pointer to CPU buffer (caller must ask for correct data type) If a read buffer is requested and this buffer is constant, the buffer will be compressed (i.e. of size equal to the number of channels)!

Definition at line 406 of file IMX_Buffer.h.

const fpreal32* IMX_Buffer::getCPUBufferRF32 ( ) const
inline

Definition at line 408 of file IMX_Buffer.h.

const int16* IMX_Buffer::getCPUBufferRI16 ( ) const
inline

Definition at line 412 of file IMX_Buffer.h.

const int32* IMX_Buffer::getCPUBufferRI32 ( ) const
inline

Definition at line 414 of file IMX_Buffer.h.

const unsigned char* IMX_Buffer::getCPUBufferRI8 ( ) const
inline

Definition at line 410 of file IMX_Buffer.h.

fpreal16* IMX_Buffer::getCPUBufferWF16 ( )
inline

Definition at line 407 of file IMX_Buffer.h.

fpreal32* IMX_Buffer::getCPUBufferWF32 ( )
inline

Definition at line 409 of file IMX_Buffer.h.

int16* IMX_Buffer::getCPUBufferWI16 ( )
inline

Definition at line 413 of file IMX_Buffer.h.

int32* IMX_Buffer::getCPUBufferWI32 ( )
inline

Definition at line 415 of file IMX_Buffer.h.

unsigned char* IMX_Buffer::getCPUBufferWI8 ( )
inline

Definition at line 411 of file IMX_Buffer.h.

UT_Vector4F IMX_Buffer::getDefaultColor ( ) const
UT_Vector4I IMX_Buffer::getDefaultColorI ( ) const

return the current integer value, which might be different

CE_Image& IMX_Buffer::getGPUBuffer ( bool  read,
bool  write 
)

Returns this buffer's GPU storage object. If read is true, isDirty must be false. If write is true then it turns off isDirty by setting isOnGPU() and turning off isOnCPU() (it is assuming caller will actually write the buffer) When using one of these methods, this buffer must be guarded with the in-use GPU flag. See setInUseGPUFlag() documentation for more information. Can throw CE exceptions.

const CE_Image& IMX_Buffer::getGPUBufferR ( ) const
CE_Image& IMX_Buffer::getGPUBufferW ( )
inline

Definition at line 454 of file IMX_Buffer.h.

cl::Buffer IMX_Buffer::getGPUStat ( ) const

Returns the stat buffer on the GPU, copying it there if necessary. This can throw CE exceptions.

int IMX_Buffer::getPixelI ( int  x,
int  y 
) const
UT_Vector4F IMX_Buffer::getPixelV4 ( int  x,
int  y 
) const

Fetches the value of an individual pixel.

UT_Vector4F IMX_Buffer::getPixelV4 ( fpreal64  x,
fpreal64  y 
) const

Fetches the value at the provided coordinates, using bilinear filtering. Returns value of the nearest pixel for integer buffers.

int IMX_Buffer::getStorageBytes ( ) const
inline

Number of bytes per channel.

Definition at line 291 of file IMX_Buffer.h.

CE_Image::StorageType IMX_Buffer::getStorageType ( ) const
inline

Get the data type used to store pixel data for each channel.

Definition at line 285 of file IMX_Buffer.h.

IMX_TypeInfo IMX_Buffer::getTypeInfo ( ) const

Returns type of the border.

const UT_SharedPtr<CE_Image>& IMX_Buffer::GPUBufferPtr ( ) const
inline

Definition at line 380 of file IMX_Buffer.h.

bool IMX_Buffer::isAligned ( const IMX_Buffer src) const

True if the buffer pixels line up: width and the transforms from image space match.

bool IMX_Buffer::isConstant ( ) const
inline

Definition at line 528 of file IMX_Buffer.h.

bool IMX_Buffer::isDirty ( ) const
inline

False if there are computed pixels in the CPU or GPU buffer.

Definition at line 503 of file IMX_Buffer.h.

bool IMX_Buffer::isInUseGPU ( ) const
inline

Returns whether the GPU data for this image is currently being used by someone.

Definition at line 471 of file IMX_Buffer.h.

bool IMX_Buffer::isOnCPU ( ) const
inline

Returns true if this buffer's data is currently on the CPU (this is not necessarily !isOnGPU()).

Definition at line 464 of file IMX_Buffer.h.

bool IMX_Buffer::isOnGPU ( ) const
inline

Returns true if this buffer's data is currently on the GPU.

Definition at line 457 of file IMX_Buffer.h.

void IMX_Buffer::makeBufferUnique ( )

Stop sharing the buffers (so that writes don't affect other layers that have called copyBuffer() on this or vice versa).

template<typename T >
void IMX_Buffer::matchAndCopyToVoxels ( UT_VoxelArray< T > &  dest) const

Resizes dest to match dimensions of this image (its Z-resolution is set to 1) and copies this buffer's data into it. Number of channels in the image should equal tuple size of T. If this layer is dirty, simply sizes the voxel array without touching its values.

void IMX_Buffer::moveBuffer ( IMX_Buffer src)

Move the buffer to this from src, src is left dirty.

IMX_Buffer& IMX_Buffer::operator= ( const IMX_Buffer other)
inline

Definition at line 335 of file IMX_Buffer.h.

IMX_Buffer& IMX_Buffer::operator= ( IMX_Buffer &&  other)
inline

Definition at line 343 of file IMX_Buffer.h.

void IMX_Buffer::setBorder ( IMX_BorderType  border)

Sets the border type of this image. Constant means it is zero.

void IMX_Buffer::setBufferSize ( int  width,
int  height 
)

Sets size of this buffer.

void IMX_Buffer::setBufferXforms ( const UT_Vector2F buffer_to_image_scale,
const UT_Vector2F buffer_to_image_xlate,
const UT_Vector2F buffer_from_image_scale,
const UT_Vector2F buffer_from_image_xlate,
const UT_Vector2F buffer_to_pixel_scale,
const UT_Vector2F buffer_to_pixel_xlate,
const UT_Matrix4F image_to_world,
const UT_Matrix4F world_to_image 
)

Set transform between image and buffer space.

void IMX_Buffer::setChannels ( int  channels)

Set channels, don't change storesIntegers or bits.

void IMX_Buffer::setConstantF ( fpreal32  i = 0.0f)
inline

Definition at line 517 of file IMX_Buffer.h.

void IMX_Buffer::setConstantI ( int32  i = 0)
void IMX_Buffer::setConstantV3 ( const UT_Vector3F i)
inline

Definition at line 516 of file IMX_Buffer.h.

void IMX_Buffer::setConstantV4 ( const UT_Vector4F i)

Make entire image the same color. This is optimized internally to a 1x1 buffer

void IMX_Buffer::setDefaultColor ( const UT_Vector4F )

Set the default color. This is returned for uncalculatable pixels, and to expand integer vectors from 2,3 to 4. Other usage is not yet determined. Initial value is 0,0,0,1 (may change)

void IMX_Buffer::setDirty ( )
inline

Turn on isDirty(). It is turned off by getCPU/GPUBuffer with write=true.

Definition at line 505 of file IMX_Buffer.h.

void IMX_Buffer::setInUseGPUFlag ( ) const
inline

Increments the user count of our GPU data. If there are no active users of the GPU data, the memory pool will be able to unload the buffer. When using one of the getGPUBuffer() methods, the in-use GPU flag must be set to prevent the GPU data from getting unloaded: // Set the in-use flag before grabbing the GPU buffer. buffer.setInUseGPUFlag(); CE_Image& img = buffer.getGPUBufferW(); // Do stuff with the CE_Image (i.e. queue up an OpenCL command with // it, can be asynchronous). ... // Flip the flag that we set earlier. buffer.clearInUseGPUFlag();

Definition at line 487 of file IMX_Buffer.h.

void IMX_Buffer::setPixelF ( int  x,
int  y,
fpreal32  i 
)
inline

Definition at line 387 of file IMX_Buffer.h.

void IMX_Buffer::setPixelI ( int  x,
int  y,
int  i 
)
inline

Definition at line 391 of file IMX_Buffer.h.

void IMX_Buffer::setPixelV4 ( int  x,
int  y,
const UT_Vector4F c 
)
inline

Sets an individual pixel.

Definition at line 383 of file IMX_Buffer.h.

void IMX_Buffer::setStealable ( bool  v) const
inline

Can be used to control what stealable() subsequently returns. If set to true, indicates to the verbs that this buffer may be stolen from.

Definition at line 350 of file IMX_Buffer.h.

void IMX_Buffer::setStorageBytes ( int  )

Set number of bytes per channel, don't change storesIntegers or channels.

void IMX_Buffer::setStorageType ( CE_Image::StorageType  storage,
int  channels 
)

Set storesIntegers, bytes, channels.

void IMX_Buffer::setStorageType ( CE_Image::StorageType  storage)

Set storesIntegers, bytes.

void IMX_Buffer::setTypeInfo ( IMX_TypeInfo  typeinfo)

Sets the semantic type info of this image.

void IMX_Buffer::setUninitialized ( )
inline

Marks that this buffer is not initialized. This means that when a read buffer is requested, we won't bother doing any copying or data validation. This is useful if you bind this as a read-write layer to a kernel, but will be doing the initialization in the same kernel. Copying from an unitialized buffer will inherit this flag without moving any data. This flag gets cleared when someone writes to this buffer.

Definition at line 526 of file IMX_Buffer.h.

bool IMX_Buffer::stealable ( ) const
inline

True if data in this buffer may be stolen from (or changed) by the verbs even if it's an input.

Definition at line 347 of file IMX_Buffer.h.

bool IMX_Buffer::storesIntegers ( ) const
inline

Does this buffer store integers?

Definition at line 287 of file IMX_Buffer.h.

void IMX_Buffer::swap ( IMX_Buffer other)

Friends And Related Function Documentation

friend class COP_OpenFXImage
friend

Definition at line 257 of file IMX_Buffer.h.

friend class IMX_CEMemoryPool
friend

Definition at line 607 of file IMX_Buffer.h.

friend class IMX_Layer
friend

Definition at line 256 of file IMX_Buffer.h.


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