MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
EXRWriter.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::IO {
6
7/**
8 * @class EXRWriter
9 * @brief ImageWriter implementation backed by tinyexr.
10 *
11 * Writes OpenEXR single-part scanline images with 32-bit float pixel data.
12 * Handles arbitrary channel counts with named channels. State textures use
13 * named channels like "position.x", "entity_id", "trigger_kind" directly,
14 * so the file is partly self-documenting.
15 *
16 * Accepts float ImageData only. Integer variants (uint8, uint16) are
17 * rejected: EXR is a floating-point format and storing integer data via
18 * reinterpret would produce files no viewer reads sensibly.
19 *
20 * Channel naming:
21 * - ImageWriteOptions::channel_names, if non-empty and sized to match
22 * data.channels, is used verbatim.
23 * - Otherwise defaults are applied by channel count:
24 * 1 : "Y"
25 * 2 : "Y", "A"
26 * 3 : "B", "G", "R" (EXR convention)
27 * 4 : "A", "B", "G", "R" (EXR convention)
28 * N (>4) : "C0", "C1", ... "C(N-1)"
29 *
30 * Compression:
31 * - ImageWriteOptions::compression is the tinyexr TINYEXR_COMPRESSIONTYPE_*
32 * value. -1 (default) maps to TINYEXR_COMPRESSIONTYPE_ZIP (scanline block
33 * zip, widest viewer support).
34 *
35 * Vertical flip:
36 * - Honored via ImageWriteOptions::flip_vertically.
37 *
38 * Limitations:
39 * - Single-part only. Multi-part EXR is deferred; for layered state
40 * textures, write multiple EXR files with a companion schema/manifest.
41 * - No tiled output, no deep images.
42 * - Half precision output not yet exposed (requires uint16 ImageData and
43 * TINYEXR_PIXELTYPE_HALF plumbing; deferred).
44 */
45class MAYAFLUX_API EXRWriter : public ImageWriter {
46public:
47 EXRWriter() = default;
48 ~EXRWriter() override = default;
49
50 [[nodiscard]] bool can_write(const std::string& filepath) const override;
51
52 bool write(
53 const std::string& filepath,
54 const ImageData& data,
55 const ImageWriteOptions& options = {}) override;
56
57 [[nodiscard]] std::vector<std::string> get_supported_extensions() const override;
58 [[nodiscard]] std::string get_last_error() const override { return m_last_error; }
59
60 /**
61 * @brief Register this writer with the ImageWriterRegistry.
62 *
63 * Called from engine/subsystem init. Idempotent.
64 */
65 static void register_with_registry();
66
67private:
68 mutable std::string m_last_error;
69
70 /**
71 * @brief Resolve channel name list based on options and channel count.
72 */
73 [[nodiscard]] std::vector<std::string> resolve_channel_names(
74 const ImageData& data, const ImageWriteOptions& options) const;
75
76 /**
77 * @brief Deinterleave source float buffer into N planar channel buffers.
78 *
79 * Source layout: pixel-interleaved (P0C0 P0C1 P0C2 P0C3 P1C0 P1C1 ...).
80 * Output layout: one vector<float> per channel, scanline order.
81 * If flip_vertically is true, rows are emitted bottom-up.
82 */
83 static std::vector<std::vector<float>> deinterleave(
84 const std::vector<float>& src,
85 uint32_t width, uint32_t height, uint32_t channels,
86 bool flip_vertically);
87};
88
89} // namespace MayaFlux::IO
uint32_t width
~EXRWriter() override=default
std::string get_last_error() const override
Last error message or empty string.
Definition EXRWriter.hpp:58
ImageWriter implementation backed by tinyexr.
Definition EXRWriter.hpp:45
Abstract base for image format writers.
Raw image data loaded from file.
Configuration for image writing.