nomlib
Loading...
Searching...
No Matches
Image.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SDL2_IMAGE_HEADERS
30#define NOMLIB_SDL2_IMAGE_HEADERS
31
32#include <string>
33#include <memory>
34
35// TODO: Forward declare
36#include <SDL.h>
37
38#include "export.hpp"
39#include "nomlib/config.hpp"
40#include "nomlib/math/Color4.hpp"
41#include "nomlib/math/Point2.hpp"
42#include "nomlib/math/Size2.hpp"
43#include "nomlib/math/Rect.hpp"
44
45namespace nom {
46
48class NOM_EXPORT Image
49{
50 public:
51 typedef Image* RawPtr;
52 typedef std::shared_ptr<Image> SharedPtr;
53
55 Image ( void );
56
61 ~Image( void );
62
64 Image ( const Image& copy );
65
67 Image& operator = ( const Image& other );
68
72 SDL_Surface* clone ( void ) const;
73
75 SDL_Surface* image ( void ) const;
76
77 SDL_Texture* texture ( void ) const;
78
80 bool valid ( void ) const;
81
90 bool initialize ( void* pixels, int32 width, int32 height,
91 int bits_per_pixel, uint16 pitch,
92 uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask
93 );
94
98 bool initialize ( int32 width, int32 height, int bits_per_pixel, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask );
99
103 bool initialize ( SDL_Surface* source );
104
111 bool create(const Point2i& size, uint32 pixel_format);
112 bool create( const Size2i& size, uint32 pixel_format );
113
121 bool initialize ( const Point2i& size );
122
123 int32 width ( void ) const;
124 int32 height ( void ) const;
125 void* pixels ( void ) const;
126 uint16 pitch ( void ) const;
127
128 uint8 bits_per_pixel ( void ) const;
129
130 const SDL_PixelFormat* pixel_format ( void ) const;
131
133 uint32 red_mask ( void ) const;
134
136 uint32 green_mask ( void ) const;
137
139 uint32 blue_mask ( void ) const;
140
142 uint32 alpha_mask ( void ) const;
143
144 const IntRect bounds ( void ) const;
145
147 bool must_lock() const;
148
155 bool locked( void ) const;
156
158 uint8 alpha ( void ) const;
159
160 const Point2i position ( void ) const;
161
162 void set_bounds ( const IntRect& bounds );
163
166 bool load( const std::string& filename, uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 );
167
176 bool load_memory( const char* buffer,
177 int buffer_size,
178 const std::string& ext,
179 uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 );
180
186 bool load_bmp ( const std::string& filename, uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 );
187
194 bool save_bmp ( const std::string& filename ) const;
195
202 bool save_png ( const std::string& filename ) const;
203
205 Size2i size() const;
206
210 const Color4i colorkey ( void ) const;
211
213 SDL_BlendMode blend_mode ( void ) const;
214
219 const Color4i color_modulation ( void ) const;
220
225 bool set_colorkey(const Color4i& colorkey, bool flag);
226
234 bool RLE(bool flag);
235
249 uint32 pixel( int x, int y ) const;
250
254 Color4i color4i_pixel( int x, int y ) const;
255
259 Color4i pixel( const Point2i& pos ) const;
260
271 void set_pixel( int x, int y, const Color4i& color );
272
274 bool set_blend_mode ( const SDL_BlendMode blend );
275
278 bool lock() const;
279
284 void unlock ( void ) const;
285
286 bool set_alpha ( uint8 opacity );
287
288 void set_position ( const Point2i& pos );
289
293 void draw ( SDL_Surface* destination, const IntRect& bounds ) const;
294
305 bool set_color_modulation ( const Color4i& color );
306
307 private:
309 std::shared_ptr<SDL_Surface> image_;
310
311 Point2i position_; // Not implemented
312 IntRect bounds_; // Not implemented
313};
314
315} // namespace nom
316
317#endif // NOMLIB_SDL_IMAGE_HEADERS defined
SDL_Surface * image(void) const
Obtain the SDL_Surface struct used in this object instance.
bool load_memory(const char *buffer, int buffer_size, const std::string &ext, uint32 pixel_format=SDL_PIXELFORMAT_ARGB8888)
Load an image surface from a memory source.
uint32 alpha_mask(void) const
Obtain the video surface's alpha mask.
bool set_color_modulation(const Color4i &color)
Set an additional color value multiplied into render copy operations.
const Color4i colorkey(void) const
void draw(SDL_Surface *destination, const IntRect &bounds) const
bool valid(void) const
Is this object initialized? Valid when NOT nullptr.
bool set_colorkey(const Color4i &colorkey, bool flag)
SDL_Surface * clone(void) const
Make a copy of the existing surface.
bool set_blend_mode(const SDL_BlendMode blend)
Set a new blending mode for blitting.
bool initialize(const Point2i &size)
Create a new memory buffer using the most optimal pixel format detected for your graphics hardware.
bool initialize(SDL_Surface *source)
Initialize a nom::Image from an existing SDL_Surface.
bool initialize(int32 width, int32 height, int bits_per_pixel, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask)
Image(void)
Default constructor – initializes to sane defaults.
uint32 red_mask(void) const
Obtain the video surface's red alpha mask.
uint32 blue_mask(void) const
Obtain the video surface's blue alpha mask.
Color4i pixel(const Point2i &pos) const
Read a RGBA pixel from the video surface.
void set_pixel(int x, int y, const Color4i &color)
Blit a RGBA pixel onto the video surface.
bool load_bmp(const std::string &filename, uint32 pixel_format=SDL_PIXELFORMAT_ARGB8888)
const Color4i color_modulation(void) const
Obtain the additional color value multiplied into render copy operations.
std::shared_ptr< SDL_Surface > image_
Container for our image pixels buffer.
Definition Image.hpp:309
bool load(const std::string &filename, uint32 pixel_format=SDL_PIXELFORMAT_ARGB8888)
uint32 green_mask(void) const
Obtain the video surface's green alpha mask.
bool create(const Point2i &size, uint32 pixel_format)
Create a new memory buffer.
bool must_lock() const
Check to see if the video surface needs locking.
bool save_bmp(const std::string &filename) const
Color4i color4i_pixel(int x, int y) const
Read a RGBA pixel from the video surface.
bool locked(void) const
~Image(void)
Destructor.
bool RLE(bool flag)
SDL_BlendMode blend_mode(void) const
Obtain the blend mode used for blitting.
bool initialize(void *pixels, int32 width, int32 height, int bits_per_pixel, uint16 pitch, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask)
bool lock() const
bool save_png(const std::string &filename) const
uint8 alpha(void) const
Obtain the alpha value of this video surface.
void unlock(void) const
uint32 pixel(int x, int y) const
Read a RGBA pixel from the video surface.
Image(const Image &copy)
Copy constructor.
Size2i size() const
Obtain the width and height (in pixels) of the stored bitmap buffer.