- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ufo::UImageIO Class Reference

A basic image loader and saver. More...

#include <uimageio.hpp>

Inheritance diagram for ufo::UImageIO:

ufo::UObject ufo::UCollectable List of all members.

Public Types

typedef std::istream IStream
typedef std::ostream OStream
typedef unsigned char *(* LoadFuncPointer )(UImageIO *imageIOA, IStream &streamA, std::string *commentA, int *widthA, int *heightA, int *componentsA)
typedef bool(* SaveFuncPointer )(UImageIO *imageIO, OStream &streamA)
enum  FilterRule {
  NoFilterRule = 0, AlphaLayer = 1, ColorTypeRGB = 2, ColorTypeRGBA = ColorTypeRGB | AlphaLayer,
  ColorTypeGray = 4, ColorTypeGrayAlpha = ColorTypeGray | AlphaLayer, FlipX = 8, FlipY = 16
}

Public Member Functions

 UImageIO ()
 UImageIO (const std::string &fileNameA)
 UImageIO (IStream &streamA, const std::string &extensionA)
 UImageIO (unsigned char *dataA, int widthA, int heightA, int componentsA)
 UImageIO (int widthA, int heightA, int componentsA)
unsigned char * getPixels ()
int getWidth ()
int getHeight ()
const UDimensiongetSize ()
std::string getComment ()
int getImageComponents ()
bool load (const std::string &fileNameA)
bool loadFromArchive (const std::string &fileNameA)
bool load (UImageIO::IStream &streamA, const std::string &extensionA)
bool save (const std::string &fileNameA)
bool save (UImageIO::OStream &streamA, const std::string &extensionA)

Static Public Member Functions

std::vector< std::string > getAvailableLoadingExtensions ()
UImageIO::LoadFuncPointer registerLoader (UImageIO::LoadFuncPointer loaderA, const std::string &extensionA)
void unregisterLoader (UImageIO::LoadFuncPointer saverA, const std::string &extensionA)
std::vector< std::string > getAvailableSavingExtensions ()
UImageIO::SaveFuncPointer registerSaver (UImageIO::SaveFuncPointer saverA, const std::string &extensionA)
void unregisterSaver (UImageIO::SaveFuncPointer saverA, const std::string &extensionA)
void init ()

Static Public Attributes

const int ALPHA_LAYER
const int COLOR_TYPE_RGB
const int COLOR_TYPE_RGB_ALPHA
const int COLOR_TYPE_GRAY
const int COLOR_TYPE_GRAY_ALPHA
const int FLIP_X
const int FLIP_Y

Protected Member Functions

virtual std::ostream & paramString (std::ostream &os) const

Detailed Description

A basic image loader and saver.

It loads given images from files of streams. The loaded pixels will be freed when the image is destroyed. Currently, only pnm and tga files are supported. But you can add you own image load and save functions by registering them with registerLoader resp. registerSaver

Author:
Johannes Schmidt


Member Enumeration Documentation

enum ufo::UImageIO::FilterRule
 

Filter rules. Used at loading time.


Constructor & Destructor Documentation

ufo::UImageIO::UImageIO  ) 
 

Creates an empty image io object.

ufo::UImageIO::UImageIO const std::string &  fileNameA  ) 
 

Creates an image io object and tries to load an image from the given file name.

Parameters:
fileName File name which should be used to load an image.

ufo::UImageIO::UImageIO IStream &  streamA,
const std::string &  extensionA
 

Parameters:
streamA the stream which should be used to get the encoded image.
extensionA The file extension describing the file type (e.g.: ".png" for PNG files)

ufo::UImageIO::UImageIO unsigned char *  dataA,
int  widthA,
int  heightA,
int  componentsA
 

Creates a UImageIO object with already decoded image data.

ufo::UImageIO::UImageIO int  widthA,
int  heightA,
int  componentsA
 

Creates an empty UImageIO object. The image data may be manipulated via getPixels().


Member Function Documentation

std::vector<std::string> ufo::UImageIO::getAvailableLoadingExtensions  )  [static]
 

Returns the possible extensions (and file formats) which can be decoded by UImageIO

std::vector<std::string> ufo::UImageIO::getAvailableSavingExtensions  )  [static]
 

Returns the possible extensions (and file formats) which can be decoded by UImageIO

std::string ufo::UImageIO::getComment  ) 
 

the comments is either a file comment or the file name itsself

int ufo::UImageIO::getImageComponents  ) 
 

Returns the bytes used for the given image.

  • 1 for gray scaled images.
  • 2 for gray scaled iamges with an alpha layer.
  • 3 for rgb images.
  • 4 for rgba images.

unsigned char* ufo::UImageIO::getPixels  ) 
 

returns the raw pixels with one of these layouts:

  • gray scaled images ( 1 byte )
  • gray scaled iamges with an alpha layer ( 2 bytes )
  • RGB ( 3 bytes )
  • RGBA ( 4 bytes )

void ufo::UImageIO::init  )  [static]
 

Initializes UImageIO. This means, registering png and bmp support. You must call this function just once.

bool ufo::UImageIO::load UImageIO::IStream &  streamA,
const std::string &  extensionA
 

Parameters:
streamA the stream which should be used to get the encoded image.
extensionA The file extension describing the file type (e.g.: ".png" for PNG files)
Returns:
true, if the file could be loaded and decoded.

bool ufo::UImageIO::load const std::string &  fileNameA  ) 
 

Loads the given image file

Returns:
true, if the file could be loaded and decoded.

bool ufo::UImageIO::loadFromArchive const std::string &  fileNameA  ) 
 

Searches the file archive for a file with the given file name and uses an appropriate image plugin for loading.

Returns:
true, if the file could be loaded and decoded.
See also:
UFileArchive

virtual std::ostream& ufo::UImageIO::paramString std::ostream &  os  )  const [protected, virtual]
 

Prints some useful internal data to the ostream os. This method is meant only for debugging purposes.

Reimplemented from ufo::UObject.

UImageIO::LoadFuncPointer ufo::UImageIO::registerLoader UImageIO::LoadFuncPointer  loaderA,
const std::string &  extensionA
[static]
 

Registers a new image loader function and returns the old registered image loader (or NULL). You can pass a NULL pointer as image saving functions to get the current image saving functions for the given extension.

Parameters:
loaderA The new image loading function.
extensionA The extension/format which can be loaded by the image loading function (e.g. .pnm for pnm images)
Returns:
The old image loading function pointer or NULL

UImageIO::SaveFuncPointer ufo::UImageIO::registerSaver UImageIO::SaveFuncPointer  saverA,
const std::string &  extensionA
[static]
 

Registers a new image saving function and returns the old registered image saver (or NULL). You can pass a NULL pointer as image saving functions to get the current image saving functions for the given extension.

Parameters:
loaderA The new image saving function.
extensionA The extension/format which can be saved by the image loading function
Returns:
The old image saving function pointer or NULL

bool ufo::UImageIO::save UImageIO::OStream &  streamA,
const std::string &  extensionA
 

Parameters:
streamA the stream which should be used to save the image.
extensionA The file extension describing the file type (e.g.: ".png" for PNG files)
Returns:
true, if the file could be saved and encoded.

bool ufo::UImageIO::save const std::string &  fileNameA  ) 
 

Saves to currently loaded byte array to the given image. The file name must have an extension returned by getAvaiableSavingExtensions()

Returns:
true, if the file could be loaded and decoded.

void ufo::UImageIO::unregisterLoader UImageIO::LoadFuncPointer  saverA,
const std::string &  extensionA
[static]
 

Unregisters an image loader. This method checks whether the current image load functions matches the given one (on the same extension) and removes it.

void ufo::UImageIO::unregisterSaver UImageIO::SaveFuncPointer  saverA,
const std::string &  extensionA
[static]
 

Unregisters an image saver. This method checks whether the current image save functions matches the given one (on the same extension) and removes it.


Member Data Documentation

const int ufo::UImageIO::COLOR_TYPE_GRAY_ALPHA [static]
 

gray alpha is equal COLOR_TYPE_GRAY | ALPHA_LAYER

const int ufo::UImageIO::COLOR_TYPE_RGB_ALPHA [static]
 

rgba is equal COLOR_TYPE_RGB | ALPHA_LAYER


The documentation for this class was generated from the following file:
The libUFO Project - written by Johannes Schmidt