| 48 | } |
| 49 | |
| 50 | void 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); |
no test coverage detected