MayaFlux 0.3.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 76 of file ImageReader.cpp.

77{
78 if (m_is_open) {
79 close();
80 }
81
82 if (!can_read(filepath)) {
83 m_last_error = "Unsupported image format: " + filepath;
85 return false;
86 }
87
88 m_image_data = load(filepath, 4); // Force RGBA
89
90 if (!m_image_data) {
91 m_last_error = "Failed to load image data";
92 return false;
93 }
94
95 m_filepath = filepath;
96 m_is_open = true;
97
99 "Opened image: {} ({}x{}, {} channels)",
100 filepath, m_image_data->width, m_image_data->height, m_image_data->channels);
101
102 return true;
103}
#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.

+ Here is the call graph for this function: