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 655 of file IOManager.cpp.

659{
660 if (!image) {
662 "save_image: null image");
663 return false;
664 }
665
666 auto fut = std::async(std::launch::async,
667 [image, filepath, options]() -> bool {
668 auto data = IO::download_image(image);
669 if (!data) {
671 "save_image task: download failed for '{}'", filepath);
672 return false;
673 }
674
675 auto writer = IO::ImageWriterRegistry::instance().create_writer(filepath);
676 if (!writer) {
678 "save_image task: no writer registered for '{}'", filepath);
679 return false;
680 }
681
682 const bool ok = writer->write(filepath, *data, options);
683 if (!ok) {
685 "save_image task: writer failed for '{}': {}",
686 filepath, writer->get_last_error());
687 } else {
689 "save_image task: wrote '{}'", filepath);
690 }
691 return ok;
692 });
693
694 std::lock_guard lock(m_save_tasks_mutex);
695 m_save_tasks.push_back(std::move(fut));
696
697 std::erase_if(m_save_tasks, [](std::future<bool>& f) {
698 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
699 });
700
701 return true;
702}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
IO::ImageData image
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: