DISTRHO Plugin Framework
 All Classes Functions Variables Enumerations Enumerator Groups Pages
Image.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2019 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 "ImageBase.hpp"
21 #include "OpenGL.hpp"
22 
23 START_NAMESPACE_DGL
24 
25 // -----------------------------------------------------------------------
26 
27 /**
28  OpenGL Image class.
29 
30  This is an Image class that handles raw image data in pixels.
31  You can init the image data on the contructor or later on by calling loadFromMemory().
32 
33  To generate raw data useful for this class see the utils/png2rgba.py script.
34  Be careful when using a PNG without alpha channel, for those the format is 'GL_BGR'
35  instead of the default 'GL_BGRA'.
36 
37  Images are drawn on screen via 2D textures.
38  */
39 class Image : public ImageBase
40 {
41 public:
42  /**
43  Constructor for a null Image.
44  */
45  Image();
46 
47  /**
48  Constructor using raw image data.
49  @note @a rawData must remain valid for the lifetime of this Image.
50  */
51  Image(const char* const rawData,
52  const uint width,
53  const uint height,
54  const GLenum format = GL_BGRA,
55  const GLenum type = GL_UNSIGNED_BYTE);
56 
57  /**
58  Constructor using raw image data.
59  @note @a rawData must remain valid for the lifetime of this Image.
60  */
61  Image(const char* const rawData,
62  const Size<uint>& size,
63  const GLenum format = GL_BGRA,
64  const GLenum type = GL_UNSIGNED_BYTE);
65 
66  /**
67  Constructor using another image data.
68  */
69  Image(const Image& image);
70 
71  /**
72  Destructor.
73  */
74  ~Image() override;
75 
76  /**
77  Load image data from memory.
78  @note @a rawData must remain valid for the lifetime of this Image.
79  */
80  void loadFromMemory(const char* const rawData,
81  const uint width,
82  const uint height,
83  const GLenum format = GL_BGRA,
84  const GLenum type = GL_UNSIGNED_BYTE) noexcept;
85 
86  /**
87  Load image data from memory.
88  @note @a rawData must remain valid for the lifetime of this Image.
89  */
90  void loadFromMemory(const char* const rawData,
91  const Size<uint>& size,
92  const GLenum format = GL_BGRA,
93  const GLenum type = GL_UNSIGNED_BYTE) noexcept;
94 
95  /**
96  Get the image format.
97  */
98  GLenum getFormat() const noexcept;
99 
100  /**
101  Get the image type.
102  */
103  GLenum getType() const noexcept;
104 
105  /**
106  TODO document this.
107  */
108  Image& operator=(const Image& image) noexcept;
109 
110 protected:
111  /** @internal */
112  void _drawAt(const Point<int>& pos) override;
113 
114 private:
115  GLenum fFormat;
116  GLenum fType;
117  GLuint fTextureId;
118  bool fIsReady;
119 };
120 
121 // -----------------------------------------------------------------------
122 
123 END_NAMESPACE_DGL
124 
125 #endif
GLenum getType() const noexcept
Image & operator=(const Image &image) noexcept
Definition: ImageBase.hpp:35
~Image() override
void loadFromMemory(const char *const rawData, const uint width, const uint height, const GLenum format=GL_BGRA, const GLenum type=GL_UNSIGNED_BYTE) noexcept
Definition: Image.hpp:39
GLenum getFormat() const noexcept