DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

Image Creation and Conversion
Note
SW Release Applicability: This tutorial is applicable to modules in both NVIDIA DriveWorks and NVIDIA DRIVE Software releases.

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.

dwImageProperties imageProperties{};
imageProperties.type = DW_IMAGE_CPU;
imageProperties.format = DW_IMAGE_FORMAT_RGB_UINT8_PLANAR;
imageProperties.width = 1200;
imageProperties.height = 800;
dwImage_create(&image, imageProperties, ...);
// CODE: Use image
dwSomeDriveWorksModule_compute(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];
// CODE: Read some data source into buffer
size_t* pitch[3];
// CODE: Calculate pitch
dwImageProperties imageProperties{};
imageProperties.type = DW_IMAGE_CPU;
imageProperties.format = DW_IMAGE_FORMAT_RGB_UINT8_PLANAR;
imageProperties.width = 1200;
imageProperties.height = 800;
dwImage_createAndBindBuffer(&image, imageProperties, buffer, pitch, ...);
// CODE: Use image
dwSomeDriveWorksModule_compute(image,...); // NOTE, buffer might be modified here
// Destroy the image handle
// Note, the user provided buffer is still available for usage

Accessing Data Explicitly

After creating an image through the demonstrated methods above, its content can be accessed in the following way:

dwImageCPU *imageCPU;
dwImage_getCPU(&imageCPU, image);
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] = ...; // this affects the 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:

dwImageProperties imageProperties{};
imageProperties.type = DW_IMAGE_CUDA;
imageProperties.format = DW_IMAGE_FORMAT_RGBA_UINT8;
imageProperties.width = 1200;
imageProperties.height = 800;
dwImageHandle_t outputImage;
dwImage_create(&outputImage, imageProperties, ...);
// CODE: Get some CUDA image
dwImageHandle_t inputImage
dwSomeDriveWorksModule_getImage(inputImage,...);
dwImage_copyConvert(outputImage, inputImage,...);
// CODE: Use outputImage
...
// Destroy the outputing image
dwImage_destroy(&outputImage);
Note
The input and output images must be of the same type.
This operation applies to DW_IMAGE_CUDA and DW_IMAGE_NVMEDIA only.