IlvBitmap: The Bitmap Image Class

Raster or bitmap images are represented by instances of the IlvBitmap class. For details on using IlvBitmap, see:

Bitmap-Related Member Functions

Special member functions dealing with bitmaps can be found in the IlvDisplay class.

Bitmaps are very often shared between different objects. For example, the same bitmap can be used as a fill pattern and an image on its own. Therefore, we need a management of bitmap resources, which is accomplished by a locking/unlocking policy.

Bitmap management is closely concerned with the ways in which you lock or unlock your bitmaps. Whenever you need a specific bitmap in one of your persistent objects, use the following mechanism to make sure that it will stay safe within your IlvDisplay instance:

void lock();

This member function of the class IlvBitmap ensures that your bitmap will never be modified or destroyed before every object that needs it tells Views to do so. Basically, this function increments a reference count initially set to 0.

void unLock();

This member function unlocks your bitmap; that is, it decrements the reference count of the bitmap and deletes it when this count becomes 0. The creation/deletion mechanism of an IlvBitmap object by the new and delete C++ operators must be reserved for bitmap objects used in a temporary way and which are not shared.

Bitmap Formats

Views allows you to create IlvBitmap objects from files or streams containing images in various formats. These formats are:

  • BMP (all subtypes, RLE and RGB encoded, Indexed and True Color). This format is very common on Microsoft Windows platforms. Not compressed.

  • Portable Network Graphics (PNG). This format is becoming more common. It allows transparent areas or colors, has indexed and high resolution true color subtypes.

Note

This format is the patent-free replacement for GIF. See http://www.libpng.org/pub/png/.

  • Joint Photographic Experts Group (JPEG and JPEG 2000) The JPEG format is widely used for photographic images. It is “lossy,” meaning that original information is missing in a JPEG image. This format allows important compression factors. The JPEG 2000 is a newer format using scalable compression.

  • Portable Pixmap (PPM, PGM, PBM) This format is very common on UNIX platforms. It is uncompressed and generates huge files.

  • WAP Bitmap (WBMP) This format is used on WAP devices, such as mobile phones. It is a monochrome format.

Loading Bitmaps: Streamers

Each of the bitmap formats is associated with a streamer object (class IlvBitmapStreamer).

Streamers can be registered at compile time or at run time. Registering a streamer at compile time consists of including the header file for this format:

Header Files for Bitmap Formats

Bitmap Format

Header File

JPEG

ilviews/bitmaps/jpg.h

JPEG 2000

ilviews/bitmaps/jpeg2kstreamer.h

PNG

ilviews/bitmaps/png.h

BMP

ilviews/bitmaps/bmp.h

PPM

ilviews/bitmaps/ppm.h

SGI RGB

ilviews/bitmaps/rgb.h

TIFF

ilviews/bitmaps/tiff.h

WBMP

ilviews/bitmaps/wbmp.h

You then just use the following call to load an image into a bitmap:

IlvBitmap* IlvDisplay::readBitmap(const char* filename);

Image type is recognized using a file signature, and the correct streamer is called automatically by readBitmap.

All the bitmap streamers are dynamic modules. It means that the reader or writer is dynamically loaded when necessary. Thus, you need only to request Views to read or write an image, and it will do it for all known formats.

Streamers are modules and can be loaded at run time if an unknown (or unregistered) file format is being loaded. The corresponding module (if any) will be loaded and the streamer registered. This works only on platforms where modules are supported.

Additional formats are always registered and do not need modules:

  • XPM

  • XBM

Loading Transparent Bitmaps

An IlvTransparentIcon object appears as a bitmap. Pixels in the source bitmap with a zero value do not affect the destination port when the drawing is performed. Usually the transparent region of the bitmap icon lets the background pattern show through. This process works only for monochrome bitmaps or colored bitmaps that have either a transparency mask or a transparent color index.

Views is able to load transparent bitmaps from the following file formats :

  • XPM

The transparent areas match the areas defined as “none” in the bitmap description file. If this information is omitted, the bitmap is not loaded as a transparent icon.

  • PNG

Views uses transparency information form the PNG stream to create transparent areas in the bitmap.