Face Engine SDK  5.14.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 {
7 
11 struct Format {
12 
15  enum Type {
21  R8,
22  R16,
26  };
27 
32  const char* toString () const noexcept {
33  switch(m_type) {
34  case Type::B8G8R8X8: return "B8G8R8X8";
35  case Type::R8G8B8X8: return "R8G8B8X8";
36  case Type::B8G8R8: return "B8G8R8";
37  case Type::R8G8B8: return "R8G8B8";
38  case Type::R8: return "R8";
39  case Type::R16: return "R16";
40  case Type::IR_X8X8X8: return "IR_X8X8X8";
41  case Type::YUV_NV21: return "YUV_NV21";
42  case Type::YUV_NV12: return "YUV_NV12";
43  default: return "Unknown";
44  }
45  }
46 
53  int getChannelCount() const noexcept {
54  switch(m_type) {
55  case B8G8R8X8:
56  case R8G8B8X8:
57  case B8G8R8:
58  case R8G8B8:
59  case IR_X8X8X8:
60  case YUV_NV21:
61  case YUV_NV12:
62  return 3;
63  case R8:
64  case R16:
65  return 1;
66  default:
67  return 0;
68  }
69  }
70 
75  int getChannelStep() const noexcept {
76  switch(m_type) {
77  case B8G8R8X8:
78  case R8G8B8X8:
79  return 4;
80  case B8G8R8:
81  case R8G8B8:
82  case IR_X8X8X8:
83  return 3;
84  case R8:
85  case R16:
86  case YUV_NV21:
87  case YUV_NV12:
88  return 1;
89  default:
90  return 0;
91  }
92  }
93 
97  int getChannelSize() const noexcept {
98  switch(m_type) {
99  case B8G8R8X8:
100  case R8G8B8X8:
101  case B8G8R8:
102  case R8G8B8:
103  case IR_X8X8X8:
104  case R8:
105  return 8;
106  case R16:
107  return 16;
108  case YUV_NV21:
109  case YUV_NV12:
110  return 12;
111  default:
112  return 0;
113  }
114  }
115 
119  int getBitDepth() const noexcept {
120  return getChannelStep() * getChannelSize();
121  }
122 
126  int getByteDepth() const noexcept {
127  if(isBlock()) {
128  assert(!"Not implemented");
129  return 0;
130  }
131  else {
132  return getBitDepth() >> 3;
133  }
134  }
135 
140  int computePitch(int rowWidth) const noexcept {
141  return rowWidth * getByteDepth();
142  }
143 
146  bool isPadded() const noexcept {
147  switch(m_type) {
148  case B8G8R8X8:
149  case R8G8B8X8:
150  return true;
151  default:
152  return false;
153  }
154  }
155 
160  bool isBGR() const noexcept {
161  switch(m_type) {
162  case B8G8R8X8:
163  case B8G8R8:
164  return true;
165  default:
166  return false;
167  }
168  }
169 
172  bool isYUV() const noexcept {
173  switch(m_type) {
174  case YUV_NV21:
175  case YUV_NV12:
176  return true;
177  default:
178  return false;
179  }
180  }
181 
186  bool isBlock() const noexcept {
187  return false;
188  }
189 
193  bool isValid() const noexcept {
194  return m_type != Unknown;
195  }
196 
200  Format() noexcept : m_type(Unknown) {}
201 
205  Format(Type type) noexcept : m_type(type) {}
206 
208  operator Type () const noexcept {
209  return m_type;
210  }
211 
212 protected:
214 };
215 }
216 
217 
int getBitDepth() const noexcept
Get number of bits per pixel.
Definition: Format.h:119
int getChannelSize() const noexcept
Get color channel size in bits.
Definition: Format.h:97
3 channel, 8 bit per channel, R-G-B color order format;
Definition: Format.h:20
unknown format.
Definition: Format.h:16
int getChannelStep() const noexcept
Get channel step.
Definition: Format.h:75
bool isBlock() const noexcept
Definition: Format.h:186
Format() noexcept
Initializes format structure.
Definition: Format.h:200
int computePitch(int rowWidth) const noexcept
Compute row size in bytes.
Definition: Format.h:140
bool isValid() const noexcept
Definition: Format.h:193
Image format.
Definition: Format.h:11
bool isBGR() const noexcept
Definition: Format.h:160
int getChannelCount() const noexcept
Get color channel count.
Definition: Format.h:53
4:2:0 planar format with a plane of 8-bit Y samples followed by interleaved 2x2 subsampled U/V 8-bit ...
Definition: Format.h:25
int getByteDepth() const noexcept
Get number of bytes per pixel.
Definition: Format.h:126
3 channel, 8 bit per channel, B-G-R color order format;
Definition: Format.h:19
Type
Format type enumeration.
Definition: Format.h:15
Type m_type
Format type.
Definition: Format.h:213
bool isPadded() const noexcept
Definition: Format.h:146
1 channel, 8 bit per channel format;
Definition: Format.h:21
3 channel, 8 bit per channel, B-G-R color order format with 8 bit padding before next pixel; ...
Definition: Format.h:17
1 channel, 16 bit per channel format;
Definition: Format.h:22
3 channel, 8 bit per channel, R-G-B color order format with 8 bit padding before next pixel; ...
Definition: Format.h:18
4:2:0 planar format with a plane of 8-bit Y samples followed by interleaved 2x2 subsampled V/U 8-bit ...
Definition: Format.h:24
bool isYUV() const noexcept
Definition: Format.h:172
const char * toString() const noexcept
Returns a string representation of a Format type.
Definition: Format.h:32
Format(Type type) noexcept
Initializes format structure.
Definition: Format.h:205
3 channel, 8 bit per channel format with InfraRed semantics;
Definition: Format.h:23