DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
Image.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_IMAGE_HPP_INCLUDED
18 #define DGL_IMAGE_HPP_INCLUDED
19 
20 #include "Geometry.hpp"
21 
22 START_NAMESPACE_DGL
23 
24 // -----------------------------------------------------------------------
25 
26 /**
27  Base DGL Image class.
28 
29  This is an Image class that handles raw image data in pixels.
30  You can init the image data on the contructor or later on by calling loadFromMemory().
31 
32  To generate raw data useful for this class see the utils/png2rgba.py script.
33  Be careful when using a PNG without alpha channel, for those the format is 'GL_BGR'
34  instead of the default 'GL_BGRA'.
35 
36  Images are drawn on screen via 2D textures.
37  */
38 class Image
39 {
40 public:
41  /**
42  Constructor for a null Image.
43  */
44  Image();
45 
46  /**
47  Constructor using raw image data.
48  @note: @a rawData must remain valid for the lifetime of this Image.
49  */
50  Image(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
51 
52  /**
53  Constructor using raw image data.
54  @note: @a rawData must remain valid for the lifetime of this Image.
55  */
56  Image(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE);
57 
58  /**
59  Constructor using another image data.
60  */
61  Image(const Image& image);
62 
63  /**
64  Destructor.
65  */
66  ~Image();
67 
68  /**
69  Load image data from memory.
70  @note: @a rawData must remain valid for the lifetime of this Image.
71  */
72  void loadFromMemory(const char* const rawData, const uint width, const uint height, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
73 
74  /**
75  Load image data from memory.
76  @note: @a rawData must remain valid for the lifetime of this Image.
77  */
78  void loadFromMemory(const char* const rawData, const Size<uint>& size, const GLenum format = GL_BGRA, const GLenum type = GL_UNSIGNED_BYTE) noexcept;
79 
80  /**
81  Check if this image is valid.
82  */
83  bool isValid() const noexcept;
84 
85  /**
86  Get width.
87  */
88  uint getWidth() const noexcept;
89 
90  /**
91  Get height.
92  */
93  uint getHeight() const noexcept;
94 
95  /**
96  Get size.
97  */
98  const Size<uint>& getSize() const noexcept;
99 
100  /**
101  Get the raw image data.
102  */
103  const char* getRawData() const noexcept;
104 
105  /**
106  Get the image format.
107  */
108  GLenum getFormat() const noexcept;
109 
110  /**
111  Get the image type.
112  */
113  GLenum getType() const noexcept;
114 
115  /**
116  Draw this image at (0, 0) point.
117  */
118  void draw();
119 
120  /**
121  Draw this image at (x, y) point.
122  */
123  void drawAt(const int x, const int y);
124 
125  /**
126  Draw this image at position @a pos.
127  */
128  void drawAt(const Point<int>& pos);
129 
130  Image& operator=(const Image& image) noexcept;
131  bool operator==(const Image& image) const noexcept;
132  bool operator!=(const Image& image) const noexcept;
133 
134 private:
135  const char* fRawData;
136  Size<uint> fSize;
137  GLenum fFormat;
138  GLenum fType;
139  GLuint fTextureId;
140  bool fIsReady;
141 };
142 
143 // -----------------------------------------------------------------------
144 
145 END_NAMESPACE_DGL
146 
147 #endif // DGL_IMAGE_HPP_INCLUDED
GLenum getType() const noexcept
uint getWidth() const noexcept
void drawAt(const int x, const int y)
void draw()
void loadFromMemory(const char *const rawData, const uint width, const uint height, const GLenum format=GL_BGRA, const GLenum type=GL_UNSIGNED_BYTE) noexcept
const char * getRawData() const noexcept
Definition: Image.hpp:38
GLenum getFormat() const noexcept
bool isValid() const noexcept
const Size< uint > & getSize() const noexcept
uint getHeight() const noexcept