MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ImageExport.cpp
Go to the documentation of this file.
1#include "ImageExport.hpp"
2
3#include "ImageWriter.hpp"
4
9
11
12namespace MayaFlux::IO {
13
14// ============================================================================
15// download_image
16// ============================================================================
17
18std::optional<ImageData> download_image(
19 const std::shared_ptr<Core::VKImage>& image)
20{
21 if (!image) {
23 "download_image: null image");
24 return std::nullopt;
25 }
26
28}
29
30// ============================================================================
31// download_texture_buffer
32// ============================================================================
33
34std::optional<ImageData> download_texture_buffer(
35 const std::shared_ptr<Buffers::TextureBuffer>& buffer)
36{
37 if (!buffer) {
39 "download_texture_buffer: null buffer");
40 return std::nullopt;
41 }
42
43 auto image = buffer->get_gpu_texture();
44 if (!image) {
46 "download_texture_buffer: buffer has no GPU texture yet "
47 "(has the buffer been processed at least once?)");
48 return std::nullopt;
49 }
50
51 return download_image(image);
52}
53
54// ============================================================================
55// save_image / save_texture_buffer / save_text_buffer
56// ============================================================================
57
59 const std::shared_ptr<Core::VKImage>& image,
60 const std::string& filepath,
61 const ImageWriteOptions& options)
62{
63 auto data = download_image(image);
64 if (!data) {
65 return false;
66 }
67
68 auto writer = ImageWriterRegistry::instance().create_writer(filepath);
69 if (!writer) {
71 "save_image: no writer registered for extension of '{}'", filepath);
72 return false;
73 }
74
75 const bool ok = writer->write(filepath, *data, options);
76 if (!ok) {
78 "save_image: writer failed: {}", writer->get_last_error());
79 }
80 return ok;
81}
82
84 const std::shared_ptr<Buffers::TextureBuffer>& buffer,
85 const std::string& filepath,
86 const ImageWriteOptions& options)
87{
88 if (!buffer) {
90 "save_texture_buffer: null buffer");
91 return false;
92 }
93 auto image = buffer->get_gpu_texture();
94 if (!image) {
96 "save_texture_buffer: buffer has no GPU texture");
97 return false;
98 }
99 return save_image(image, filepath, options);
100}
101
103 const std::shared_ptr<Buffers::TextBuffer>& buffer,
104 const std::string& filepath,
105 const ImageWriteOptions& options)
106{
107 return save_texture_buffer(buffer, filepath, options);
108}
109
110} // namespace MayaFlux::IO
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:47
std::shared_ptr< NetworkGeometryBuffer > buffer
static WriterRegistry & instance()
std::unique_ptr< Writer > create_writer(const std::string &filepath) const
std::optional< Kakshya::ImageData > download_image(const std::shared_ptr< Core::VKImage > &image, const std::shared_ptr< Buffers::VKBuffer > &staging=nullptr, vk::ImageLayout restore_layout=vk::ImageLayout::eShaderReadOnlyOptimal, vk::PipelineStageFlags restore_stage=vk::PipelineStageFlagBits::eFragmentShader)
Download the base level of an image as typed pixels.
std::optional< ImageData > download_texture_buffer(const std::shared_ptr< Buffers::TextureBuffer > &buffer)
Download a TextureBuffer's GPU texture into host ImageData.
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_image(const std::shared_ptr< Core::VKImage > &image)
Download pixel data from a GPU-resident VKImage into host ImageData.
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_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.
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.
Configuration for image writing.