diff options
author | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
commit | 60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (patch) | |
tree | 02ec83cc8387abfd08bd5ee7ea4e8115f1bfb8d0 /source/Game/Image.hpp | |
parent | c2ef7737536bf1f8c81fcfae95c0183b21c9753f (diff) |
Changeset: 63 [WIP] Rename directories
Diffstat (limited to 'source/Game/Image.hpp')
-rw-r--r-- | source/Game/Image.hpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/source/Game/Image.hpp b/source/Game/Image.hpp new file mode 100644 index 0000000..c577c24 --- /dev/null +++ b/source/Game/Image.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "Color.hpp" +#include "RcPtr.hpp" + +#include <cstdint> +#include <glm/glm.hpp> +#include <memory> +#include <span> + +/// Image is a 2d array of pixels, stored as a continuous array in memory, with the first pixel +/// being the top-left pixel. If a vertically flipped image data is needed, load using stb_image +/// yourself, or flip the data here. +class Image : public RefCounted { +private: + std::unique_ptr<uint8_t[]> mData; + glm::ivec2 mSize; + int mChannels; + +public: + Image(); + + bool InitFromImageFile(const char* filePath, int desiredChannels = 0); + bool InitFromImageData(std::span<uint8_t> data, int desiredChannels = 0); + bool InitFromPixels(std::span<uint8_t> pixels, glm::ivec2 dimensions, int channels); + bool InitFromPixels(std::unique_ptr<uint8_t[]> pixels, glm::ivec2 dimensions, int channels); + + /// Get the pixel at the given location. + RgbaColor GetPixel(int x, int y) const; + void SetPixel(int x, int y, RgbaColor color); + + uint8_t* GetDataPtr() const; + size_t GetDataLength() const; + std::span<uint8_t> GetData() const; + glm::ivec2 GetSize() const; + int GetChannels() const; + bool IsEmpty() const; +}; |