| FreeImage Documentation - Contents Previous Next Up |
Advanced load functions
FreeImage_LoadFromHandle functions are slightly more advanced than the simple load functions, but still quite easy to use. The idea of these functions is that FreeImage doesn't care how it gets its data as long as it gets it. It shouldn't matter if the bitmap is loaded from file, memory or the internet since data is data not matter where it comes from. To make this idea of data abstraction work a new, abstract file I/O system is used: FreeImageIO . FreeImageIO is a structure containing pointers to 4 functions: a read function, write function, seek function and tell function. All these functions have to be implemented so that data is delivered. The handle representing the data is made abstract as well and is named fi_handle . Loading a bitmap using the FromHandle functions involves four things. First the 4 file i/o functions are implemented and a FreeImageIO structure is filled with the pointers. Then the file is opened (that is, if we are in fact dealing with a file). After that one of the LoadFromHandle functions can be called. If the bitmap is succesfully loaded the file has to be closed. Example:
unsigned
_ReadProc(void *buffer, unsigned s, unsigned c, fi_handle handle) { return fread(buffer, s, c, (FILE *)handle); } unsigned _WriteProc(void *buffer, unsigned s, unsigned c, fi_handle handle){ return fwrite(buffer, s, c, (FILE *)handle); } int _SeekProc(fi_handle handle, long offset, int origin) { return fseek((FILE *)handle, offset, origin); } long _TellProc(fi_handle handle) { return ftell((FILE *)handle); } FreeImageIO io; io.read_proc = _ReadProc; io.write_proc = _WriteProc; io.seek_proc = _SeekProc; io.tell_proc = _TellProc; FILE *file = fopen("test.bmp", "rb"); if (file != NULL) { void *dib = FreeImage_LoadBMPFromHandle(&io, (fi_handle)file); FreeImage_Free(dib); fclose(file); } Subsections
FreeImage_LoadBMPFromHandle
void *FreeImage_LoadBMPFromHandle(FreeImageIO *io, fi_handle handle, BMPFlags flags = BMP_DEFAULT);
Loads the given BMP file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadBMPFromHandle returns NULL. FreeImage_LoadICOFromHandle
void *FreeImage_LoadICOFromHandle(FreeImageIO *io, fi_handle handle, ICOFlags flags = ICO_DEFAULT);
Loads the given ICO file into a FreeImage bitmap using the given FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadICOFromHandle returns NULL. FreeImage_LoadJPEGFromHandle
void *FreeImage_LoadJPEGFromHandle(FreeImageIO *io, fi_handle handle, JPEGFlags flags = JPEG_DEFAULT);
Loads the given JPEG file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadJPEGFromHandle returns NULL. FreeImage_LoadKOALAFromHandle
void *FreeImage_LoadKOALAFromHandle(FreeImageIO *io, fi_handle handle, KOALAFlags flags = KOALA_DEFAULT);
Loads the given KOALA file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadKOALAFromHandle returns NULL. FreeImage_LoadPCDFromHandle
void *FreeImage_LoadJPEGFromHandle(FreeImageIO *io, fi_handle handle, JPEGFlags flags = JPEG_DEFAULT);
Loads the given Kodak PhotoCD file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadPCDFromHandle returns NULL. FreeImage_LoadPCXFromHandle
void *FreeImage_LoadPCXFromHandle(FreeImageIO *io, fi_handle handle, PCXFlags flags = PCX_DEFAULT);
Loads the given PCX file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadPCXFromHandle returns NULL. FreeImage_LoadPNMFromHandle
void *FreeImage_LoadPNMFromHandle(FreeImageIO *io, fi_handle handle, PNMFlags flags = PNM_DEFAULT);
Loads the given PBM, PGM or PPM file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadPNMFromHandle returns NULL. FreeImage_LoadPNGFromHandle
void *FreeImage_LoadPNGFromHandle(FreeImageIO *io, fi_handle handle, PNGFlags flags = PNG_DEFAULT);
Loads the given PNG file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadPNGFromHandle returns NULL. FreeImage_LoadRASFromHandle
void *FreeImage_LoadRASFromHandle(FreeImageIO *io, fi_handle handle, RASFlags flags = RAS_DEFAULT);
Loads the given Sun Rasterfile into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadRASFromHandle returns NULL. FreeImage_LoadTARGAFromHandle
void *FreeImage_LoadTARGAFromHandle(FreeImageIO *io, fi_handle handle, TARGAFlags flags = TARGA_DEFAULT);
Loads the given TARGA file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadTARGAFromHandle returns NULL. FreeImage_LoadTIFFFromHandle
void *FreeImage_LoadTIFFFromHandle(FreeImageIO *io, fi_handle handle, TIFFFlags flags = TIFF_DEFAULT);
Loads the given TIFF file into a FreeImage bitmap using the specified FreeImageIO struct and fi_handle. If the file is loaded succesfully, memory for it is allocated and a void pointer is returned. If the file couldn't be loaded, FreeImage_LoadTIFFFromHandle returns NULL. Copyright 2000 Floris van den Berg (freeimage@wxs.nl) |