1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
3 @page image_usecase5 Image Creation and Conversion
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
8 This section demonstrates the different methods to create an @ref image_mainsection.
10 Once an image is created, you can stream it from host (CPU) memory to device (CUDA) memory across:
11 - A [single process and thread](@ref image_usecase2).
12 - [Multiple processes](@ref image_usecase3).
13 - [Multiple threads](@ref image_usecase4).
15 @section image_usecase5_creation Creating an Image
17 @subsection image_usecase5_basic Basic Creation
19 This is the simplest method to create an image.<br>
20 The ownership for the image is transferred to the application, which is responsible for destroying the object when no longer needed.
23 dwImageProperties imageProperties{};
24 imageProperties.type = DW_IMAGE_CPU;
25 imageProperties.format = DW_IMAGE_FORMAT_RGB_UINT8_PLANAR;
26 imageProperties.width = 1200;
27 imageProperties.height = 800;
28 dwImageHandle_t image;
29 dwImage_create(&image, imageProperties, ...);
32 dwSomeDriveWorksModule_compute(image,...);
34 dwImage_destroy(&image);
37 @subsection image_usecase5_buffer Creation with Provided Buffer
39 This method is similar to the Basic Creation. In this case, the application provides the memory buffer used to store the image.
43 // CODE: Read some data source into buffer
45 // CODE: Calculate pitch
47 dwImageProperties imageProperties{};
48 imageProperties.type = DW_IMAGE_CPU;
49 imageProperties.format = DW_IMAGE_FORMAT_RGB_UINT8_PLANAR;
50 imageProperties.width = 1200;
51 imageProperties.height = 800;
53 dwImageHandle_t image;
54 dwImage_createAndBindBuffer(&image, imageProperties, buffer, pitch, ...);
57 dwSomeDriveWorksModule_compute(image,...); // NOTE, buffer might be modified here
59 // Destroy the image handle
60 dwImage_destroy(&image);
62 // Note, the user provided buffer is still available for usage
65 @section image_usecase5_access_data Accessing Data Explicitly
67 After creating an image through the demonstrated methods above, its content can be accessed in the following way:
71 dwImage_getCPU(&imageCPU, image);
74 dwImage_getPlaneCount(&planeCount, DW_IMAGE_FORMAT_RGB_UINT8_PLANAR);
76 for (uint32_t plane = 0; plane < planeCount; ++p) {
77 for (uint32_t i = 0; i < imageProperties.height; ++i) {
78 for (uint32_t j = 0; j < imageProperties.width; ++j) {
79 imageCPU->data[plane][i * imageCPU->pitch[plane] + j] = ...; // this affects the image
85 @note This snippet assumes the type of the image created is ::DW_IMAGE_CPU.
87 @section image_usecase5_conversion Converting Format
89 An image's format and properties can be converted in the following way:
92 dwImageProperties imageProperties{};
93 imageProperties.type = DW_IMAGE_CUDA;
94 imageProperties.format = DW_IMAGE_FORMAT_RGBA_UINT8;
95 imageProperties.width = 1200;
96 imageProperties.height = 800;
97 dwImageHandle_t outputImage;
98 dwImage_create(&outputImage, imageProperties, ...);
100 // CODE: Get some CUDA image
101 dwImageHandle_t inputImage
102 dwSomeDriveWorksModule_getImage(inputImage,...);
104 dwImage_copyConvert(outputImage, inputImage,...);
106 // CODE: Use outputImage
109 // Destroy the outputing image
110 dwImage_destroy(&outputImage);
113 @note The input and output images must be of the same type.
114 @note This operation applies to ::DW_IMAGE_CUDA and ::DW_IMAGE_NVMEDIA only.