FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
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 render (const Rect &rect, const ImagePtr &overlay, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, uint8_t alpha=255, uint8_t const *rgb=0)
 
virtual void renderZ (const Rect &rect, float vertexZ, const ImagePtr &overlay, uint8_t alpha=255, uint8_t const *rgb=0)
 
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
 
Rect getArea () 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 48 of file image.h.

Constructor & Destructor Documentation

◆ Image() [1/6]

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

Constructor.

Definition at line 41 of file image.cpp.

◆ Image() [2/6]

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

Definition at line 49 of file image.cpp.

◆ Image() [3/6]

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().

◆ Image() [4/6]

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

Definition at line 66 of file image.cpp.

References reset().

◆ Image() [5/6]

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.

◆ Image() [6/6]

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.

◆ ~Image()

FIFE::Image::~Image ( )
virtual

Destructor.

Definition at line 120 of file image.cpp.

References reset().

Member Function Documentation

◆ copySubimage()

void FIFE::Image::copySubimage ( uint32_t  xoffset,
uint32_t  yoffset,
const ImagePtr img 
)
virtual

◆ createUniqueImageName()

std::string FIFE::Image::createUniqueImageName ( )
private

Definition at line 301 of file image.cpp.

◆ detachSurface()

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 145 of file image.cpp.

References m_surface.

Referenced by FIFE::InstanceRenderer::getMultiColorOverlay(), and renderZ().

+ Here is the caller graph for this function:

◆ forceLoadInternal()

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

◆ free()

void FIFE::Image::free ( )
virtual

Implements FIFE::IResource.

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

Definition at line 135 of file image.cpp.

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

Referenced by FIFE::LibRocketRenderInterface::freeTextures(), and getYShift().

+ Here is the caller graph for this function:

◆ getArea()

Rect FIFE::Image::getArea ( ) const

Definition at line 176 of file image.cpp.

References getHeight(), and getWidth().

Referenced by FIFE::RenderBackendSDL::attachRenderTarget(), FIFE::RenderBackendOpenGL::attachRenderTarget(), getSurface(), and FIFE::SDLImage::render().

+ Here is the caller graph for this function:

◆ getHeight()

◆ getPixelRGBA()

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

◆ getSize()

size_t FIFE::Image::getSize ( )
virtual

Implements FIFE::IResource.

Reimplemented in FIFE::SDLImage.

Definition at line 169 of file image.cpp.

References m_shared, and m_surface.

Referenced by getYShift().

+ Here is the caller graph for this function:

◆ getSubImageRect()

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

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

Definition at line 152 of file image.h.

References copySubimage(), and m_subimagerect.

Referenced by copySubimage(), and FIFE::SDLImage::render().

+ Here is the caller graph for this function:

◆ getSurface() [1/2]

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

◆ getSurface() [2/2]

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

Definition at line 97 of file image.h.

References getArea(), getHeight(), getWidth(), m_surface, putPixel(), saveAsPng(), saveImage(), and setSurface().

◆ getWidth()

◆ getXShift()

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

Definition at line 122 of file image.h.

References m_xshift.

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

+ Here is the caller graph for this function:

◆ getYShift()

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

◆ invalidate()

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

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

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

◆ isSharedImage()

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

Returns true if this image shares data with another one.

Definition at line 148 of file image.h.

References m_shared.

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

+ Here is the caller graph for this function:

◆ load()

◆ putPixel()

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

◆ render() [1/2]

◆ render() [2/2]

virtual void FIFE::Image::render ( const Rect rect,
const ImagePtr overlay,
uint8_t  alpha = 255,
uint8_t const *  rgb = 0 
)
inlinevirtual

Reimplemented in FIFE::GLImage.

Definition at line 85 of file image.h.

◆ renderZ() [1/3]

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

Reimplemented in FIFE::GLImage.

Definition at line 86 of file image.h.

Referenced by FIFE::InstanceRenderer::renderOverlay(), and FIFE::InstanceRenderer::renderUnsorted().

+ Here is the caller graph for this function:

◆ renderZ() [2/3]

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

Reimplemented in FIFE::GLImage.

Definition at line 87 of file image.h.

◆ renderZ() [3/3]

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

Definition at line 89 of file image.h.

References detachSurface().

◆ reset()

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(), and ~Image().

+ Here is the caller graph for this function:

◆ saveAsPng()

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

Saves the SDL_Surface to png format.

Definition at line 231 of file image.cpp.

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

+ Here is the caller graph for this function:

◆ saveImage()

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

Saves the image using given filename.

Definition at line 227 of file image.cpp.

References m_surface, and saveAsPng().

Referenced by getSurface().

+ Here is the caller graph for this function:

◆ setSurface()

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, and FIFE::SDLImage.

Referenced by FIFE::InstanceRenderer::getMultiColorOverlay(), getSurface(), and FIFE::ImageLoader::load().

+ Here is the caller graph for this function:

◆ setXShift()

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

Definition at line 119 of file image.h.

References m_xshift.

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

+ Here is the caller graph for this function:

◆ setYShift()

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

Definition at line 125 of file image.h.

References m_yshift.

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

+ Here is the caller graph for this function:

◆ useSharedImage()

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::GLImage, and FIFE::SDLImage.

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

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_shared

◆ m_subimagerect

◆ m_surface

◆ m_xshift

int32_t FIFE::Image::m_xshift
protected

Definition at line 162 of file image.h.

Referenced by FIFE::SDLImage::free(), FIFE::GLImage::free(), free(), getXShift(), reset(), and setXShift().

◆ m_yshift

int32_t FIFE::Image::m_yshift
protected

Definition at line 164 of file image.h.

Referenced by FIFE::SDLImage::free(), FIFE::GLImage::free(), free(), getYShift(), reset(), and setYShift().


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