GdkPixbuf as a Replacement for Imlib

Federico Mena Quintero

    federico@gimp.org
  

This article describes the architecture of GdkPixbuf, the image loading library that will be used in the next major version of GNOME. Older versions of GNOME, as of October 1999, used the Imlib library, which has numerous design limitations. This article also describes the differences between Imlib and GdkPixbuf so that application developers can take these considerations into account when updating their applications.


Table of Contents
Introduction
Memory Management
Image Loading and Creation
Image Transformations
Rendering
Differences Between Imlib and the GdkPixbuf Framework
References

Introduction

As of October 1999, GNOME programs and the core libraries use the Imlib library for loading and rendering images. Unfortunately, Imlib has several important design limitations that make it hard to write efficient and highly modular applications.

GdkPixbuf is a new GNOME library designed to solve part of Imlib's problems. The GdkPixbuf library provides a basic, reference counted structure called GdkPixbuf. This structure points to a block of image data, has fields that describe the format of the image data, and also contains a reference count. The library also provides a simple mechanism for loading images from files, and a more sophisticated mechanism for loading images progressively from arbitrary buffers. It also provides utility functions to transform pixbufs and render them to GDK drawables.

The GdkPixbuf framework is thus composed of the following parts. Not all of the functionality is provided by the GdkPixbuf library itself; parts are provided by the Libart and GdkRGB libraries.

ArtPixBuf. This is a structure in the Libart library that contains a buffer for image data and information about how the data is laid out in memory. Currently it support RGB images with optional transparency (alpha channel) and 8 bits of information per channel.

GdkPixbuf. This is a simple structure that wraps an ArtPixBuf and extends it with reference counting capabilities. This is necessary to write applications that need to share image data between different portions of the code, while maintaining correctness in memory management.

In addition, the GdkPixbuf library provides loaders for common image formats. Images can be loaded synchronously from a file, or progressively from user-supplied buffers. This lets simple applications load images with a single function call, and it also lets more sophisticated applications load an image progressively as they obtain more data. For example, a web browser will read chunks of data from the network and feed them progressively to a GdkPixbufLoader object. The loader will take care of parsing the image data as it gets it.

Libart transformations. The Libart library provides generalized affine transformations for image buffers, so images can be rotated, scaled, and sheared in any way.

GdkRGB. This part of the GDK library handles fast color reduction and dithering of images to render them to an X drawable.

The following sections explore these parts in detail, and they describe how to modify existing applications that use Imlib to use the new framework.