This example shows how to do basic database lookups.
#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)
{
for (
int j = 0; mount->
Compat [j]; j++)
g_print (
"\tCompat: %s\n", mount->
Compat [j]);
}
{
g_print ("Camera: %s / %s %s%s%s\n",
g_print (
"\tCrop factor: %g\n", camera->
CropFactor);
}
{
g_print ("Lens: %s / %s\n",
g_print (
"\tCrop factor: %g\n", lens->
CropFactor);
for (
int j = 0; lens->
Mounts [j]; 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':
break;
case 'h':
DisplayUsage();
return 0;
case 'V':
DisplayVersion ();
return 0;
default:
return -1;
}
}
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);
ldb->Destroy ();
return 0;
}
#define LF_VERSION_MICRO
Library micro version number.
Definition: lensfun.h:68
#define LF_VERSION_MAJOR
Major library version number.
Definition: lensfun.h:64
const char * lf_mlstr_get(const lfMLstr str)
Get a string corresponding to current locale from a multi-language string.
#define LF_VERSION_MINOR
Minor library version number.
Definition: lensfun.h:66
const char * lf_db_mount_name(const lfDatabase *db, const char *mount)
@ LF_SEARCH_LOOSE
This flag selects a looser search algorithm resulting in more results (still sorted by score).
Definition: lensfun.h:1507
Camera data. Unknown fields are set to NULL.
Definition: lensfun.h:355
lfMLstr Model
Model name (ex: "Rolleiflex SL35") – same as in EXIF.
Definition: lensfun.h:359
lfMLstr Variant
Camera variant. Some cameras use same EXIF id for different models.
Definition: lensfun.h:361
lfMLstr Maker
Camera maker (ex: "Rollei") – same as in EXIF.
Definition: lensfun.h:357
char * Mount
Camera mount type (ex: "QBM")
Definition: lensfun.h:363
float CropFactor
Camera crop factor (ex: 1.0). Must be defined.
Definition: lensfun.h:365
A lens database object.
Definition: lensfun.h:1536
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....
lfError Load()
Find and load the lens database.
Lens data. Unknown fields are set to NULL or 0.
Definition: lensfun.h:1011
lfMLstr Model
Definition: lensfun.h:1015
DEPRECATED float AspectRatio
Definition: lensfun.h:1043
lfMLstr Maker
Definition: lensfun.h:1013
float CenterY
Definition: lensfun.h:1039
DEPRECATED float CropFactor
Definition: lensfun.h:1041
DEPRECATED char ** Mounts
Definition: lensfun.h:1025
float MinFocal
Definition: lensfun.h:1017
float MaxFocal
Definition: lensfun.h:1019
float MinAperture
Definition: lensfun.h:1021
float MaxAperture
Definition: lensfun.h:1023
float CenterX
Definition: lensfun.h:1037
This structure contains everything specific to a camera mount.
Definition: lensfun.h:219
DEPRECATED char ** Compat
Definition: lensfun.h:227
lfMLstr Name
Camera mount name.
Definition: lensfun.h:225