NGL  6.5
The NCCA Graphics Library
Image.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU 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  This program 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 General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #ifndef IMAGE_H_
18 #define IMAGE_H_
19 #include <string>
27 #include <memory>
28 #include "Types.h"
29 #include "Colour.h"
30 namespace ngl
31 {
32 
34 {
35 public:
36  //----------------------------------------------------------------------------------------------------------------------
38  //----------------------------------------------------------------------------------------------------------------------
39  Image() =default;
40  //----------------------------------------------------------------------------------------------------------------------
43  //----------------------------------------------------------------------------------------------------------------------
44  Image(const std::string &_fname);
45  //----------------------------------------------------------------------------------------------------------------------
48  //----------------------------------------------------------------------------------------------------------------------
49  Image(const Image &_i);
50  //----------------------------------------------------------------------------------------------------------------------
52  //----------------------------------------------------------------------------------------------------------------------
53  ~Image()=default;
54  //----------------------------------------------------------------------------------------------------------------------
58  //----------------------------------------------------------------------------------------------------------------------
59  bool load(const std::string &_fname) noexcept;
60  //----------------------------------------------------------------------------------------------------------------------
63  //----------------------------------------------------------------------------------------------------------------------
64  unsigned char *getPixels() const noexcept {return m_data.get();}
65  //----------------------------------------------------------------------------------------------------------------------
73  //----------------------------------------------------------------------------------------------------------------------
74  enum class ImageModes : char {RGB,RGBA};
75  static void saveFrameBufferToFile(const std::string &_fname, int _x, int _y, int _width, int _height,ImageModes _mode=ImageModes::RGB);
76  //----------------------------------------------------------------------------------------------------------------------
79  //----------------------------------------------------------------------------------------------------------------------
80  GLuint width()const noexcept{return m_width;}
81  //----------------------------------------------------------------------------------------------------------------------
84  //----------------------------------------------------------------------------------------------------------------------
85  GLuint height()const noexcept{return m_height;}
86  //----------------------------------------------------------------------------------------------------------------------
89  //----------------------------------------------------------------------------------------------------------------------
90  GLuint format()const noexcept{return m_format;}
91  //----------------------------------------------------------------------------------------------------------------------
94  //----------------------------------------------------------------------------------------------------------------------
95  GLuint channels()const noexcept{return m_channels;}
96  //----------------------------------------------------------------------------------------------------------------------
100  //----------------------------------------------------------------------------------------------------------------------
101  Colour getColour(const GLuint _x, const GLuint _y ) const noexcept;
102  //----------------------------------------------------------------------------------------------------------------------
106  //----------------------------------------------------------------------------------------------------------------------
107  Colour getColour(const Real _uvX, const Real _uvY) const noexcept;
108 
109 private :
110  //----------------------------------------------------------------------------------------------------------------------
113  //----------------------------------------------------------------------------------------------------------------------
114  std::unique_ptr <unsigned char[] > m_data;
115  //----------------------------------------------------------------------------------------------------------------------
117  //----------------------------------------------------------------------------------------------------------------------
118  GLuint m_width=0;
119  //----------------------------------------------------------------------------------------------------------------------
121  //----------------------------------------------------------------------------------------------------------------------
122  GLuint m_height=0;
123  //----------------------------------------------------------------------------------------------------------------------
125  //----------------------------------------------------------------------------------------------------------------------
126  GLuint m_channels=3;
127  //----------------------------------------------------------------------------------------------------------------------
129  //----------------------------------------------------------------------------------------------------------------------
130  GLuint m_format=GL_RGB;
131  //----------------------------------------------------------------------------------------------------------------------
133  //----------------------------------------------------------------------------------------------------------------------
134  bool m_loaded=false;
135  //----------------------------------------------------------------------------------------------------------------------
137  //----------------------------------------------------------------------------------------------------------------------
138  bool m_hasAlpha=false;
139 
140 };
141 
142 
143 
144 
145 }
146 
147 #endif
unsigned int GLuint
Definition: glew.h:280
simple class to hold colour information and set the basic opengl colour state. also has overloaded me...
Definition: Colour.h:40
a simple colour class for RGBA colour
main definition of types and namespace
#define NGL_DLLEXPORT
Definition: Types.h:65
implementation files for RibExport class
Definition: AABB.cpp:22
GLuint format() const noexcept
Get the pixel format.
Definition: Image.h:90
GLuint channels() const noexcept
gets the number of channels
Definition: Image.h:95
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
GLuint width() const noexcept
Get the width of the texture.
Definition: Image.h:80
#define GL_RGB
Definition: glew.h:680
unsigned char * getPixels() const noexcept
raw access to unsigned char pixel data
Definition: Image.h:64
std::unique_ptr< unsigned char[] > m_data
the actual image data loaded packed in r,g,b,(a) format in contiguous memory stored in a smart_pointe...
Definition: Image.h:114
GLsizei const GLchar *const * string
Definition: glew.h:1847
GLuint height() const noexcept
Get the height of the texture.
Definition: Image.h:85
ImageModes
save the FrameBuffer to file using current built in I/O
Definition: Image.h:74