Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Image.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "ArrayRef.h"
32 #include "Path.h"
33 #include "Portability.h"
34 #include "Vector.h"
35 
36 namespace gf {
37 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 inline namespace v1 {
39 #endif
40 
41  class InputStream;
42 
47  enum PixelFormat {
50  };
51 
80  class GF_API Image {
81  public:
87  Image();
88 
96  Image(Vector2i size);
97 
104  Image(Vector2i size, Color4u color);
105 
112  Image(Vector2i size, Color3u color);
113 
125  Image(Vector2i size, const uint8_t *pixels, PixelFormat format = PixelFormat::Rgba32);
126 
137  Image(const Path& filename);
138 
149  Image(ArrayRef<uint8_t> content);
150 
161  Image(InputStream& stream);
162 
166  Image(const Image&) = default;
167 
171  Image& operator=(const Image&) = default;
172 
176  Image(Image&&) = default;
177 
181  Image& operator=(Image&&) = default;
182 
195  bool saveToFile(const Path& filename) const;
196 
202  Vector2i getSize() const;
203 
214  void createMaskFromColor(const Color4u& color, uint8_t alpha = 0);
215 
228  void setPixel(Vector2i pos, const Color4u& color);
229 
243  Color4u getPixel(Vector2i pos) const;
244 
257  const uint8_t* getPixelsPtr() const;
258 
264  void flipHorizontally();
265 
266  private:
267  Vector2i m_size;
268  std::vector<uint8_t> m_pixels;
269 
270  };
271 
272 #ifndef DOXYGEN_SHOULD_SKIP_THIS
273 }
274 #endif
275 }
276 
277 #endif // GF_IMAGE_H
PixelFormat
Pixel format.
Definition: Image.h:47
Class for loading, manipulating and saving images.
Definition: Image.h:80
The namespace for gf classes.
Definition: Action.h:35
Abstract class for custom file input streams.
Definition: Stream.h:55
A 4D vector.
Definition: Vector.h:852
Four 8-bit channels.
Definition: Image.h:48
Three 8-bit channels.
Definition: Image.h:49
boost::filesystem::path Path
A path in the filesystem.
Definition: Path.h:44
A 3D vector.
Definition: Vector.h:570