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,...);
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,...);
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] = ...;
}
}
}
- 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);
- Note
- The input and output images must be of the same type.
-
This operation applies to DW_IMAGE_CUDA and DW_IMAGE_NVMEDIA only.