lensfun  0.2.7.0
tfun.cpp

This example shows how to do basic database lookups.

/*
Test for database search functions.
*/
#include "lensfun.h"
#include <glib.h>
#include <getopt.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
static void DisplayVersion ()
{
g_print ("lensfun version %d.%d.%d: test database search routines\n",
g_print ("Copyright (C) 2007 Andrew Zabolotny\n\n");
g_print ("For distribution rules and conditions of use see the file\n");
g_print ("COPYING which is part of the distribution.\n");
}
static void DisplayUsage ()
{
DisplayVersion ();
g_print ("\nIf no options are given, some standard tests will be run.\n");
g_print ("Command-line options:\n\n");
g_print (" -L# --lens=# Use calibration data for this lens\n");
g_print (" -m# --max=# Limit the amount results\n");
g_print (" -f --fuzzy More fuzzy search algorithm\n");
g_print (" -V --version Display program version and exit\n");
g_print (" -h --help Display this help text\n");
}
static void PrintMount (const lfMount *mount)
{
g_print ("Mount: %s\n", lf_mlstr_get (mount->Name));
if (mount->Compat)
for (int j = 0; mount->Compat [j]; j++)
g_print ("\tCompat: %s\n", mount->Compat [j]);
}
static void PrintCamera (const lfCamera *camera, const lfDatabase *ldb)
{
g_print ("Camera: %s / %s %s%s%s\n",
lf_mlstr_get (camera->Maker),
lf_mlstr_get (camera->Model),
camera->Variant ? "(" : "",
camera->Variant ? lf_mlstr_get (camera->Variant) : "",
camera->Variant ? ")" : "");
g_print ("\tMount: %s\n", lf_db_mount_name (ldb, camera->Mount));
g_print ("\tCrop factor: %g\n", camera->CropFactor);
}
static void PrintLens (const lfLens *lens, const lfDatabase *ldb)
{
g_print ("Lens: %s / %s\n",
lf_mlstr_get (lens->Model));
g_print ("\tCrop factor: %g\n", lens->CropFactor);
g_print ("\tFocal: %g-%g\n", lens->MinFocal, lens->MaxFocal);
g_print ("\tAperture: %g-%g\n", lens->MinAperture, lens->MaxAperture);
g_print ("\tCenter: %g,%g\n", lens->CenterX, lens->CenterY);
g_print ("\tCCI: %g/%g/%g\n", lens->RedCCI, lens->GreenCCI, lens->BlueCCI);
if (lens->Mounts)
for (int j = 0; lens->Mounts [j]; j++)
g_print ("\tMount: %s\n", lf_db_mount_name (ldb, lens->Mounts [j]));
}
static void PrintCameras (const lfCamera **cameras, const lfDatabase *ldb, int maxEntries=-1)
{
if (cameras)
for (int i = 0; cameras [i]; i++)
{
g_print ("--- camera %d: ---\n", i + 1);
PrintCamera (cameras [i], ldb);
if ((maxEntries > 0) && (i>=maxEntries-1))
break;
}
else
g_print ("\t- failed\n");
}
static void PrintLenses (const lfLens **lenses, const lfDatabase *ldb, int maxEntries=-1)
{
if (lenses)
for (int i = 0; lenses [i]; i++)
{
g_print ("--- lens %d, score %d: ---\n", i + 1, lenses [i]->Score);
PrintLens (lenses [i], ldb);
if ((maxEntries > 0) && (i>=maxEntries-1))
break;
}
else
g_print ("\t- failed\n");
}
int main (int argc, char **argv)
{
static struct option long_options[] =
{
{"lens", required_argument, NULL, 'L'},
{"max", required_argument, NULL, 'm'},
{"fuzzy", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{0, 0, 0, 0}
};
static struct
{
int maxResults;
bool fuzzySearch;
const char *Lens;
} opts =
{
-1,
0,
NULL,
};
setlocale (LC_ALL, "");
int c;
while ((c = getopt_long (argc, argv, "L:m:fhV", long_options, NULL)) != EOF)
{
switch (c)
{
case'L':
opts.Lens = optarg;
break;
case 'm':
opts.maxResults = atoi(optarg);
break;
case 'f':
opts.fuzzySearch = LF_SEARCH_LOOSE;
break;
case 'h':
DisplayUsage();
return 0;
case 'V':
DisplayVersion ();
return 0;
default:
return -1;
}
}
lfDatabase *ldb = lf_db_new ();
ldb->Load ();
// if no arguments are passed, do standard tests
if (argc==1)
{
g_print (">>> Looking for mount 'pEnTaX K' ...\n");
const lfMount *mount = ldb->FindMount ("pEnTaX K");
if (mount)
PrintMount (mount);
else
g_print ("\t- failed\n");
g_print (">>> Looking for camera 'sOnY CyBeRsHoT' ...\n");
const lfCamera **cameras = ldb->FindCameras ("sOnY", "CyBeRsHoT");
PrintCameras (cameras, ldb);
lf_free (cameras);
g_print (">>> Looking for Zenit cameras ...\n");
cameras = ldb->FindCameras ("KMZ", NULL);
PrintCameras (cameras, ldb);
g_print (">>> Looking for lenses 'pEntax 50-200 ED'\n");
const lfLens **lenses = ldb->FindLenses (NULL, NULL, "pEntax 50-200 ED");
PrintLenses (lenses, ldb);
lf_free (lenses);
g_print (">>> Looking for 'Nikkor IF' lenses\n");
lenses = ldb->FindLenses (NULL, NULL, "Nikkor IF");
PrintLenses (lenses, ldb);
g_print (">>> Saving results into 'tfun-results.xml' ...\n");
const lfMount *mounts [2] = { mount, NULL };
lfError e = ldb->Save ("tfun-results.xml", mounts, cameras, lenses);
if (e == LF_NO_ERROR)
g_print ("\t- success\n");
else
g_print ("\t- failed, error code %d\n", e);
lf_free (cameras);
lf_free (lenses);
}
else
{
if (opts.Lens == NULL)
{
g_print ("No lens name is given\n");
DisplayUsage();
ldb->Destroy ();
return -1;
}
g_print (">>> Looking for lens '%s' %d\n", opts.Lens, opts.fuzzySearch);
const lfLens **lenses = ldb->FindLenses (NULL, NULL, opts.Lens, opts.fuzzySearch);
PrintLenses (lenses, ldb, opts.maxResults);
lf_free (lenses);
}
ldb->Destroy ();
return 0;
}
lfCamera
Camera data.
Definition: lensfun.h:273
lfCamera::Maker
lfMLstr Maker
Camera maker (ex: "Rollei") – same as in EXIF.
Definition: lensfun.h:275
lfCamera::Model
lfMLstr Model
Model name (ex: "Rolleiflex SL35") – same as in EXIF.
Definition: lensfun.h:277
lfMount::Compat
char ** Compat
A list of compatible mounts.
Definition: lensfun.h:171
LF_SEARCH_LOOSE
@ LF_SEARCH_LOOSE
This flag selects a looser search algorithm resulting in more results (still sorted by score).
Definition: lensfun.h:1129
lfLens::CenterY
float CenterY
The vertical shift of all lens distortions.
Definition: lensfun.h:696
lfLens::Maker
lfMLstr Maker
Lens maker (ex: "Rollei")
Definition: lensfun.h:672
lfError
lfError
liblensdb error codes: negative codes are -errno, positive are here
Definition: lensfun.h:94
lfCamera::Variant
lfMLstr Variant
Camera variant.
Definition: lensfun.h:279
lfCamera::CropFactor
float CropFactor
Camera crop factor (ex: 1.0).
Definition: lensfun.h:283
LF_NO_ERROR
@ LF_NO_ERROR
No error occured.
Definition: lensfun.h:96
lfDatabase::FindLenses
const lfLens ** FindLenses(const lfCamera *camera, const char *maker, const char *model, int sflags=0) const
Parse a human-friendly lens description (ex: "smc PENTAX-F 35-105mm F4-5.6" or "SIGMA AF 28-300 F3....
lfLens::MinFocal
float MinFocal
Minimum focal length, mm (ex: 35).
Definition: lensfun.h:676
lfCamera::Mount
char * Mount
Camera mount type (ex: "QBM")
Definition: lensfun.h:281
lfLens::GreenCCI
float GreenCCI
Green component of lens CCI.
Definition: lensfun.h:700
lfLens::CropFactor
float CropFactor
Crop factor at which calibration measurements were taken.
Definition: lensfun.h:704
lfMount::Name
lfMLstr Name
Camera mount name.
Definition: lensfun.h:169
lfLens::Mounts
char ** Mounts
Available mounts (NULL-terminated list) (ex: { "QBM", NULL })
Definition: lensfun.h:684
lf_db_mount_name
const char * lf_db_mount_name(const lfDatabase *db, const char *mount)
lensfun.h
lf_mlstr_get
const char * lf_mlstr_get(const lfMLstr str)
Get a string corresponding to current locale from a multi-language string.
lfLens::MaxFocal
float MaxFocal
Maximum focal length, mm (ex: 105).
Definition: lensfun.h:678
LF_VERSION_MICRO
#define LF_VERSION_MICRO
Library micro version number.
Definition: lensfun.h:52
lfDatabase::Load
lfError Load()
Load the whole lens database.
lfMount
This structure contains everything specific to a camera mount.
Definition: lensfun.h:167
lfDatabase::FindCameras
const lfCamera ** FindCameras(const char *maker, const char *model) const
Find a set of cameras that fit given criteria.
LF_VERSION_MAJOR
#define LF_VERSION_MAJOR
Major library version number.
Definition: lensfun.h:48
lfLens::MinAperture
float MinAperture
Aperture at minimum focal length (ex: 3.5).
Definition: lensfun.h:680
lfDatabase::Destroy
void Destroy()
Destroy the database object and free all loaded data.
lfLens::MaxAperture
float MaxAperture
Aperture at maximum focal length (ex: 4.3).
Definition: lensfun.h:682
lf_db_new
lfDatabase * lf_db_new(void)
Create a new empty database object.
lfLens::Model
lfMLstr Model
Lens model (ex: "Zoom-Rolleinar")
Definition: lensfun.h:674
lfDatabase
A lens database object.
Definition: lensfun.h:1155
lfLens::RedCCI
float RedCCI
Lens colour contribution index (ISO/CCI, ISO 6728:1983).
Definition: lensfun.h:698
lfDatabase::FindMount
const lfMount * FindMount(const char *mount) const
Return the lfMount structure given the (basic) mount name.
lfDatabase::Save
lfError Save(const char *filename) const
Save the whole database to a file.
lfLens
Lens data.
Definition: lensfun.h:670
lfLens::CenterX
float CenterX
The horizontal shift of all lens distortions.
Definition: lensfun.h:694
lf_free
void lf_free(void *data)
The basics of memory allocation: never free objects allocated by the library yourselves,...
LF_VERSION_MINOR
#define LF_VERSION_MINOR
Minor library version number.
Definition: lensfun.h:50
lfLens::BlueCCI
float BlueCCI
Blue component of lens CCI.
Definition: lensfun.h:702