BIL - Bernie's Image Library

BIL is an image library created for my honours project during 2000. However, I have since used it in a lot of other smaller personal projects. I have also used the basic design (eg: the streaming interface) in a lot of projects at work. I am very proud of this library. Its design is simple yet powerful, the code is clean and robust. If anybody asked to see some "resume" quality code to showcase my abilities, I would give them BIL.

BIL allows loading and saving of JPEG, PNG and PPM images. However, due to its plug-in architecture, support for more formats can be easily added. Currently under development are drivers to load and save TIFF, GIF, TGA and RGB images.

BIL provides a very flexible interface to loading and saving images. It does not assume that the images are stored on disk. To encode (save) an image, the user simply requests the encoded data block by block. To decode (load) an image, the user presents the image data to BIL block by block. In essence, the library has a streaming interface.

BIL has been compiled and used on Win32 (Win95 to WinXP), Linux (back in 2000), IRIX and SunOS. On Win32, BIL and its drivers can be built as DLLs, enabling runtime driver loading! There are no sample programs that do this, so you will have to figure it out yourself :)

API Summary

The following functions are used to create and destroy an image in memory:

BILimage   bilNewImage(BILsizei width, BILsizei height);
BILboolean bilDeleteImage(BILimage image);

File formats are registered before encoding and decoding using the following functions:

BILboolean bil{format}RegisterEncoder();
BILboolean bil{format}RegisterDecoder();

eg: bilJpegRegisterEncoder();

Encoding (saving) is performed using the following functions:

BILcontext bilBeginEncode(BILimage image, const BILchar *key);
BILsizei  bilEncodeBlock (BILcontext context, BILvoid *block, BILsizei size);
BILboolean bilEndEncode  (BILcontext context);

Decoding (loading) is performed using the following functions:

BILcontext bilBeginDecode(BILimage image, const BILchar *key);
BILsizei   bilDecodeBlock(BILcontext context, const BILvoid *block, BILsizei size);
BILboolean bilEndDecode  (BILcontext context);

For example, to load a JPEG image from a disk file, the following code is used:

image   = bilNewImage(0, 0);
context = bilBeginDecode(image, "jpeg");
while ((size = fread(buffer, 1, sizeof(buffer), file)) > 0)
  bilDecodeBlock(context, buffer, size);
bilEndDecode(context);

There are convenience functions to save and load images to and from disk:

BILboolean bilSaveImage(BILimage *image, const BILchar *fileName, const BILchar *driver);
BILboolean bilLoadImage(BILimage *image, const BILchar *fileName, const BILchar *driver);

Every BIL function returns BIL_FALSE (0 or NULL) on error. To check the error condition, the following function is used:

BILerror bilGetError();

Download

Download (27th June, 2004):