Image.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <etk/types.hpp>
9 #include <vector>
10 #include <etk/math/Vector2D.hpp>
11 #include <etk/Color.hpp>
12 #include <etk/stdTools.hpp>
13 #include <ememory/memory.hpp>
14 
15 namespace egami {
16  enum class colorType {
17  undefined,
18  RGBA8,
19  RGB8,
20  RGBAf,
21  RGBf,
22  //unsignedInt8,
23  unsignedInt16,
24  unsignedInt32,
25  float32,
26  float64,
27  };
28  std::ostream& operator <<(std::ostream& _os, const enum egami::colorType _obj);
29 
30  class ImagePrivate {
31  public:
32  ImagePrivate() {};
33  virtual ~ImagePrivate() {};
34  virtual void* getTextureDataPointer() {
35  return nullptr;
36  };
37  virtual const ivec2& getSize() const = 0;
38  virtual int32_t getWidth() const {
39  return 0;
40  };
41  virtual int32_t getHeight() const {
42  return 0;
43  };
44  virtual enum colorType getType() const {
45  return egami::colorType::RGBA8;
46  };
47  virtual void clear() = 0;
48  virtual void resize(const ivec2& _size, const etk::Color<uint8_t, 4>& _color, const ivec2& _startPos) = 0;
49  virtual void resize(const ivec2& _size, const etk::Color<float, 4>& _color, const ivec2& _startPos) = 0;
50  virtual void resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos) = 0;
51  virtual void resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos) = 0;
52  virtual void resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos) = 0;
53  virtual void resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos) = 0;
54  virtual void resize(const ivec2& _size, const ivec2& _startPos) = 0;
55  virtual void set(const ivec2& _pos, const etk::Color<>& _newColor) = 0;
56  virtual void set(const ivec2& _pos, const etk::Color<float>& _newColor) = 0;
57  virtual void set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) = 0;
58  virtual void set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) = 0;
59  virtual void set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) = 0;
60  virtual void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) = 0;
61  virtual etk::Color<> get(const ivec2& _pos) const = 0;
62  virtual void set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size) = 0;
63  virtual void set(const std::vector<etk::Color<uint8_t,4>>& _data, const ivec2& _size) = 0;
64  };
65 
66  class Image {
67  private:
68  // TODO : Change this in a unique_ptr ...
70  public:
75  Image();
76  Image(const ivec2& _size,
77  enum colorType _type = egami::colorType::undefined);
78  ~Image();
79  // TODO : IMplement move operator ... and copy operator...
80  public:
81  void configure(const ivec2& _size=ivec2(32,32),
82  enum colorType _type=egami::colorType::RGBA8);
83  void* getTextureDataPointer();
84  enum colorType getType() const;
85  bool exist() {
86  return m_data != nullptr;
87  }
88  // -----------------------------------------------
89  // -- basic tools :
90  // -----------------------------------------------
91  public :
92  void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0));
93  // TODO : Create a template function ...
94  void resize(const ivec2& _size, const etk::Color<>& _color, const ivec2& _startPos=ivec2(0,0));
95  void resize(const ivec2& _size, const etk::Color<float>& _color, const ivec2& _startPos=ivec2(0,0));
96  void resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos=ivec2(0,0));
97  void resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos=ivec2(0,0));
98  void resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos=ivec2(0,0));
99  void resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos=ivec2(0,0));
100 
101  const ivec2& getSize() const;
102  int32_t getWidth() const;
103  int32_t getHeight() const;
104  void clear(const etk::Color<>& _color);
105  void clear(const etk::Color<float>& _color);
106  void clear(const etk::Color<uint16_t, 1>& _color);
107  void clear(const etk::Color<uint32_t, 1>& _color);
108  void clear(const etk::Color<float, 1>& _color);
109  void clear(const etk::Color<double, 1>& _color);
110 
111  etk::Color<> get(const ivec2& _pos) const;
112  /*
113  etk::Color<> getRGBA8(const ivec2& _pos) const;
114  etk::Color<float> getRGBAf(const ivec2& _pos) const;
115  uint16_t getU16(const ivec2& _pos) const;
116  uint32_t getU32(const ivec2& _pos) const;
117  float getFloat(const ivec2& _pos) const;
118  double getDouble(const ivec2& _pos) const;
119  */
120  void set(const ivec2& _pos, const etk::Color<>& _newColor);
121  void set(const ivec2& _pos, const etk::Color<float>& _newColor);
122  void set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor);
123  void set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor);
124  void set(const ivec2& _pos, const etk::Color<float, 1>& _newColor);
125  void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor);
126  void insert(const ivec2& _pos, const egami::Image& _input);
132  void scale(const ivec2& _size);
133 
134  void set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size);
135  void set(const std::vector<etk::Color<uint8_t,4>>& _data, const ivec2& _size);
136  };
137 }
138 
Definition: debug.hpp:10
void clear()
Definition: Image.hpp:66
Definition: Image.hpp:30