#pragma once #include #include #include namespace ui { /** * @brief An image in the TGA file format. */ class Image : public Shareable { public: /** * @brief Load a new TGA image from a file. * * @param path The path to open. * @return Result> An error, or a new Image object. */ static Result> load(const os::Path& path); /** * @brief Return the array of pixels contained in the image. * * @return u32* The array of pixels. */ u32* pixels() { return (u32*)m_image_data.data(); } /** * @brief Return the width of the image. * * @return u16 The width. */ u16 width() { return m_tga_header.w; } /** * @brief Return the height of the image. * * @return u16 The height. */ u16 height() { return m_tga_header.h; } private: struct [[gnu::packed]] TGAHeader { u8 idlen; u8 colormap; u8 encoding; u16 cmaporig, cmaplen; u8 cmapent; u16 x; u16 y; u16 w; u16 h; u8 bpp; u8 pixeltype; }; TGAHeader m_tga_header; Buffer m_image_data; }; }