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

◆ save_image() [4/4]

bool MayaFlux::IO::IOManager::save_image ( IO::ImageData  data,
const std::string &  filepath,
const IO::ImageWriteOptions options = {} 
)

Save an already-downloaded ImageData to disk asynchronously.

For callers that have an ImageData in hand (e.g. from IO::download_image) and want to avoid the GPU download step. Purely CPU-bound from here, so no thread restrictions on the caller.

Definition at line 734 of file IOManager.cpp.

738{
739 auto fut = std::async(std::launch::async,
740 [data = std::move(data),
741 filepath,
742 options]() -> bool {
743 auto writer = IO::ImageWriterRegistry::instance().create_writer(filepath);
744 if (!writer) {
746 "save_image task: no writer registered for '{}'", filepath);
747 return false;
748 }
749 const bool ok = writer->write(filepath, data, options);
750 if (!ok) {
752 "save_image task: writer failed for '{}': {}",
753 filepath, writer->get_last_error());
754 } else {
756 "save_image task: wrote '{}'", filepath);
757 }
758 return ok;
759 });
760
761 std::lock_guard lock(m_save_tasks_mutex);
762 m_save_tasks.push_back(std::move(fut));
763
764 std::erase_if(m_save_tasks, [](std::future<bool>& f) {
765 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
766 });
767
768 return true;
769}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
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()
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

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

+ Here is the call graph for this function: