HDK
|
#include <IMX_Buffer.h>
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_Buffer & | operator= (const IMX_Buffer &other) |
void | deepCopy (const IMX_Buffer &other) |
void | swap (IMX_Buffer &other) |
IMX_Buffer & | operator= (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_Raster > | buildRaster () 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 fpreal16 * | getCPUBufferRF16 () const |
fpreal16 * | getCPUBufferWF16 () |
const fpreal32 * | getCPUBufferRF32 () const |
fpreal32 * | getCPUBufferWF32 () |
const unsigned char * | getCPUBufferRI8 () const |
unsigned char * | getCPUBufferWI8 () |
const int16 * | getCPUBufferRI16 () const |
int16 * | getCPUBufferWI16 () |
const int32 * | getCPUBufferRI32 () const |
int32 * | getCPUBufferWI32 () |
void * | getCPUBuffer (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_Image & | getGPUBuffer (bool read, bool write) |
const CE_Image & | getGPUBufferR () const |
CE_Image & | getGPUBufferW () |
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 |
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.
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.
|
inline |
Definition at line 263 of file IMX_Buffer.h.
|
inlinenoexcept |
Definition at line 264 of file IMX_Buffer.h.
IMX_Buffer::IMX_Buffer | ( | const PXL_Raster & | rp | ) |
IMX_Buffer::~IMX_Buffer | ( | ) |
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.
|
inline |
True if getCPU/GPUBuffer has been done since last freeBuffers()
Definition at line 511 of file IMX_Buffer.h.
|
inline |
Get height (number of rows) of the buffer.
Definition at line 298 of file IMX_Buffer.h.
|
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
|
inline |
Set storesIntegers, bytes, channels.
Definition at line 274 of file IMX_Buffer.h.
|
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.
|
inline |
Get the number of channels per pixel.
Definition at line 289 of file IMX_Buffer.h.
|
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.
|
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.
|
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.
|
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.
|
inline |
Definition at line 408 of file IMX_Buffer.h.
|
inline |
Definition at line 412 of file IMX_Buffer.h.
|
inline |
Definition at line 414 of file IMX_Buffer.h.
|
inline |
Definition at line 410 of file IMX_Buffer.h.
|
inline |
Definition at line 407 of file IMX_Buffer.h.
|
inline |
Definition at line 409 of file IMX_Buffer.h.
|
inline |
Definition at line 413 of file IMX_Buffer.h.
|
inline |
Definition at line 415 of file IMX_Buffer.h.
|
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 |
|
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.
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.
|
inline |
Number of bytes per channel.
Definition at line 291 of file IMX_Buffer.h.
|
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.
|
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.
|
inline |
Definition at line 528 of file IMX_Buffer.h.
|
inline |
False if there are computed pixels in the CPU or GPU buffer.
Definition at line 503 of file IMX_Buffer.h.
|
inline |
Returns whether the GPU data for this image is currently being used by someone.
Definition at line 471 of file IMX_Buffer.h.
|
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.
|
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).
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.
|
inline |
Definition at line 335 of file IMX_Buffer.h.
|
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::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.
Definition at line 517 of file IMX_Buffer.h.
|
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)
|
inline |
Turn on isDirty(). It is turned off by getCPU/GPUBuffer with write=true.
Definition at line 505 of file IMX_Buffer.h.
|
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.
Definition at line 387 of file IMX_Buffer.h.
Definition at line 391 of file IMX_Buffer.h.
|
inline |
Sets an individual pixel.
Definition at line 383 of file IMX_Buffer.h.
|
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.
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.
|
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.
|
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.
|
inline |
Does this buffer store integers?
Definition at line 287 of file IMX_Buffer.h.
void IMX_Buffer::swap | ( | IMX_Buffer & | other | ) |
|
friend |
Definition at line 257 of file IMX_Buffer.h.
|
friend |
Definition at line 607 of file IMX_Buffer.h.
Definition at line 256 of file IMX_Buffer.h.