lensfun: example.c

lensfun 0.3.4.0

example.c

Sample program demonstrating basic usage of C API.

/*
A simple example of library usage from plain C
*/
#include "lensfun.h"
#include <stdio.h>
#include <locale.h>
#include <glib.h>
int main ()
{
int i, j;
const struct lfMount *const *mounts;
const struct lfCamera *const *cameras;
const struct lfLens *const *lenses;
struct lfDatabase *ldb;
lfError e;
/* Initialize locale in order to get translated names */
setlocale (LC_ALL, "");
ldb = lf_db_new ();
if (!ldb)
{
fprintf (stderr, "Failed to create database\n");
return -1;
}
g_print ("HomeDataDir: %s\n", ldb->HomeDataDir);
lf_db_load (ldb);
g_print ("< --------------- < Mounts > --------------- >\n");
mounts = lf_db_get_mounts (ldb);
for (i = 0; mounts [i]; i++)
{
g_print ("Mount: %s\n", lf_mlstr_get (mounts [i]->Name));
if (mounts [i]->Compat)
for (j = 0; mounts [i]->Compat [j]; j++)
g_print ("\tCompat: %s\n", mounts [i]->Compat [j]);
}
g_print ("< --------------- < Cameras > --------------- >\n");
cameras = lf_db_get_cameras (ldb);
for (i = 0; cameras [i]; i++)
{
g_print ("Camera: %s / %s %s%s%s\n",
lf_mlstr_get (cameras [i]->Maker),
lf_mlstr_get (cameras [i]->Model),
cameras [i]->Variant ? "(" : "",
cameras [i]->Variant ? lf_mlstr_get (cameras [i]->Variant) : "",
cameras [i]->Variant ? ")" : "");
g_print ("\tMount: %s\n", lf_db_mount_name (ldb, cameras [i]->Mount));
g_print ("\tCrop factor: %g\n", cameras [i]->CropFactor);
}
g_print ("< --------------- < Lenses > --------------- >\n");
lenses = lf_db_get_lenses (ldb);
for (i = 0; lenses [i]; i++)
{
g_print ("Lens: %s / %s\n",
lf_mlstr_get (lenses [i]->Maker),
lf_mlstr_get (lenses [i]->Model));
g_print ("\tCrop factor: %g\n", lenses [i]->CropFactor);
g_print ("\tAspect ratio: %g\n", lenses [i]->AspectRatio);
g_print ("\tFocal: %g-%g\n", lenses [i]->MinFocal, lenses [i]->MaxFocal);
g_print ("\tAperture: %g-%g\n", lenses [i]->MinAperture, lenses [i]->MaxAperture);
g_print ("\tCenter: %g,%g\n", lenses [i]->CenterX, lenses [i]->CenterY);
if (lenses [i]->Mounts)
for (j = 0; lenses [i]->Mounts [j]; j++)
g_print ("\tMount: %s\n", lf_db_mount_name (ldb, lenses [i]->Mounts [j]));
}
g_print ("< ---< Saving database into one big file >--- >\n");
e = lf_db_save_file (ldb, "example-big.xml", mounts, cameras, lenses);
if (e != LF_NO_ERROR)
fprintf (stderr, "Failed writing to file, error code %d\n", e);
lf_db_destroy (ldb);
return 0;
}
lf_mlstr_get
const char * lf_mlstr_get(const lfMLstr str)
Get a string corresponding to current locale from a multi-language string.
lfError
lfError
Definition lensfun.h:114
LF_NO_ERROR
@ LF_NO_ERROR
Definition lensfun.h:116
lf_db_mount_name
const char * lf_db_mount_name(const lfDatabase *db, const char *mount)
lf_db_load
lfError lf_db_load(lfDatabase *db)
lf_db_get_mounts
const lfMount *const * lf_db_get_mounts(const lfDatabase *db)
lf_db_get_cameras
const lfCamera *const * lf_db_get_cameras(const lfDatabase *db)
lf_db_save_file
lfError lf_db_save_file(const lfDatabase *db, const char *filename, const lfMount *const *mounts, const lfCamera *const *cameras, const lfLens *const *lenses)
lf_db_new
lfDatabase * lf_db_new(void)
Create a new empty database object.
lf_db_get_lenses
const lfLens *const * lf_db_get_lenses(const lfDatabase *db)
lf_db_destroy
void lf_db_destroy(lfDatabase *db)
Destroy the database object.
lensfun.h
lfCamera
Camera data. Unknown fields are set to NULL.
Definition lensfun.h:321
lfCamera::Variant
lfMLstr Variant
Camera variant. Some cameras use same EXIF id for different models.
Definition lensfun.h:327
lfDatabase
A lens database object.
Definition lensfun.h:1362
lfDatabase::HomeDataDir
char * HomeDataDir
Home lens database directory (something like "~/.local/share/lensfun")
Definition lensfun.h:1364
lfLens
Lens data. Unknown fields are set to NULL or 0.
Definition lensfun.h:802
lfLens::Mounts
char ** Mounts
Definition lensfun.h:816
lfMount
This structure contains everything specific to a camera mount.
Definition lensfun.h:204
lfMount::Compat
char ** Compat
Definition lensfun.h:212