VIPS has a simple system for adding support for new image file formats. You can ask VIPS to find a format to load a file with or to select a image file writer based on a filename. Convenience functions copy a file to an IMAGE, or an IMAGE to a file. New formats may be added to VIPS by simply defining a new subclass of VipsFormat.
This is a parallel API to im_open(), see §2.2.4. The format system is useful for images which are large or slow to open, because you pass a descriptor to write to and so control how and where the decompressed image is held. im_open() is useful for images in formats which can be directly read from disc, since you will avoid a copy operation and can directly control the disc file. The inplace operations (see §4.2.8), for example, will only work directly on disc images if you use im_open().
See the man page for VipsFormat for full details, but briefly, an image format consists of the following items:
The interface to the format system is defined by the abstract base class VipsFormat. Formats subclass this and implement some or all of the methods. Any of the functions may be left NULL and VIPS will try to make do with what you do supply. Of course a format with all functions as NULL will not be very useful.
As an example, Figure 2.9 shows how to register a new format in a plugin.
You can loop over the subclasses of VipsFormat in order of priority with vips_format_map(). Like all the map functions in VIPS, this take a function and applies it to every element in the table until the function returns non-zero or until the table ends.
You find an VipsFormatClass to use to open a file with vips_format_for_file(). This finds the first format whose is_a() function returns true or whose suffix list matches the suffix of the filename, setting an error message and returning NULL if no format is found.
You find a format to write a file with vips_format_for_name(). This returns the first format with a save function whose suffix list matches the suffix of the supplied filename.
A pair of convenience functions, vips_format_write() and vips_format_read(), will copy an image to and from disc using the appropriate format.