zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Image.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
32 #ifndef ZENI_IMAGE_H
33 #define ZENI_IMAGE_H
34 
35 #include <Zeni/Color.h>
36 #include <Zeni/Coordinate.h>
37 #include <Zeni/Core.h>
38 #include <Zeni/String.h>
39 
40 /* \cond */
41 #ifndef ANDROID
42 #ifdef _MACOSX
43 #include <SDL/SDL.h>
44 #else
45 #include <SDL/SDL.h>
46 #endif
47 #endif
48 /* \endcond */
49 
50 namespace Zeni {
51 
52  class ZENI_GRAPHICS_DLL Image {
53  public:
54  enum Color_Space {Luminance, Luminance_Alpha, RGB, RGBA};
55 
56  Image();
57  Image(const String &filename, const bool &tileable_ = false);
58  Image(const Point2i &size_, const Color_Space &color_space_, const bool &tileable_ = false);
59 
60  inline Color_Space color_space() const;
61  inline const Uint8 * get_data() const;
62  inline Uint8 * get_data();
63  inline const Point2i & size() const;
64  inline int width() const;
65  inline int height() const;
66  inline bool tileable() const;
67 
68  void set_Color(const Point2i &pixel, const Color &color);
69  void set_RGBA(const Point2i &pixel, const Uint32 &rgba);
70  Color extract_Color(const Point2i &pixel) const;
71  Uint32 extract_RGBA(const Point2i &pixel) const;
72 
73  Color extract_Color(const Point2f &coordinate) const;
74 
75  void resize(const int &width, const int &height);
76  bool blit(const Point2i &upper_left, const Image &source);
77 
78  private:
79  const Uint8 * get_pixel(const Point2i &pixel) const;
80  Uint8 * get_pixel(const Point2i &pixel);
81 
82  Point2i m_size;
83  Color_Space m_color_space;
84 
85  int m_bytes_per_pixel;
86  int m_row_size;
87 
88 #ifdef _WINDOWS
89 #pragma warning( push )
90 #pragma warning( disable : 4251 )
91 #endif
92  std::vector<Uint8> m_data;
93 #ifdef _WINDOWS
94 #pragma warning( pop )
95 #endif
96 
97  bool m_tileable;
98  };
99 
100  struct ZENI_GRAPHICS_DLL Image_Init_Failure : public Error {
101  Image_Init_Failure() : Error("Zeni Image Failed to Initialize Correctly") {}
102  };
103 
104  struct ZENI_GRAPHICS_DLL Image_Index_Error : public Error {
105  Image_Index_Error() : Error("Zeni Image Indexed Out of Bounds") {}
106  };
107 
108 }
109 
110 #endif
Definition: edid.h:20
GLuint color
Definition: glew.h:7185
EGLSurface EGLint EGLint EGLint EGLint height
Definition: eglext.h:293
Image.
Definition: Image.h:52
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
EGLSurface EGLint EGLint EGLint width
Definition: eglext.h:293
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:129
The Error Class.
Definition: Error.h:52
A 2D Point represented with floats.
Definition: Coordinate.h:98
GLsizei GLsizei GLchar * source
Definition: gl2ext.h:994
Color.
Definition: Color.h:41
Color_Space
Definition: Image.h:54
GLsizei size
Definition: gl2ext.h:1467
A 2D Point represented with integers.
Definition: Coordinate.h:85