Bitmap Operations

paintlib works on bitmaps. The abstract class CBmp defines an interface for bitmap storage and manipulation. The actual details of storage are defined in derived classes. The contents of a bitmap can be changed either via Filter objects or by directly accessing the bits. Among others, filters for resizing, cropping, rotating and blurring an image are included.

Currently, three classes derived from CBmp are defined: CWinBmp for windows DIBs (Device Independent Bitmaps), CAnyBmp for simple OS-independent storage, and CDIBSection for windows DIB sections. New classes can be defined for other operating systems and storage formats, the only restriction being that pixels in one line are stored consecutively and not as separate planes. To be compatible with the decoders, a bitmap class must define formats with 1, 8 and 32 bpp.

[Bernard Delmées piclook (one of the sample programs) contains CDrawDibBmp, a derived bitmap class that uses the windows DrawDIB api for blitting.]

There is virtually no difference in speed between using the OS-independent interface and directly accessing OS-dependent data. The power of this design is demonstrated by the testdib demo. This demo includes classes which implement complex bitblts with alpha information, resizing, and transparency in an OS-independent fashion. The classes are documented in the read.me file in the testdib directory.

Image File Decoding

paintlib can decode image files and store the data in an object of any of the CBmp-derived classes. Supported file formats are PNG, TGA, TIFF, JPEG/JFIF, PCX, Windows BMP, and Mac PICT as well as TIFF previews in EPS files. Support for PNG is through the PNG reference library libpng. TIFF is supported through use of Sam Leffler's libtiff. This library is the most complete implementation of the TIFF standard that I know of. The Independent JPEG Group's libjpeg provides solid support for the JPEG/JFIF format. The TGA, BMP, and PICT decoders are my work. They have been tested with a wide variety of files. The PICT decoder skips any non-bitmap data in the file and supports PICT/JPEG. Meng Bo wrote the PCX decoder.

The library is capable of auto-detection of the image file type. Input data can come from memory or disk - or from a custom data source. Under windows, images linked into the .exe as resources can also be loaded. All data is converted to 8 or 32 bpp before being handed to the application. 1 bpp tiffs are an exception to this rule - they get handed to the application as 1 bpp.

Image File Encoding

The encoding classes store images. Currently implemented are TIFF (via libtiff) and JPEG (via libjpeg). Data storage is handled by data sink classes. A data sink for disk files is provided; others can be implemented.

Open Design

One of the primary design goals for paintlib was openness for expansion. Implementing additional en- and decoders is simple because many basic operations (data source management, MSB/LSB conversion, error handling,...) have been taken care of already. Integrating libpng, for example, took Gilles and me about two days (total) of work. The data sources and sinks and the bitmap format can be tailored to suit the needs of the users. The filter interface is very thin, so creating new filters is easy.

While most of the development is being done under Microsoft Visual C++, paintlib is plattform-independent. Care was taken to ensure that the speed of the library did not suffer more than necessary through plattform- and data source-independence.