Chira Engine
A customizable MIT-licensed game engine.
Image.h
1 #pragma once
2 
3 #include <math/Types.h>
4 #include <resource/Resource.h>
5 
6 namespace chira {
7 
8 class Image : public Resource {
9 public:
10  explicit Image(std::string identifier_, bool vFlip = true);
11  ~Image() override;
12  Image(const Image& other) = delete;
13  Image& operator=(const Image& other) = delete;
14  Image(Image&& other) noexcept = default;
15  Image& operator=(Image&& other) noexcept = default;
16 
17  void compile(const byte buffer[], std::size_t bufferLen) override;
18  [[nodiscard]] inline byte* getData() const {
19  return this->image;
20  }
21  [[nodiscard]] inline int getWidth() const {
22  return this->width;
23  }
24  [[nodiscard]] inline int getHeight() const {
25  return this->height;
26  }
27  [[nodiscard]] inline int getBitDepth() const {
28  return this->bitDepth;
29  }
30  [[nodiscard]] inline bool isVerticallyFlipped() const {
31  return this->verticalFlip;
32  }
33 
34  [[nodiscard]] static byte* getUncompressedImage(const byte buffer[], int bufferLen, int* width, int* height, int* fileChannels, int desiredChannels, bool vflip);
35  [[nodiscard]] static byte* getUncompressedImage(const byte buffer[], int bufferLen, int desiredChannels, bool vflip);
36  [[nodiscard]] static byte* getUncompressedImage(std::string_view filepath, int* width, int* height, int* fileChannels, int desiredChannels, bool vflip);
37  [[nodiscard]] static byte* getUncompressedImage(std::string_view filepath, int desiredChannels, bool vflip);
38  static void deleteUncompressedImage(byte* image);
39 protected:
40  byte* image = nullptr;
41  int width = -1;
42  int height = -1;
43  int bitDepth = -1;
44  bool verticalFlip = true;
45 private:
46  CHIRA_REGISTER_DEFAULT_RESOURCE(Image, "file://textures/missing.png");
47 };
48 
49 } // namespace chira
A chunk of data, usually a file. Is typically cached and shared.
Definition: Resource.h:19