MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ImageWriter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ImageReader.hpp"
5
6namespace MayaFlux::IO {
7
8/**
9 * @struct ImageWriteOptions
10 * @brief Configuration for image writing.
11 *
12 * Format-specific knobs are interpreted by the concrete writer; unsupported
13 * options are silently ignored. Compression maps differently per format:
14 * PNG : deflate level [0..9], default 6
15 * JPG : quality [1..100], default 90
16 * EXR : compression code (zip/piz/rle), default zip
17 * TGA : RLE flag, default false
18 */
20 int compression { -1 };
21 int quality { 90 };
22 bool flip_vertically { false };
23
24 std::vector<std::string> channel_names;
25};
26
27/**
28 * @class ImageWriter
29 * @brief Abstract base for image format writers.
30 *
31 * Parallels ImageReader. Each concrete writer handles one or more file
32 * extensions and validates that the supplied ImageData matches the format's
33 * expected pixel variant (uint8 for PNG/JPG/BMP/TGA, float for EXR/HDR,
34 * uint16 for 16-bit PNG).
35 *
36 * Writers are single-shot: one call to write() produces one file. No open/
37 * close lifecycle because image formats are whole-file atomic.
38 */
39class MAYAFLUX_API ImageWriter {
40public:
41 virtual ~ImageWriter() = default;
42
43 /**
44 * @brief Check whether this writer handles the given filepath.
45 */
46 [[nodiscard]] virtual bool can_write(const std::string& filepath) const = 0;
47
48 /**
49 * @brief Write image data to disk.
50 * @param filepath Destination path.
51 * @param data Image data. Must satisfy ImageData::is_consistent().
52 * @param options Format-specific options.
53 * @return true on success. On failure call get_last_error().
54 */
55 virtual bool write(
56 const std::string& filepath,
57 const ImageData& data,
58 const ImageWriteOptions& options = {}) = 0;
59
60 /**
61 * @brief File extensions handled by this writer (without dot).
62 */
63 [[nodiscard]] virtual std::vector<std::string> get_supported_extensions() const = 0;
64
65 /**
66 * @brief Last error message or empty string.
67 */
68 [[nodiscard]] virtual std::string get_last_error() const = 0;
69};
70
72
73/**
74 * @brief Singleton registry dispatching image writes by file extension.
75 *
76 * See WriterRegistry for behavior. Concrete writers register themselves on
77 * static initialization.
78 */
80
81} // namespace MayaFlux::IO
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.
Singleton registry dispatching single-shot writes by file extension.
std::function< std::unique_ptr< Writer >()> WriterFactory
WriterFactory< ImageWriter > ImageWriterFactory
std::vector< std::string > channel_names
Configuration for image writing.
Raw image data loaded from file or read back from a GPU image.
Definition ImageData.hpp:55