25 lines
671 B
C++
25 lines
671 B
C++
|
#include <os/File.h>
|
||
|
#include <ui/Image.h>
|
||
|
|
||
|
namespace ui
|
||
|
{
|
||
|
Result<SharedPtr<Image>> Image::load(const os::Path& path)
|
||
|
{
|
||
|
auto image = TRY(make_shared<Image>());
|
||
|
auto file = TRY(os::File::open(path, os::File::ReadOnly));
|
||
|
|
||
|
TRY(file->read_typed(image->m_tga_header));
|
||
|
|
||
|
if (image->m_tga_header.encoding != 2) todo();
|
||
|
if (image->m_tga_header.bpp != 32) todo();
|
||
|
|
||
|
Buffer image_id;
|
||
|
TRY(file->read(image_id, image->m_tga_header.idlen));
|
||
|
|
||
|
TRY(file->read(image->m_image_data,
|
||
|
image->m_tga_header.w * image->m_tga_header.h * (image->m_tga_header.bpp / 8)));
|
||
|
|
||
|
return image;
|
||
|
}
|
||
|
}
|