MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ImageExport.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Core {
6class VKImage;
7}
8namespace MayaFlux::Buffers {
9class TextureBuffer;
10class TextBuffer;
11}
12
13namespace MayaFlux::IO {
14
15/**
16 * @brief Download pixel data from a GPU-resident VKImage into host ImageData.
17 *
18 * Performs a blocking GPU->host transfer via TextureLoom::download_data,
19 * allocating a host buffer of the appropriate variant for the image format.
20 * The source image is restored to eShaderReadOnlyOptimal / eFragmentShader
21 * after the copy; pass a different restore layout/stage via the overload if
22 * the image was, for example, in a compute write state.
23 *
24 * Multi-layer and multi-mip images are downloaded at layer 0, mip 0 only.
25 * Array and mipmap export is a separate concern.
26 *
27 * @param image Fully-initialized VKImage to read from.
28 * @return Populated ImageData, or std::nullopt on failure.
29 */
30[[nodiscard]] std::optional<ImageData> download_image(
31 const std::shared_ptr<Core::VKImage>& image);
32
33/**
34 * @brief Download a TextureBuffer's GPU texture into host ImageData.
35 *
36 * Convenience wrapper over download_image() that pulls the VKImage from
37 * TextureBuffer::get_gpu_texture(). Returns nullopt if the texture is not
38 * yet allocated (buffer has not been processed at least once).
39 */
40[[nodiscard]] std::optional<ImageData> download_texture_buffer(
41 const std::shared_ptr<Buffers::TextureBuffer>& buffer);
42
43/**
44 * @brief Save a VKImage directly to disk via the ImageWriter registry.
45 *
46 * Combines download_image() with ImageWriterRegistry::create_writer(). The
47 * file extension selects the writer. Format-variant compatibility is the
48 * writer's responsibility: saving a float VKImage as PNG will fail at the
49 * writer (uint8 mismatch), saving a uint8 VKImage as EXR will fail too.
50 *
51 * @param image VKImage to save.
52 * @param filepath Destination path with extension.
53 * @param options Format-specific writer options.
54 * @return True on success.
55 */
56bool save_image(
57 const std::shared_ptr<Core::VKImage>& image,
58 const std::string& filepath,
59 const ImageWriteOptions& options = {});
60
61/**
62 * @brief Save a TextureBuffer's current GPU state to disk.
63 *
64 * Equivalent to download_texture_buffer() + save_image(). Most common entry
65 * point for writing rendered output to a file.
66 */
68 const std::shared_ptr<Buffers::TextureBuffer>& buffer,
69 const std::string& filepath,
70 const ImageWriteOptions& options = {});
71
72/**
73 * @brief Save a TextBuffer's rendered glyph texture to disk.
74 *
75 * TextBuffer inherits from TextureBuffer, so this is a convenience alias
76 * with type-specific documentation. The RGBA8 coverage texture is written
77 * to disk with transparency preserved when the target format supports it
78 * (PNG, TGA, EXR). JPG discards alpha.
79 */
81 const std::shared_ptr<Buffers::TextBuffer>& buffer,
82 const std::string& filepath,
83 const ImageWriteOptions& options = {});
84
85} // namespace MayaFlux::IO
IO::ImageData image
bool save_texture_buffer(const std::shared_ptr< Buffers::TextureBuffer > &buffer, const std::string &filepath, const ImageWriteOptions &options)
Save a TextureBuffer's current GPU state to disk.
bool save_image(const std::shared_ptr< Core::VKImage > &image, const std::string &filepath, const ImageWriteOptions &options)
Save a VKImage directly to disk via the ImageWriter registry.
bool save_text_buffer(const std::shared_ptr< Buffers::TextBuffer > &buffer, const std::string &filepath, const ImageWriteOptions &options)
Save a TextBuffer's rendered glyph texture to disk.
std::optional< ImageData > download_texture_buffer(const std::shared_ptr< Buffers::TextureBuffer > &buffer)
Download a TextureBuffer's GPU texture into host ImageData.
std::optional< ImageData > download_image(const std::shared_ptr< Core::VKImage > &image)
Download pixel data from a GPU-resident VKImage into host ImageData.