NGL  6.5
The NCCA Graphics Library
ngl::Image Class Reference

#include <Image.h>

+ Collaboration diagram for ngl::Image:

Public Types

enum  ImageModes : char { ImageModes::RGB, ImageModes::RGBA }
 save the FrameBuffer to file using current built in I/O More...
 

Public Member Functions

 Image ()=default
 default ctor More...
 
 Image (const std::string &_fname)
 ctor passing in filename More...
 
 Image (const Image &_i)
 copy ctor (does a deep copy so could be expensive) More...
 
 ~Image ()=default
 dtor as we use a smart pointer the data will release automatically More...
 
bool load (const std::string &_fname) noexcept
 load the image data, this will clear the previous data and attempt to load the new image data More...
 
unsigned char * getPixels () const noexcept
 raw access to unsigned char pixel data More...
 
GLuint width () const noexcept
 Get the width of the texture. More...
 
GLuint height () const noexcept
 Get the height of the texture. More...
 
GLuint format () const noexcept
 Get the pixel format. More...
 
GLuint channels () const noexcept
 gets the number of channels More...
 
Colour getColour (const GLuint _x, const GLuint _y) const noexcept
 get the colour value from X,Y co-ordinates (image absolute 0,0 = top Left) More...
 
Colour getColour (const Real _uvX, const Real _uvY) const noexcept
 get the colour value from X,Y co-ordinates in texture space More...
 

Static Public Member Functions

static void saveFrameBufferToFile (const std::string &_fname, int _x, int _y, int _width, int _height, ImageModes _mode=ImageModes::RGB)
 

Private Attributes

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_pointer for safety More...
 
GLuint m_width =0
 the size of the image in the X direction More...
 
GLuint m_height =0
 the size of the image in the Y direction More...
 
GLuint m_channels =3
 bits per pixel (RGB / RGBA) More...
 
GLuint m_format =GL_RGB
 image format, use GL types for this as we are going to use this class mainly for OpenGL More...
 
bool m_loaded =false
 loaded flag More...
 
bool m_hasAlpha =false
 do we have an alpha channel More...
 

Detailed Description

Definition at line 33 of file Image.h.

Member Enumeration Documentation

enum ngl::Image::ImageModes : char
strong

save the FrameBuffer to file using current built in I/O

Parameters
_fnamethe name / path of the file to save _x the x position into the framebuffer This location is the lower left corner of a rectangular block of pixels _y the y position into the framebuffer This location is the lower left corner of a rectangular block of pixels _width of the rectangle _height the height of the rectangle _mode RGB or RGBA image
Enumerator
RGB 
RGBA 

Definition at line 74 of file Image.h.

Constructor & Destructor Documentation

ngl::Image::Image ( )
default

default ctor

ngl::Image::Image ( const std::string _fname)

ctor passing in filename

Parameters
_fnamethe name of the file to load.

Definition at line 41 of file Image.cpp.

References load().

+ Here is the call graph for this function:

ngl::Image::Image ( const Image _i)

copy ctor (does a deep copy so could be expensive)

Parameters
_iimage to copy

Definition at line 46 of file Image.cpp.

References m_channels, m_data, m_height, and m_width.

ngl::Image::~Image ( )
default

dtor as we use a smart pointer the data will release automatically

Member Function Documentation

GLuint ngl::Image::channels ( ) const
inlinenoexcept

gets the number of channels

Returns
usually 3 (RGB) or 4 (RGBA) but can handle others depending on libl

Definition at line 95 of file Image.h.

+ Here is the caller graph for this function:

GLuint ngl::Image::format ( ) const
inlinenoexcept

Get the pixel format.

Returns
pixel format of the texture

Definition at line 90 of file Image.h.

+ Here is the caller graph for this function:

Colour ngl::Image::getColour ( const GLuint  _x,
const GLuint  _y 
) const
noexcept

get the colour value from X,Y co-ordinates (image absolute 0,0 = top Left)

Parameters
[in]_xthe x position in the image
[in]_ythe y position in the image

Definition at line 56 of file Image.cpp.

References m_channels, m_data, m_height, m_width, and NGL_ASSERT.

Colour ngl::Image::getColour ( const Real  _uvX,
const Real  _uvY 
) const
noexcept

get the colour value from X,Y co-ordinates in texture space

Parameters
[in]_uvXthe x position in the image
[in]_uvYthe y position in the image

Definition at line 79 of file Image.cpp.

References m_channels, m_data, m_height, m_width, and NGL_ASSERT.

unsigned char* ngl::Image::getPixels ( ) const
inlinenoexcept

raw access to unsigned char pixel data

Returns
a pointer to the first image pixel element.

Definition at line 64 of file Image.h.

+ Here is the caller graph for this function:

GLuint ngl::Image::height ( ) const
inlinenoexcept

Get the height of the texture.

Returns
height of the texture

Definition at line 85 of file Image.h.

+ Here is the caller graph for this function:

bool ngl::Image::load ( const std::string _fname)
noexcept

load the image data, this will clear the previous data and attempt to load the new image data

Parameters
_fnamename of the file to load
Returns
true is loaded ok, else false

+ Here is the caller graph for this function:

void ngl::Image::saveFrameBufferToFile ( const std::string _fname,
int  _x,
int  _y,
int  _width,
int  _height,
ImageModes  _mode = ImageModes::RGB 
)
static

Definition at line 105 of file Image.cpp.

References GL_RGB, GL_RGBA, GL_UNSIGNED_BYTE, glReadPixels(), load(), m_channels, m_data, m_format, m_hasAlpha, m_height, m_width, NGL_ASSERT, and RGBA.

+ Here is the call graph for this function:

GLuint ngl::Image::width ( ) const
inlinenoexcept

Get the width of the texture.

Returns
width of the texture

Definition at line 80 of file Image.h.

+ Here is the caller graph for this function:

Member Data Documentation

GLuint ngl::Image::m_channels =3
private

bits per pixel (RGB / RGBA)

Definition at line 126 of file Image.h.

std::unique_ptr<unsigned char[] > ngl::Image::m_data
private

the actual image data loaded packed in r,g,b,(a) format in contiguous memory stored in a smart_pointer for safety

Definition at line 114 of file Image.h.

GLuint ngl::Image::m_format =GL_RGB
private

image format, use GL types for this as we are going to use this class mainly for OpenGL

Definition at line 130 of file Image.h.

bool ngl::Image::m_hasAlpha =false
private

do we have an alpha channel

Definition at line 138 of file Image.h.

GLuint ngl::Image::m_height =0
private

the size of the image in the Y direction

Definition at line 122 of file Image.h.

bool ngl::Image::m_loaded =false
private

loaded flag

Definition at line 134 of file Image.h.

GLuint ngl::Image::m_width =0
private

the size of the image in the X direction

Definition at line 118 of file Image.h.


The documentation for this class was generated from the following files: