VPI - Vision Programming Interface

1.2 Release

OpenCVUtils.hpp
1 /*
2  * Copyright 2020 NVIDIA Corporation. All rights reserved.
3  *
4  * NOTICE TO LICENSEE:
5  *
6  * This source code and/or documentation ("Licensed Deliverables") are
7  * subject to NVIDIA intellectual property rights under U.S. and
8  * international Copyright laws.
9  *
10  * These Licensed Deliverables contained herein is PROPRIETARY and
11  * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12  * conditions of a form of NVIDIA software license agreement by and
13  * between NVIDIA and Licensee ("License Agreement") or electronically
14  * accepted by Licensee. Notwithstanding any terms or conditions to
15  * the contrary in the License Agreement, reproduction or disclosure
16  * of the Licensed Deliverables to any third party without the express
17  * written consent of NVIDIA is prohibited.
18  *
19  * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20  * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21  * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22  * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23  * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24  * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25  * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26  * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27  * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28  * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29  * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32  * OF THESE LICENSED DELIVERABLES.
33  *
34  * U.S. Government End Users. These Licensed Deliverables are a
35  * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36  * 1995), consisting of "commercial computer software" and "commercial
37  * computer software documentation" as such terms are used in 48
38  * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39  * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40  * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41  * U.S. Government End Users acquire the Licensed Deliverables with
42  * only those rights set forth herein.
43  *
44  * Any use of the Licensed Deliverables in individual and commercial
45  * software must include, in the user documentation and internal
46  * comments to the code, the above Disclaimer and U.S. Government End
47  * Users Notice.
48  */
49 
50 #ifndef NV_VPI_DETAIL_OPENCV_UTILS_HPP
51 #define NV_VPI_DETAIL_OPENCV_UTILS_HPP
52 
53 #include "../Image.h"
54 #include "../ImageFormat.h"
55 #include "../Status.h"
56 
57 #include <opencv2/core/core.hpp>
58 
59 #include <stdint.h>
60 
61 #include <cassert>
62 #include <vector>
63 
64 namespace nv { namespace vpi { namespace detail {
65 
66 inline VPIImageFormat ToImageFormatFromOpenCVType(int cvType)
67 {
69 
70  switch (CV_MAT_DEPTH(cvType))
71  {
72  case CV_8U:
73  switch (CV_MAT_CN(cvType))
74  {
75  case 1:
76  imgFormat = VPI_IMAGE_FORMAT_U8;
77  break;
78 
79  case 2:
80  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, UNSIGNED, XY00, 1, X8_Y8);
81  break;
82 
83  case 3:
84  imgFormat = VPI_IMAGE_FORMAT_BGR8;
85  break;
86 
87  case 4:
88  imgFormat = VPI_IMAGE_FORMAT_BGRA8;
89  break;
90  }
91  break;
92 
93  case CV_8S:
94  switch (CV_MAT_CN(cvType))
95  {
96  case 1:
97  imgFormat = VPI_IMAGE_FORMAT_S8;
98  break;
99 
100  case 2:
101  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XY00, 1, X8_Y8);
102  break;
103 
104  case 3:
105  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XYZ0, 1, X8_Y8_Z8);
106  break;
107 
108  case 4:
109  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XYZW, 1, X8_Y8_Z8_W8);
110  break;
111  }
112  break;
113 
114  case CV_16U:
115  switch (CV_MAT_CN(cvType))
116  {
117  case 1:
118  imgFormat = VPI_IMAGE_FORMAT_U16;
119  break;
120 
121  case 2:
122  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, UNSIGNED, XY00, 1, X16_Y16);
123  break;
124 
125  case 3:
126  // BGR
127  imgFormat = VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(RGB, UNDEFINED, PL, UNSIGNED, ZYX1, 1, X16_Y16_Z16);
128  break;
129 
130  case 4:
131  // ABGR
132  imgFormat = VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(RGB, UNDEFINED, PL, UNSIGNED, WZYX, 1, X16_Y16_Z16_W16);
133  break;
134  }
135  break;
136 
137  case CV_16S:
138  switch (CV_MAT_CN(cvType))
139  {
140  case 1:
141  imgFormat = VPI_IMAGE_FORMAT_S16;
142  break;
143 
144  case 2:
145  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XY00, 1, X16_Y16);
146  break;
147 
148  case 3:
149  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XYZ0, 1, X16_Y16_Z16);
150  break;
151 
152  case 4:
153  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XYZW, 1, X16_Y16_Z16_W16);
154  break;
155  }
156  break;
157 
158  case CV_32S:
159  switch (CV_MAT_CN(cvType))
160  {
161  case 1:
162  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, X000, 1, X32);
163  break;
164 
165  case 2:
166  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XY00, 1, X32_Y32);
167  break;
168 
169  case 3:
170  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XYZ0, 1, X32_Y32_Z32);
171  break;
172 
173  case 4:
174  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, SIGNED, XYZW, 1, X32_Y32_Z32_W32);
175  break;
176  }
177  break;
178 
179  case CV_32F:
180  switch (CV_MAT_CN(cvType))
181  {
182  case 1:
183  imgFormat = VPI_IMAGE_FORMAT_F32;
184  break;
185 
186  case 2:
187  imgFormat = VPI_IMAGE_FORMAT_2F32;
188  break;
189 
190  case 3:
191  imgFormat = VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(RGB, UNDEFINED, PL, FLOAT, ZYX1, 1, X32_Y32_Z32);
192  break;
193 
194  case 4:
195  imgFormat = VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(RGB, UNDEFINED, PL, FLOAT, WZYX, 1, X32_Y32_Z32_W32);
196  break;
197  }
198  break;
199 
200  case CV_64F:
201  switch (CV_MAT_CN(cvType))
202  {
203  case 1:
204  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, FLOAT, X000, 1, X64);
205  break;
206 
207  case 2:
208  imgFormat = VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(PL, FLOAT, XY00, 1, X64_Y64);
209  break;
210 
211  case 3:
212  imgFormat = VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(RGB, UNDEFINED, PL, FLOAT, ZYX1, 1, X64_Y64_Z64);
213  break;
214 
215  case 4:
216  imgFormat = VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(RGB, UNDEFINED, PL, FLOAT, WZYX, 1, X64_Y64_Z64_W64);
217  break;
218  }
219  break;
220  }
221 
222  return imgFormat;
223 }
224 
225 inline int ToOpenCVType(VPIPixelType pixType)
226 {
228  {
229  return -1;
230  }
231 
232  int depth = -1;
233  VPIDataType dataType = vpiPixelTypeGetDataType(pixType);
234  int elemSize = 0;
235 
236  if (dataType == VPI_DATA_TYPE_UNSIGNED)
237  {
238  switch (vpiPixelTypeGetPacking(pixType))
239  {
240  case VPI_PACKING_X8:
241  case VPI_PACKING_X8_Y8:
246  depth = CV_8U;
247  elemSize = 8;
248  break;
249 
250  case VPI_PACKING_X16:
251  case VPI_PACKING_X16_Y16:
254  depth = CV_16U;
255  elemSize = 16;
256  break;
257 
258  default:
259  return -1;
260  }
261  }
262  else if (dataType == VPI_DATA_TYPE_SIGNED)
263  {
264  switch (vpiPixelTypeGetPacking(pixType))
265  {
266  case VPI_PACKING_X8:
267  case VPI_PACKING_X8_Y8:
272  depth = CV_8S;
273  elemSize = 8;
274  break;
275 
276  case VPI_PACKING_X16:
277  case VPI_PACKING_X16_Y16:
280  depth = CV_16S;
281  elemSize = 16;
282  break;
283 
284  case VPI_PACKING_X32:
285  case VPI_PACKING_X32_Y32:
288  depth = CV_32S;
289  elemSize = 32;
290  break;
291 
292  default:
293  return -1;
294  }
295  }
296  else if (dataType == VPI_DATA_TYPE_FLOAT)
297  {
298  switch (vpiPixelTypeGetPacking(pixType))
299  {
300  case VPI_PACKING_X32:
301  case VPI_PACKING_X32_Y32:
304  depth = CV_32F;
305  elemSize = 32;
306  break;
307 
308  case VPI_PACKING_X64:
309  case VPI_PACKING_X64_Y64:
312  depth = CV_64F;
313  elemSize = 64;
314  break;
315 
316  default:
317  return -1;
318  }
319  }
320  else
321  {
322  return -1;
323  }
324 
325  assert(elemSize != 0);
326 
327  return CV_MAKE_TYPE(depth, vpiPixelTypeGetBitsPerPixel(pixType) / elemSize);
328 }
329 
330 inline VPIStatus FillImageDataOnePlaneImpl(const cv::Mat &mat, VPIImageFormat fmt, VPIImageData *imgData)
331 {
333 
334  if (ToOpenCVType(pixType) != mat.type())
335  {
337  }
338 
339  imgData->planes[0].width = mat.cols;
340  imgData->planes[0].height = mat.rows;
341  imgData->planes[0].pitchBytes = mat.step[0];
342  imgData->planes[0].data = mat.data;
343  imgData->planes[0].pixelType = pixType;
344  return VPI_SUCCESS;
345 }
346 
347 inline VPIStatus FillImageDataTwoPlanesImpl(const cv::Mat &mat, VPIImageFormat fmt, VPIImageData *imgData)
348 {
350 
352  {
354  }
355 
356  if (mat.type() == CV_8UC1)
357  {
360  {
362  }
363  }
364  else if (mat.type() == CV_16UC1)
365  {
368  {
370  }
371  }
372  else
373  {
375  }
376 
377  imgData->planes[0].pixelType = vpiImageFormatGetPlanePixelType(fmt, 0);
378  imgData->planes[1].pixelType = vpiImageFormatGetPlanePixelType(fmt, 1);
379 
380  imgData->planes[0].width = mat.cols;
381  imgData->planes[1].width = mat.cols / 2;
382 
384  {
385  case 4:
386  imgData->planes[0].height = mat.rows / 2;
387  break;
388 
389  case 2:
390  imgData->planes[0].height = mat.rows * 2 / 3;
391  break;
392 
393  case 1:
394  imgData->planes[0].height = mat.rows * 4 / 5;
395  break;
396 
397  default:
399  }
400 
401  imgData->planes[1].height = mat.rows - imgData->planes[0].height;
402 
403  imgData->planes[0].pitchBytes = mat.step[0];
404  imgData->planes[1].pitchBytes = mat.step[0];
405 
406  imgData->planes[0].data = mat.data;
407  imgData->planes[1].data = const_cast<uint8_t *>(mat.ptr(imgData->planes[0].height, 0));
408 
409  return VPI_SUCCESS;
410 }
411 
412 inline VPIStatus FillImageDataThreePlanesImpl(const cv::Mat &mat, VPIImageFormat fmt, VPIImageData *imgData)
413 {
415 
417  {
419  }
420 
421  // column count must be even
422  if (mat.cols & 1)
423  {
425  }
426 
427  switch (mat.type())
428  {
429  case CV_8UC1:
430  // must have packed rows
431  if (mat.step[0] != (size_t)mat.cols)
432  {
434  }
435 
436  for (int p = 0; p < 3; ++p)
437  {
439  {
441  }
442  }
443  break;
444 
445  case CV_16UC1:
446  // must have packed rows
447  if (mat.step[0] != (size_t)mat.cols * 2)
448  {
450  }
451 
452  for (int p = 0; p < 3; ++p)
453  {
455  {
457  }
458  }
459  break;
460 
461  default:
463  }
464 
465  imgData->planes[0].pixelType = vpiImageFormatGetPlanePixelType(fmt, 0);
466  imgData->planes[1].pixelType = vpiImageFormatGetPlanePixelType(fmt, 1);
467  imgData->planes[2].pixelType = vpiImageFormatGetPlanePixelType(fmt, 2);
468 
469  imgData->planes[0].width = mat.cols;
470  imgData->planes[1].width = mat.cols / 2;
471  imgData->planes[2].width = mat.cols / 2;
472 
474  {
475  case 4:
476  imgData->planes[0].height = mat.rows / 2;
477  break;
478  case 2:
479  imgData->planes[0].height = mat.rows * 2 / 3;
480  break;
481  case 1:
482  imgData->planes[0].height = mat.rows * 4 / 5;
483  break;
484  default:
486  }
487 
488  imgData->planes[1].height = mat.rows - imgData->planes[0].height;
489  imgData->planes[2].height = imgData->planes[1].height;
490 
491  imgData->planes[0].pitchBytes = mat.step[0];
492  imgData->planes[1].pitchBytes = mat.step[0] / 2;
493  imgData->planes[2].pitchBytes = mat.step[0] / 2;
494 
495  imgData->planes[0].data = mat.data;
496  imgData->planes[1].data = mat.data + mat.step[0] * imgData->planes[0].height;
497  imgData->planes[2].data = reinterpret_cast<uint8_t *>(imgData->planes[1].data) +
498  imgData->planes[1].height * imgData->planes[1].pitchBytes;
499 
500  return VPI_SUCCESS;
501 }
502 
503 inline VPIStatus FillImageData(const cv::Mat &mat, VPIImageFormat fmt, VPIImageData *imgData)
504 {
505  assert(imgData != NULL);
506 
507  if (mat.data == NULL)
508  {
510  }
511 
512  if (mat.dims != 2)
513  {
515  }
516 
518  {
520  }
521 
522  int numPlanes = vpiImageFormatGetPlaneCount(fmt);
523 
524  VPIStatus status;
525  switch (numPlanes)
526  {
527  case 1:
528  status = FillImageDataOnePlaneImpl(mat, fmt, imgData);
529  break;
530 
531  case 2:
532  status = FillImageDataTwoPlanesImpl(mat, fmt, imgData);
533  break;
534 
535  case 3:
536  status = FillImageDataThreePlanesImpl(mat, fmt, imgData);
537  break;
538 
539  default:
540  status = VPI_ERROR_INTERNAL;
541  break;
542  }
543 
544  if (status == VPI_SUCCESS)
545  {
546  imgData->format = fmt;
547  imgData->numPlanes = numPlanes;
548  }
549 
550  return status;
551 }
552 
553 inline VPIStatus FillImageData(const std::vector<cv::Mat> &matPlanes, VPIImageFormat fmt, VPIImageData *imgData)
554 {
555  assert(imgData != NULL);
556 
557  if (matPlanes.empty())
558  {
560  }
561 
562  if (matPlanes.size() != (size_t)vpiImageFormatGetPlaneCount(fmt))
563  {
565  }
566 
567  imgData->format = fmt;
568  imgData->numPlanes = matPlanes.size();
569 
570  for (size_t p = 0; p < matPlanes.size(); ++p)
571  {
572  const cv::Mat &mat = matPlanes[p];
573 
574  if (mat.data == NULL)
575  {
577  }
578 
579  if (mat.dims != 2)
580  {
582  }
583 
585 
586  if (ToOpenCVType(pixType) != mat.type())
587  {
589  }
590 
591  imgData->planes[p].width = mat.cols;
592  imgData->planes[p].height = mat.rows;
593  imgData->planes[p].pitchBytes = mat.step[0];
594  imgData->planes[p].data = mat.data;
595  imgData->planes[p].pixelType = pixType;
596  }
597 
598  return VPI_SUCCESS;
599 }
600 
601 inline VPIStatus FillImageData(const cv::Mat &mat, VPIImageData *imgData)
602 {
603  assert(imgData != NULL);
604 
605  if (mat.data == NULL)
606  {
608  }
609 
610  if (mat.dims != 2)
611  {
613  }
614 
615  VPIImageFormat fmt = ToImageFormatFromOpenCVType(mat.type());
616  if (fmt == VPI_IMAGE_FORMAT_INVALID)
617  {
619  }
620 
621  imgData->format = fmt;
622  imgData->numPlanes = 1;
623  imgData->planes[0].width = mat.cols;
624  imgData->planes[0].height = mat.rows;
625  imgData->planes[0].pitchBytes = mat.step[0];
626  imgData->planes[0].data = mat.data;
627  imgData->planes[0].pixelType = vpiImageFormatGetPlanePixelType(fmt, 0);
628 
629  return VPI_SUCCESS;
630 }
631 
632 inline VPIStatus CalcHeightOpenCVMatOnePlane(const VPIImageData &imgData, int &height)
633 {
634  height = imgData.planes[0].height;
635  return VPI_SUCCESS;
636 }
637 
638 inline VPIStatus CalcHeightOpenCVMatTwoPlanes(const VPIImageData &imgData, int &height)
639 {
641 
643  {
645  }
646 
647  if (imgData.planes[0].pitchBytes != imgData.planes[1].pitchBytes)
648  {
650  }
651 
652  if (imgData.planes[1].width * 2 != imgData.planes[0].width)
653  {
655  }
656 
657  if (imgData.planes[1].data !=
658  reinterpret_cast<uint8_t *>(imgData.planes[0].data) + imgData.planes[0].height * imgData.planes[0].pitchBytes)
659  {
661  }
662 
664  {
665  case 1:
666  case 2:
667  case 4:
668  height = imgData.planes[0].height + imgData.planes[1].height;
669  break;
670 
671  default:
673  }
674 
675  return VPI_SUCCESS;
676 }
677 
678 inline VPIStatus CalcHeightOpenCVMatThreePlanes(const VPIImageData &imgData, int &height)
679 {
681 
682  // All planes must have packed rows
683  for (int i = 0; i < 3; ++i)
684  {
685  if (imgData.planes[i].pitchBytes !=
686  imgData.planes[i].width * vpiPixelTypeGetBitsPerPixel(imgData.planes[i].pixelType) / 8)
687  {
689  }
690  }
691 
692  if (imgData.planes[0].pitchBytes != imgData.planes[1].pitchBytes * 2 ||
693  imgData.planes[1].pitchBytes != imgData.planes[2].pitchBytes)
694  {
696  }
697 
698  int samplesVert = vpiChromaSubsamplingGetSamplesVert(css);
699 
700  if ((imgData.planes[1].height * 4 + samplesVert - 1) / samplesVert != imgData.planes[0].height)
701  {
703  }
704 
705  if (imgData.planes[2].height != imgData.planes[1].height)
706  {
708  }
709 
710  for (int i = 0; i < 2; ++i)
711  {
712  if (imgData.planes[i + 1].data != reinterpret_cast<uint8_t *>(imgData.planes[i].data) +
713  imgData.planes[i].height * imgData.planes[i].pitchBytes)
714  {
716  }
717  }
718 
720  {
721  case 1:
722  case 2:
723  case 4:
724  height = imgData.planes[0].height + imgData.planes[1].height;
725  break;
726 
727  default:
729  }
730 
731  return VPI_SUCCESS;
732 }
733 
734 inline VPIStatus ExportOpenCVMat(const VPIImageData &imgData, cv::Mat &mat)
735 {
736  VPIStatus status;
737  int height;
738  switch (imgData.numPlanes)
739  {
740  case 1:
741  status = CalcHeightOpenCVMatOnePlane(imgData, height);
742  break;
743 
744  case 2:
745  status = CalcHeightOpenCVMatTwoPlanes(imgData, height);
746  break;
747 
748  case 3:
749  status = CalcHeightOpenCVMatThreePlanes(imgData, height);
750  break;
751 
752  default:
754  }
755 
756  if (status == VPI_SUCCESS)
757  {
758  int cvType = ToOpenCVType(imgData.planes[0].pixelType);
759  if (cvType == -1)
760  {
762  }
763 
764  mat = cv::Mat(height, imgData.planes[0].width, cvType, imgData.planes[0].data, imgData.planes[0].pitchBytes);
765  }
766 
767  return status;
768 }
769 
770 inline VPIStatus ExportOpenCVMatPlanes(const VPIImageData &imgData, std::vector<cv::Mat> &mat)
771 {
772  if (imgData.numPlanes > VPI_MAX_PLANE_COUNT)
773  {
775  }
776 
777  int cvTypes[VPI_MAX_PLANE_COUNT];
778  for (int i = 0; i < imgData.numPlanes; ++i)
779  {
780  cvTypes[i] = ToOpenCVType(imgData.planes[i].pixelType);
781 
782  if (cvTypes[i] == -1)
783  {
785  }
786  }
787 
788  mat.resize(imgData.numPlanes);
789 
790  for (int i = 0; i < imgData.numPlanes; ++i)
791  {
792  mat[i] = cv::Mat(imgData.planes[i].height, imgData.planes[i].width, cvTypes[i], imgData.planes[i].data,
793  imgData.planes[i].pitchBytes);
794  }
795 
796  return VPI_SUCCESS;
797 }
798 
799 }}} // namespace nv::vpi::detail
800 
801 #endif // NV_VPI_DETAIL_OPENCV_UTILS_HPP
VPIPixelType vpiImageFormatGetPlanePixelType(VPIImageFormat fmt, int plane)
Get the pixel type of image format's plane.
VPIChromaSubsampling vpiImageFormatGetChromaSubsampling(VPIImageFormat fmt)
Get the image format's chroma subsampling type.
VPIMemLayout vpiImageFormatGetMemLayout(VPIImageFormat fmt)
Get the image format's memory layout.
VPIPacking vpiImageFormatGetPlanePacking(VPIImageFormat fmt, int plane)
Get the packing for a given plane of an image format.
#define VPI_MAKE_COLOR_IMAGE_FORMAT_ABBREV(colorModel, colorSpec, memLayout, dataType, swizzle, numPlanes, packing0, packing1,...)
Creates a user-defined color image format constant using abbreviated parameters.
Definition: ImageFormat.h:374
#define VPI_MAKE_NONCOLOR_IMAGE_FORMAT_ABBREV(memLayout, dataType, swizzle, numPlanes, packing0, packing1,...)
Creates a user-defined non-color image format constant using abbreviated parameters.
Definition: ImageFormat.h:430
int vpiImageFormatGetPlaneCount(VPIImageFormat fmt)
Get the number of planes of an image format.
VPIMemLayout vpiPixelTypeGetMemLayout(VPIPixelType type)
Get the memory layout of a pixel type.
VPIPacking vpiPixelTypeGetPacking(VPIPixelType type)
Get the packing of a pixel type.
VPIDataType vpiPixelTypeGetDataType(VPIPixelType type)
Get the data type of a pixel type.
int vpiPixelTypeGetBitsPerPixel(VPIPixelType type)
Get the number of bits per pixel of a pixel type.
VPIChromaSubsampling
Defines how chroma-subsampling is done.
Definition: ColorSpec.h:398
int vpiChromaSubsamplingGetSamplesVert(VPIChromaSubsampling css)
Get the number of chroma samples for each group of 4 vertical luma samples.
int vpiChromaSubsamplingGetSamplesHoriz(VPIChromaSubsampling css)
Get the number of chroma samples for each group of 4 horizontal luma samples.
VPIDataType
Defines the channel data type.
Definition: DataLayout.h:210
@ VPI_PACKING_X64
One 64-bit channel.
Definition: DataLayout.h:188
@ VPI_PACKING_X8_Y8_Z8_W8
Four 8-bit channels in one 32-bit word.
Definition: DataLayout.h:181
@ VPI_PACKING_X8_Y8_Z8
Three 8-bit channels in three 8-bit words.
Definition: DataLayout.h:169
@ VPI_PACKING_X32_Y32_Z32_W32
Four 32-bit channels in three 32-bit words.
Definition: DataLayout.h:197
@ VPI_PACKING_X8
One 8-bit channel.
Definition: DataLayout.h:137
@ VPI_PACKING_X32_Y32_Z32
Three 32-bit channels in three 32-bit words.
Definition: DataLayout.h:193
@ VPI_PACKING_X32
One 32-bit channel.
Definition: DataLayout.h:171
@ VPI_PACKING_X8_Y8
Two 8-bit channels in two 8-bit words.
Definition: DataLayout.h:150
@ VPI_PACKING_X64_Y64_Z64
Three 64-bit channels in three 64-bit words.
Definition: DataLayout.h:200
@ VPI_PACKING_X64_Y64_Z64_W64
Four 64-bit channels in four 64-bit words.
Definition: DataLayout.h:203
@ VPI_PACKING_X16_Y16_Z16
Three 16-bit channels in three 16-bit words.
Definition: DataLayout.h:186
@ VPI_PACKING_X16
One 16-bit channel.
Definition: DataLayout.h:143
@ VPI_PACKING_X16_Y16
Two 16-bit channels in two 16-bit words.
Definition: DataLayout.h:174
@ VPI_PACKING_X16_Y16_Z16_W16
Four 16-bit channels in one 64-bit word.
Definition: DataLayout.h:190
@ VPI_PACKING_X8_Y8__X8_Z8
2 pixels of 2 8-bit channels each, totalling 4 8-bit words.
Definition: DataLayout.h:164
@ VPI_PACKING_X32_Y32
Two 32-bit channels in two 32-bit words.
Definition: DataLayout.h:189
@ VPI_PACKING_Y8_X8__Z8_X8
2 pixels of 2 swapped 8-bit channels each, totalling 4 8-bit words.
Definition: DataLayout.h:165
@ VPI_MEM_LAYOUT_PITCH_LINEAR
Pixels are laid out in row-major order, i.e., .
Definition: DataLayout.h:230
@ VPI_DATA_TYPE_FLOAT
Channel are floating point values.
Definition: DataLayout.h:214
@ VPI_DATA_TYPE_UNSIGNED
Channels are unsigned integer values.
Definition: DataLayout.h:212
@ VPI_DATA_TYPE_SIGNED
Channels are signed integer values.
Definition: DataLayout.h:213
VPIImageFormat
Pre-defined image formats.
Definition: ImageFormat.h:99
VPIPixelType
Pre-defined pixel types.
Definition: PixelType.h:84
@ VPI_IMAGE_FORMAT_BGR8
Single plane with interleaved BGR 8-bit channel.
Definition: ImageFormat.h:278
@ VPI_IMAGE_FORMAT_INVALID
Denotes an invalid image format.
Definition: ImageFormat.h:101
@ VPI_IMAGE_FORMAT_U16
Single plane with one 16-bit unsigned integer channel.
Definition: ImageFormat.h:110
@ VPI_IMAGE_FORMAT_U8
Single plane with one 8-bit unsigned integer channel.
Definition: ImageFormat.h:104
@ VPI_IMAGE_FORMAT_2F32
Single plane with two interleaved 32-bit floating point channels.
Definition: ImageFormat.h:134
@ VPI_IMAGE_FORMAT_BGRA8
Single plane with interleaved BGRA 8-bit channel.
Definition: ImageFormat.h:284
@ VPI_IMAGE_FORMAT_S16
Single plane with one 16-bit signed integer channel.
Definition: ImageFormat.h:113
@ VPI_IMAGE_FORMAT_F32
Single plane with one 32-bit floating point channel.
Definition: ImageFormat.h:128
@ VPI_IMAGE_FORMAT_S8
Single plane with one 8-bit signed integer channel.
Definition: ImageFormat.h:107
int32_t height
Height of this plane in pixels.
Definition: Image.h:138
VPIPixelType pixelType
Type of each pixel within this plane.
Definition: Image.h:136
int32_t numPlanes
Number of planes.
Definition: Image.h:161
int32_t width
Width of this plane in pixels.
Definition: Image.h:137
void * data
Pointer to the first row of this plane.
Definition: Image.h:147
int32_t pitchBytes
Difference in bytes of beginning of one row and the beginning of the previous.
Definition: Image.h:139
VPIImagePlane planes[VPI_MAX_PLANE_COUNT]
Data of all image planes.
Definition: Image.h:166
VPIImageFormat format
Image format.
Definition: Image.h:160
#define VPI_MAX_PLANE_COUNT
Maximum number of data planes an image can have.
Definition: Image.h:155
Stores information about image characteristics and content.
Definition: Image.h:159
VPIStatus
Status codes.
Definition: Status.h:81
@ VPI_SUCCESS
Operation completed successfully.
Definition: Status.h:82
@ VPI_ERROR_INTERNAL
Internal, non specific error.
Definition: Status.h:94
@ VPI_ERROR_INVALID_ARGUMENT
Invalid argument, either wrong range or value not accepted.
Definition: Status.h:84
@ VPI_ERROR_INVALID_IMAGE_FORMAT
Image type not accepted.
Definition: Status.h:85