Image.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. 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 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON 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
26 SOFTWARE, 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 <iostream>
33 #include <string>
34 #include <cstdlib>
35 #include <memory>
36 
37 #include "SDL.h"
38 #include "SDL_image.h"
39 
40 #include "nomlib/config.hpp"
41 #include "nomlib/math/Color.hpp"
42 #include "nomlib/math/Coords.hpp"
43 #include "nomlib/math/Point2-inl.hpp"
44 #include "nomlib/SDL_helpers.hpp"
45 
46 namespace nom {
47 
49 class Image
50 {
51  public:
53  Image ( void );
54 
56  virtual ~Image ( void );
57 
60  Image ( uint32 img_flags );
61 
63  Image ( const Image& other );
64 
66  Image& operator = ( const Image& other );
67 
76  bool initialize( void* pixels, int32 width, int32 height,
77  int32 bpp, uint16 pitch,
78  uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask );
79 
81  SDL_SURFACE::RawPtr image ( void ) const;
82 
84  bool valid ( void ) const;
85 
86  int32 width ( void ) const;
87  int32 height ( void ) const;
88  void* pixels ( void ) const;
89  uint16 pitch ( void ) const;
90 
92  uint8 bits_per_pixel ( void ) const;
93 
94  const SDL_PIXELFORMAT::RawPtr pixel_format ( void ) const;
95 
97  const uint32 red_mask ( void ) const;
98 
100  const uint32 green_mask ( void ) const;
101 
103  const uint32 blue_mask ( void ) const;
104 
106  const uint32 alpha_mask ( void ) const;
107 
115  //bool getCanvasLock ( void ) const;
116 
120  //bool lock ( void ) const;
121 
126  //void unlock ( void ) const;
127 
128  const Coords bounds ( void ) const;
129 
130  void set_bounds ( const Coords& clip_bounds );
131 
134  bool load ( const std::string& filename );
135 
141  bool load_bmp ( const std::string& filename );
142 
148  bool save ( const std::string& filename, SDL_SURFACE::RawPtr video_buffer ) const;
149 
154  bool save ( const std::string& filename ) const;
155 
157  const Point2i size ( void ) const;
158 
162  const Color colorkey ( void ) const;
163 
165  const SDL_BlendMode blend_mode ( void ) const;
166 
171  bool set_colorkey ( const Color& colorkey, bool flag );
172 
180  bool RLE ( bool flag );
181 
189  uint32 pixel ( int32 x, int32 y );
190 
192  bool set_blend_mode ( const SDL_BlendMode blend );
193 
194  private:
195  SDL_SURFACE::SharedPtr image_;
196 };
197 
198 
199 } // namespace nom
200 
201 #endif // NOMLIB_SDL_IMAGE_HEADERS defined
bool load_bmp(const std::string &filename)
Definition: Image.cpp:202
Image & operator=(const Image &other)
Copy assignment constructor.
Definition: Image.cpp:67
virtual ~Image(void)
Destructor.
Definition: Image.cpp:45
const Point2i size(void) const
Obtain the width and height (in pixels) of the stored bitmap buffer.
Definition: Image.cpp:237
const uint32 green_mask(void) const
Obtain the video surface&#39;s green alpha mask.
Definition: Image.cpp:147
Image(void)
Default constructor – initializes to sane defaults.
Definition: Image.cpp:33
uint32 pixel(int32 x, int32 y)
Definition: Image.cpp:306
SDL_SURFACE::RawPtr image(void) const
Obtain the SDL_Surface struct used in this object instance.
Definition: Image.cpp:93
bool RLE(bool flag)
Definition: Image.cpp:296
bool set_colorkey(const Color &colorkey, bool flag)
Definition: Image.cpp:274
const Coords bounds(void) const
Definition: Image.cpp:162
bool load(const std::string &filename)
Definition: Image.cpp:185
const uint32 alpha_mask(void) const
Obtain the video surface&#39;s alpha mask.
Definition: Image.cpp:157
const uint32 blue_mask(void) const
Obtain the video surface&#39;s blue alpha mask.
Definition: Image.cpp:152
Bitmap storage container.
Definition: Image.hpp:49
const SDL_BlendMode blend_mode(void) const
Obtain the blend mode used for blitting.
Definition: Image.cpp:261
bool set_blend_mode(const SDL_BlendMode blend)
Set a new blending mode for blitting.
Definition: Image.cpp:346
bool initialize(void *pixels, int32 width, int32 height, int32 bpp, uint16 pitch, uint32 Rmask, uint32 Gmask, uint32 Bmask, uint32 Amask)
Definition: Image.cpp:74
bool valid(void) const
Is this object initialized? Valid when NOT nullptr.
Definition: Image.cpp:98
uint8 bits_per_pixel(void) const
Definition: Image.cpp:129
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44
bool save(const std::string &filename, SDL_SURFACE::RawPtr video_buffer) const
Definition: Image.cpp:218
const Color colorkey(void) const
Definition: Image.cpp:245
const uint32 red_mask(void) const
Obtain the video surface&#39;s red alpha mask.
Definition: Image.cpp:142
Utility class container for RGBA colors.
Definition: Color.hpp:43