Gamedev Framework (gf)  0.20.0
A C++17 framework for 2D games
Image.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 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 "CoreApi.h"
32 #include "Path.h"
33 #include "Span.h"
34 #include "Vector.h"
35 #include "Rect.h"
36 
37 namespace gf {
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 inline namespace v1 {
40 #endif
41 
42  class InputStream;
43 
48  enum PixelFormat {
51  };
52 
81  class GF_CORE_API Image {
82  public:
88  Image();
89 
97  Image(Vector2i size);
98 
105  Image(Vector2i size, Color4u color);
106 
113  Image(Vector2i size, Color3u color);
114 
126  Image(Vector2i size, const uint8_t *pixels, PixelFormat format = PixelFormat::Rgba32);
127 
138  Image(const Path& filename);
139 
150  Image(Span<const uint8_t> content);
151 
162  Image(InputStream& stream);
163 
167  Image(const Image&) = default;
168 
172  Image& operator=(const Image&) = default;
173 
177  Image(Image&&) = default;
178 
182  Image& operator=(Image&&) = default;
183 
196  bool saveToFile(const Path& filename) const;
197 
208  Image subImage(const RectI& area) const;
209 
215  Vector2i getSize() const;
216 
227  void createMaskFromColor(const Color4u& color, uint8_t alpha = 0);
228 
241  void setPixel(Vector2i pos, const Color4u& color);
242 
256  Color4u getPixel(Vector2i pos) const;
257 
270  const uint8_t* getPixelsPtr() const;
271 
277  void flipHorizontally();
278 
279  private:
280  Vector2i m_size;
281  std::vector<uint8_t> m_pixels;
282 
283  };
284 
285 #ifndef DOXYGEN_SHOULD_SKIP_THIS
286 }
287 #endif
288 }
289 
290 #endif // GF_IMAGE_H
Three 8-bit channels.
Definition: Image.h:50
std::filesystem::path Path
A path in the filesystem.
Definition: Path.h:40
PixelFormat
Pixel format.
Definition: Image.h:48
Class for loading, manipulating and saving images.
Definition: Image.h:81
The namespace for gf classes.
Definition: Action.h:35
Abstract class for custom file input streams.
Definition: Stream.h:54
A 4D vector.
Definition: Vector.h:852
Four 8-bit channels.
Definition: Image.h:49
A 3D vector.
Definition: Vector.h:570