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

Format.h
1 #pragma once
2
3 #include <cassert>
4
5 namespace fsdk
6 {
7
11 struct Format {
12
15 enum Type {
16 Unknown,
17 B8G8R8X8,
18 R8G8B8X8,
19 B8G8R8,
20 R8G8B8,
21 R8,
22 R16,
23 IR_X8X8X8,
24 YUV_NV21,
25 YUV_NV12
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:
213 Type m_type;
214 };
215 }
216
217
fsdk::Format::getBitDepth
int getBitDepth() const noexcept
Get number of bits per pixel.
Definition: Format.h:119
fsdk::Format::getChannelSize
int getChannelSize() const noexcept
Get color channel size in bits.
Definition: Format.h:97
fsdk::Format::R8G8B8
3 channel, 8 bit per channel, R-G-B color order format;
Definition: Format.h:20
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Format::Unknown
unknown format.
Definition: Format.h:16
fsdk::Format::getChannelStep
int getChannelStep() const noexcept
Get channel step.
Definition: Format.h:75
fsdk::Format::isBlock
bool isBlock() const noexcept
Definition: Format.h:186
fsdk::Format::Format
Format() noexcept
Initializes format structure.
Definition: Format.h:200
fsdk::Format::computePitch
int computePitch(int rowWidth) const noexcept
Compute row size in bytes.
Definition: Format.h:140
fsdk::Format::isValid
bool isValid() const noexcept
Definition: Format.h:193
fsdk::Format
Image format.
Definition: Format.h:11
fsdk::Format::isBGR
bool isBGR() const noexcept
Definition: Format.h:160
fsdk::Format::getChannelCount
int getChannelCount() const noexcept
Get color channel count.
Definition: Format.h:53
fsdk::Format::YUV_NV12
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
fsdk::Format::getByteDepth
int getByteDepth() const noexcept
Get number of bytes per pixel.
Definition: Format.h:126
fsdk::Format::B8G8R8
3 channel, 8 bit per channel, B-G-R color order format;
Definition: Format.h:19
fsdk::Format::Type
Type
Format type enumeration.
Definition: Format.h:15
fsdk::Format::m_type
Type m_type
Format type.
Definition: Format.h:213
fsdk::Format::isPadded
bool isPadded() const noexcept
Definition: Format.h:146
fsdk::Format::R8
1 channel, 8 bit per channel format;
Definition: Format.h:21
fsdk::Format::B8G8R8X8
3 channel, 8 bit per channel, B-G-R color order format with 8 bit padding before next pixel; ...
Definition: Format.h:17
fsdk::Format::R16
1 channel, 16 bit per channel format;
Definition: Format.h:22
fsdk::Format::R8G8B8X8
3 channel, 8 bit per channel, R-G-B color order format with 8 bit padding before next pixel; ...
Definition: Format.h:18
fsdk::Format::YUV_NV21
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
fsdk::Format::isYUV
bool isYUV() const noexcept
Definition: Format.h:172
fsdk::Format::toString
const char * toString() const noexcept
Returns a string representation of a Format type.
Definition: Format.h:32
fsdk::Format::Format
Format(Type type) noexcept
Initializes format structure.
Definition: Format.h:205
fsdk::Format::IR_X8X8X8
3 channel, 8 bit per channel format with InfraRed semantics;
Definition: Format.h:23