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

◆ open()

bool MayaFlux::IO::ImageReader::open ( const std::string &  filepath,
FileReadOptions  options = FileReadOptions::ALL 
)
overridevirtual

Open a file for reading.

Parameters
filepathPath to the file.
optionsReading options (see FileReadOptions).
Returns
true if file was successfully opened.

Implements MayaFlux::IO::FileReader.

Definition at line 43 of file ImageReader.cpp.

44{
45 if (m_is_open) {
46 close();
47 }
48
49 if (!can_read(filepath)) {
50 m_last_error = "Unsupported image format: " + filepath;
52 return false;
53 }
54
55 m_image_data = load(filepath, 4); // Force RGBA
56
57 if (!m_image_data) {
58 m_last_error = "Failed to load image data";
59 return false;
60 }
61
62 m_filepath = filepath;
63 m_is_open = true;
64
66 "Opened image: {} ({}x{}, {} channels)",
67 filepath, m_image_data->width, m_image_data->height, m_image_data->channels);
68
69 return true;
70}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
static std::optional< ImageData > load(const std::string &path, int desired_channels=4)
Load image from file (static utility)
std::optional< ImageData > m_image_data
void close() override
Close the currently open file.
bool can_read(const std::string &filepath) const override
Check if a file can be read by this reader.
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.

References can_read(), close(), MayaFlux::Journal::FileIO, MayaFlux::Journal::IO, load(), m_filepath, m_image_data, m_is_open, m_last_error, MF_ERROR, and MF_INFO.

Referenced by MayaFlux::load_image_file().

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