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

986{
987 auto fut = std::async(std::launch::async,
988 [data = std::move(data),
989 filepath,
990 options]() -> bool {
991 auto writer = IO::ImageWriterRegistry::instance().create_writer(filepath);
992 if (!writer) {
994 "save_image task: no writer registered for '{}'", filepath);
995 return false;
996 }
997 const bool ok = writer->write(filepath, data, options);
998 if (!ok) {
1000 "save_image task: writer failed for '{}': {}",
1001 filepath, writer->get_last_error());
1002 } else {
1004 "save_image task: wrote '{}'", filepath);
1005 }
1006 return ok;
1007 });
1008
1009 std::lock_guard lock(m_save_tasks_mutex);
1010 m_save_tasks.push_back(std::move(fut));
1011
1012 std::erase_if(m_save_tasks, [](std::future<bool>& f) {
1013 return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
1014 });
1015
1016 return true;
1017}
#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: