Face Engine SDK
5.23.1
A face detection, recognition and tracking engine.
|
00001 #pragma once 00002 00003 #include <cassert> 00004 #include <cstring> 00005 00006 namespace fsdk { 00007 00011 struct Format { 00012 00015 enum Type { 00017 Unknown, 00018 00020 B8G8R8X8, 00021 00023 R8G8B8X8, 00024 00026 B8G8R8, 00027 00029 R8G8B8, 00030 00032 R8, 00033 00035 R16, 00036 00038 IR_X8X8X8, 00039 00042 YUV_NV21, 00043 00046 YUV_NV12 00047 }; 00048 00053 const char* toString() const noexcept { 00054 switch(m_type) { 00055 case Type::B8G8R8X8: 00056 return "B8G8R8X8"; 00057 case Type::R8G8B8X8: 00058 return "R8G8B8X8"; 00059 case Type::B8G8R8: 00060 return "B8G8R8"; 00061 case Type::R8G8B8: 00062 return "R8G8B8"; 00063 case Type::R8: 00064 return "R8"; 00065 case Type::R16: 00066 return "R16"; 00067 case Type::IR_X8X8X8: 00068 return "IR_X8X8X8"; 00069 case Type::YUV_NV21: 00070 return "YUV_NV21"; 00071 case Type::YUV_NV12: 00072 return "YUV_NV12"; 00073 default: 00074 return "Unknown"; 00075 } 00076 } 00077 00084 static Format fromString(const char* str) noexcept { 00085 if(strcmp(str, "B8G8R8X8") == 0) { 00086 return Format{Type::B8G8R8X8}; 00087 } else if(strcmp(str, "R8G8B8X8") == 0) { 00088 return Format{Type::R8G8B8X8}; 00089 } else if(strcmp(str, "B8G8R8") == 0) { 00090 return Format{Type::B8G8R8}; 00091 } else if(strcmp(str, "R8G8B8") == 0) { 00092 return Format{Type::R8G8B8}; 00093 } else if(strcmp(str, "R8") == 0) { 00094 return Format{Type::R8}; 00095 } else if(strcmp(str, "R16") == 0) { 00096 return Format{Type::R16}; 00097 } else if(strcmp(str, "IR_X8X8X8") == 0) { 00098 return Format{Type::IR_X8X8X8}; 00099 } else if(strcmp(str, "YUV_NV21") == 0) { 00100 return Format{Type::YUV_NV21}; 00101 } else if(strcmp(str, "YUV_NV12") == 0) { 00102 return Format{Type::YUV_NV12}; 00103 } else { 00104 return Format{Type::Unknown}; 00105 } 00106 } 00107 00114 int getChannelCount() const noexcept { 00115 switch(m_type) { 00116 case B8G8R8X8: 00117 case R8G8B8X8: 00118 case B8G8R8: 00119 case R8G8B8: 00120 case IR_X8X8X8: 00121 case YUV_NV21: 00122 case YUV_NV12: 00123 return 3; 00124 case R8: 00125 case R16: 00126 return 1; 00127 default: 00128 return 0; 00129 } 00130 } 00131 00136 int getChannelStep() const noexcept { 00137 switch(m_type) { 00138 case B8G8R8X8: 00139 case R8G8B8X8: 00140 return 4; 00141 case B8G8R8: 00142 case R8G8B8: 00143 case IR_X8X8X8: 00144 return 3; 00145 case R8: 00146 case R16: 00147 case YUV_NV21: 00148 case YUV_NV12: 00149 return 1; 00150 default: 00151 return 0; 00152 } 00153 } 00154 00158 int getChannelSize() const noexcept { 00159 switch(m_type) { 00160 case B8G8R8X8: 00161 case R8G8B8X8: 00162 case B8G8R8: 00163 case R8G8B8: 00164 case IR_X8X8X8: 00165 case R8: 00166 return 8; 00167 case R16: 00168 return 16; 00169 case YUV_NV21: 00170 case YUV_NV12: 00171 return 12; 00172 default: 00173 return 0; 00174 } 00175 } 00176 00180 int getBitDepth() const noexcept { 00181 return getChannelStep() * getChannelSize(); 00182 } 00183 00187 int getByteDepth() const noexcept { 00188 if(isBlock()) { 00189 assert(!"Not implemented"); 00190 return 0; 00191 } else { 00192 return getBitDepth() >> 3; 00193 } 00194 } 00195 00200 int computePitch(int rowWidth) const noexcept { 00201 return rowWidth * getByteDepth(); 00202 } 00203 00206 bool isPadded() const noexcept { 00207 switch(m_type) { 00208 case B8G8R8X8: 00209 case R8G8B8X8: 00210 return true; 00211 default: 00212 return false; 00213 } 00214 } 00215 00220 bool isBGR() const noexcept { 00221 switch(m_type) { 00222 case B8G8R8X8: 00223 case B8G8R8: 00224 return true; 00225 default: 00226 return false; 00227 } 00228 } 00229 00232 bool isYUV() const noexcept { 00233 switch(m_type) { 00234 case YUV_NV21: 00235 case YUV_NV12: 00236 return true; 00237 default: 00238 return false; 00239 } 00240 } 00241 00246 bool isBlock() const noexcept { 00247 return false; 00248 } 00249 00253 bool isValid() const noexcept { 00254 return m_type != Unknown; 00255 } 00256 00260 Format() noexcept 00261 : m_type(Unknown) { 00262 } 00263 00267 Format(Type type) noexcept 00268 : m_type(type) { 00269 } 00270 00272 operator Type() const noexcept { 00273 return m_type; 00274 } 00275 00276 protected: 00277 Type m_type; 00278 }; 00279 00280 constexpr int format_as(Format::Type in) { 00281 return static_cast<int>(in); 00282 } 00283 } // namespace fsdk