Face Engine SDK  5.21.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Format.h
1 #pragma once
2 
3 #include <cassert>
4 
5 namespace fsdk {
6 
10  struct Format {
11 
14  enum Type {
17 
20 
23 
26 
29 
31  R8,
32 
34  R16,
35 
38 
42 
45  YUV_NV12
46  };
47 
52  const char* toString() const noexcept {
53  switch(m_type) {
54  case Type::B8G8R8X8:
55  return "B8G8R8X8";
56  case Type::R8G8B8X8:
57  return "R8G8B8X8";
58  case Type::B8G8R8:
59  return "B8G8R8";
60  case Type::R8G8B8:
61  return "R8G8B8";
62  case Type::R8:
63  return "R8";
64  case Type::R16:
65  return "R16";
66  case Type::IR_X8X8X8:
67  return "IR_X8X8X8";
68  case Type::YUV_NV21:
69  return "YUV_NV21";
70  case Type::YUV_NV12:
71  return "YUV_NV12";
72  default:
73  return "Unknown";
74  }
75  }
76 
83  int getChannelCount() const noexcept {
84  switch(m_type) {
85  case B8G8R8X8:
86  case R8G8B8X8:
87  case B8G8R8:
88  case R8G8B8:
89  case IR_X8X8X8:
90  case YUV_NV21:
91  case YUV_NV12:
92  return 3;
93  case R8:
94  case R16:
95  return 1;
96  default:
97  return 0;
98  }
99  }
100 
105  int getChannelStep() const noexcept {
106  switch(m_type) {
107  case B8G8R8X8:
108  case R8G8B8X8:
109  return 4;
110  case B8G8R8:
111  case R8G8B8:
112  case IR_X8X8X8:
113  return 3;
114  case R8:
115  case R16:
116  case YUV_NV21:
117  case YUV_NV12:
118  return 1;
119  default:
120  return 0;
121  }
122  }
123 
127  int getChannelSize() const noexcept {
128  switch(m_type) {
129  case B8G8R8X8:
130  case R8G8B8X8:
131  case B8G8R8:
132  case R8G8B8:
133  case IR_X8X8X8:
134  case R8:
135  return 8;
136  case R16:
137  return 16;
138  case YUV_NV21:
139  case YUV_NV12:
140  return 12;
141  default:
142  return 0;
143  }
144  }
145 
149  int getBitDepth() const noexcept {
150  return getChannelStep() * getChannelSize();
151  }
152 
156  int getByteDepth() const noexcept {
157  if(isBlock()) {
158  assert(!"Not implemented");
159  return 0;
160  } else {
161  return getBitDepth() >> 3;
162  }
163  }
164 
169  int computePitch(int rowWidth) const noexcept {
170  return rowWidth * getByteDepth();
171  }
172 
175  bool isPadded() const noexcept {
176  switch(m_type) {
177  case B8G8R8X8:
178  case R8G8B8X8:
179  return true;
180  default:
181  return false;
182  }
183  }
184 
189  bool isBGR() const noexcept {
190  switch(m_type) {
191  case B8G8R8X8:
192  case B8G8R8:
193  return true;
194  default:
195  return false;
196  }
197  }
198 
201  bool isYUV() const noexcept {
202  switch(m_type) {
203  case YUV_NV21:
204  case YUV_NV12:
205  return true;
206  default:
207  return false;
208  }
209  }
210 
215  bool isBlock() const noexcept {
216  return false;
217  }
218 
222  bool isValid() const noexcept {
223  return m_type != Unknown;
224  }
225 
229  Format() noexcept
230  : m_type(Unknown) {
231  }
232 
236  Format(Type type) noexcept
237  : m_type(type) {
238  }
239 
241  operator Type() const noexcept {
242  return m_type;
243  }
244 
245  protected:
247  };
248 
249  constexpr int format_as(Format::Type in) {
250  return static_cast<int>(in);
251  }
252 } // namespace fsdk
int getBitDepth() const noexcept
Get number of bits per pixel.
Definition: Format.h:149
int getChannelSize() const noexcept
Get color channel size in bits.
Definition: Format.h:127
1 channel, 8 bit per channel format;
Definition: Format.h:28
unknown format.
Definition: Format.h:16
int getChannelStep() const noexcept
Get channel step.
Definition: Format.h:105
bool isBlock() const noexcept
Definition: Format.h:215
Format() noexcept
Initializes format structure.
Definition: Format.h:229
int computePitch(int rowWidth) const noexcept
Compute row size in bytes.
Definition: Format.h:169
bool isValid() const noexcept
Definition: Format.h:222
Image format.
Definition: Format.h:10
bool isBGR() const noexcept
Definition: Format.h:189
int getChannelCount() const noexcept
Get color channel count.
Definition: Format.h:83
int getByteDepth() const noexcept
Get number of bytes per pixel.
Definition: Format.h:156
3 channel, 8 bit per channel, R-G-B color order format;
Definition: Format.h:25
Type
Format type enumeration.
Definition: Format.h:14
Type m_type
Format type.
Definition: Format.h:246
bool isPadded() const noexcept
Definition: Format.h:175
1 channel, 16 bit per channel format;
Definition: Format.h:31
3 channel, 8 bit per channel, R-G-B color order format with 8 bit padding before next pixel; ...
Definition: Format.h:19
3 channel, 8 bit per channel format with InfraRed semantics;
Definition: Format.h:34
3 channel, 8 bit per channel, B-G-R color order format;
Definition: Format.h:22
Definition: Format.h:41
bool isYUV() const noexcept
Definition: Format.h:201
const char * toString() const noexcept
Returns a string representation of a Format type.
Definition: Format.h:52
Format(Type type) noexcept
Initializes format structure.
Definition: Format.h:236
Definition: Format.h:37