The VIPS file format
3
VIPS Library
File format
The VIPS file format
Introduction
VIPS has a simple, native file format. It's very fast, there is no image
size limit, and it supports
arbitrary metadata. Although few other programs can read these images
(though recent versions of ImageMagick do support .vips
format), it can be useful as an intermediate format for command-line
processing. For example:
$ vips invert input.tif t.v
$ vips gamma t.v output.tif
is faster than using .tif
for the temporary intermediate
image. This section documents the VIPS file format.
VIPS comes with a command-line program called
vipsedit which is useful for destructively changing
fields in a vips image. The vipsheader program can be
used to extract any metadata.
VIPS files come in three parts. First, there is a 64-byte header,
containing an identifying magic number and a set of very basic fields,
such as image width in pixels. Next, the image data is stored as a set
of band-interleaved scanlines, from the top of the image to the bottom.
Finally, after the pixel data comes an optional block of XML containing
any extra metadata, such as ICC profiles.
The image data
If coding
is set to #VIPS_CODING_NONE, pixels are stored in
native C format, that is, the native format of the
machine that wrote the data. If you open a big-endian image on a
little-endian machine, VIPS will automatically byte-swap for you.
VIPS has 10 band formats, see #VipsBandFormat.
Image data is stored as a simple list of scanlines, from the top of the
image to the bottom. Pixels are band-interleaved, so RGBRGBRGBRGB,
for example. There is no padding at the end of scanlines.
If coding
is set to #VIPS_CODING_LABQ, each pixel is four
bytes, with 10 bits for L* and 11 bits for each of a* and b*. These
32 bits are packed into 4 bytes, with the most significant 8 bits of each
value in the first 3 bytes, and the left-over bits packed into the final
byte as 2:3:3.
If coding
is set to #VIPS_CODING_RAD, each pixel is
RGB or XYZ float, with 8 bytes of mantissa
and then 8 bytes of exponent, shared between the three channels. This
coding style is used by the Radiance family of programs (and the HDR
format) commonly used for HDR imaging.
Other values of coding
can set other coding styles. Use
VIPS_IMAGE_SIZEOF_IMAGE() to calculate the size of the image data
section.
The metadata
Following the image data is a chunk of XML holding a simple list of
name-value pairs. Binary data is encoded with base64. Use
vips_image_set() and friends to set and get image metadata.
You can use vipsheader -f getext x.v to get the
XML from a VIPS image, and
vipsedit --setext x.v < file.xml to replace the
XML.