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 header The fields in the VIPS header are always stored least-significant byte first (Intel ordering). Only the most basic information about the image is in the header: most metadata is stored in the XML extension block after the pixel data. The VIPS header Bytes Type VIPS name Meaning 0 -- 3 VIPS magic number, 08 f2 f6 b6 4 -- 7 %gint width Width of image, in pixels 8 -- 11 %gint height Height of image, in pixels 12 -- 15 %gint bands Number of image bands 16 -- 19 Unused 20 -- 23 #VipsBandFormat format Band format 24 -- 27 #VipsCoding coding Image coding 28 -- 31 #VipsInterpretation interpretation Pixel interpretation 32 -- 35 %gfloat xres Horizontal resolution, in pixels per millimetre 36 -- 39 %gfloat yres Vertical resolution, in pixels per millimetre 40 -- 47 Unused 48 -- 51 %gint xoffset Horizontal offset of origin, in pixels 52 -- 55 %gint yoffset Vertical offset of origin, in pixels
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.