FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FIFE::Image Class Referenceabstract

Base Class for Images. More...

#include <image.h>

+ Inheritance diagram for FIFE::Image:
+ Collaboration diagram for FIFE::Image:

Public Member Functions

 Image (IResourceLoader *loader=0)
 Constructor. More...
 
 Image (const std::string &name, IResourceLoader *loader=0)
 
 Image (SDL_Surface *surface)
 Constructor. More...
 
 Image (const std::string &name, SDL_Surface *surface)
 
 Image (const uint8_t *data, uint32_t width, uint32_t height)
 Constructor. More...
 
 Image (const std::string &name, const uint8_t *data, uint32_t width, uint32_t height)
 
virtual ~Image ()
 Destructor. More...
 
virtual void invalidate ()=0
 Invalidates the Image causing it to be reset or re-loaded. More...
 
virtual void render (const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)=0
 Renders itself to the current render target (main screen or attached destination image) at the rectangle rect. More...
 
virtual void renderZ (const Rect &rect, float vertexZ, uint8_t alpha=255, bool forceNewBatch=false, uint8_t const *rgb=0)
 
SDL_Surface * detachSurface ()
 Removes underlying SDL_Surface from the image (if exists) and returns this. More...
 
SDL_Surface * getSurface ()
 
const SDL_Surface * getSurface () const
 
virtual void setSurface (SDL_Surface *surface)=0
 This frees the current suface and replaces it with the surface passed in the parameter (which can be NULL). More...
 
void saveImage (const std::string &filename)
 Saves the image using given filename. More...
 
uint32_t getWidth () const
 
uint32_t getHeight () const
 
const RectgetArea () const
 
void setXShift (int32_t xshift)
 
int32_t getXShift () const
 
void setYShift (int32_t yshift)
 
int32_t getYShift () const
 
void getPixelRGBA (int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
 
virtual size_t getSize ()
 
virtual void load ()
 
virtual void free ()
 
virtual void useSharedImage (const ImagePtr &shared, const Rect &region)=0
 After this call all image data will be taken from the given image and its subregion. More...
 
virtual void forceLoadInternal ()=0
 Forces to load the image into internal memory of GPU. More...
 
bool isSharedImage () const
 Returns true if this image shares data with another one. More...
 
const RectgetSubImageRect () const
 Returns area of the image it occupies in the shared image. More...
 
virtual void copySubimage (uint32_t xoffset, uint32_t yoffset, const ImagePtr &img)
 Copies given image into this one with respect to given offsets. More...
 
- Public Member Functions inherited from FIFE::IResource
 IResource (const std::string &name, IResourceLoader *loader=0)
 
virtual ~IResource ()
 
virtual const std::string & getName ()
 
ResourceHandle getHandle ()
 
virtual ResourceState getState ()
 
virtual void setState (const ResourceState &state)
 

Static Public Member Functions

static void saveAsPng (const std::string &filename, const SDL_Surface &surface)
 Saves the SDL_Surface to png format. More...
 
static bool putPixel (SDL_Surface *surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
 

Protected Member Functions

void reset (SDL_Surface *surface)
 Resets the image to default values (including the x and y shift values), frees the current surface and sets the surface to the passed SDL_Surface (which can be NULL). More...
 

Protected Attributes

SDL_Surface * m_surface
 
int32_t m_xshift
 
int32_t m_yshift
 
bool m_shared
 
Rect m_subimagerect
 
- Protected Attributes inherited from FIFE::IResource
std::string m_name
 
IResourceLoaderm_loader
 
ResourceState m_state
 

Private Member Functions

std::string createUniqueImageName ()
 

Additional Inherited Members

- Public Types inherited from FIFE::IResource
enum  ResourceState { RES_INVALID = 0, RES_NOT_LOADED, RES_LOADED }
 

Detailed Description

Base Class for Images.

Definition at line 47 of file image.h.

Constructor & Destructor Documentation

FIFE::Image::Image ( IResourceLoader loader = 0)

Constructor.

Definition at line 41 of file image.cpp.

FIFE::Image::Image ( const std::string &  name,
IResourceLoader loader = 0 
)

Definition at line 49 of file image.cpp.

FIFE::Image::Image ( SDL_Surface *  surface)

Constructor.

Note
Takes ownership of the SDL Surface
Parameters
surfaceSDL Surface in RGBA format

Definition at line 57 of file image.cpp.

References reset().

FIFE::Image::Image ( const std::string &  name,
SDL_Surface *  surface 
)

Definition at line 66 of file image.cpp.

References reset().

FIFE::Image::Image ( const uint8_t *  data,
uint32_t  width,
uint32_t  height 
)

Constructor.

Parameters
dataPointer to the imagedata (needs to be in RGBA, 8 bits per channel).
widthWidth of the image.
heightHeight of the image.

Definition at line 76 of file image.cpp.

References FIFE::AMASK, FIFE::BMASK, FIFE::GMASK, reset(), and FIFE::RMASK.

FIFE::Image::Image ( const std::string &  name,
const uint8_t *  data,
uint32_t  width,
uint32_t  height 
)

Definition at line 93 of file image.cpp.

References FIFE::AMASK, FIFE::BMASK, FIFE::GMASK, reset(), and FIFE::RMASK.

FIFE::Image::~Image ( )
virtual

Destructor.

Definition at line 120 of file image.cpp.

References reset().

Member Function Documentation

void FIFE::Image::copySubimage ( uint32_t  xoffset,
uint32_t  yoffset,
const ImagePtr img 
)
virtual
std::string FIFE::Image::createUniqueImageName ( )
private

Definition at line 296 of file image.cpp.

SDL_Surface * FIFE::Image::detachSurface ( )

Removes underlying SDL_Surface from the image (if exists) and returns this.

Note
this effectively causes SDL_Surface not to be freed on destruction

Definition at line 140 of file image.cpp.

References m_surface.

virtual void FIFE::Image::forceLoadInternal ( )
pure virtual
void FIFE::Image::free ( )
virtual

Implements FIFE::IResource.

Reimplemented in FIFE::GLeImage, FIFE::GLImage, and FIFE::SDLImage.

Definition at line 135 of file image.cpp.

References FIFE::IResource::m_state, FIFE::IResource::RES_NOT_LOADED, and reset().

const Rect & FIFE::Image::getArea ( ) const

Definition at line 171 of file image.cpp.

References getHeight(), and getWidth().

Referenced by FIFE::RenderBackendOpenGL::attachRenderTarget(), FIFE::RenderBackendSDL::attachRenderTarget(), and FIFE::RenderBackendOpenGLe::attachRenderTarget().

+ Here is the caller graph for this function:

void FIFE::Image::getPixelRGBA ( int32_t  x,
int32_t  y,
uint8_t *  r,
uint8_t *  g,
uint8_t *  b,
uint8_t *  a 
)
size_t FIFE::Image::getSize ( )
virtual

Implements FIFE::IResource.

Reimplemented in FIFE::SDLImage.

Definition at line 164 of file image.cpp.

References m_shared, and m_surface.

const Rect& FIFE::Image::getSubImageRect ( ) const
inline

Returns area of the image it occupies in the shared image.

Definition at line 147 of file image.h.

References m_subimagerect.

Referenced by copySubimage().

+ Here is the caller graph for this function:

const SDL_Surface* FIFE::Image::getSurface ( ) const
inline

Definition at line 92 of file image.h.

References m_surface.

int32_t FIFE::Image::getXShift ( ) const
inline

Definition at line 117 of file image.h.

References m_xshift.

Referenced by FIFE::Cursor::draw(), FIFE::ImageLoader::load(), FIFE::LayerCache::updatePosition(), and FIFE::LayerCache::updateVisual().

+ Here is the caller graph for this function:

int32_t FIFE::Image::getYShift ( ) const
inline

Definition at line 123 of file image.h.

References m_yshift.

Referenced by FIFE::Cursor::draw(), FIFE::ImageLoader::load(), FIFE::LayerCache::updatePosition(), and FIFE::LayerCache::updateVisual().

+ Here is the caller graph for this function:

virtual void FIFE::Image::invalidate ( )
pure virtual

Invalidates the Image causing it to be reset or re-loaded.

Implemented in FIFE::GLImage, FIFE::GLeImage, and FIFE::SDLImage.

bool FIFE::Image::isSharedImage ( ) const
inline

Returns true if this image shares data with another one.

Definition at line 143 of file image.h.

References m_shared.

Referenced by FIFE::InstanceRenderer::bindColoring(), FIFE::InstanceRenderer::bindOutline(), copySubimage(), FIFE::Camera::getMatchingInstances(), getPixelRGBA(), and FIFE::ImageLoader::load().

+ Here is the caller graph for this function:

bool FIFE::Image::putPixel ( SDL_Surface *  surface,
int32_t  x,
int32_t  y,
uint8_t  r,
uint8_t  g,
uint8_t  b,
uint8_t  a = 255 
)
static

Definition at line 346 of file image.cpp.

Referenced by FIFE::InstanceRenderer::bindColoring(), FIFE::InstanceRenderer::bindOutline(), and FIFE::RenderBackendSDL::putPixel().

+ Here is the caller graph for this function:

virtual void FIFE::Image::renderZ ( const Rect rect,
float  vertexZ,
uint8_t  alpha = 255,
bool  forceNewBatch = false,
uint8_t const *  rgb = 0 
)
inlinevirtual

Reimplemented in FIFE::GLeImage.

Definition at line 84 of file image.h.

Referenced by FIFE::InstanceRenderer::renderUnsorted().

+ Here is the caller graph for this function:

void FIFE::Image::reset ( SDL_Surface *  surface)
protected

Resets the image to default values (including the x and y shift values), frees the current surface and sets the surface to the passed SDL_Surface (which can be NULL).

See Also
IImage::setSurface(SDL_Surface* surface)
Parameters
surfacethe SDL_Surface to use for this image

Definition at line 110 of file image.cpp.

References m_shared, m_surface, m_xshift, and m_yshift.

Referenced by free(), Image(), FIFE::SDLImage::setSurface(), FIFE::GLImage::setSurface(), FIFE::GLeImage::setSurface(), and ~Image().

+ Here is the caller graph for this function:

void FIFE::Image::saveAsPng ( const std::string &  filename,
const SDL_Surface &  surface 
)
static

Saves the SDL_Surface to png format.

Definition at line 226 of file image.cpp.

Referenced by FIFE::RenderBackendOpenGL::captureScreen(), FIFE::RenderBackendSDL::captureScreen(), FIFE::RenderBackendOpenGLe::captureScreen(), and saveImage().

+ Here is the caller graph for this function:

void FIFE::Image::saveImage ( const std::string &  filename)

Saves the image using given filename.

Definition at line 222 of file image.cpp.

References m_surface, and saveAsPng().

virtual void FIFE::Image::setSurface ( SDL_Surface *  surface)
pure virtual

This frees the current suface and replaces it with the surface passed in the parameter (which can be NULL).

See Also
Image::reset(SDL_Surface* surface)
Parameters
surfacethe SDL_Surface to use for this image

Implemented in FIFE::GLImage, FIFE::GLeImage, and FIFE::SDLImage.

Referenced by FIFE::ImageLoader::load().

+ Here is the caller graph for this function:

void FIFE::Image::setXShift ( int32_t  xshift)
inline

Definition at line 114 of file image.h.

References m_xshift.

Referenced by FIFE::ImageLoader::load(), FIFE::AnimationLoader::load(), FIFE::ObjectLoader::load(), and FIFE::AtlasLoader::parseObject().

+ Here is the caller graph for this function:

void FIFE::Image::setYShift ( int32_t  yshift)
inline

Definition at line 120 of file image.h.

References m_yshift.

Referenced by FIFE::ImageLoader::load(), FIFE::AnimationLoader::load(), FIFE::ObjectLoader::load(), and FIFE::AtlasLoader::parseObject().

+ Here is the caller graph for this function:

virtual void FIFE::Image::useSharedImage ( const ImagePtr shared,
const Rect region 
)
pure virtual

After this call all image data will be taken from the given image and its subregion.

Implemented in FIFE::GLeImage, FIFE::GLImage, and FIFE::SDLImage.

Referenced by FIFE::ObjectLoader::load(), and FIFE::AtlasLoader::load().

+ Here is the caller graph for this function:

Member Data Documentation

int32_t FIFE::Image::m_xshift
protected

Definition at line 157 of file image.h.

Referenced by getXShift(), reset(), and setXShift().

int32_t FIFE::Image::m_yshift
protected

Definition at line 159 of file image.h.

Referenced by getYShift(), reset(), and setYShift().


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