Image.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages 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 freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef CPP3DS_IMAGE_HPP
26 #define CPP3DS_IMAGE_HPP
27 
29 // Headers
31 #include <cpp3ds/Graphics/Color.hpp>
32 #include <cpp3ds/Graphics/Rect.hpp>
33 #include <string>
34 #include <vector>
35 
36 
37 namespace cpp3ds
38 {
39 class InputStream;
40 
45 class Image
46 {
47 public :
48 
55  Image();
56 
61  ~Image();
62 
71  void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0));
72 
86  void create(unsigned int width, unsigned int height, const Uint8* pixels);
87 
103  bool loadFromFile(const std::string& filename);
104 
121  bool loadFromMemory(const void* data, std::size_t size);
122 
138  bool loadFromStream(InputStream& stream);
139 
155  bool saveToFile(const std::string& filename) const;
156 
163  Vector2u getSize() const;
164 
176  void createMaskFromColor(const Color& color, Uint8 alpha = 0);
177 
198  void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false);
199 
214  void setPixel(unsigned int x, unsigned int y, const Color& color);
215 
231  Color getPixel(unsigned int x, unsigned int y) const;
232 
246  const Uint8* getPixelsPtr() const;
247 
252  void flipHorizontally();
253 
258  void flipVertically();
259 
260 private :
261 
263  // Member data
265  Vector2u m_size;
266  std::vector<Uint8> m_pixels;
267 };
268 
269 }
270 
271 
272 #endif
273 
274 
~Image()
Destructor.
void setPixel(unsigned int x, unsigned int y, const Color &color)
Change the color of a pixel.
Abstract class for custom file input streams.
Definition: InputStream.hpp:40
Color getPixel(unsigned int x, unsigned int y) const
Get the color of a pixel.
Utility class for manpulating RGBA colors.
Definition: Color.hpp:36
bool loadFromStream(InputStream &stream)
Load the image from a custom stream.
bool loadFromFile(const std::string &filename)
Load the image from a file on disk.
void copy(const Image &source, unsigned int destX, unsigned int destY, const IntRect &sourceRect=IntRect(0, 0, 0, 0), bool applyAlpha=false)
Copy pixels from another image onto this one.
bool loadFromMemory(const void *data, std::size_t size)
Load the image from a file in memory.
void flipHorizontally()
Flip the image horizontally (left <-> right)
const Uint8 * getPixelsPtr() const
Get a read-only pointer to the array of pixels.
bool saveToFile(const std::string &filename) const
Save the image to a file on disk.
Class for loading, manipulating and saving images.
Definition: Image.hpp:45
Image()
Default constructor.
Vector2u getSize() const
Return the size (width and height) of the image.
void flipVertically()
Flip the image vertically (top <-> bottom)
void createMaskFromColor(const Color &color, Uint8 alpha=0)
Create a transparency mask from a specified color-key.
void create(unsigned int width, unsigned int height, const Color &color=Color(0, 0, 0))
Create the image and fill it with a unique color.