Public Member Functions | Private Member Functions | Private Attributes

Image Class Reference

Image Class. More...

#include <Image.h>

Inheritance diagram for Image:
Resource

List of all members.

Public Member Functions

 Image (const std::string &filePath)
 Image (const std::string &filePath, int x, int y, int width, int height)
 Image (Image *src, int x, int y, int width, int height)
 Loads a portion of an existing Image object.
 Image (void *buffer, int size)
 Image (const Image &src)
 Image ()
Imageoperator= (const Image &rhs)
 ~Image ()
 Frees pixel data and cleans up after itself.
SDL_Surface * getPixels () const
int getWidth () const
int getHeight () const

Private Member Functions

void load ()
void loadDefault ()
void loadSlice (int x, int y, int width, int height)
void loadFromSource (Image *src, int x, int y, int width, int height)
void createSurface (const char *data, int dataLength)

Private Attributes

SDL_Surface * mPixels
int mWidth
int mHeight

Detailed Description

Image Class.

Parameters:
char Path to an image file.

Stores an image as a representation of pixels in memory.


Constructor & Destructor Documentation

Image::Image ( const std::string &  filePath  ) 
Image::Image ( const std::string &  filePath,
int  x,
int  y,
int  width,
int  height 
)
Image::Image ( Image src,
int  x,
int  y,
int  width,
int  height 
)

Loads a portion of an existing Image object.

Parameters:
src Pointer to an existing Image object.
x 'X' Coordinate to grab from source Image object.
y 'Y' Coordinate to grab from source Image object.
width Width of the rectangular area to grab from source Image object.
height Height of the rectangular area to grab from source Image object.

If the load fails, a default image is stored indicating an error condition.

Image::Image ( void *  buffer,
int  size 
)

Creates an image from a byte array.

Parameters:
buffer A pointer to a byte array.
size Size of the buffer.
Note:
The buffer array must contain the complete binary data for an image file supported by SDL_Image. Convert using Bin2C.
Image::Image ( const Image src  ) 

Copy Constructor.

Image::Image (  ) 

Default Constructor.

This Constructor should almost never be invoked. It initializes the Image Resource to a valid state with valid pixel data. Generally this method of instantiating an Image should be for testing purposes or to indicate an error condition.

Todo:
This constructor assumes that mPixels was properly initialized. The simple fact is that even though mPixels' initialization should never fail under normal circumstances there are times where it may and it needs to be prepared to handle such a case. For the time being I have an assert macro enabled but this will only work in debug builds.
Image::~Image (  )  [inline]

Frees pixel data and cleans up after itself.


Member Function Documentation

void Image::createSurface ( const char *  data,
int  dataLength 
) [private]

Converts the pixel formats internally to prevent unnecessary on-the-fly conversions.

Todo:
This function is poorly named as it creates the surface that it then converts.
int Image::getHeight (  )  const

Returns the height in pixels of the image.

SDL_Surface * Image::getPixels (  )  const

Returns the pixel data used in the Image Resource.

int Image::getWidth (  )  const

Returns the width in pixels of the image.

void Image::load (  )  [private, virtual]

Loads an image file from disk.

Attempts to load an image file from disk.

If loading fails, Image will be set to a valid internal state with a default image indicating an error.

Implements Resource.

void Image::loadDefault (  )  [private]
void Image::loadFromSource ( Image src,
int  x,
int  y,
int  width,
int  height 
) [private]

Loads a portion of an image from an existing Image object.

Note:
If loading fails, Image will be set to a valid internal state with a default image indicating an error.
void Image::loadSlice ( int  x,
int  y,
int  width,
int  height 
) [private]

Loads a portion of an image file from disk.

Note:
If loading fails, Image will be set to a valid internal state with a default image indicating an error.
Parameters:
x X-Coordinate to start copying pixel data from.
y Y-Coordinate to start copying pixel data from.
width Width of the area to start copying pixel data from.
height Height of the area to start copying pixel data from.
Image & Image::operator= ( const Image rhs  ) 

Member Data Documentation

int Image::mHeight [private]

Internal Width and Height of the Image.

SDL_Surface* Image::mPixels [private]
Todo:
This may be better off as a straight-up char* buffer which can be converted by the renderers as necessary. This will likely require a modification to the SDL Renderer that stores 'SDL_Surfaces' in a similar manner to the way the OpenGL Renderer stores references to OGL Textures.

SDL_Surface containing the Pixel Data.

int Image::mWidth [private]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines