Gamedev Framework (gf)  0.7.0
A C++14 framework for 2D games
Image.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  *
21  * Part of this file comes from SFML, with the same license:
22  * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23  */
24 #ifndef GF_IMAGE_H
25 #define GF_IMAGE_H
26 
27 #include <cstddef>
28 #include <cstdint>
29 #include <vector>
30 
31 #include "Path.h"
32 #include "Portability.h"
33 #include "Vector.h"
34 
35 namespace gf {
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 inline namespace v1 {
38 #endif
39 
40  class InputStream;
41 
92  class GF_API Image {
93  public:
99  Image();
100 
104  Image(const Image&) = default;
105 
109  Image& operator=(const Image&) = default;
110 
114  Image(Image&&) = default;
115 
119  Image& operator=(Image&&) = default;
120 
127  void create(Vector2u size, const Color4u& color = Color4u{0x00, 0x00, 0x00, 0xFF});
128 
139  void create(Vector2u size, const uint8_t* pixels);
140 
151  void createRGB(Vector2u size, const uint8_t* pixels);
152 
167  bool loadFromFile(const Path& filename);
168 
184  bool loadFromMemory(const uint8_t* data, std::size_t length);
185 
200  bool loadFromStream(InputStream& stream);
201 
216  bool saveToFile(const Path& filename) const;
217 
223  Vector2u getSize() const;
224 
235  void createMaskFromColor(const Color4u& color, uint8_t alpha = 0);
236 
249  void setPixel(Vector2u pos, const Color4u& color);
250 
264  Color4u getPixel(Vector2u pos) const;
265 
278  const uint8_t* getPixelsPtr() const;
279 
285  void flipHorizontally();
286 
287  private:
288  Vector2u m_size;
289  std::vector<uint8_t> m_pixels;
290 
291  };
292 
293 #ifndef DOXYGEN_SHOULD_SKIP_THIS
294 }
295 #endif
296 }
297 
298 #endif // GF_IMAGE_H
Class for loading, manipulating and saving images.
Definition: Image.h:92
The namespace for gf classes.
Definition: Action.h:34
Abstract class for custom file input streams.
Definition: InputStream.h:51
boost::filesystem::path Path
A path in the filesystem.
Definition: Path.h:41