All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Luminous::Image Class Reference

Simple image handling class. More...

#include <Luminous/Image.hpp>

Public Member Functions

void allocate (int width, int height, const PixelFormat &pf)
 Allocates memory, for an image of given size and format. More...
 
float aspect () const
 Get the aspect ratio (width / height) of the image. More...
 
unsigned char * bytes ()
 Get a pointer to image data. More...
 
const unsigned char * bytes () const
 Get a pointer to image data. More...
 
void changed ()
 Increments the generation count. More...
 
void clear ()
 Clears the image, freeing the data.
 
const Luminous::TextureconstTexture () const
 Get a texture object based on the image This function is thread-safe so it can be used in render functions. More...
 
bool copyResample (const Image &source, int w, int h)
 
Resample a source image using straightforward bilinear

interpolation. More...

 
unsigned char * data ()
 Get a pointer to image data. More...
 
const unsigned char * data () const
 Get a pointer to image data. More...
 
void flipVertical ()
 Flip the image upside down.
 
void forgetLastLine ()
 Removes the last line from the image. More...
 
void forgetLastLines (int n)
 Remove lines from the bottom of the image. More...
 
bool forgetLastPixels (int n)
 Remove pixels from the right edge of the image. More...
 
void fromData (const unsigned char *bytes, int width, int height, PixelFormat format)
 Create an image object from data provided by the user. More...
 
size_t generation () const
 The generation count of the image object The generation count can be used to indicate that the image has changed, and one should update the corresponding OpenGL texture wo match the same generation. More...
 
bool hasAlpha () const
 Returns true if the image has an alpha channel. More...
 
bool hasTexture () const
 Check if the image associated texture has been initialized. More...
 
int height () const
 Get the image height. More...
 
 Image ()
 Construct an empty image.
 
 Image (const Image &img)
 Copy constructor. More...
 
 Image (Image &&img)
 Move constructor. More...
 
bool isEmpty () const
 Returns true if the image does not contain any data. More...
 
unsigned char * line (unsigned y)
 Get a pointer to image data on specific line. More...
 
const unsigned char * line (unsigned y) const
 Get a pointer to image data on specific line. More...
 
int lineSize () const
 The number of bytes a single line in the image takes. More...
 
void makeValidTexture ()
 Checks that the image dimensions are feasible for a texture. More...
 
void minify (const Image &src, int w, int h)
 Scale an image to a smaller size. More...
 
Imageoperator= (const Image &img)
 Makes a deep copy of the given image. More...
 
Imageoperator= (Image &&img)
 Move operator. More...
 
Nimble::Vector4 pixel (int x, int y) const
 Gets the color of a given pixel. More...
 
unsigned char pixelAlpha (Nimble::Vector2 relativeCoord) const
 Returns the alpha value [0,255] for the given relative coordinates in the image. More...
 
const PixelFormatpixelFormat () const
 Returns the pixel format of the image.
 
bool quarterSize (const Image &source)
 Down-sample the given image to quarter size. More...
 
bool read (const QString &filename)
 Load an image from the given filename. More...
 
Nimble::Vector4 safePixel (int x, int y) const
 Get a pixel from the image. More...
 
void setPixel (unsigned x, unsigned y, const Nimble::Vector4 &pixel)
 Set a pixel to given color. More...
 
bool setPixelFormat (const PixelFormat &format)
 Sets the new format and converts the image data to new format if necessary. More...
 
Nimble::Size size () const
 Get the image size. More...
 
Luminous::Texturetexture () const
 Get a texture object based on the image This function is thread-safe so it can be used in render functions. More...
 
int width () const
 Get the image width. More...
 
bool write (const QString &filename) const
 Save the image to a file. More...
 
void zero ()
 Fills the image with zeros.
 
virtual ~Image ()
 Destructor.
 

Static Public Member Functions

static CodecRegistrycodecs ()
 Returns a pointer to the file-format codecs. More...
 
static bool ping (const QString &filename, ImageInfo &info)
 Get basic image information from a file. More...
 

Protected Attributes

unsigned char * m_data
 Pointer to the raw image data. More...
 
size_t m_generation
 Generation count of the image used to indicate changes in the image data to determine when associated textures should be updated. More...
 
int m_height
 Height of the image in pixels.
 
PixelFormat m_pixelFormat
 Pixel format of the image data.
 
int m_width
 Width of the image in pixels.
 

Detailed Description

Simple image handling class.

This class is used mainly to load/save image data in various formats. It provides minimal image processing support (resizing).

The image data is stored in a single, straightforward buffer.

Examples:
Widget3DExample.cpp.

Constructor & Destructor Documentation

Luminous::Image::Image ( const Image img)

Copy constructor.

Parameters
imgimage to copy
Luminous::Image::Image ( Image &&  img)

Move constructor.

Parameters
imgimage to move

Member Function Documentation

void Luminous::Image::allocate ( int  width,
int  height,
const PixelFormat pf 
)

Allocates memory, for an image of given size and format.

Parameters
widthwidth in pixels
heightheight in pixels
pfpixel format
float Luminous::Image::aspect ( ) const
inline

Get the aspect ratio (width / height) of the image.

Returns
aspect ratio
unsigned char* Luminous::Image::bytes ( )
inline

Get a pointer to image data.

Returns
pointer to image data
const unsigned char* Luminous::Image::bytes ( ) const
inline

Get a pointer to image data.

Returns
pointer to image data
void Luminous::Image::changed ( )
inline

Increments the generation count.

This function should be called when the image has been modified.

static CodecRegistry* Luminous::Image::codecs ( )
static

Returns a pointer to the file-format codecs.

Returns
pointer to the codec registry
const Luminous::Texture& Luminous::Image::constTexture ( ) const

Get a texture object based on the image This function is thread-safe so it can be used in render functions.

Returns
texture matching the image
bool Luminous::Image::copyResample ( const Image source,
int  w,
int  h 
)

Resample a source image using straightforward bilinear

interpolation.

Parameters
sourceimage to resample
wnew width
hnew height
Returns
true if the resamping succeed
unsigned char* Luminous::Image::data ( )
inline

Get a pointer to image data.

Returns
pointer to image data
const unsigned char* Luminous::Image::data ( ) const
inline

Get a pointer to image data.

Returns
pointer to image data
void Luminous::Image::forgetLastLine ( )

Removes the last line from the image.

void Luminous::Image::forgetLastLines ( int  n)

Remove lines from the bottom of the image.

Parameters
nnumber of lines to remove
bool Luminous::Image::forgetLastPixels ( int  n)

Remove pixels from the right edge of the image.

Works for RGB images.

Parameters
nnumber of pixels to remove
Returns
false if the image is of unsupported pixel format
void Luminous::Image::fromData ( const unsigned char *  bytes,
int  width,
int  height,
PixelFormat  format 
)

Create an image object from data provided by the user.

Parameters
bytespointer to image data
widthwidth of the image data
heightheight of the image data
formatpixel format of the image data
size_t Luminous::Image::generation ( ) const
inline

The generation count of the image object The generation count can be used to indicate that the image has changed, and one should update the corresponding OpenGL texture wo match the same generation.

Returns
current generation count
bool Luminous::Image::hasAlpha ( ) const

Returns true if the image has an alpha channel.

Returns
true if the image has alpha channel
bool Luminous::Image::hasTexture ( ) const

Check if the image associated texture has been initialized.

The texture is initialized lazily when calling texture() method.

Returns
true if the texture has been created
See Also
texture
int Luminous::Image::height ( ) const
inline

Get the image height.

Returns
height in pixels
bool Luminous::Image::isEmpty ( ) const
inline

Returns true if the image does not contain any data.

Returns
true if the data is nullptr; otherwise false
unsigned char* Luminous::Image::line ( unsigned  y)
inline

Get a pointer to image data on specific line.

Parameters
yline to query for
Returns
pointer to beginning of the line
const unsigned char* Luminous::Image::line ( unsigned  y) const
inline

Get a pointer to image data on specific line.

Parameters
yline to query for
Returns
pointer to beginning of the line
int Luminous::Image::lineSize ( ) const
inline

The number of bytes a single line in the image takes.

Returns
line size in bytes
void Luminous::Image::makeValidTexture ( )

Checks that the image dimensions are feasible for a texture.

In practice this functions removes pixels from the right and bottom, to make the width and height multiples of two.

void Luminous::Image::minify ( const Image src,
int  w,
int  h 
)

Scale an image to a smaller size.

The given width and height should be smaller than in the source image.

Parameters
srcsource image
wnew width
hnew height
Image& Luminous::Image::operator= ( const Image img)

Makes a deep copy of the given image.

Parameters
imgimage to copy
Returns
reference to this image
Image& Luminous::Image::operator= ( Image &&  img)

Move operator.

Parameters
imgimage to move
Returns
reference to this image
static bool Luminous::Image::ping ( const QString &  filename,
ImageInfo info 
)
static

Get basic image information from a file.

This function does not decode the actual image data, typically just the header.

Parameters
filenamefilename to query
[out]infoimage information
Returns
true if the operation was successful; otherwise false
Nimble::Vector4 Luminous::Image::pixel ( int  x,
int  y 
) const

Gets the color of a given pixel.

The color is normalized, with each component in range 0-1.

Parameters
xpixel x coordinate
ypixel y coordinate
Returns
color at the given pixel
unsigned char Luminous::Image::pixelAlpha ( Nimble::Vector2  relativeCoord) const

Returns the alpha value [0,255] for the given relative coordinates in the image.

Parameters
relativeCoordrelative pixel coordinate x,y in [0,1]
Returns
alpha of the given pixel or 255 if image does not have alpha channel
bool Luminous::Image::quarterSize ( const Image source)

Down-sample the given image to quarter size.

Parameters
sourceimage to resample
Returns
true if resampling succeeded
bool Luminous::Image::read ( const QString &  filename)

Load an image from the given filename.

Parameters
filenamename of the file to read from
Returns
true if the image was successfully read
Nimble::Vector4 Luminous::Image::safePixel ( int  x,
int  y 
) const

Get a pixel from the image.

This function does additional checks for make sure the requested pixels are within the image. If the requested pixel falls outside the image, transparent color is returned. The color is normalized.

Parameters
xpixel x coordinate
ypixel y coordinate
Returns
pixel color
void Luminous::Image::setPixel ( unsigned  x,
unsigned  y,
const Nimble::Vector4 pixel 
)

Set a pixel to given color.

The color must be normalized.

Parameters
xx coordinate of the pixel
yy coordinate of the pixel
pixelpixel color
bool Luminous::Image::setPixelFormat ( const PixelFormat format)

Sets the new format and converts the image data to new format if necessary.

Parameters
formatnew pixel format for the image
Returns
Returns true if the conversion was successful
Nimble::Size Luminous::Image::size ( ) const
inline

Get the image size.

Returns
image size in pixels
Luminous::Texture& Luminous::Image::texture ( ) const

Get a texture object based on the image This function is thread-safe so it can be used in render functions.

Returns
texture matching the image
int Luminous::Image::width ( ) const
inline

Get the image width.

Returns
width in pixels
bool Luminous::Image::write ( const QString &  filename) const

Save the image to a file.

Parameters
filenamename of the file to write to
Returns
true if the image was successfully written

Member Data Documentation

unsigned char* Luminous::Image::m_data
protected

Pointer to the raw image data.

size_t Luminous::Image::m_generation
protected

Generation count of the image used to indicate changes in the image data to determine when associated textures should be updated.