lensfun  0.3.95.0
Library architecture

The library provides five basic types of objects to work with: mounts (lfMount), cameras (lfCamera), lenses (lfLens), databases (lfDatabase) and modificators (lfModifier).

The lfMount structure provides the information about a mount. For now the only information about a mount is its name and the list of compatible mounts.

The lfCamera structure provides information about a particular camera. Camera maker, model name, mount type and other things are included here.

The lfLens structure provides information about a lens. This structure contains a lot of information, since it's the heart of the library. Besides other things, this contains a list of lens calibration data. This information tells the library how to correct images distorted by a certain lens.

The lfDatabase class provides a interface to the XML database. It allows to load, save XML files and to search the database for lenses, cameras and mounts.

Finally, the lfModifier class will allow you to modify images. Not only correct for distortion introduced by lenses but also apply special effects on a image such as emulating certain lens (e.g. apply a reverse transform), modify the geometry of a image (e.g. convert a fisheye image to a rectilinear etc).

A typical application will first load the database by creating a lfDatabase object and invoking the respective lfDatabase::Load() method. After that it can look for a Lens object using the bits of information from the user or from the source file. For example, the EXIF data contains the camera maker and camera model. Using this you can search for the respective camera in the database. In camera record you look at the mount field, and then do a lens search based on at least mount name. Additionaly, you may provide the lens manufacturer and/or model name from the EXIF data (which is not always possible). You get a list of possible lenses. If it's just one lens, you can assume that it's exactly the lens that was used to take the shot (this is true for compact cameras which have a fixed mount).

Now if you found more than one matching lens you must provide the user a choice. User chooses the exact lens that was used to make a shot. After that you can create a lfModifier object using lens data. Using this object the image may be modified according to user preferences.

Lensfun transformations – at least those involving TCA and vignetting correction – must be applied to linear RGB data in the sensor's original colour space. Linear RGB can only be retrieved from RAW files, as JPEG files from most cameras already have colour transfromations applied. This is very important. If you do e.g. TCA correction on sRGB data, the colour fringes are still visible. And if you do vignetting correction after a gamma has been applied, the corners probably will look too bright. So make sure that Lensfun comes early enough in your processing chain.