Babl is a dynamic, any to any, pixel format conversion library. It provides conversions between the myriad of buffer types images can be stored in. Babl doesn't only help with existing pixel formats, but also facilitates creation of new and uncommon ones.
GEGL uses babl both for enumeration of pixel formats as well as conversions between them.
Features
- Tiny API in normal use.
- Planar and linear buffers.
- Thread safe processing.
- Extendable formats, color models, components and datatypes
- Reference 64bit floating point conversions for data types and color models.
Download
The latest versioned development version of babl can be found in ftp://ftp.gtk.org/pub/babl/.
Babl development happens in GNOME Subversion in the babl module. It can be browsed online and checked out with:
svn co http://svn.gnome.org/svn/babl/trunk/ babl
The following is a list of the major changes that have gone into each babl release. If there are significant improvements to babl when a GEGL release is done a babl release is most often put out just prior to the GEGL release.
Documentation
When using BablFishes to do your conversions, you request a fish to convert between two formats, and an optimal fish to babls capability is provided that you can use to do your conversions. Babl also provides the capability to describe new formats based on a vocabulary of user registered color models and data types.
Babl provides a base vocabulary in BablBase and some extensions that are thought to be generally useful.
When performing further extensions to the vocabulary of babl, the internal consistency is governed by reference conversions that operate on double (64 bit floating point values). The only color model created during BablCore bootstrap is RGBA (linear light RGB, 0.0 - 1.0, with a linear 0.0 - 1.0 opacity channel) backed by the double datatype.
If babls conversion isn't fast enough, you can provide your own conversion shortcut between two formats. The registered shortcut might also be used by babl as an intermediate conversion when constructing BablFishes for other conversions.
Babl extensions are shared objects. If you have already developed some fast conversion functions, wrapping them as babl extensions should not take much time and will speed up babl for other users as well.
Usage
The simplest scenario for using babl is converting between linear buffers represented by an existing BablPixelFormat.
babl_process (babl_fish ("srgb", "CIE Lab float"), srgb_buffer, lab_buffer, pixel_count);
If the existing pixel formats are not sufficient for your conversion needs, new ones can be created on the fly. The constructor will provide the prior created one if duplicates are registered.
format = babl_format_new (babl_model ("R'G'B'"), babl_type ("u8"), babl_component ("B'"), babl_component ("G'"), babl_component ("R'"), NULL);
babl_process (babl_fish (source_format, destination_format), source_buffer, destination_buffer, pixel_count);
Vocabulary
Shortcut coverage
The diagram shown below visualizes the coverage of current shortcut conversions. A DHTML version is also available.
Extending
For samples of how the current internal API specification of data types, color models, and conversions look in the extensions/ directory. The tables in this HTML file is directly generated based on the data registered by BablCore (double and RGBA), BablBase (core datatypes, and RGB models), extensions (CIE Lab, naive CMYK, various shortcut conversions).
TODO
- Validate that a created BablFishPath is actually faster than the BablFishReference it is a replacement for.
- Compile-time instead of runtime profiling / storage of profiling and loss data.. (The speed of conversions is bound to 'wobble', according to architecture, compiler flags, concurrently running processes and phase of moon.)
- Horizontal chroma subsampling (4:2:2 and 4:1:1)
- Thread safety (locking) for mutations of the type system.
- Support for conversions between formats that have higher dimensionality than RGBA.
- Support for datatypes that are not a multiple of 8bit.
- dithering
Copyright
Babl is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Authors
