| Face Engine SDK 5.32.0 A face detection, recognition and tracking engine.

Format.h
1 #pragma once
2
3 #include <cassert>
4 #include <cstring>
5
6 namespace fsdk {
7
11 struct Format {
12
15 enum Type {
17 Unknown,
18
20 B8G8R8X8,
21
23 R8G8B8X8,
24
26 B8G8R8,
27
29 R8G8B8,
30
32 R8,
33
35 R16,
36
38 IR_X8X8X8,
39
42 YUV_NV21,
43
46 YUV_NV12
47 };
48
53 const char* toString() const noexcept {
54 switch(m_type) {
55 case Type::B8G8R8X8:
56 return "B8G8R8X8";
57 case Type::R8G8B8X8:
58 return "R8G8B8X8";
59 case Type::B8G8R8:
60 return "B8G8R8";
61 case Type::R8G8B8:
62 return "R8G8B8";
63 case Type::R8:
64 return "R8";
65 case Type::R16:
66 return "R16";
67 case Type::IR_X8X8X8:
68 return "IR_X8X8X8";
69 case Type::YUV_NV21:
70 return "YUV_NV21";
71 case Type::YUV_NV12:
72 return "YUV_NV12";
73 default:
74 return "Unknown";
75 }
76 }
77
84 static Format fromString(const char* str) noexcept {
85 if(strcmp(str, "B8G8R8X8") == 0) {
86 return Format{Type::B8G8R8X8};
87 } else if(strcmp(str, "R8G8B8X8") == 0) {
88 return Format{Type::R8G8B8X8};
89 } else if(strcmp(str, "B8G8R8") == 0) {
90 return Format{Type::B8G8R8};
91 } else if(strcmp(str, "R8G8B8") == 0) {
92 return Format{Type::R8G8B8};
93 } else if(strcmp(str, "R8") == 0) {
94 return Format{Type::R8};
95 } else if(strcmp(str, "R16") == 0) {
96 return Format{Type::R16};
97 } else if(strcmp(str, "IR_X8X8X8") == 0) {
98 return Format{Type::IR_X8X8X8};
99 } else if(strcmp(str, "YUV_NV21") == 0) {
100 return Format{Type::YUV_NV21};
101 } else if(strcmp(str, "YUV_NV12") == 0) {
102 return Format{Type::YUV_NV12};
103 } else {
104 return Format{Type::Unknown};
105 }
106 }
107
114 int getChannelCount() const noexcept {
115 switch(m_type) {
116 case B8G8R8X8:
117 case R8G8B8X8:
118 case B8G8R8:
119 case R8G8B8:
120 case IR_X8X8X8:
121 case YUV_NV21:
122 case YUV_NV12:
123 return 3;
124 case R8:
125 case R16:
126 return 1;
127 default:
128 return 0;
129 }
130 }
131
136 int getChannelStep() const noexcept {
137 switch(m_type) {
138 case B8G8R8X8:
139 case R8G8B8X8:
140 return 4;
141 case B8G8R8:
142 case R8G8B8:
143 case IR_X8X8X8:
144 return 3;
145 case R8:
146 case R16:
147 case YUV_NV21:
148 case YUV_NV12:
149 return 1;
150 default:
151 return 0;
152 }
153 }
154
158 int getChannelSize() const noexcept {
159 switch(m_type) {
160 case B8G8R8X8:
161 case R8G8B8X8:
162 case B8G8R8:
163 case R8G8B8:
164 case IR_X8X8X8:
165 case R8:
166 return 8;
167 case R16:
168 return 16;
169 case YUV_NV21:
170 case YUV_NV12:
171 return 12;
172 default:
173 return 0;
174 }
175 }
176
180 int getBitDepth() const noexcept {
181 return getChannelStep() * getChannelSize();
182 }
183
187 int getByteDepth() const noexcept {
188 if(isBlock()) {
189 assert(!"Not implemented");
190 return 0;
191 } else {
192 return getBitDepth() >> 3;
193 }
194 }
195
200 int computePitch(int rowWidth) const noexcept {
201 return rowWidth * getByteDepth();
202 }
203
206 bool isPadded() const noexcept {
207 switch(m_type) {
208 case B8G8R8X8:
209 case R8G8B8X8:
210 return true;
211 default:
212 return false;
213 }
214 }
215
220 bool isBGR() const noexcept {
221 switch(m_type) {
222 case B8G8R8X8:
223 case B8G8R8:
224 return true;
225 default:
226 return false;
227 }
228 }
229
232 bool isYUV() const noexcept {
233 switch(m_type) {
234 case YUV_NV21:
235 case YUV_NV12:
236 return true;
237 default:
238 return false;
239 }
240 }
241
246 bool isBlock() const noexcept {
247 return false;
248 }
249
253 bool isValid() const noexcept {
254 return m_type != Unknown;
255 }
256
260 Format() noexcept
261 : m_type(Unknown) {
262 }
263
267 Format(Type type) noexcept
268 : m_type(type) {
269 }
270
272 operator Type() const noexcept {
273 return m_type;
274 }
275
276 protected:
277 Type m_type;
278 };
279
280 constexpr int format_as(Format::Type in) {
281 return static_cast<int>(in);
282 }
283 } // namespace fsdk
fsdk::Format::getBitDepth
int getBitDepth() const noexcept
Get number of bits per pixel.
Definition: Format.h:180
fsdk::Format::getChannelSize
int getChannelSize() const noexcept
Get color channel size in bits.
Definition: Format.h:158
fsdk::Format::R8G8B8
1 channel, 8 bit per channel format;
Definition: Format.h:29
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Format::Unknown
unknown format.
Definition: Format.h:17
fsdk::Format::getChannelStep
int getChannelStep() const noexcept
Get channel step.
Definition: Format.h:136
fsdk::Format::isBlock
bool isBlock() const noexcept
Definition: Format.h:246
fsdk::Format::Format
Format() noexcept
Initializes format structure.
Definition: Format.h:260
fsdk::Format::computePitch
int computePitch(int rowWidth) const noexcept
Compute row size in bytes.
Definition: Format.h:200
fsdk::Format::isValid
bool isValid() const noexcept
Definition: Format.h:253
fsdk::Format
Image format.
Definition: Format.h:11
fsdk::Format::isBGR
bool isBGR() const noexcept
Definition: Format.h:220
fsdk::Format::getChannelCount
int getChannelCount() const noexcept
Get color channel count.
Definition: Format.h:114
fsdk::Format::getByteDepth
int getByteDepth() const noexcept
Get number of bytes per pixel.
Definition: Format.h:187
fsdk::Format::B8G8R8
3 channel, 8 bit per channel, R-G-B color order format;
Definition: Format.h:26
fsdk::Format::Type
Type
Format type enumeration.
Definition: Format.h:15
fsdk::Format::m_type
Type m_type
Format type.
Definition: Format.h:277
fsdk::Format::isPadded
bool isPadded() const noexcept
Definition: Format.h:206
fsdk::Format::fromString
static Format fromString(const char *str) noexcept
Creates a Format object by parsing a string representation.
Definition: Format.h:84
fsdk::Format::R8
1 channel, 16 bit per channel format;
Definition: Format.h:32
fsdk::Format::B8G8R8X8
3 channel, 8 bit per channel, R-G-B color order format with 8 bit padding before next pixel; ...
Definition: Format.h:20
fsdk::Format::R16
3 channel, 8 bit per channel format with InfraRed semantics;
Definition: Format.h:35
fsdk::Format::R8G8B8X8
3 channel, 8 bit per channel, B-G-R color order format;
Definition: Format.h:23
fsdk::Format::YUV_NV21
Definition: Format.h:42
fsdk::Format::isYUV
bool isYUV() const noexcept
Definition: Format.h:232
fsdk::Format::toString
const char * toString() const noexcept
Returns a string representation of a Format type.
Definition: Format.h:53
fsdk::Format::Format
Format(Type type) noexcept
Initializes format structure.
Definition: Format.h:267
fsdk::Format::IR_X8X8X8
Definition: Format.h:38