Loading...
Searching...
No Matches
Image.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2009 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 SFML_IMAGE_HPP
26#define SFML_IMAGE_HPP
27
29// Headers
34#include <string>
35#include <vector>
36
37
38namespace sf
39{
40class RenderWindow;
41
46class SFML_API Image : public Resource<Image>
47{
48public :
49
55
62 Image(const Image& Copy);
63
72 Image(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255));
73
82 Image(unsigned int Width, unsigned int Height, const Uint8* Data);
83
89
98 bool LoadFromFile(const std::string& Filename);
99
109 bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
110
121 bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data);
122
131 bool SaveToFile(const std::string& Filename) const;
132
143 bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));
144
152 void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0);
153
166 void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false);
167
178 bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
179
188 void SetPixel(unsigned int X, unsigned int Y, const Color& Col);
189
199 const Color& GetPixel(unsigned int X, unsigned int Y) const;
200
209 const Uint8* GetPixelsPtr() const;
210
215 void Bind() const;
216
224 void SetSmooth(bool Smooth);
225
232 unsigned int GetWidth() const;
233
240 unsigned int GetHeight() const;
241
248 bool IsSmooth() const;
249
260
269 static unsigned int GetValidTextureSize(unsigned int Size);
270
279 Image& operator =(const Image& Other);
280
281private :
282
289 bool CreateTexture();
290
295 void EnsureTextureUpdate() const;
296
301 void EnsureArrayUpdate() const;
302
307 void Reset();
308
313 void DestroyTexture();
314
316 // Member data
318 unsigned int myWidth;
319 unsigned int myHeight;
320 unsigned int myTextureWidth;
321 unsigned int myTextureHeight;
322 unsigned int myTexture;
323 bool myIsSmooth;
324 mutable std::vector<Color> myPixels;
325 mutable bool myNeedTextureUpdate;
326 mutable bool myNeedArrayUpdate;
327};
328
329} // namespace sf
330
331
332#endif // SFML_IMAGE_HPP
#define SFML_API
Definition Config.hpp:114
Color is an utility class for manipulating 32-bits RGBA colors.
Definition Color.hpp:41
unsigned int GetHeight() const
Return the height of the image.
~Image()
Destructor.
void Bind() const
Bind the image for rendering.
bool SaveToFile(const std::string &Filename) const
Save the content of the image to a file.
static unsigned int GetValidTextureSize(unsigned int Size)
Get a valid texture size according to hardware support.
Image(unsigned int Width, unsigned int Height, const Color &Col=Color(0, 0, 0, 255))
Construct an empty image.
const Uint8 * GetPixelsPtr() const
Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) Array size is GetWid...
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 Create(unsigned int Width, unsigned int Height, Color Col=Color(0, 0, 0, 255))
Create an empty image.
void SetPixel(unsigned int X, unsigned int Y, const Color &Col)
Change the color of a pixel.
bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8 *Data)
Load the image directly from an array of pixels.
unsigned int GetWidth() const
Return the width of the image.
Image(unsigned int Width, unsigned int Height, const Uint8 *Data)
Construct the image from pixels in memory.
bool LoadFromMemory(const char *Data, std::size_t SizeInBytes)
Load the image from a file in memory.
const Color & GetPixel(unsigned int X, unsigned int Y) const
Get a pixel from the image.
bool LoadFromFile(const std::string &Filename)
Load the image from a file.
bool CopyScreen(RenderWindow &Window, const IntRect &SourceRect=IntRect(0, 0, 0, 0))
Create the image from the current contents of the given window.
Image(const Image &Copy)
Copy constructor.
Image()
Default constructor.
FloatRect GetTexCoords(const IntRect &Rect) const
Convert a subrect expressed in pixels, into float texture coordinates.
void SetSmooth(bool Smooth)
Enable or disable image smooth filter.
bool IsSmooth() const
Tells whether the smooth filtering is enabled or not.
void CreateMaskFromColor(Color ColorKey, Uint8 Alpha=0)
Create transparency mask from a specified colorkey.
Rect is an utility class for manipulating rectangles.
Definition Rect.hpp:42
Simple wrapper for sf::Window that allows easy 2D rendering.
Window is a rendering window ; it can create a new window or connect to an existing one.
Rect< int > IntRect
Definition Rect.hpp:121
Rect< float > FloatRect
Definition Rect.hpp:122