MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ detect()

const TensorFormat * MayaFlux::IO::TensorFormatRegistry::detect ( const std::string & filepath) const
nodiscard

Format recognised by content, then by extension, or nullptr.

Definition at line 48 of file TensorFormat.cpp.

49{
50 const auto path = FileReader::resolve_path(filepath);
51
52 if (const auto head = Detail::read_file_head(path, 4096)) {
53 for (const auto& format : m_formats) {
54 if (format.probe && format.make_reader && format.probe(head->bytes, head->file_size))
55 return &format;
56 }
57 }
58 return by_extension(path, false);
59}
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
std::vector< TensorFormat > m_formats
const TensorFormat * by_extension(const std::string &filepath, bool need_writer) const
std::optional< FileHead > read_file_head(const std::string &path, size_t limit)
Read up to limit leading bytes of a file, or std::nullopt if it cannot be opened.

References by_extension(), m_formats, MayaFlux::IO::Detail::read_file_head(), and MayaFlux::IO::FileReader::resolve_path().

Referenced by create_reader().

Here is the call graph for this function:
Here is the caller graph for this function: