45 [[nodiscard]]
virtual bool can_write(
const std::string& filepath)
const = 0;
55 const std::string& filepath,
89 const std::vector<std::string>& extensions,
92 for (
const auto& ext : extensions) {
93 m_factories[ext] = factory;
97 [[nodiscard]] std::unique_ptr<ImageWriter>
create_writer(
const std::string& filepath)
const
99 auto ext = std::filesystem::path(filepath).extension().string();
100 if (!ext.empty() && ext[0] ==
'.') {
104 auto it = m_factories.find(ext);
105 if (it != m_factories.end()) {
113 std::vector<std::string> exts;
114 exts.reserve(m_factories.size());
115 for (
const auto& [ext, _] : m_factories) {
std::unique_ptr< ImageWriter > create_writer(const std::string &filepath) const
static ImageWriterRegistry & instance()
std::vector< std::string > get_registered_extensions() const
void register_writer(const std::vector< std::string > &extensions, const ImageWriterFactory &factory)
std::unordered_map< std::string, ImageWriterFactory > m_factories
Singleton registry dispatching image writes by file extension.
virtual ~ImageWriter()=default
virtual std::string get_last_error() const =0
Last error message or empty string.
virtual bool write(const std::string &filepath, const ImageData &data, const ImageWriteOptions &options={})=0
Write image data to disk.
virtual bool can_write(const std::string &filepath) const =0
Check whether this writer handles the given filepath.
virtual std::vector< std::string > get_supported_extensions() const =0
File extensions handled by this writer (without dot).
Abstract base for image format writers.
std::function< std::unique_ptr< ImageWriter >()> ImageWriterFactory
Raw image data loaded from file.
std::vector< std::string > channel_names
Configuration for image writing.