MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
STBImageWriter.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::IO {
6
7/**
8 * @class STBImageWriter
9 * @brief ImageWriter implementation backed by stb_image_write.
10 *
11 * Handles PNG, JPG, BMP, TGA, and HDR. Accepts:
12 * - uint8 ImageData for PNG/JPG/BMP/TGA (RGBA8/RGB8/etc.)
13 * - float ImageData for HDR (RGB32F/RGBA32F, scanline radiance encoding)
14 *
15 * EXR is not handled here. Float data routed to PNG/JPG/BMP/TGA is rejected
16 * with a clear error; use EXRWriter for float-precision outputs.
17 *
18 * Options honored:
19 * - ImageWriteOptions::compression : PNG deflate level [0..9]
20 * - ImageWriteOptions::quality : JPG quality [1..100]
21 * - ImageWriteOptions::flip_vertically : vertical flip before encode
22 */
23class MAYAFLUX_API STBImageWriter : public ImageWriter {
24public:
25 STBImageWriter() = default;
26 ~STBImageWriter() override = default;
27
28 [[nodiscard]] bool can_write(const std::string& filepath) const override;
29
30 bool write(
31 const std::string& filepath,
32 const ImageData& data,
33 const ImageWriteOptions& options = {}) override;
34
35 [[nodiscard]] std::vector<std::string> get_supported_extensions() const override;
36 [[nodiscard]] std::string get_last_error() const override { return m_last_error; }
37
38 /**
39 * @brief Register this writer with the ImageWriterRegistry.
40 *
41 * Called from engine/subsystem init. Idempotent.
42 */
43 static void register_with_registry();
44
45private:
46 mutable std::string m_last_error;
47
48 bool write_png(const std::string& filepath, const ImageData& data, const ImageWriteOptions& options);
49 bool write_jpg(const std::string& filepath, const ImageData& data, const ImageWriteOptions& options);
50 bool write_bmp(const std::string& filepath, const ImageData& data);
51 bool write_tga(const std::string& filepath, const ImageData& data);
52 bool write_hdr(const std::string& filepath, const ImageData& data);
53};
54
55} // namespace MayaFlux::IO
Abstract base for image format writers.
std::string get_last_error() const override
Last error message or empty string.
~STBImageWriter() override=default
ImageWriter implementation backed by stb_image_write.
Raw image data loaded from file.
Configuration for image writing.