MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / FillTensorData

Function FillTensorData

src/nvcv/src/priv/TensorData.cpp:50–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50void FillTensorData(IImage &img, NVCVTensorData &tensorData)
51{
52 ImageFormat fmt = img.format();
53
54 // Must do a lot of checks to see if image is compatible with a tensor representation.
55
56 if (img.format().memLayout() != NVCV_MEM_LAYOUT_PL)
57 {
58 throw Exception(NVCV_ERROR_INVALID_ARGUMENT) << "Image format's memory layout must be pitch-linear";
59 }
60
61 if (img.format().css() != NVCV_CSS_444)
62 {
63 throw Exception(NVCV_ERROR_INVALID_ARGUMENT) << "Image format's memory layout must not have sub-sampled planes";
64 }
65
66 for (int p = 1; p < fmt.numPlanes(); ++p)
67 {
68 if (fmt.planeDataType(p) != fmt.planeDataType(0))
69 {
70 throw Exception(NVCV_ERROR_INVALID_ARGUMENT) << "Data type of all image planes must be the same";
71 }
72 }
73
74 NVCVImageData imgData;
75 img.exportData(imgData);
76
77 if (imgData.bufferType != NVCV_IMAGE_BUFFER_STRIDED_CUDA)
78 {
79 throw Exception(NVCV_ERROR_INVALID_ARGUMENT)
80 << "Only cuda-accessible images with pitch-linear data are accepted";
81 }
82
83 NVCVImageBufferStrided &imgStrided = imgData.buffer.strided;
84
85 for (int p = 1; p < imgStrided.numPlanes; ++p)
86 {
87 if (imgStrided.planes[p].width != imgStrided.planes[0].width
88 || imgStrided.planes[p].height != imgStrided.planes[0].height)
89 {
90 throw Exception(NVCV_ERROR_INVALID_ARGUMENT) << "All image planes must have the same dimensions";
91 }
92
93 if (imgStrided.planes[p].rowStride != imgStrided.planes[0].rowStride)
94 {
95 throw Exception(NVCV_ERROR_INVALID_ARGUMENT) << "All image planes must have the same row pitch";
96 }
97
98 if (imgStrided.planes[p].basePtr <= imgStrided.planes[0].basePtr)
99 {
100 throw Exception(NVCV_ERROR_INVALID_ARGUMENT)
101 << "Consecutive image planes must have increasing memory addresses";
102 }
103
104 if (p >= 2)
105 {
106 intptr_t planeStride = reinterpret_cast<const std::byte *>(imgStrided.planes[1].basePtr)
107 - reinterpret_cast<const std::byte *>(imgStrided.planes[0].basePtr);

Callers 1

Tensor.cppFile · 0.85

Calls 12

ExceptionClass · 0.85
cssMethod · 0.80
formatMethod · 0.45
memLayoutMethod · 0.45
numPlanesMethod · 0.45
planeDataTypeMethod · 0.45
exportDataMethod · 0.45
bpcMethod · 0.45
numChannelsMethod · 0.45
planePixelStrideBytesMethod · 0.45
valueMethod · 0.45
channelTypeMethod · 0.45

Tested by

no test coverage detected