This section demonstrates the different methods to create an Image.
Once an image is created, you can stream it from host (CPU) memory to device (CUDA) memory across:
Creating an Image
Basic Creation
This is the simplest method to create an image.
The ownership for the image is transferred to the application, which is responsible for destroying the object when no longer needed.
imageProperties.width = 1200;
imageProperties.height = 800;
dwSomeDriveWorksModule_compute(image,...);
dwImageType type
Specifies the type of image.
struct dwImageObject * dwImageHandle_t
DW_API_PUBLIC dwStatus dwImage_create(dwImageHandle_t *const image, dwImageProperties properties, dwContextHandle_t const ctx)
Creates and allocates resources for a dwImageHandle_t based on the properties passed as input.
DW_API_PUBLIC dwStatus dwImage_destroy(dwImageHandle_t const image)
Destroys the image handle and frees any memory created by dwImage_create().
@ DW_IMAGE_FORMAT_RGB_UINT8_PLANAR
Defines the properties of the image.
Creation with Provided Buffer
This method is similar to the Basic Creation. In this case, the application provides the memory buffer used to store the image.
uint8_t* buffer[3];
size_t* pitch[3];
imageProperties.width = 1200;
imageProperties.height = 800;
dwSomeDriveWorksModule_compute(image,...);
DW_API_PUBLIC dwStatus dwImage_createAndBindBuffer(dwImageHandle_t *const image, dwImageProperties properties, void *const buffersIn[DW_MAX_IMAGE_PLANES], size_t const pitches[DW_MAX_IMAGE_PLANES], size_t const bufferCount, dwContextHandle_t const ctx)
Creates a dwImageHandle_t based on the properties passed and binds a memory buffer provided by the ap...
Accessing Data Explicitly
After creating an image through the demonstrated methods above, its content can be accessed in the following way:
size_t planeCount;
for (uint32_t plane = 0; plane < planeCount; ++p) {
for (uint32_t i = 0; i < imageProperties.height; ++i) {
for (uint32_t j = 0; j < imageProperties.width; ++j) {
imageCPU->
data[plane][i * imageCPU->
pitch[plane] + j] = ...;
}
}
}
size_t pitch[DW_MAX_IMAGE_PLANES]
Specifies the pitch of the image in bytes.
uint8_t * data[DW_MAX_IMAGE_PLANES]
Specifies the raw image data.
DW_API_PUBLIC dwStatus dwImage_getPlaneCount(size_t *const planeCount, dwImageFormat const format)
Retrieves number of planes of the image format.
DW_API_PUBLIC dwStatus dwImage_getCPU(dwImageCPU **const imageCPU, dwImageHandle_t const image)
Retrieves the dwImageCPU of a dwImageHandle_t.
Defines a CPU-based image.
- Note
- This snippet assumes the type of the image created is DW_IMAGE_CPU.
Converting Format
An image's format and properties can be converted in the following way:
imageProperties.width = 1200;
imageProperties.height = 800;
dwSomeDriveWorksModule_getImage(inputImage,...);
...
dwImage_destroy(&outputImage);
DW_API_PUBLIC dwStatus dwImage_copyConvert(dwImageHandle_t const output, dwConstImageHandle_t const input, dwContextHandle_t const context)
Converts CUDA or NvMedia images by copying into an output image, following the properties in the outp...
@ DW_IMAGE_FORMAT_RGBA_UINT8
- Note
- The input and output images must be of the same type.
-
This operation applies to DW_IMAGE_CUDA and DW_IMAGE_NVMEDIA only.