Adonthell  0.4
image Class Reference

Image manipulation class. More...

#include <image.h>

Inheritance diagram for image:
Collaboration diagram for image:

Public Member Functions

 image ()
 Default constructor. More...
 
 image (u_int16 l, u_int16 h, const u_int8 &scale=1)
 Creates an image with a specified size. More...
 
 image (SDL_Surface *s, const SDL_Color &color)
 Create image from SDL_Surface. More...
 
virtual ~image ()
 Destructor. More...
 
void resize (u_int16 l, u_int16 h)
 Resize this image. More...
 
void clear ()
 Resets the image to it's initial state, that is totally empty. More...
 
imageoperator= (const image &src)
 Image copy (similar to copy ()). More...
 
void copy (const image &src)
 Synonym of operator = to guarantee its access from Python. More...
 
Loading / Saving Methods.

These methods allows you to load and save an image in different formats.

s_int8 get (igzstream &file)
 Loads an image from an opened file, saved in game internal format, with alpha and mask values. More...
 
s_int8 load (string fname)
 Loads an image from a file name, in game internal format, with alpha and mask values. More...
 
s_int8 get_raw (igzstream &file)
 Loads an image from an opened file, saved in game internal format, without alpha and mask values. More...
 
s_int8 load_raw (string fname)
 Loads an image from a file name, in game internal format, without alpha and mask values. More...
 
s_int8 get_pnm (SDL_RWops *file)
 Loads an image from an opened file, in PNM format, without alpha and mask values. More...
 
s_int8 load_pnm (string fname)
 Loads an image from a file name, in PNM format, without alpha and mask values. More...
 
s_int8 put (ogzstream &file) const
 Saves an image into an opened file, in game format, with alpha and mask values. More...
 
s_int8 save (string fname) const
 Saves an image into an file, in game format, with alpha and mask values. More...
 
s_int8 put_raw (ogzstream &file) const
 Saves an image into an opened file, in game format, without alpha and mask values. More...
 
s_int8 save_raw (string fname) const
 Saves an image into an file, in game format, without alpha and mask values. More...
 
s_int8 put_pnm (SDL_RWops *file) const
 Saves an image into an opened file, in PNM format, without alpha and mask values. More...
 
s_int8 save_pnm (string fname) const
 Saves an image into an file, in PNM format, without alpha and mask values. More...
 
Special FX Methods.

Allows you to put fantasy in your image manipulations! Can eventually even be usefull...

void zoom (const surface &src)
 Zooms a surface. More...
 
void zoom (const surface &src, u_int16 l, u_int16 h, u_int16 x=0, u_int16 y=0)
 Zooms a surface. More...
 
void zoom_to (const surface &src, u_int16 l, u_int16 h, u_int16 x=0, u_int16 y=0)
 Synonym of zoom () to guarantee its access from Python. More...
 
void tile (const surface &src)
 Tiles a surface. More...
 
void tile (const surface &src, u_int16 l, u_int16 h, u_int16 x=0, u_int16 y=0)
 Tiles a surface. More...
 
void tile_to (const surface &src, u_int16 l, u_int16 h, u_int16 x=0, u_int16 y=0)
 Synonym of tile () to guarantee its access from Python. More...
 
void brightness (const surface &src, u_int8 cont, bool proceed_mask=false)
 Applies a "brightness" to a surface. More...
 
- Public Member Functions inherited from surface
 surface (const u_int8 &scale=1)
 Default constructor. More...
 
virtual ~surface ()
 Destructor. More...
 
surfaceoperator= (const surface &src)
 Surface copy (similar to copy ()). More...
 
void copy (const surface &src)
 Synonym of operator = to guarantee its access from Python. More...
 
bool is_masked () const
 Returns whether a surface is masked or not. More...
 
void set_mask (bool m)
 Sets the mask parameter of the surface. More...
 
u_int8 alpha () const
 Returns the alpha value of the surface. More...
 
void set_alpha (u_int8 a, const bool &alpha_channel=false)
 Sets the alpha value of the surface. More...
 
bool has_alpha_channel () const
 Returns whether the surface has an alpha channel. More...
 
u_int8 scale () const
 Get the surfaces current scaling factor. More...
 
void set_scale (const u_int8 &scale)
 Change the scale of the surface to the given value, resizing the internal texture appropriately. More...
 
void draw (s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw the surface. More...
 
void draw (s_int16 x, s_int16 y, s_int16 sx, s_int16 sy, u_int16 sl, u_int16 sh, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Draw a part of the surface. More...
 
void draw_part (s_int16 x, s_int16 y, s_int16 sx, s_int16 sy, u_int16 sl, u_int16 sh, const drawing_area *da_opt=NULL, surface *target=NULL) const
 Synonym of draw () to guarantee its access from Python. More...
 
void fillrect (s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int32 col, drawing_area *da_opt=NULL)
 Fills an area of the surface with a given color. More...
 
u_int32 map_color (const u_int8 &r, const u_int8 &g, const u_int8 &b, const u_int8 &a=255) const
 
void unmap_color (u_int32 col, u_int8 &r, u_int8 &g, u_int8 &b, u_int8 &a) const
 
void lock () const
 Locks the surface. More...
 
void unlock () const
 Unlock the surface after you've worked on it's pixels with the get_pix () and put_pix () methods. More...
 
void put_pix (u_int16 x, u_int16 y, u_int32 col)
 Puts a pixel of a given color. More...
 
void put_pix (u_int16 x, u_int16 y, u_int8 r, u_int8 g, u_int8 b)
 Puts a pixel of a given color. More...
 
void put_pix_rgb (u_int16 x, u_int16 y, u_int8 r, u_int8 g, u_int8 b)
 Synonym of put_pix () to guarantee its access from Python. More...
 
u_int32 get_pix (u_int16 x, u_int16 y) const
 Gets a pixel from the surface. More...
 
void get_pix (u_int16 x, u_int16 y, u_int8 &r, u_int8 &g, u_int8 &b) const
 Gets a pixel from a surface. More...
 
void get_pix_rgb (u_int16 x, u_int16 y, u_int8 r, u_int8 g, u_int8 b) const
 Synonym of get_pix () to guarantee its access from Python. More...
 
- Public Member Functions inherited from drawable
 drawable ()
 Default constructor. More...
 
virtual ~drawable ()
 Destructor. More...
 
u_int16 length () const
 Returns the length of the drawable. More...
 
u_int16 height () const
 Returns the height of the drawable. More...
 
virtual bool update ()
 Virtual update function, provided for objects which doesn't need one. More...
 
virtual bool input_update ()
 Virtual input update function, provided for objects which doesn't need one. More...
 

Additional Inherited Members

- Protected Member Functions inherited from surface
void resize (u_int16 l, u_int16 h)
 Resize this surface. More...
 
void clear ()
 Resets the surface to it's initial state, that is totally empty. More...
 
void set_data (void *data, u_int16 l, u_int16 h, u_int8 bytes_per_pixel=BYTES_PER_PIXEL, u_int32 red_mask=R_MASK, u_int32 green_mask=G_MASK, u_int32 blue_mask=B_MASK, u_int32 alpha_mask=0)
 
void * get_data (u_int8 bytes_per_pixel, u_int32 red_mask, u_int32 green_mask, u_int32 blue_mask, u_int32 alpha_mask) const
 
SDL_Surface * to_sw_surface (SDL_Rect *rect=NULL) const
 Create a software surface backed by the (streaming) texture data. More...
 
void lock (SDL_Rect *rect) const
 lock part of the surface specified by rect More...
 
- Protected Member Functions inherited from drawable
void set_length (u_int16 l)
 Sets the length of the drawable. More...
 
void set_height (u_int16 h)
 Sets the height of the drawable. More...
 
- Protected Attributes inherited from surface
SDL_Texture * Surface
 the surface More...
 
u_int8 scale_
 current scale More...
 
s_int16 offset_x_
 sub-pixel offset More...
 

Detailed Description

Image manipulation class.

Designed to work with single images, without having to care about the bit depth. This class is widely used through the game - in fact it handles everything that is displayed on the screen. This class highly relies on surface, so you'll probably want to have a look at it before using image.

Definition at line 45 of file image.h.

Constructor & Destructor Documentation

image::image ( )

Default constructor.

The image created via this constructor is totally empty.

Definition at line 35 of file image.cc.

image::image ( u_int16  l,
u_int16  h,
const u_int8 scale = 1 
)

Creates an image with a specified size.

Parameters
llength of the image.
hheight of the image.
scalethe initial scale of the image (default 1)
Attention
Not accessible from Python.

Definition at line 39 of file image.cc.

image::image ( SDL_Surface *  s,
const SDL_Color &  color 
)

Create image from SDL_Surface.

Parameters
ssurface

Definition at line 44 of file image.cc.

image::~image ( )
virtual

Destructor.

Definition at line 59 of file image.cc.

Member Function Documentation

void image::resize ( u_int16  l,
u_int16  h 
)

Resize this image.

All the content will be lost. If you want to zoom the image you'll want to see the zoom () function instead.

Parameters
lnew length.
hnew height.
See also
zoom ()

Definition at line 63 of file image.cc.

void image::clear ( )

Resets the image to it's initial state, that is totally empty.

Definition at line 68 of file image.cc.

s_int8 image::get ( igzstream file)

Loads an image from an opened file, saved in game internal format, with alpha and mask values.

Parameters
filethe opened file from which to read.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
load ()

Definition at line 73 of file image.cc.

s_int8 image::load ( string  fname)

Loads an image from a file name, in game internal format, with alpha and mask values.

Parameters
fnamethe name of the file to load.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
get ()

Definition at line 92 of file image.cc.

s_int8 image::get_raw ( igzstream file)

Loads an image from an opened file, saved in game internal format, without alpha and mask values.

Parameters
filethe opened file from which to read.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
load_raw ()

Definition at line 104 of file image.cc.

s_int8 image::load_raw ( string  fname)

Loads an image from a file name, in game internal format, without alpha and mask values.

Parameters
fnamethe name of the file to load.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
get_raw ()

Definition at line 128 of file image.cc.

s_int8 image::get_pnm ( SDL_RWops *  file)

Loads an image from an opened file, in PNM format, without alpha and mask values.

Parameters
filethe opened file from which to read.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
load_pnm ()

Definition at line 144 of file image.cc.

s_int8 image::load_pnm ( string  fname)

Loads an image from a file name, in PNM format, without alpha and mask values.

Parameters
fnamethe name of the file to load.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
get_pnm ()

Definition at line 163 of file image.cc.

s_int8 image::put ( ogzstream file) const

Saves an image into an opened file, in game format, with alpha and mask values.

Warning
as the image which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving images with full truecolor quality, use image_edit instead.
Parameters
fileopened file where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
save ()

Definition at line 179 of file image.cc.

s_int8 image::save ( string  fname) const

Saves an image into an file, in game format, with alpha and mask values.

Warning
as the image which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving images with full truecolor quality, use image_edit instead.
Parameters
fnamefile name where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
put ()

Definition at line 192 of file image.cc.

s_int8 image::put_raw ( ogzstream file) const

Saves an image into an opened file, in game format, without alpha and mask values.

Warning
as the image which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving images with full truecolor quality, use image_edit instead.
Parameters
fileopened file where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
save_raw ()

Definition at line 204 of file image.cc.

s_int8 image::save_raw ( string  fname) const

Saves an image into an file, in game format, without alpha and mask values.

Warning
as the image which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving images with full truecolor quality, use image_edit instead.
Parameters
fnamefile name where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
put_raw ()

Definition at line 218 of file image.cc.

s_int8 image::put_pnm ( SDL_RWops *  file) const

Saves an image into an opened file, in PNM format, without alpha and mask values.

Warning
as the image which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving images with full truecolor quality, use image_edit instead.
Parameters
fileopened file where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
save_pnm ()

Definition at line 230 of file image.cc.

s_int8 image::save_pnm ( string  fname) const

Saves an image into an file, in PNM format, without alpha and mask values.

Warning
as the image which is saved comes from a screen's depth surface, it will be slightly altered during the save. If you want a class capable of saving images with full truecolor quality, use image_edit instead.
Parameters
fnamefile name where to save into.
Returns
  • 0 in case of success.
  • -1 in case of error.
See also
put_pnm ()

Definition at line 239 of file image.cc.

void image::zoom ( const surface src)
inline

Zooms a surface.

Zoom the content of the src surface into this image, to it's own size.

Parameters
srcthe source image to zoom.

Definition at line 265 of file image.h.

void image::zoom ( const surface src,
u_int16  l,
u_int16  h,
u_int16  x = 0,
u_int16  y = 0 
)

Zooms a surface.

Zoom the content of the src surface into this image, to the size (l, h), at position (x, y) on this image.

Parameters
srcThe source surface to zoom.
llength of the zoomed image.
hheight of the zoomed image.
xX offset on the destination image.
yY offset on the destination image.
Attention
Not available from Python. Use zoom_to () from Python instead.
See also
zoom_to ()

Definition at line 252 of file image.cc.

void image::zoom_to ( const surface src,
u_int16  l,
u_int16  h,
u_int16  x = 0,
u_int16  y = 0 
)
inline

Synonym of zoom () to guarantee its access from Python.

See also
zoom ()

Definition at line 294 of file image.h.

void image::tile ( const surface src)
inline

Tiles a surface.

Tiles the src surface so this image is totally filled.

Parameters
sourcethe source surface to tile.

Definition at line 303 of file image.h.

void image::tile ( const surface src,
u_int16  l,
u_int16  h,
u_int16  x = 0,
u_int16  y = 0 
)

Tiles a surface.

Tiles the src surface so the area of this image starting at position (x, y) and (l, h) sized is totally filled.

Parameters
sourcethe source surface to tile.
llength of the area to tile.
hheight of the area to tile.
xX offset on the destination image.
yY offset on the destination image.
Attention
Not available from Python. Use tile_to () from Python instead.
See also
tile_to ()

Definition at line 286 of file image.cc.

void image::tile_to ( const surface src,
u_int16  l,
u_int16  h,
u_int16  x = 0,
u_int16  y = 0 
)
inline

Synonym of tile () to guarantee its access from Python.

See also
tile ()

Definition at line 331 of file image.h.

void image::brightness ( const surface src,
u_int8  cont,
bool  proceed_mask = false 
)

Applies a "brightness" to a surface.

Lighten (or darken) the src surface and put the result into this image. This image will be resized to the src surface's size.

Parameters
srcthe source surface to lighten/darken.
contthe "brightness" value, if < 256 the image will be darkened.
Todo:
modify it so when < 128 -> darken, > 128 -> brighten.
Parameters
proceed_maskif set to true, then the translucent pixels will be lightened/darkened too.

Definition at line 298 of file image.cc.

image & image::operator= ( const image src)

Image copy (similar to copy ()).

Attention
Not available from Python. Use copy () from Python instead.
See also
copy ()

Definition at line 331 of file image.cc.

void image::copy ( const image src)
inline

Synonym of operator = to guarantee its access from Python.

See also
operator =

Definition at line 366 of file image.h.


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