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

◆ load_image()

std::shared_ptr< Buffers::TextureBuffer > MayaFlux::IO::IOManager::load_image ( const std::string &  filepath,
int  desired_channels = 4,
std::optional< Kakshya::Region >  region = std::nullopt 
)

Load an image file into a TextureBuffer.

Opens the file via ImageReader, decodes to the requested channel layout, and creates a TextureBuffer containing the pixel data. The reader is retained for the lifetime of IOManager.

Parameters
filepathPath to the image file (PNG, JPG, BMP, TGA, etc.).
desired_channelsChannel count passed to ImageReader (0 keeps the source layout).
regionOptional source-pixel rectangle with inclusive end coordinates.
Returns
TextureBuffer with pixel data, or nullptr on failure.

Definition at line 755 of file IOManager.cpp.

757{
758 auto reader = std::make_shared<IO::ImageReader>(desired_channels, std::move(region));
759
760 if (!reader->open(filepath)) {
762 "Failed to open image: {}", filepath);
763 return nullptr;
764 }
765
766 auto texture_buffer = reader->create_texture_buffer();
767
768 if (!texture_buffer) {
770 "Failed to create texture buffer from: {}", filepath);
771 return nullptr;
772 }
773
774 m_image_readers.push_back(std::move(reader));
775
777 "Loaded image: {} ({}x{})",
778 std::filesystem::path(filepath).filename().string(),
779 texture_buffer->get_width(),
780 texture_buffer->get_height());
781
782 return texture_buffer;
783}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
std::vector< std::shared_ptr< ImageReader > > m_image_readers
@ FileIO
Filesystem I/O operations.
@ API
MayaFlux/API Wrapper and convenience functions.

References MayaFlux::Journal::API, MayaFlux::Journal::FileIO, m_image_readers, MF_ERROR, and MF_INFO.