MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ save_image() [3/4]

bool MayaFlux::IO::IOManager::save_image ( const std::shared_ptr< Core::VKImage > &  image,
const std::string &  filepath,
const IO::ImageWriteOptions options = {} 
)

Save image data to disk asynchronously.

The source is downloaded from the GPU on the calling thread (must have command queue access) and the encode + disk flush is dispatched to a worker. Returns once the download completes and the encode task is queued; encode/flush failures are logged but do not block the caller.

For synchronous semantics (e.g. shutdown flush, tests) use the IO::save_image / IO::save_texture_buffer free functions in ImageExport.hpp.

The extension of filepath selects the writer via ImageWriterRegistry. Format-variant compatibility is the writer's responsibility (PNG wants uint8, EXR wants float, etc.).

Returns
True if the download succeeded and the encode task was queued.

Definition at line 903 of file IOManager.cpp.

907{
908 if (!image) {
910 "save_image: null image");
911 return false;
912 }
913
914 auto fut = std::async(std::launch::async,
915 [image, filepath, options]() -> bool {
916 auto data = IO::download_image(image);
917 if (!data) {
919 "save_image task: download failed for '{}'", filepath);
920 return false;
921 }
922
923 auto writer = IO::ImageWriterRegistry::instance().create_writer(filepath);
924 if (!writer) {
926 "save_image task: no writer registered for '{}'", filepath);
927 return false;
928 }
929
930 const bool ok = writer->write(filepath, *data, options);
931 if (!ok) {
933 "save_image task: writer failed for '{}': {}",
934 filepath, writer->get_last_error());
935 } else {
937 "save_image task: wrote '{}'", filepath);
938 }
939 return ok;
940 });
941
942 std::lock_guard lock(m_save_tasks_mutex);
943 m_save_tasks.push_back(std::move(fut));
944
945 std::erase_if(m_save_tasks, [](std::future<bool>& f) {
946 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
947 });
948
949 return true;
950}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
Definition Decoder.cpp:57
std::mutex m_save_tasks_mutex
std::vector< std::future< bool > > m_save_tasks
std::unique_ptr< ImageWriter > create_writer(const std::string &filepath) const
static ImageWriterRegistry & instance()
std::optional< ImageData > download_image(const std::shared_ptr< Core::VKImage > &image)
Download pixel data from a GPU-resident VKImage into host ImageData.
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References MayaFlux::IO::ImageWriterRegistry::create_writer(), MayaFlux::IO::download_image(), MayaFlux::Journal::FileIO, image, MayaFlux::IO::ImageWriterRegistry::instance(), MayaFlux::Journal::IO, m_save_tasks, m_save_tasks_mutex, MF_ERROR, and MF_INFO.

Referenced by save_image(), and save_image().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: