An abstract representation of a 2D image. More...
Data Structures | |
struct | VPIImagePlanePitchLinear |
Represents one image plane in pitch-linear layout. More... | |
struct | VPIImageBufferPitchLinear |
Stores the image plane contents. More... | |
union | VPIImageBuffer |
Represents the available methods to access image contents. More... | |
struct | VPIImageData |
Stores information about image characteristics and content. More... | |
struct | VPIImageWrapperParams |
Parameters for customizing image wrapping. More... | |
Macros | |
#define | VPI_MAX_PLANE_COUNT (6) |
Maximum number of data planes an image can have. | |
Typedefs | |
typedef struct VPIImageImpl * | VPIImage |
A handle to an image. | |
Enumerations | |
enum | VPIImageBufferType |
Represents how the image data is stored. More... | |
Functions | |
VPIStatus | vpiImageCreate (int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img) |
Create an empty image instance with the specified flags. More... | |
VPIStatus | vpiInitImageWrapperParams (VPIImageWrapperParams *params) |
Initialize VPIImageWrapperParams with default values. More... | |
VPIStatus | vpiImageCreateView (VPIImage imgParent, const VPIRectangleI *clipBounds, uint64_t flags, VPIImage *imgView) |
Create an image that wraps an axis-aligned rectangular sub-region of an existing image. More... | |
VPIStatus | vpiImageSetView (VPIImage view, VPIImage parent, const VPIRectangleI *clipBounds) |
Redefines the image view position inside a parent image. More... | |
VPIStatus | vpiImageCreateWrapper (const VPIImageData *data, const VPIImageWrapperParams *params, uint64_t flags, VPIImage *img) |
Create an image object by wrapping an existing memory block. More... | |
VPIStatus | vpiImageSetWrapper (VPIImage img, const VPIImageData *data) |
Redefines the wrapped memory in an existing VPIImage wrapper. More... | |
void | vpiImageDestroy (VPIImage img) |
Destroy an image instance. More... | |
VPIStatus | vpiImageGetSize (VPIImage img, int32_t *width, int32_t *height) |
Get the image dimensions in pixels. More... | |
VPIStatus | vpiImageGetFormat (VPIImage img, VPIImageFormat *format) |
Get the image format. More... | |
VPIStatus | vpiImageGetFlags (VPIImage img, uint64_t *flags) |
Get the image flags. More... | |
VPIStatus | vpiImageLock (VPIImage img, VPILockMode mode) |
Acquires the lock on an image object. More... | |
VPIStatus | vpiImageLockData (VPIImage img, VPILockMode mode, VPIImageBufferType bufType, VPIImageData *data) |
Acquires the lock on an image object and returns the image contents. More... | |
VPIStatus | vpiImageUnlock (VPIImage img) |
Releases the lock on an image object. More... | |
An abstract representation of a 2D image.
There are two ways of creating 2D image containers with the API. The most basic one is to use vpiImageCreate to allocate and initialize an empty (zeroed) VPIImage object. The memory for the image data is allocated and managed by VPI. Parameters such as width, height and pixel type are immutable and specified at the construction time. The internal memory layout is also backend-specific. More importantly, efficient exchange of image data between different hardware backends might force the implementation to allocate the memory in multiple memory pools (e.g. dGPU and system DRAM). In some scenarios (to optimize performance and memory use), it might be beneficial to constrain the internal allocation policy to support only a particular set of backends.
To enable interop with existing memory buffers, the user can also create an image object that wraps a user-allocated (and managed) image data using vpiImageCreateWrapper. Similarly to vpiImageCreate, image parameters passed to it are fixed.
The wrapped memory can be redefined by calling vpiImageSetWrapper corresponding to the image wrapper creation function used, as long as the new wrapped memory has the same capacity and type as the one originally wrapped. It's more efficient to create the VPIImage wrapper once and reuse it later then creating and destroying it all the time.
The set of vpiImageLockData / vpiImageUnlock allows the user to read from/write to the image data from the host. These functions are non-blocking and oblivious to the stream command queue, so it's up to the user to make sure that all pending operations using this image as input or output are finished. Also, depending on which device the memory is allocated, lock/unlock operation might be time-consuming and, for example, involve copying data over PCIe bus for dGPUs.
struct VPIImagePlanePitchLinear |
Data Fields | ||
---|---|---|
VPIPixelType | pixelType |
Type of each pixel within this plane. If it is VPI_PIXEL_TYPE_INVALID, it will be inferred from VPIImageBufferPitchLinear::format. |
int32_t | width |
Width of this plane in pixels.
|
int32_t | height |
Height of this plane in pixels.
|
int32_t | pitchBytes |
Difference in bytes of beginning of one row and the beginning of the previous. This is used to address every row (and ultimately every pixel) in the plane. int32_t pitchBytes Difference in bytes of beginning of one row and the beginning of the previous. Definition: Image.h:134 where T is the C type related to pixelType.
|
void * | data |
Pointer to the first row of this plane. This points to the actual data represented by this plane. Depending on how the plane is used, the pointer might be addressing a GPU memory or host memory. Care is needed to know when it is allowed to dereference this memory. |
struct VPIImageBufferPitchLinear |
Data Fields | ||
---|---|---|
VPIImageFormat | format | Image format. |
int32_t | numPlanes |
Number of planes.
|
VPIImagePlanePitchLinear | planes[VPI_MAX_PLANE_COUNT] |
Data of all image planes in pitch-linear layout.
|
union VPIImageBuffer |
Represents the available methods to access image contents.
The correct method depends on VPIImageData::bufferType.
Data Fields | ||
---|---|---|
VPIImageBufferPitchLinear | pitch |
Image stored in pitch-linear layout. To be used when VPIImageData::bufferType is: |
cudaArray_t | cudaarray |
Image stored in a cudaArray_t . To be used when VPIImageData::bufferType is: |
EGLImageKHR | egl |
Image stored as an EGLImageKHR. To be used when VPIImageData::bufferType is: |
int | fd |
Image stored as an NvBuffer file descriptor. To be used when VPIImageData::bufferType is: |
struct VPIImageData |
Data Fields | ||
---|---|---|
VPIImageBufferType | bufferType |
Type of image buffer. It defines which member of the VPIImageBuffer tagged union that must be used to access the image contents. |
VPIImageBuffer | buffer | Stores the image contents. |
struct VPIImageWrapperParams |
Parameters for customizing image wrapping.
These parameters are used to customize how image wrapping will be made. Make sure to call vpiInitImageWrapperParams to initialize this structure before updating its attributes. This guarantees that new attributes added in future versions will have a suitable default value assigned.
Data Fields | ||
---|---|---|
VPIColorSpec | colorSpec |
Color spec to override the one defined by the VPIImageData wrapper. If set to VPI_COLOR_SPEC_DEFAULT, infer the color spec from VPIImageData, i.e., no overriding will be done. |
enum VPIImageBufferType |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Represents how the image data is stored.
Enumerator | |
---|---|
VPI_IMAGE_BUFFER_INVALID | Invalid buffer type. This is commonly used to inform that no buffer type was selected. |
VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR | Host-accessible with planes in pitch-linear memory layout. |
VPI_IMAGE_BUFFER_CUDA_PITCH_LINEAR | CUDA-accessible with planes in pitch-linear memory layout. |
VPI_IMAGE_BUFFER_CUDA_ARRAY | Buffer stored in a cudaArray_t. Please consult cudaArray_t for more information. |
VPI_IMAGE_BUFFER_EGLIMAGE | EGLImage. Please consult EGLImageKHR for more information. |
VPI_IMAGE_BUFFER_NVBUFFER | NvBuffer. Please consult NvBuffer for more information.
|
VPIStatus vpiImageCreate | ( | int32_t | width, |
int32_t | height, | ||
VPIImageFormat | fmt, | ||
uint64_t | flags, | ||
VPIImage * | img | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Create an empty image instance with the specified flags.
Image data is zeroed.
The following flags affect the behavior of the allocated image
[in] | width,height | Dimensions of the created image.
|
[in] | fmt | Format of the created image.
|
[in] | flags | Bit field specifying the desired characteristics of the image.
|
[out] | img | Pointer to memory that will receive the created image handle. |
VPI_ERROR_INVALID_ARGUMENT | Output img handle is NULL. |
VPI_ERROR_INVALID_ARGUMENT | width or height outside valid range. |
VPI_ERROR_INVALID_ARGUMENT | fmt is invalid or not supported. |
VPI_ERROR_INVALID_ARGUMENT | flags is invalid. |
VPI_ERROR_INVALID_ARGUMENT | No backend were given and VPI_REQUIRE_BACKENDS is set. |
VPI_ERROR_OUT_OF_MEMORY | Not enough resources to allocate image. |
VPI_ERROR_INVALID_CONTEXT | Current context was destroyed. |
VPI_ERROR_INVALID_OPERATION | Some requested backend isn't enabled in current context. |
VPI_ERROR_INVALID_OPERATION | Some requested backend can't be created with given image parameters. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiInitImageWrapperParams | ( | VPIImageWrapperParams * | params | ) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Initialize VPIImageWrapperParams with default values.
Default values are:
[in] | params | Structure to be initialized with default values.
|
VPI_ERROR_INVALID_ARGUMENT | params is NULL. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageCreateView | ( | VPIImage | imgParent, |
const VPIRectangleI * | clipBounds, | ||
uint64_t | flags, | ||
VPIImage * | imgView | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Create an image that wraps an axis-aligned rectangular sub-region of an existing image.
Create an image instance that is a view of the input image with specific position (x, y), dimensions (width, height) and flags. The resulting image shares the underlying data with the input image, i.e. there is no copy involved in the creation of a view. Similarly to creating image instances that wrap around external buffers, the resulting image view instances do not own the data. It is legal to create a view from another image view instance.
[in] | imgParent | Handle to the input parent image.
|
[in] | clipBounds | Rectangle defining the clip bounds of the created image view.
|
[in] | flags | Flags with the characteristics of the created image view.
|
[out] | imgView | Pointer to memory that will receive the created image view handle.
|
VPI_ERROR_INVALID_OPERATION | imgView cannot be created with the given imgParent . |
VPI_ERROR_INVALID_OPERATION | The backends in imgParent and flags are not compatible. |
VPI_ERROR_INVALID_ARGUMENT | Input parent image imgParent is NULL. |
VPI_ERROR_INVALID_ARGUMENT | imgParent has no backends. |
VPI_ERROR_INVALID_ARGUMENT | output handle is NULL. |
VPI_ERROR_INVALID_ARGUMENT | clipBounds is NULL or outside the valid range. |
VPI_ERROR_INVALID_ARGUMENT | flags are invalid. |
VPI_ERROR_NOT_IMPLEMENTED | Image view is not implemented for the given input parent image. |
VPI_ERROR_INVALID_CONTEXT | imgParent and imgView contexts are different. |
VPI_ERROR_INVALID_CONTEXT | Current context was destroyed. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageSetView | ( | VPIImage | view, |
VPIImage | parent, | ||
const VPIRectangleI * | clipBounds | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Redefines the image view position inside a parent image.
This operation is efficient and does not allocate memory. The view memory will be accessible to the same backends specified during view creation. The parent image may be the original parent of the view or a new parent.
[in] | view | Handle to image view.
|
[in] | parent | Handle to a potentially new input parent image.
|
[in] | clipBounds | Rectangle defining the clip bounds of the redefined image view.
|
VPI_ERROR_INVALID_ARGUMENT | Input view is NULL. |
VPI_ERROR_INVALID_ARGUMENT | Input parent is NULL. |
VPI_ERROR_INVALID_ARGUMENT | clipBounds is NULL. |
VPI_ERROR_INVALID_ARGUMENT | clipBounds is outside valid range. |
VPI_ERROR_INVALID_ARGUMENT | clipBounds has different size than image view. |
VPI_ERROR_INVALID_ARGUMENT | parent image format does not match view image format. |
VPI_ERROR_INVALID_ARGUMENT | parent has no backends. |
VPI_ERROR_INVALID_OPERATION | view is not created using vpiImageCreateView. |
VPI_ERROR_INVALID_OPERATION | view cannot be redefined with the given parent . |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageCreateWrapper | ( | const VPIImageData * | data, |
const VPIImageWrapperParams * | params, | ||
uint64_t | flags, | ||
VPIImage * | img | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Create an image object by wrapping an existing memory block.
The underlying image object does not own/claim the memory block.
[in] | data | Pointer to structure with memory to be wrapped.
| ||||||
[in] | params | If not NULL, use the parameters to modify how data is wrapped. Otherwise, it'll use defaults given by vpiInitImageWrapperParams. | ||||||
[in] | flags | Bit field specifying the desired characteristics of the image. Depending on some buffer types, the following flags will be added automatically:
|
[out] | img | Pointer to memory that will receive the created image handle. |
VPI_ERROR_INVALID_ARGUMENT | img is NULL. |
VPI_ERROR_INVALID_ARGUMENT | data is NULL or contains invalid/unsupported values. |
VPI_ERROR_INVALID_ARGUMENT | Buffer type in data isn't supported. |
VPI_ERROR_INVALID_ARGUMENT | EGLImage handle is NULL or invalid (e.g. EGL_NO_IMAGE). |
VPI_ERROR_INVALID_ARGUMENT | NvBuffer file descriptor is invalid. |
VPI_ERROR_INVALID_ARGUMENT | No backend were given and VPI_REQUIRE_BACKENDS is set. |
VPI_ERROR_OUT_OF_MEMORY | Not enough resources to create image. |
VPI_ERROR_INTERNAL | Can't retrieve default EGLDisplay when wrapping EGLImage, or some unspecified internal error. |
VPI_ERROR_INVALID_CONTEXT | Current context is destroyed. |
VPI_ERROR_INVALID_OPERATION | Requested backend isn't enabled in current context. |
VPI_ERROR_INVALID_OPERATION | A requested backend can't be created with given image parameters. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageSetWrapper | ( | VPIImage | img, |
const VPIImageData * | data | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Redefines the wrapped memory in an existing VPIImage wrapper.
This operation is efficient and does not allocate memory. The wrapped memory will be accessible to the same backends specified during wrapper creation.
The wrapped memory must not be deallocated while it's still being wrapped.
[in] | img | Handle to image.
|
[in] | data | Pointer to structure with memory buffer to be wrapped.
|
VPI_ERROR_INVALID_ARGUMENT | data is NULL. |
VPI_ERROR_INVALID_ARGUMENT | New and old buffer types don't match. |
VPI_ERROR_INVALID_ARGUMENT | data dimensions and/or format don't match img . |
VPI_ERROR_INVALID_ARGUMENT | Wrapped EGLImage is invalid (e.g. EGL_NO_IMAGE). |
VPI_ERROR_INTERNAL | Cannot retrieve EGLDisplay. |
VPI_ERROR_INVALID_OPERATION | img is not created using vpiImageCreateWrapper. |
VPI_ERROR_INVALID_OPERATION | img is locked. |
VPI_ERROR_INVALID_OPERATION | EGL/NvBuffer wrapping not supported on this platform. |
VPI_SUCCESS | Operation executed successfully. |
void vpiImageDestroy | ( | VPIImage | img | ) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Destroy an image instance.
This function deallocates all resources allocated by the image creation function. When destroying an VPIImage wrapper, the wrapped memory itself isn't deallocated.
[in] | img | img to be destroyed. Passing NULL is allowed, to which the function simply does nothing.
|
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Get the image dimensions in pixels.
[in] | img | Image to be queried.
|
[out] | width,height | Pointers to buffers where the image width and height (respectively) will be written to. |
VPI_ERROR_INVALID_ARGUMENT | img is NULL or doesn't represent a VPIImage instance. |
VPI_ERROR_INVALID_ARGUMENT | Output width or height pointers are NULL. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageGetFormat | ( | VPIImage | img, |
VPIImageFormat * | format | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Get the image format.
[in] | img | Image to be queried.
|
[out] | format | A pointer to where the mage format will be written to.
|
VPI_ERROR_INVALID_ARGUMENT | img is NULL or doesn't represent a VPIImage instance. |
VPI_ERROR_INVALID_ARGUMENT | format pointer is NULL. |
VPI_SUCCESS | Operation executed successfully |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Get the image flags.
[in] | img | Image to be queried.
|
[out] | flags | A pointer to where the flags will be written to.
|
VPI_ERROR_INVALID_ARGUMENT | flags pointer is NULL. |
VPI_ERROR_INVALID_ARGUMENT | img is NULL or doesn't represent a VPIImage instance. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageLock | ( | VPIImage | img, |
VPILockMode | mode | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Acquires the lock on an image object.
Image locking is required when the image object wraps externally-accessible buffers, and these buffers will be accessed outside VPI. As long as the lock is held, any attempt of VPI to access the image in a mode not compatible with the lock mode will result in asynchronous stream errors, VPI_ERROR_BUFFER_LOCKED.
The image can be locked multiple times. Each lock operation increments a counter and must be matched by a corresponding vpiImageUnlock call.
[in] | img | Image to be locked.
|
[in] | mode | Lock mode, depending on whether the memory will be written to and/or read from.
|
VPI_ERROR_INVALID_ARGUMENT | img is NULL or doesn't represent a VPIImage instance. |
VPI_ERROR_BUFFER_LOCKED | Image is already locked by either a stream or the user. |
VPI_SUCCESS | Operation executed successfully. |
VPIStatus vpiImageLockData | ( | VPIImage | img, |
VPILockMode | mode, | ||
VPIImageBufferType | bufType, | ||
VPIImageData * | data | ||
) |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Acquires the lock on an image object and returns the image contents.
Depending on the internal image representation, as well as the actual location in memory, this function might have a significant performance overhead due to format conversion, layout conversion, device-to-host memory copy, etc.
The image can be locked multiple times. Each lock operation increments a counter and must be matched by a corresponding vpiImageUnlock call.
[in] | img | Image to be locked.
| ||||||
[in] | mode | Lock mode, depending on whether the memory will be written to and/or read from.
| ||||||
[in] | bufType | The type of buffer returned in data . It defines how the image contents can be accessed by the caller. Valid types are:
| ||||||
[out] | data | A pointer to a structure that will be filled with image memory contents information.
|
VPI_ERROR_INVALID_ARGUMENT | img is NULL or doesn't represent a VPIImage instance. |
VPI_ERROR_INVALID_ARGUMENT | data must not be NULL. |
VPI_ERROR_INVALID_ARGUMENT | bufType isn't supported. |
VPI_ERROR_INVALID_OPERATION | img doesn't have required backends enabled. |
VPI_ERROR_BUFFER_LOCKED | Image is already locked by either a stream or the user. |
VPI_SUCCESS | Operation executed successfully. |
#include </opt/nvidia/vpi2/include/vpi/Image.h>
Releases the lock on an image object.
The image is effectively unlocked when the internal lock counter reaches 0.
[in] | img | Image to be unlocked.
|
VPI_ERROR_INVALID_ARGUMENT | img is NULL or doesn't represent a VPIImage instance. |
VPI_ERROR_INVALID_OPERATION | img isn't locked. |
VPI_SUCCESS | Operation executed successfully. |