MayaFlux 0.4.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 266 of file ImageReader.cpp.

267{
268 if (m_is_open) {
269 close();
270 }
271
272 if (!can_read(filepath)) {
273 m_last_error = "Unsupported image format: " + filepath;
275 return false;
276 }
277
278 auto resolved = resolve_path(filepath);
279
280 m_image_data = load(resolved, 4); // Force RGBA
281
282 if (!m_image_data) {
283 m_last_error = "Failed to load image data";
284 return false;
285 }
286
287 m_filepath = filepath;
288 m_is_open = true;
289
291 "Opened image: {} ({}x{}, {} channels)",
292 filepath, m_image_data->width, m_image_data->height, m_image_data->channels);
293
294 return true;
295}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
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, MF_INFO, and MayaFlux::IO::FileReader::resolve_path().

+ Here is the call graph for this function: