Jetson Inference
DNN Vision Library
imageFormat.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __IMAGE_FORMAT_H_
24 #define __IMAGE_FORMAT_H_
25 
26 
27 // include vector types (float4, float3, uchar4, uchar3, ect.)
28 #include "cudaUtility.h"
29 
30 
50 {
51  // RGB
57  // BGR
63  // YUV
72  // Bayer
78  // grayscale
82  // extras
86 };
87 
98 {
101 };
102 
109 
115 inline const char* imageFormatToStr( imageFormat format );
116 
123 inline imageFormat imageFormatFromStr( const char* str );
124 
130 inline size_t imageFormatChannels( imageFormat format );
131 
145 inline size_t imageFormatDepth( imageFormat format );
146 
151 inline size_t imageFormatSize( imageFormat format, size_t width, size_t height );
152 
161 inline bool imageFormatIsRGB( imageFormat format );
162 
171 inline bool imageFormatIsBGR( imageFormat format );
172 
181 inline bool imageFormatIsYUV( imageFormat format );
182 
190 inline bool imageFormatIsGray( imageFormat format );
191 
200 inline bool imageFormatIsBayer( imageFormat format );
201 
209 inline void imageFormatErrorMsg( const char* module, const char* function, imageFormat format );
210 
211 
217 
219 
220 // get the IMAGE_RGB* formats from uchar3/uchar4/float3/float4
221 template<typename T> inline imageFormat imageFormatFromType();
222 
223 template<> inline imageFormat imageFormatFromType<uchar3>();
224 template<> inline imageFormat imageFormatFromType<uchar4>();
225 template<> inline imageFormat imageFormatFromType<float3>();
226 template<> inline imageFormat imageFormatFromType<float4>();
227 
228 // templated version of base type / vector type
229 template<imageFormat format> struct imageFormatType;
230 
231 template<> struct imageFormatType<IMAGE_RGB8> { typedef uint8_t Base; typedef uchar3 Vector; };
232 template<> struct imageFormatType<IMAGE_RGBA8> { typedef uint8_t Base; typedef uchar4 Vector; };
233 
234 template<> struct imageFormatType<IMAGE_RGB32F> { typedef float Base; typedef float3 Vector; };
235 template<> struct imageFormatType<IMAGE_RGBA32F> { typedef float Base; typedef float4 Vector; };
236 
238 
239 // inline implementations
240 #include "imageFormat.inl"
241 
242 
243 #endif
244 
uint8_t Base
Definition: imageFormat.h:232
8-bit Bayer GBRG (&#39;bayer-gbrg&#39;)
Definition: imageFormat.h:74
size_t imageFormatDepth(imageFormat format)
Get the pixel bit depth (in bits, not bytes).
float grayscale (&#39;gray32f&#39;)
Definition: imageFormat.h:80
imageFormat imageFormatFromType< float4 >()
uchar3 Vector
Definition: imageFormat.h:231
Definition: imageFormat.h:100
imageFormat imageFormatFromStr(const char *str)
Parse an imageFormat enum from a string.
bool imageFormatIsBayer(imageFormat format)
Check if an image format is one of the Bayer formats.
Definition: imageFormat.h:229
imageBaseType
The imageBaseType enum is used to identify the base data type of an imageFormat - either uint8 or flo...
Definition: imageFormat.h:97
bool imageFormatIsRGB(imageFormat format)
Check if an image format is one of the RGB/RGBA formats.
8-bit Bayer GRBG (&#39;bayer-grbg&#39;)
Definition: imageFormat.h:75
float3 RGB32F (&#39;rgb32f&#39;)
Definition: imageFormat.h:54
float4 BGRA32F (&#39;bgra32f&#39;)
Definition: imageFormat.h:61
imageFormat imageFormatFromType< uchar3 >()
The number of image formats.
Definition: imageFormat.h:83
uint8 grayscale (&#39;gray8&#39;)
Definition: imageFormat.h:79
YUV YVYU 4:2:2 packed (&#39;yvyu&#39;)
Definition: imageFormat.h:66
bool imageFormatIsBGR(imageFormat format)
Check if an image format is one of the BGR/BGRA formats.
Default format (IMAGE_RGBA32F)
Definition: imageFormat.h:85
const char * imageFormatToStr(imageFormat format)
Convert an imageFormat enum to a string.
imageBaseType imageFormatBaseType(imageFormat format)
Get the base type of an image format (uint8 or float).
size_t imageFormatChannels(imageFormat format)
Get the number of image channels in each format.
Definition: imageFormat.h:99
bool imageFormatIsYUV(imageFormat format)
Check if an image format is one of the YUV formats.
float3 Vector
Definition: imageFormat.h:234
void imageFormatErrorMsg(const char *module, const char *function, imageFormat format)
Print out an error message that the image format isn&#39;t supported.
uchar4 Vector
Definition: imageFormat.h:232
imageFormat imageFormatFromType()
float3 BGR32F (&#39;bgr32f&#39;)
Definition: imageFormat.h:60
uchar3 BGR8 (&#39;bgr8&#39;)
Definition: imageFormat.h:58
float4 Vector
Definition: imageFormat.h:235
size_t imageFormatSize(imageFormat format, size_t width, size_t height)
Compute the size of an image (in bytes)
uchar4 BGRA8 (&#39;bgra8&#39;)
Definition: imageFormat.h:59
8-bit Bayer BGGR (&#39;bayer-bggr&#39;)
Definition: imageFormat.h:73
imageFormat imageFormatFromType< float3 >()
uchar4 RGBA8 (&#39;rgba8&#39;)
Definition: imageFormat.h:53
bool imageFormatIsGray(imageFormat format)
Check if an image format is one of the grayscale formats.
YUV NV12 4:2:0 planar (&#39;nv12&#39;)
Definition: imageFormat.h:70
YUV YUYV 4:2:2 packed (&#39;yuyv&#39;)
Definition: imageFormat.h:64
8-bit Bayer RGGB (&#39;bayer-rggb&#39;)
Definition: imageFormat.h:76
YUV UYVY 4:2:2 packed (&#39;uyvy&#39;)
Definition: imageFormat.h:67
float4 RGBA32F (&#39;rgba32f&#39;)
Definition: imageFormat.h:55
Unknown/undefined format.
Definition: imageFormat.h:84
uchar3 RGB8 (&#39;rgb8&#39;)
Definition: imageFormat.h:52
YUV I420 4:2:0 planar (&#39;i420&#39;)
Definition: imageFormat.h:68
imageFormat imageFormatFromType< uchar4 >()
float Base
Definition: imageFormat.h:234
YUV YV12 4:2:0 planar (&#39;yv12&#39;)
Definition: imageFormat.h:69
float Base
Definition: imageFormat.h:235
uint8_t Base
Definition: imageFormat.h:231
Duplicate of YUYV (&#39;yuy2&#39;)
Definition: imageFormat.h:65
imageFormat
The imageFormat enum is used to identify the pixel format and colorspace of an image.
Definition: imageFormat.h:49