Skip to main content

FormatSpec.h File

Typed media/pixel/tensor format tags for public options. More...

Included Headers

#include <algorithm> #include <cctype> #include <ostream> #include <string>

Namespaces Index

namespacesimaai
namespaceneat

Classes Index

structFormatSpec

Thin wrapper around FormatTag with implicit string conversions. More...

Description

Typed media/pixel/tensor format tags for public options.

FormatTag is the framework-wide enum identifying every payload format the pipeline understands: raw video (RGB/BGR/GRAY8/NV12/I420/YUYV), encoded video (H.264, generic ENCODED), tensor element types (FP32/INT8/UINT8/BF16 and their EVXX_ aliases), opaque byte-stream payloads, and a few pipeline-internal payload kinds (MLA, BBOX, ARGMAX, DETESSDEQUANT). FormatSpec is a tiny wrapper that converts implicitly to/from string forms used in caps strings and config files.

See Also

Tensor.h for the underlying Sample/Tensor types.

See Also

Run.h for how format tags appear on RunOptions and stream caps.

File Listing

The file content with the documentation metadata removed is:

1
17#pragma once
18
19#include <algorithm>
20#include <cctype>
21#include <ostream>
22#include <string>
23
24namespace simaai::neat {
25
36enum class FormatTag {
37 Auto = 0,
38 RGB,
39 BGR,
40 GRAY8,
41 NV12,
42 I420,
43 YUYV,
44 ENCODED,
45 H264,
47 MLA,
48 BBOX,
49 ARGMAX,
51 FP32,
52 INT8,
53 UINT8,
54 BF16,
58};
59
61inline const char* format_tag_name(FormatTag tag) {
62 switch (tag) {
64 return "";
66 return "RGB";
68 return "BGR";
70 return "GRAY8";
72 return "NV12";
74 return "I420";
76 return "YUYV";
78 return "ENCODED";
80 return "H264";
82 return "BYTESTREAM";
84 return "MLA";
86 return "BBOX";
88 return "ARGMAX";
90 return "DETESSDEQUANT";
92 return "FP32";
94 return "INT8";
96 return "UINT8";
98 return "BF16";
100 return "EVXX_FLOAT32";
102 return "EVXX_INT8";
104 return "EVXX_BFLOAT16";
105 }
106 return "";
107}
108
110inline std::string format_tag_to_string(FormatTag tag) {
111 return std::string(format_tag_name(tag));
112}
113
115inline std::string upper_copy_ascii(std::string value) {
116 std::transform(value.begin(), value.end(), value.begin(),
117 [](unsigned char c) { return static_cast<char>(std::toupper(c)); });
118 return value;
119}
120
122inline bool tensor_format_is_bf16_alias(std::string value) {
123 const std::string up = upper_copy_ascii(std::move(value));
124 return up == "BF16" || up == "BFLOAT16" || up == "EVXX_BF16" || up == "EVXX_BFLOAT16";
125}
126
128inline bool tensor_format_is_fp32_alias(std::string value) {
129 const std::string up = upper_copy_ascii(std::move(value));
130 return up == "FP32" || up == "FLOAT32" || up == "EVXX_FLOAT32";
131}
132
134inline bool tensor_format_is_int8_alias(std::string value) {
135 const std::string up = upper_copy_ascii(std::move(value));
136 return up == "INT8" || up == "EVXX_INT8";
137}
138
140inline bool tensor_format_is_int16_alias(std::string value) {
141 const std::string up = upper_copy_ascii(std::move(value));
142 return up == "INT16" || up == "EVXX_INT16";
143}
144
146inline bool tensor_format_is_int32_alias(std::string value) {
147 const std::string up = upper_copy_ascii(std::move(value));
148 return up == "INT32" || up == "EVXX_INT32";
149}
150
157inline std::string normalize_tensor_caps_format(std::string value) {
158 if (tensor_format_is_fp32_alias(value)) {
159 return "EVXX_FLOAT32";
160 }
161 if (tensor_format_is_bf16_alias(value)) {
162 return "EVXX_BFLOAT16";
163 }
164 if (tensor_format_is_int8_alias(value)) {
165 return "EVXX_INT8";
166 }
168 return "EVXX_INT16";
169 }
171 return "EVXX_INT32";
172 }
173 return value;
174}
175
187inline std::string normalize_caps_format_for_media(std::string media_type, std::string format) {
188 if (format.empty()) {
189 return format;
190 }
191 const std::string media_up = upper_copy_ascii(std::move(media_type));
192 if (media_up == "APPLICATION/VND.SIMAAI.TENSOR") {
193 return normalize_tensor_caps_format(std::move(format));
194 }
195 return format;
196}
197
199inline FormatTag format_tag_from_string(const std::string& value) {
200 const std::string up = upper_copy_ascii(value);
201 if (up.empty())
202 return FormatTag::Auto;
203 if (up == "RGB")
204 return FormatTag::RGB;
205 if (up == "BGR")
206 return FormatTag::BGR;
207 if (up == "GRAY" || up == "GRAY8")
208 return FormatTag::GRAY8;
209 if (up == "NV12")
210 return FormatTag::NV12;
211 if (up == "I420" || up == "YUV420")
212 return FormatTag::I420;
213 if (up == "YUYV")
214 return FormatTag::YUYV;
215 if (up == "ENCODED")
216 return FormatTag::ENCODED;
217 if (up == "H264")
218 return FormatTag::H264;
219 if (up == "BYTESTREAM" || up == "BYTE_STREAM" || up == "BYTE-STREAM" || up == "RAW_BYTES" ||
220 up == "RAW-BYTES" || up == "OPAQUE_BYTES" || up == "OPAQUE-BYTES" || up == "OCTET_STREAM" ||
221 up == "OCTET-STREAM")
223 if (up == "MLA")
224 return FormatTag::MLA;
225 if (up == "BBOX")
226 return FormatTag::BBOX;
227 if (up == "ARGMAX")
228 return FormatTag::ARGMAX;
229 if (up == "DETESSDEQUANT")
231 if (up == "FP32")
232 return FormatTag::FP32;
233 if (up == "INT8")
234 return FormatTag::INT8;
235 if (up == "UINT8")
236 return FormatTag::UINT8;
237 if (up == "BF16" || up == "BFLOAT16")
238 return FormatTag::BF16;
239 if (up == "EVXX_BF16")
241 if (up == "EVXX_FLOAT32")
243 if (up == "EVXX_INT8")
245 if (up == "EVXX_BFLOAT16")
247 return FormatTag::Auto;
248}
249
252 return tag == FormatTag::RGB || tag == FormatTag::BGR || tag == FormatTag::GRAY8 ||
253 tag == FormatTag::NV12 || tag == FormatTag::I420 || tag == FormatTag::YUYV;
254}
255
258 return tag == FormatTag::ByteStream || tag == FormatTag::MLA || tag == FormatTag::BBOX ||
260 tag == FormatTag::INT8 || tag == FormatTag::UINT8 || tag == FormatTag::BF16 ||
263}
264
276struct FormatSpec {
278
280 constexpr FormatSpec() = default;
282 constexpr FormatSpec(FormatTag value) : tag(value) {}
284 FormatSpec(const std::string& value) : tag(format_tag_from_string(value)) {}
286 FormatSpec(const char* value)
287 : tag(format_tag_from_string(value ? std::string(value) : std::string{})) {}
288
291 tag = value;
292 return *this;
293 }
295 FormatSpec& operator=(const std::string& value) {
297 return *this;
298 }
300 FormatSpec& operator=(const char* value) {
301 tag = format_tag_from_string(value ? std::string(value) : std::string{});
302 return *this;
303 }
304
306 bool empty() const {
307 return tag == FormatTag::Auto;
308 }
310 bool operator==(const FormatSpec& other) const {
311 return tag == other.tag;
312 }
314 bool operator!=(const FormatSpec& other) const {
315 return tag != other.tag;
316 }
318 std::string str() const {
320 }
322 explicit operator bool() const {
323 return tag != FormatTag::Auto;
324 }
326 operator std::string() const {
327 return str();
328 }
329};
330
332inline std::ostream& operator<<(std::ostream& os, const FormatSpec& spec) {
333 os << spec.str();
334 return os;
335}
336
337} // namespace simaai::neat

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.