-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoderRegistry.h
More file actions
56 lines (41 loc) · 1.92 KB
/
Copy pathDecoderRegistry.h
File metadata and controls
56 lines (41 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include "ImageRequest.h"
#include <string>
#include <string_view>
#include <span>
#include <unordered_map>
#include <vector>
#include <memory>
#include <mutex>
namespace ImageCore
{
class IImageDecoderFactory;
// Registry for registering/querying extensions supported by decoders
class DecoderRegistry final
{
public:
static DecoderRegistry& Instance();
// Register a decoder factory (apps can register custom decoders without modifying ImageCore source)
// Returns false if a factory with the same id is already registered.
bool RegisterFactory(const std::shared_ptr<IImageDecoderFactory>& factory);
// Unregister (optional)
bool UnregisterFactory(std::wstring_view id);
// Determines support based on the extension of the given path
bool IsSupportedPath(const std::wstring& path) const;
// Determines whether the given extension (e.g., L".dds") is supported
bool IsSupportedExtension(std::wstring_view ext) const;
std::vector<std::wstring> GetSupportedExtensions() const;
// List of factories to try for this request (in priority order)
std::vector<std::shared_ptr<IImageDecoderFactory>> GetCandidateFactories(const ImageRequest& request) const;
std::vector<std::shared_ptr<IImageDecoderFactory>> GetCandidateFactories(const ImageRequest& request, std::span<const uint8_t> header) const;
private:
DecoderRegistry() = default;
static std::wstring NormalizeExtension(std::wstring_view ext);
static std::wstring GetLowerExtensionFromPath(const std::wstring& path);
// id -> factory
std::unordered_map<std::wstring, std::shared_ptr<IImageDecoderFactory>> m_factoriesById {};
// ext -> factory ids (priority order)
std::unordered_map<std::wstring, std::vector<std::wstring>> m_factoriesByExtension {};
mutable std::mutex m_mutex {};
};
}