LensSerious 0.1
Lens-correction mathematics as data, not as a library of callbacks
Loading...
Searching...
No Matches
lensserious.h
Go to the documentation of this file.
1/*
2 LensSerious — lens-correction mathematics as data, not as a library of callbacks.
3
4 Copyright (C) 2026 Aurélien PIERRE.
5 Model evaluators, coordinate conventions and interpolation semantics ported from
6 Lensfun 0.3.4 (libs/lensfun/{modifier,mod-coord,mod-subpix,mod-color,lens,auxfun}.cpp),
7 Copyright (C) 2007 Andrew Zabolotny and the Lensfun contributors.
8
9 This library is free software: you can redistribute it and/or modify it under the
10 terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation, either version 3 of the License, or (at your option) any later version.
12
13 It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the GNU Lesser General Public License for more details.
16*/
17
49#ifndef LENSSERIOUS_H
50#define LENSSERIOUS_H
51
52#include <stddef.h>
53
54/* The closed forms themselves, shared verbatim with opencl/lensserious.cl. */
55#include "lensserious_eval.h"
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
69
76
83
85typedef struct ls_calib_dist_t { ls_dist_model_t model; float focal; float terms[3]; } ls_calib_dist_t;
86typedef struct ls_calib_tca_t { ls_tca_model_t model; float focal; float terms[6]; } ls_calib_tca_t;
91
92enum { LS_MAX_CALIB = 512 }; /* the densest lens in the 2026 database has ~300 vignetting points */
93
106
130
131#define LS_ENABLE_DISTORTION (1 << 0)
132#define LS_ENABLE_TCA (1 << 1)
133#define LS_ENABLE_VIGNETTING (1 << 2)
134#define LS_ENABLE_SCALE (1 << 3)
135#define LS_ENABLE_GEOMETRY (1 << 4)
136
182
190typedef struct ls_modifier_t
191{
192 /* Coordinate system — ported from lfModifier::lfModifier() (modifier.cpp).
193 * norm_scale converts centred pixel coordinates to the calibration sensor's
194 * normalized system; centre includes the lens's optical-centre shift. */
196 float aspect_ratio_correction; /* vignetting works in the half-diagonal system */
197 float center_x, center_y; /* in normalized coordinates */
198 float width, height; /* the (dimension − 1) values, lensfun's own convention */
199
200 int enabled; /* LS_ENABLE_* actually resolved (calibration present) */
201 int reverse; /* non-zero for the reverse direction (lensfun's `reverse`) */
202 /* Set when the requested projection change cannot be expressed radially -- panoramic or
203 * equirectangular on either side. Those two map x and y differently; everything else
204 * (rectilinear, the four fisheyes, thoby) goes through ls_eval_geometry(). */
206
207 float scale; /* linear scaling factor, applied first (priority 100) */
208 int geom_from, geom_to; /* projection change, ls_lens_type_t (priority 500) */
209 float geom_focal; /* focal / 12mm, the normalized-radius reference */
210 ls_calib_dist_t dist; /* resolved (interpolated) at the shooting focal */
213
214 /* The alternative to the three above: a maker's own measured table, already turned to
215 * face the requested direction. Filled by ls_modifier_init_knots(), left zeroed by
216 * ls_modifier_init(), and never both.
217 *
218 * Shaped the way ls_eval_t holds it rather than the way ls_knots_t states it, because
219 * turning it round is what this struct is for and doing it twice is how the two would
220 * drift. The radii are per channel HERE and shared THERE: inverting sends each channel to
221 * its own set of radii, so only the direction that needs them can carry them. */
230
253int ls_modifier_init(ls_modifier_t *mod, const ls_lens_t *lens,
254 float crop, int width, int height,
255 float focal, float aperture, float distance,
256 float scale, int target_type, int flags, int reverse);
257
317int ls_modifier_init_knots(ls_modifier_t *mod, const ls_knots_t *knots,
318 int width, int height, float scale, int flags, int reverse);
319
344float ls_modifier_autoscale(const ls_modifier_t *mod);
345
383int ls_modifier_set_projection(ls_modifier_t *mod, int from_type, int to_type,
384 float focal_mm, float crop_factor);
385
398int ls_eval_from_modifier(const ls_modifier_t *mod, ls_eval_t *out);
399
421int ls_eval_adopt_vignetting(ls_eval_t *dst, const ls_eval_t *src);
422
430 float xu, float yu, int width, int height,
431 float *res);
432
438 float xu, float yu, int width, int height,
439 float *rgba, int row_stride_bytes);
440
441#ifdef __cplusplus
442}
443#endif
444
445#endif /* LENSSERIOUS_H */
@ LS_MAX_CALIB
Definition lensserious.h:92
int ls_eval_from_modifier(const ls_modifier_t *mod, ls_eval_t *out)
Flatten a resolved modifier into the scalar block a kernel can take by value.
float ls_modifier_autoscale(const ls_modifier_t *mod)
The scale that just removes the black borders a correction leaves behind.
struct ls_calib_real_focal_t ls_calib_real_focal_t
struct ls_modifier_t ls_modifier_t
A modifier: the lens resolved at one shooting configuration.
ls_tca_model_t
Definition lensserious.h:71
@ LS_TCA_LINEAR
Definition lensserious.h:73
@ LS_TCA_POLY3
Definition lensserious.h:74
@ LS_TCA_NONE
Definition lensserious.h:72
int ls_modifier_init_knots(ls_modifier_t *mod, const ls_knots_t *knots, int width, int height, float scale, int flags, int reverse)
Resolve a maker's embedded profile, in place of a database lens.
int ls_modifier_apply_vignetting(const ls_modifier_t *mod, float xu, float yu, int width, int height, float *rgba, int row_stride_bytes)
pa vignetting, multiplied in place over RGBA float rows. Contract of lfModifier::ApplyColorModificati...
struct ls_knots_t ls_knots_t
A lens correction the camera maker measured and wrote into the file, as knots.
struct ls_lens_t ls_lens_t
struct ls_calib_tca_t ls_calib_tca_t
ls_vig_model_t
Definition lensserious.h:78
@ LS_VIG_NONE
Definition lensserious.h:79
@ LS_VIG_PA
Definition lensserious.h:80
@ LS_VIG_KNOTS
Definition lensserious.h:81
int ls_modifier_set_projection(ls_modifier_t *mod, int from_type, int to_type, float focal_mm, float crop_factor)
Add a projection change to an already-resolved modifier.
ls_lens_type_t
Definition lensserious.h:95
@ LS_LENS_FISHEYE
Definition lensserious.h:98
@ LS_LENS_RECTILINEAR
Definition lensserious.h:97
@ LS_LENS_EQUIRECTANGULAR
@ LS_LENS_FISHEYE_ORTHOGRAPHIC
@ LS_LENS_UNKNOWN
Definition lensserious.h:96
@ LS_LENS_FISHEYE_EQUISOLID
@ LS_LENS_FISHEYE_STEREOGRAPHIC
@ LS_LENS_FISHEYE_THOBY
@ LS_LENS_PANORAMIC
Definition lensserious.h:99
int ls_modifier_init(ls_modifier_t *mod, const ls_lens_t *lens, float crop, int width, int height, float focal, float aperture, float distance, float scale, int target_type, int flags, int reverse)
Resolve a lens at one (crop, geometry, focal, aperture, distance, scale).
int ls_modifier_apply_subpixel_geometry(const ls_modifier_t *mod, float xu, float yu, int width, int height, float *res)
The geometry map: for count output pixels starting at (xu, yu), write 6 floats per pixel — source coo...
struct ls_calib_vig_t ls_calib_vig_t
struct ls_calib_dist_t ls_calib_dist_t
ls_dist_model_t
Definition lensserious.h:62
@ LS_DIST_NONE
Definition lensserious.h:63
@ LS_DIST_PTLENS
Definition lensserious.h:66
@ LS_DIST_POLY5
Definition lensserious.h:65
@ LS_DIST_KNOTS
Definition lensserious.h:67
@ LS_DIST_POLY3
Definition lensserious.h:64
int ls_eval_adopt_vignetting(ls_eval_t *dst, const ls_eval_t *src)
Move src's vignetting into dst, leaving dst's geometry untouched.
The closed forms, written once, compiled as C99 and as OpenCL C.
#define LS_MAX_KNOTS
ls_dist_model_t model
Definition lensserious.h:85
ls_tca_model_t model
Definition lensserious.h:86
float terms[6]
Definition lensserious.h:86
ls_vig_model_t model
Definition lensserious.h:87
float terms[3]
Definition lensserious.h:87
One lens resolved at one shooting configuration, as a flat block of scalars.
A lens correction the camera maker measured and wrote into the file, as knots.
float cor_rgb[3][16]
float vig_radius[16]
float vig[16]
float radius[16]
float crop_factor
ls_lens_type_t type
ls_calib_vig_t vig[LS_MAX_CALIB]
float center_x
ls_calib_real_focal_t real_focal[LS_MAX_CALIB]
ls_calib_tca_t tca[LS_MAX_CALIB]
float min_focal
float center_y
ls_calib_dist_t dist[LS_MAX_CALIB]
float aspect_ratio
float max_focal
int n_real_focal
A modifier: the lens resolved at one shooting configuration.
float knot_c[3][16]
ls_calib_tca_t tca
float knot_vr[16]
ls_calib_dist_t dist
float knot_v[16]
ls_calib_vig_t vig
float knot_r[3][16]
int geometry_unsupported
float aspect_ratio_correction