Difference between revisions of "GameTools loadImg"
SteveBaker (Talk | contribs) (New page: 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...) |
(No difference)
|
Latest revision as of 20:51, 23 October 2007
A handy-dandy image loader that recognises '.rgb', '.png' and '.tif' image formats and can load all sorts of image types and precisions:
Contents
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 : |
| gameTools - File Formats : |
gameTools - Source Code :
|
| Wikiid Pages relating to Lemur of Lima (edit) |
| Lemur of Lima - Main page |
| Lemur of Lima - Controls |
| Lemur of Lima - Levels : |
| Lemur of Lima - Java Plugins : |
| Lemur of Lima - Source Code Documentation : |