|
LensSerious 0.1
Lens-correction mathematics as data, not as a library of callbacks
|
#include "lensserious.h"#include "lensserious_import.h"#include "lensserious_db.h"#include <lensfun.h>#include <sqlite3.h>#include <dirent.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>
Include dependency graph for lensserious_import.c:Go to the source code of this file.
Data Structures | |
| struct | name_ctx_t |
Functions | |
| static void | die (const char *what, sqlite3 *db) |
| static void | exec_or_die (sqlite3 *db, const char *sql) |
| static sqlite3_stmt * | prep (sqlite3 *db, const char *sql) |
| static void | step_reset (sqlite3 *db, sqlite3_stmt *st) |
| static void | for_each_mlstr (const lfMLstr s, void(*fn)(const char *lang, const char *value, void *ud), void *ud) |
| Walk an lfMLstr: the default string, then (lang, translation) pairs. | |
| static void | insert_name (const char *lang, const char *value, void *ud) |
| static int | dist_model (enum lfDistortionModel m) |
| static int | tca_model (enum lfTCAModel m) |
| static int | lens_type (enum lfLensType t) |
| static long long | mount_id_for (sqlite3 *db, sqlite3_stmt *sel, sqlite3_stmt *ins, const char *name) |
| static char * | read_file (const char *path) |
| static int | _load_directory (lfDatabase *ldb, const char *dirname) |
Load every XML file in a directory into ldb. | |
| int | ls_import_run (const char *schema_path, const char *out_path, const char *base_xml_dir, const char *xml_dir) |
| Read a lensfun database and write it as a LensSerious SQLite file. | |
Variables | |
| static const char * | SCHEMA_PATH_HINT = "src/schema.sql" |
|
static |
Load every XML file in a directory into ldb.
lf_db_load_directory() does exactly this and is the obvious call, but it only arrived in liblensfun 0.3.3. Ubuntu 22.04 – which is what this project's consumers build their nightlies on – still ships 0.3.2, where the symbol does not exist and the link fails outright. So the directory walk is written out for that case.
The two loaders also report success in OPPOSITE conventions, which is worth being explicit about: lf_db_load() returns an lfError, where 0 means success, while lf_db_load_directory() and lf_db_load_file() return a cbool/lfError pair that do not agree with each other. Treating them alike made the directory path fail on a directory it had just read correctly – a path nothing exercised until a consumer started importing from fetched XML rather than from the installed database. This function returns one convention: non-zero for success.
Definition at line 264 of file lensserious_import.c.
Referenced by ls_import_run().
|
static |
Definition at line 67 of file lensserious_import.c.
Referenced by ls_import_run(), prep(), and step_reset().
|
static |
Definition at line 174 of file lensserious_import.c.
References LS_DIST_NONE, LS_DIST_POLY3, LS_DIST_POLY5, and LS_DIST_PTLENS.
Referenced by ls_import_run().
|
static |
Definition at line 74 of file lensserious_import.c.
Referenced by ls_import_run().
|
static |
Walk an lfMLstr: the default string, then (lang, translation) pairs.
Definition at line 102 of file lensserious_import.c.
Referenced by ls_import_run().
|
static |
Definition at line 130 of file lensserious_import.c.
References name_ctx_t::db, name_ctx_t::kind, ls_db_normalize(), ls_db_token_digest(), ls_db_tokenize(), name_ctx_t::owner_id, name_ctx_t::st, step_reset(), and name_ctx_t::tok.
Referenced by ls_import_run().
|
static |
Definition at line 195 of file lensserious_import.c.
References LS_LENS_EQUIRECTANGULAR, LS_LENS_FISHEYE, LS_LENS_FISHEYE_EQUISOLID, LS_LENS_FISHEYE_ORTHOGRAPHIC, LS_LENS_FISHEYE_STEREOGRAPHIC, LS_LENS_FISHEYE_THOBY, LS_LENS_PANORAMIC, LS_LENS_RECTILINEAR, and LS_LENS_UNKNOWN.
Referenced by ls_import_run().
| int ls_import_run | ( | const char * | schema_path, |
| const char * | out_path, | ||
| const char * | base_xml_dir, | ||
| const char * | xml_dir ) |
Read a lensfun database and write it as a LensSerious SQLite file.
| schema_path | the SQL schema to create the file from (src/schema.sql). |
| out_path | where to write. The file is written to a temporary and RENAMED into place, so a reader opening it with immutable=1 never sees a partial database and a killed run cannot leave one that looks complete. See lensserious_db.h. |
| base_xml_dir | a directory of lensfun XML to load FIRST, or NULL. Everything loaded afterwards can override a lens defined here, and a lens nobody else defines survives – lensfun's own "later definitions override earlier" rule, applied by lensfun. |
This is what makes an update additive rather than a replacement. A consumer that ships a database passes its own calibrations here and the machine's profiles are merged over the top; without it, a machine with no system-wide lensfun yields a database holding only the few profiles its user wrote by hand, which is a catastrophic thing to install in place of fifteen hundred lenses.
| xml_dir | a directory of lensfun XML to read, or NULL. |
NULL is the interesting value, and is what a consumer's updater wants: it calls lensfun's own lf_db_load(), which searches all four standard locations – the system database, the system updates directory, the user's updates directory, and the user's own ~/.local/share/lensfun. That last one is where hand-written profiles live, and the aggregation and override rules between the four are lensfun's, not this project's approximation of them. Passing a directory instead reads exactly that directory, which is what a reproducible package build wants, since a build machine has no user profiles.
Definition at line 291 of file lensserious_import.c.
References _load_directory(), die(), dist_model(), exec_or_die(), for_each_mlstr(), insert_name(), name_ctx_t::kind, lens_type(), LS_VIG_PA, mount_id_for(), prep(), read_file(), SCHEMA_PATH_HINT, step_reset(), and tca_model().
Referenced by main().
|
static |
Definition at line 213 of file lensserious_import.c.
References step_reset().
Referenced by ls_import_run().
|
static |
Definition at line 85 of file lensserious_import.c.
References die().
Referenced by ls_import_run().
|
static |
Definition at line 230 of file lensserious_import.c.
Referenced by ls_import_run().
|
static |
Definition at line 92 of file lensserious_import.c.
References die().
Referenced by insert_name(), ls_import_run(), and mount_id_for().
|
static |
Definition at line 185 of file lensserious_import.c.
References LS_TCA_LINEAR, LS_TCA_NONE, and LS_TCA_POLY3.
Referenced by ls_import_run().
|
static |
Definition at line 63 of file lensserious_import.c.
Referenced by ls_import_run().