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 "nomlib/config.hpp"
39#include "nomlib/math/Color4.hpp"
40#include "nomlib/math/Point2.hpp"
41#include "nomlib/math/Size2.hpp"
42#include "nomlib/math/Rect.hpp"
43
44namespace nom {
45
47class Image
48{
49 public:
50 typedef Image* RawPtr;
51 typedef std::shared_ptr<Image> SharedPtr;
52
54 Image ( void );
55
60 ~Image( void );
61
63 Image ( const Image& copy );
64
66 Image& operator = ( const Image& other );
67
71 SDL_Surface* clone ( void ) const;
72
74 SDL_Surface* image ( void ) const;
75
76 SDL_Texture* texture ( void ) const;
77
79 bool valid ( void ) const;
80
89 bool initialize ( void* pixels, int32 width, int32 height,
90 int bits_per_pixel, uint16 pitch,
91 uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask
92 );
93
97 bool initialize ( int32 width, int32 height, int bits_per_pixel, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask );
98
102 bool initialize ( SDL_Surface* source );
103
110 bool create(const Point2i& size, uint32 pixel_format);
111 bool create( const Size2i& size, uint32 pixel_format );
112
120 bool initialize ( const Point2i& size );
121
122 int32 width ( void ) const;
123 int32 height ( void ) const;
124 void* pixels ( void ) const;
125 uint16 pitch ( void ) const;
126
127 uint8 bits_per_pixel ( void ) const;
128
129 const SDL_PixelFormat* pixel_format ( void ) const;
130
132 uint32 red_mask ( void ) const;
133
135 uint32 green_mask ( void ) const;
136
138 uint32 blue_mask ( void ) const;
139
141 uint32 alpha_mask ( void ) const;
142
143 const IntRect bounds ( void ) const;
144
146 bool must_lock() const;
147
154 bool locked( void ) const;
155
157 uint8 alpha ( void ) const;
158
159 const Point2i position ( void ) const;
160
161 void set_bounds ( const IntRect& bounds );
162
165 bool load( const std::string& filename, uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 );
166
175 bool load_memory( const char* buffer,
176 int buffer_size,
177 const std::string& ext,
178 uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 );
179
185 bool load_bmp ( const std::string& filename, uint32 pixel_format = SDL_PIXELFORMAT_ARGB8888 );
186
193 bool save_bmp ( const std::string& filename ) const;
194
201 bool save_png ( const std::string& filename ) const;
202
204 Size2i size() const;
205
209 const Color4i colorkey ( void ) const;
210
212 const SDL_BlendMode blend_mode ( void ) const;
213
218 const Color4i color_modulation ( void ) const;
219
224 bool set_colorkey(const Color4i& colorkey, bool flag);
225
233 bool RLE(bool flag);
234
248 uint32 pixel( int x, int y ) const;
249
253 Color4i color4i_pixel( int x, int y ) const;
254
258 Color4i pixel( const Point2i& pos ) const;
259
270 void set_pixel( int x, int y, const Color4i& color );
271
273 bool set_blend_mode ( const SDL_BlendMode blend );
274
277 bool lock() const;
278
283 void unlock ( void ) const;
284
285 bool set_alpha ( uint8 opacity );
286
287 void set_position ( const Point2i& pos );
288
292 void draw ( SDL_Surface* destination, const IntRect& bounds ) const;
293
304 bool set_color_modulation ( const Color4i& color );
305
306 private:
308 std::shared_ptr<SDL_Surface> image_;
309
310 Point2i position_; // Not implemented
311 IntRect bounds_; // Not implemented
312};
313
314} // namespace nom
315
316#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.
Image & operator=(const Image &other)
Copy assignment constructor.
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:308
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.
const SDL_BlendMode blend_mode(void) const
Obtain the blend mode used for blitting.
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)
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.