GameTools loadImg

From Wikiid
Jump to: navigation, search

A handy-dandy image loader that recognises '.rgb', '.png' and '.tif' image formats and can load all sorts of image types and precisions:

enum liImageFormat

A handy enum to tell you what the original file type was:

 enum liImageFormat
 {
   LI_IMAGE_FORMAT_NONE,
   LI_IMAGE_FORMAT_RGB,
   LI_IMAGE_FORMAT_PNG,
   LI_IMAGE_FORMAT_TIF,
   LI_IMAGE_FORMAT_ILLEGAL
 } ;
 #define LI_IMAGE_TYPE_CUBE_MAP    0x12345678

Data types

We need to use OpenGL datatypes for speed/efficiency/simplicity, but this header file may be linked into applications that don't include GL/gl.h.

LIGL_BYTE, LIGL_UNSIGNED_BYTE, LIGL_SHORT, LIGL_UNSIGNED_SHORT, LIGL_INT, LIGL_UNSIGNED_INT, LIGL_FLOAT                                , LIGL_DOUBLE, LIGL_HALF

...and to save typing:

LIGL_UBYTE, LIGL_USHORT, LIGL_UINT

All of these are compatible with the corresponding OpenGL data type enumerations.

Utility Functions

 int liIsAPowerOfTwo ( unsigned int n ) ;

class liImageParameters

This contains all of the 'header' information for an image - but without the actual pixels that make it up.

 class liImageParameters
 {
   liImageParameters () ;
   liImageParameters ( int xs, int ys, int zs, int nc,
                       int type, bool _mipmapped = false ) ;
   virtual ~liImageParameters () ;
   int getXsize           () ;
   int getYsize           () ;
   int getZsize           () ;
   int getNumComponents   () ;
   int getNumMIPlevels    () ;
   int getNumDimensions   () ;
   int getComponentType   () ;
   int getComponentSize   () ;
   int getTexelSize       () ;
   const char *getComponentTypeName () ;
   float *getImageMinima () ;
   float *getImageMaxima () ;
   float *getImageMean   () ;
   bool isMIPmapped () ;
   bool isValidOpenGLTexture () ;
 } ;

class liImage

This class represents an entire image - with all of it's parameters - in memory.

 class liImage : public liImageParameters
 {
   liImage () ;
   liImage  ( int xs, int ys, int zs, int nc,
              int type, bool _mipmapped = false ) ;
   virtual ~liImage () ;
   const char *getFileName () ;
   void setFileName ( const char *_fname ) ;
   void collectStatistics () ;
   bool loadedOK () ;
   void print ( FILE *fd = stdout ) ;
   virtual liImageFormat getImageFormat () ;
   void giveTexels ( unsigned char *imagedata, int mip_level = 0 ) ;
   unsigned char *takeTexels ( int mip_level = 0 ) ;
   unsigned char *getTexels ( int mip_level ) ;
   unsigned char *getTexels () ;
   unsigned char *getSafeTexelComponent ( int x, int y, int z, int c ) ;
   unsigned char *getTexelComponent     ( int x, int y, int z, int c ) ;
   void makeMIPmaps () ;
   virtual int getType () ;
   virtual unsigned short getMaterialCode ( int which ) ;
 } ;

liImageFactory

In reality, each file format uses a derived class of liImage. Picking the correct one and taking care of each one's little foibles is painful - so there are a couple of 'helper' functions to which you can pass some basic data and let them take care of everything:

liImageFactory constructs and returns a liImage of an appropriate sub-class for the filename - or NULL if something goes horribly wrong. Use the first form to load an image from disk - use the second form to generate a blank image that will automatically be written out to disk when you call the liImage destructor function. In both cases, the filename extension determines the file format used.

 liImage *liImageFactory ( const char *fname ) ;
 liImage *liImageFactory ( const char *fname,
                           int xs, int yz, int zs,
                           int ncomp,
                           int texel_type = LIGL_UBYTE,
                           bool mipmapped = false ) ;


liGetSizeOfImage fetches the Width, Height and Depth (1,2,3 or 4 bytes per pixel) of a specified image file. Returns 'true' on success, 'false' otherwise.

 int liGetSizeOfImage ( const char *fname,
                        int *w, int *h, int *d,
                        int *ncomponents, int *data_size ) ;

liGetImageDataFormat lets you know the data format:

 int liGetImageDataFormat ( const char* fname, int* format ) ;


Wikiid Pages relating to gameTools (edit)
gameTools - Main page
gameTools - Support Tools :
plb_to_ac3d, mklevel, mktile, mktree, tiled, autogen_java, mk3dgallery
gameTools - File Formats :
title_screen.rgb, ultimate.xml, material.xml, decoration.xml, physics.xml
tiled.xml, tiled_autotiles.xml, Level files, Tile naming scheme, PLB files
gameTools - Source Code :
Game functions: gameCamera, gameClock, gameChecksum/gameHashTable, gameHTTP,
gameIsect, gameJoystick, gameParticleManager, gameScreen/gameMouse,
gameSky, gameStarter, gameStrokeFont, gameUtils
Material database: MatList/MatEntry
Tile map handling: TileObject/MapFlag/MapEntry/Map
Java Interfacing: JavaLink
Image file loading: liImage/liImageFactory
3D Model file loading: loadPLB, PLB exporter
Physics: Sabot, Bullet, gameTools - Use with Blender, PLB exporter
Object management: Object


Wikiid Pages relating to Lemur of Lima (edit)
Lemur of Lima - Main page
Lemur of Lima - Controls
Lemur of Lima - Levels :
List of Levels, Level design, Screen shots, Models
Lemur of Lima - Java Plugins :
Java plugin API, Event handling, Flags, GameInterface API , Alphabetical Index
Lemur of Lima - Source Code Documentation :
Initialisation, Main Loop, gameTools