lensfun 0.3.1.0

- Main Page
- Related Pages
- Modules
- Classes
- Files
- Examples

- File List
- File Members

lensfun.h
Go to the documentation of this file.
1 /* -*- mode:c++ -*- */
2 /*
3 LensFun - a library for maintaining a database of photographical lenses,
4 and providing the means to correct some of the typical lens distortions.
5 Copyright (C) 2007 by Andrew Zabolotny
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public
18 License along with this library; if not, write to the Free
19 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef __LENSFUN_H__
23 #define __LENSFUN_H__
24
25 #include <stddef.h>
26
27 #ifdef __cplusplus
28 extern "C" {
30 # define C_TYPEDEF(t,c)
31 #else
32 # define C_TYPEDEF(t,c) typedef t c c;
33 #endif
34
40 /*----------------------------------------------------------------------------*/
41
48 #define LF_VERSION_MAJOR 0
50 #define LF_VERSION_MINOR 3
52 #define LF_VERSION_MICRO 1
54 #define LF_VERSION_BUGFIX 0
56 #define LF_VERSION ((LF_VERSION_MAJOR << 24) | (LF_VERSION_MINOR << 16) | (LF_VERSION_MICRO << 8) | LF_VERSION_BUGFIX)
58
60 #define LF_MAX_DATABASE_VERSION 1
61
62 #if defined CONF_LENSFUN_STATIC
63 # define LF_EXPORT
65 #else
66 # ifdef CONF_SYMBOL_VISIBILITY
67 # if defined PLATFORM_WINDOWS
68 # define LF_EXPORT __declspec(dllexport)
69 # elif defined CONF_COMPILER_GCC || __clang__
70 # define LF_EXPORT __attribute__((visibility("default")))
71 # else
72 # error "I don't know how to change symbol visibility for your compiler"
73 # endif
74 # else
75 # if defined PLATFORM_WINDOWS || defined _MSC_VER
76 # define LF_EXPORT __declspec(dllimport)
77 # else
78 # define LF_EXPORT
79 # endif
80 # endif
81 #endif
82
83 #ifndef CONF_LENSFUN_INTERNAL
84 # ifdef __GNUC__
86 # define DEPRECATED __attribute__((deprecated))
87 # elif defined(_MSC_VER)
88 # define DEPRECATED __declspec(deprecated)
89 # else
90 # pragma message("WARNING: You need to implement DEPRECATED for this compiler")
91 # define DEPRECATED
92 # endif
93 #else
94 # define DEPRECATED
95 #endif
96
98 #define cbool int
99
108 typedef char *lfMLstr;
109
111 enum lfError
112 {
114 LF_NO_ERROR = 0,
116 LF_WRONG_FORMAT
117 };
118
119 C_TYPEDEF (enum, lfError)
120
121
129 LF_EXPORT void lf_free (void *data);
130
139 LF_EXPORT const char *lf_mlstr_get (const lfMLstr str);
140
157 LF_EXPORT lfMLstr lf_mlstr_add (lfMLstr str, const char *lang, const char *trstr);
158
167 LF_EXPORT lfMLstr lf_mlstr_dup (const lfMLstr str);
168
171 /*----------------------------------------------------------------------------*/
172
188 struct LF_EXPORT lfMount
189 {
195 lfMLstr Name;
197 char **Compat;
198
199 #ifdef __cplusplus
200
203 lfMount ();
204
208 lfMount &operator = (const lfMount &other);
209
213 ~lfMount ();
214
225 void SetName (const char *val, const char *lang = NULL);
226
232 void AddCompat (const char *val);
233
239 bool Check ();
240 #endif
241 };
242
243 C_TYPEDEF (struct, lfMount)
244
245
252 LF_EXPORT lfMount *lf_mount_new ();
253
263 LF_EXPORT void lf_mount_destroy (lfMount *mount);
264
274 LF_EXPORT void lf_mount_copy (lfMount *dest, const lfMount *source);
275
277 LF_EXPORT cbool lf_mount_check (lfMount *mount);
278
281 /*----------------------------------------------------------------------------*/
282
300 struct LF_EXPORT lfCamera
301 {
303 lfMLstr Maker;
305 lfMLstr Model;
307 lfMLstr Variant;
309 char *Mount;
311 float CropFactor;
313 int Score;
314
315 #ifdef __cplusplus
316
319 lfCamera ();
320
324 lfCamera (const lfCamera &other);
325
329 ~lfCamera ();
330
334 lfCamera &operator = (const lfCamera &other);
335
346 void SetMaker (const char *val, const char *lang = NULL);
347
358 void SetModel (const char *val, const char *lang = NULL);
359
370 void SetVariant (const char *val, const char *lang = NULL);
371
377 void SetMount (const char *val);
378
384 bool Check ();
385 #endif
386 };
387
388 C_TYPEDEF (struct, lfCamera)
389
390
397 LF_EXPORT lfCamera *lf_camera_new ();
398
408 LF_EXPORT void lf_camera_destroy (lfCamera *camera);
409
419 LF_EXPORT void lf_camera_copy (lfCamera *dest, const lfCamera *source);
420
422 LF_EXPORT cbool lf_camera_check (lfCamera *camera);
423
426 /*----------------------------------------------------------------------------*/
427
448 enum lfDistortionModel
449 {
451 LF_DIST_MODEL_NONE,
459 LF_DIST_MODEL_POLY3,
468 LF_DIST_MODEL_POLY5,
476 LF_DIST_MODEL_PTLENS,
477 };
478
479 C_TYPEDEF (enum, lfDistortionModel)
480
481
487 struct lfLensCalibDistortion
488 {
490 enum lfDistortionModel Model;
492 float Focal;
494 float Terms [3];
495 };
496
497 C_TYPEDEF (struct, lfLensCalibDistortion)
498
499
512 enum lfTCAModel
513 {
515 LF_TCA_MODEL_NONE,
527 LF_TCA_MODEL_LINEAR,
528
540 LF_TCA_MODEL_POLY3
541 };
542
543 C_TYPEDEF (enum, lfTCAModel)
544
545
552 struct lfLensCalibTCA
553 {
555 enum lfTCAModel Model;
557 float Focal;
559 float Terms [6];
560 };
561
562 C_TYPEDEF (struct, lfLensCalibTCA)
563
564
580 enum lfVignettingModel
581 {
583 LF_VIGNETTING_MODEL_NONE,
593 LF_VIGNETTING_MODEL_PA
594 };
595
596 C_TYPEDEF (enum, lfVignettingModel)
597
598
605 struct lfLensCalibVignetting
606 {
608 enum lfVignettingModel Model;
610 float Focal;
612 float Aperture;
614 float Distance;
616 float Terms [3];
617 };
618
619 C_TYPEDEF (struct, lfLensCalibVignetting)
620
621
624 enum lfCropMode
625 {
627 LF_NO_CROP,
629 LF_CROP_RECTANGLE,
631 LF_CROP_CIRCLE
632 };
633
634 C_TYPEDEF(enum, lfCropMode)
635
636
639 struct lfLensCalibCrop
640 {
642 float Focal;
644 enum lfCropMode CropMode;
653 float Crop [4];
654 };
655
656 C_TYPEDEF (struct, lfLensCalibCrop)
657
658
665 struct lfLensCalibFov
666 {
668 float Focal;
678 float FieldOfView;
679 };
680
681 C_TYPEDEF (struct, lfLensCalibFov)
682
683
687 struct lfLensCalibRealFocal
688 {
690 float Focal;
702 float RealFocal;
703 };
704
705 C_TYPEDEF (struct, lfLensCalibRealFocal)
706
707
710 struct lfParameter
711 {
713 const char *Name;
715 float Min;
717 float Max;
719 float Default;
720 };
721
722 C_TYPEDEF (struct, lfParameter)
723
724
727 enum lfLensType
728 {
730 LF_UNKNOWN,
735 LF_RECTILINEAR,
741 LF_FISHEYE,
748 LF_PANORAMIC,
755 LF_EQUIRECTANGULAR,
757 LF_FISHEYE_ORTHOGRAPHIC,
759 LF_FISHEYE_STEREOGRAPHIC,
761 LF_FISHEYE_EQUISOLID,
767 LF_FISHEYE_THOBY
768 };
769
770 C_TYPEDEF (enum, lfLensType)
771
772
782 struct LF_EXPORT lfLens
783 {
785 lfMLstr Maker;
787 lfMLstr Model;
789 float MinFocal;
791 float MaxFocal;
793 float MinAperture;
795 float MaxAperture;
797 char **Mounts;
807 float CenterX;
809 float CenterY;
811 float CropFactor;
813 float AspectRatio;
815 lfLensType Type;
817 lfLensCalibDistortion **CalibDistortion;
819 lfLensCalibTCA **CalibTCA;
821 lfLensCalibVignetting **CalibVignetting;
823 lfLensCalibCrop **CalibCrop;
825 lfLensCalibFov **CalibFov;
827 lfLensCalibRealFocal **CalibRealFocal;
829 int Score;
830
831 #ifdef __cplusplus
832
835 lfLens ();
836
840 lfLens (const lfLens &other);
841
845 ~lfLens ();
846
850 lfLens &operator = (const lfLens &other);
851
862 void SetMaker (const char *val, const char *lang = NULL);
863
874 void SetModel (const char *val, const char *lang = NULL);
875
883 void AddMount (const char *val);
884
893 void AddCalibDistortion (const lfLensCalibDistortion *dc);
894
900 bool RemoveCalibDistortion (int idx);
901
911 void AddCalibTCA (const lfLensCalibTCA *tcac);
912
918 bool RemoveCalibTCA (int idx);
919
928 void AddCalibVignetting (const lfLensCalibVignetting *vc);
929
935 bool RemoveCalibVignetting (int idx);
936
945 void AddCalibCrop (const lfLensCalibCrop *cc);
946
952 bool RemoveCalibCrop (int idx);
953
965 DEPRECATED void AddCalibFov (const lfLensCalibFov *cf);
966
976 DEPRECATED bool RemoveCalibFov (int idx);
977
986 void AddCalibRealFocal (const lfLensCalibRealFocal *cf);
987
994 bool RemoveCalibRealFocal (int idx);
995
1004 void GuessParameters ();
1005
1011 bool Check ();
1012
1028 static const char *GetDistortionModelDesc (
1029 lfDistortionModel model, const char **details, const lfParameter ***params);
1045 static const char *GetTCAModelDesc (
1046 lfTCAModel model, const char **details, const lfParameter ***params);
1047
1063 static const char *GetVignettingModelDesc (
1064 lfVignettingModel model, const char **details, const lfParameter ***params);
1065
1081 static const char *GetCropDesc (
1082 lfCropMode mode, const char **details, const lfParameter ***params);
1083
1095 static const char *GetLensTypeDesc (lfLensType type, const char **details);
1096
1104 bool InterpolateDistortion (float focal, lfLensCalibDistortion &res) const;
1105
1113 bool InterpolateTCA (float focal, lfLensCalibTCA &res) const;
1114
1128 bool InterpolateVignetting (
1129 float focal, float aperture, float distance, lfLensCalibVignetting &res) const;
1130
1138 bool InterpolateCrop (float focal, lfLensCalibCrop &res) const;
1139
1151 DEPRECATED bool InterpolateFov (float focal, lfLensCalibFov &res) const;
1152
1164 bool InterpolateRealFocal (float focal, lfLensCalibRealFocal &res) const;
1165 #endif
1166 };
1167
1168 C_TYPEDEF (struct, lfLens)
1169
1170
1177 LF_EXPORT lfLens *lf_lens_new ();
1178
1188 LF_EXPORT void lf_lens_destroy (lfLens *lens);
1189
1199 LF_EXPORT void lf_lens_copy (lfLens *dest, const lfLens *source);
1200
1202 LF_EXPORT cbool lf_lens_check (lfLens *lens);
1203
1205 LF_EXPORT void lf_lens_guess_parameters (lfLens *lens);
1206
1208 LF_EXPORT const char *lf_get_distortion_model_desc (
1209 enum lfDistortionModel model, const char **details, const lfParameter ***params);
1210
1212 LF_EXPORT const char *lf_get_tca_model_desc (
1213 enum lfTCAModel model, const char **details, const lfParameter ***params);
1214
1216 LF_EXPORT const char *lf_get_vignetting_model_desc (
1217 enum lfVignettingModel model, const char **details, const lfParameter ***params);
1218
1220 LF_EXPORT const char *lf_get_crop_desc (
1221 enum lfCropMode mode, const char **details, const lfParameter ***params);
1222
1224 LF_EXPORT const char *lf_get_lens_type_desc (
1225 enum lfLensType type, const char **details);
1226
1228 LF_EXPORT cbool lf_lens_interpolate_distortion (const lfLens *lens, float focal,
1229 lfLensCalibDistortion *res);
1230
1232 LF_EXPORT cbool lf_lens_interpolate_tca (const lfLens *lens, float focal, lfLensCalibTCA *res);
1233
1235 LF_EXPORT cbool lf_lens_interpolate_vignetting (const lfLens *lens, float focal, float aperture,
1236 float distance, lfLensCalibVignetting *res);
1237
1239 LF_EXPORT cbool lf_lens_interpolate_crop (const lfLens *lens, float focal,
1240 lfLensCalibCrop *res);
1241
1243 DEPRECATED LF_EXPORT cbool lf_lens_interpolate_fov (const lfLens *lens, float focal,
1244 lfLensCalibFov *res);
1245
1247 LF_EXPORT cbool lf_lens_interpolate_real_focal (const lfLens *lens, float focal,
1248 lfLensCalibRealFocal *res);
1249
1251 LF_EXPORT void lf_lens_add_calib_distortion (lfLens *lens, const lfLensCalibDistortion *dc);
1252
1254 LF_EXPORT cbool lf_lens_remove_calib_distortion (lfLens *lens, int idx);
1255
1257 LF_EXPORT void lf_lens_add_calib_tca (lfLens *lens, const lfLensCalibTCA *tcac);
1258
1260 LF_EXPORT cbool lf_lens_remove_calib_tca (lfLens *lens, int idx);
1261
1263 LF_EXPORT void lf_lens_add_calib_vignetting (lfLens *lens, const lfLensCalibVignetting *vc);
1264
1266 LF_EXPORT cbool lf_lens_remove_calib_vignetting (lfLens *lens, int idx);
1267
1269 LF_EXPORT void lf_lens_add_calib_crop (lfLens *lens, const lfLensCalibCrop *cc);
1270
1272 LF_EXPORT cbool lf_lens_remove_calib_crop (lfLens *lens, int idx);
1273
1275 DEPRECATED LF_EXPORT void lf_lens_add_calib_fov (lfLens *lens, const lfLensCalibFov *cf);
1276
1278 DEPRECATED LF_EXPORT cbool lf_lens_remove_calib_fov (lfLens *lens, int idx);
1279
1281 LF_EXPORT void lf_lens_add_calib_real_focal (lfLens *lens, const lfLensCalibRealFocal *cf);
1282
1284 LF_EXPORT cbool lf_lens_remove_calib_real_focal (lfLens *lens, int idx);
1285
1288 /*----------------------------------------------------------------------------*/
1289
1299 enum
1300 {
1308 LF_SEARCH_LOOSE = 1,
1320 LF_SEARCH_SORT_AND_UNIQUIFY = 2
1321 };
1322
1345 struct LF_EXPORT lfDatabase
1346 {
1348 char *HomeDataDir;
1351 char *UserUpdatesDir;
1352
1353 #ifdef __cplusplus
1354
1357 static lfDatabase *Create ();
1358
1362 void Destroy ();
1363
1373 lfError Load ();
1374
1387 lfError Load (const char *filename);
1388
1403 lfError Load (const char *errcontext, const char *data, size_t data_size);
1404
1412 lfError Save (const char *filename) const;
1413
1427 lfError Save (const char *filename,
1428 const lfMount *const *mounts,
1429 const lfCamera *const *cameras,
1430 const lfLens *const *lenses) const;
1431
1444 static char *Save (const lfMount *const *mounts,
1445 const lfCamera *const *cameras,
1446 const lfLens *const *lenses);
1447
1472 const lfCamera **FindCameras (const char *maker, const char *model) const;
1473
1494 const lfCamera **FindCamerasExt (const char *maker, const char *model,
1495 int sflags = 0) const;
1496
1504 const lfCamera *const *GetCameras () const;
1505
1543 const lfLens **FindLenses (const lfCamera *camera, const char *maker,
1544 const char *model, int sflags = 0) const;
1545
1563 const lfLens **FindLenses (const lfLens *lens, int sflags = 0) const;
1564
1572 const lfLens *const *GetLenses () const;
1573
1581 const lfMount *FindMount (const char *mount) const;
1582
1590 const char *MountName (const char *mount) const;
1591
1599 const lfMount *const *GetMounts () const;
1600
1601 protected:
1602 /* Prevent user from creating and destroying such objects */
1603 lfDatabase () {}
1604 ~lfDatabase () {}
1605 #endif
1606 };
1607
1608 C_TYPEDEF (struct, lfDatabase)
1609
1610
1620 LF_EXPORT lfDatabase *lf_db_new (void);
1621
1631 LF_EXPORT void lf_db_destroy (lfDatabase *db);
1632
1634 LF_EXPORT lfError lf_db_load (lfDatabase *db);
1635
1637 LF_EXPORT lfError lf_db_load_file (lfDatabase *db, const char *filename);
1638
1640 LF_EXPORT lfError lf_db_load_data (lfDatabase *db, const char *errcontext,
1641 const char *data, size_t data_size);
1642
1644 LF_EXPORT lfError lf_db_save_all (const lfDatabase *db, const char *filename);
1645
1647 LF_EXPORT lfError lf_db_save_file (const lfDatabase *db, const char *filename,
1648 const lfMount *const *mounts,
1649 const lfCamera *const *cameras,
1650 const lfLens *const *lenses);
1651
1653 LF_EXPORT char *lf_db_save (const lfMount *const *mounts,
1654 const lfCamera *const *cameras,
1655 const lfLens *const *lenses);
1656
1658 LF_EXPORT const lfCamera **lf_db_find_cameras (
1659 const lfDatabase *db, const char *maker, const char *model);
1660
1662 LF_EXPORT const lfCamera **lf_db_find_cameras_ext (
1663 const lfDatabase *db, const char *maker, const char *model, int sflags);
1664
1666 LF_EXPORT const lfCamera *const *lf_db_get_cameras (const lfDatabase *db);
1667
1669 LF_EXPORT const lfLens **lf_db_find_lenses_hd (
1670 const lfDatabase *db, const lfCamera *camera, const char *maker,
1671 const char *lens, int sflags);
1672
1674 LF_EXPORT const lfLens **lf_db_find_lenses (
1675 const lfDatabase *db, const lfLens *lens, int sflags);
1676
1678 LF_EXPORT const lfLens *const *lf_db_get_lenses (const lfDatabase *db);
1679
1681 LF_EXPORT const lfMount *lf_db_find_mount (const lfDatabase *db, const char *mount);
1682
1684 LF_EXPORT const char *lf_db_mount_name (const lfDatabase *db, const char *mount);
1685
1687 LF_EXPORT const lfMount *const *lf_db_get_mounts (const lfDatabase *db);
1688
1691 /*----------------------------------------------------------------------------*/
1692
1701 enum
1702 {
1704 LF_MODIFY_TCA = 0x00000001,
1706 LF_MODIFY_VIGNETTING = 0x00000002,
1707 /* Value 0x00000004 is deprecated. */
1709 LF_MODIFY_DISTORTION = 0x00000008,
1711 LF_MODIFY_GEOMETRY = 0x00000010,
1713 LF_MODIFY_SCALE = 0x00000020,
1715 LF_MODIFY_ALL = ~0
1716 };
1717
1719 enum lfPixelFormat
1720 {
1722 LF_PF_U8,
1724 LF_PF_U16,
1726 LF_PF_U32,
1728 LF_PF_F32,
1730 LF_PF_F64
1731 };
1732
1733 C_TYPEDEF (enum, lfPixelFormat)
1734
1735
1738 enum lfComponentRole
1739 {
1744 LF_CR_END = 0,
1751 LF_CR_NEXT,
1753 LF_CR_UNKNOWN,
1755 LF_CR_INTENSITY,
1757 LF_CR_RED,
1759 LF_CR_GREEN,
1761 LF_CR_BLUE
1762 };
1763
1764 C_TYPEDEF (enum, lfComponentRole)
1765
1766
1767 #define LF_CR_1(a) (LF_CR_ ## a)
1768
1769 #define LF_CR_2(a,b) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4))
1770
1771 #define LF_CR_3(a,b,c) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1772 ((LF_CR_ ## c) << 8))
1773
1774 #define LF_CR_4(a,b,c,d) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1775 ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12))
1776
1777 #define LF_CR_5(a,b,c,d,e) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1778 ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1779 ((LF_CR_ ## e) << 16))
1780
1781 #define LF_CR_6(a,b,c,d,e,f) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1782 ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1783 ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20))
1784
1785 #define LF_CR_7(a,b,c,d,e,f,g) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1786 ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1787 ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20) | \
1788 ((LF_CR_ ## g) << 24))
1789
1790 #define LF_CR_8(a,b,c,d,e,f,g,h) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1791 ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1792 ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20) | \
1793 ((LF_CR_ ## g) << 24) | ((LF_CR_ ## h) << 28))
1794
1810 typedef void (*lfSubpixelCoordFunc) (void *data, float *iocoord, int count);
1811
1836 typedef void (*lfModifyColorFunc) (void *data, float x, float y,
1837 void *pixels, int comp_role, int count);
1838
1851 typedef void (*lfModifyCoordFunc) (void *data, float *iocoord, int count);
1852
1932 struct LF_EXPORT lfModifier
1933 {
1934 #ifdef __cplusplus
1935
1958 static lfModifier *Create (const lfLens *lens, float crop, int width, int height);
1959
2005 int Initialize (
2006 const lfLens *lens, lfPixelFormat format, float focal, float aperture,
2007 float distance, float scale, lfLensType targeom, int flags, bool reverse);
2008
2014 void Destroy ();
2015
2032 void AddCoordCallback (lfModifyCoordFunc callback, int priority,
2033 void *data, size_t data_size);
2034
2052 void AddSubpixelCallback (lfSubpixelCoordFunc callback, int priority,
2053 void *data, size_t data_size);
2054
2071 void AddColorCallback (lfModifyColorFunc callback, int priority,
2072 void *data, size_t data_size);
2073
2088 bool AddSubpixelCallbackTCA (lfLensCalibTCA &model, bool reverse = false);
2089
2104 bool AddColorCallbackVignetting (lfLensCalibVignetting &model, lfPixelFormat format,
2105 bool reverse = false);
2106
2120 bool AddCoordCallbackDistortion (lfLensCalibDistortion &model, bool reverse = false);
2121
2136 bool AddCoordCallbackGeometry (lfLensType from, lfLensType to, float focal);
2137
2154 bool AddCoordCallbackScale (float scale, bool reverse = false);
2155
2169 float GetAutoScale (bool reverse);
2170
2200 bool ApplyColorModification (void *pixels, float x, float y, int width, int height,
2201 int comp_role, int row_stride) const;
2202
2233 bool ApplyGeometryDistortion (float xu, float yu, int width, int height,
2234 float *res) const;
2235
2267 bool ApplySubpixelDistortion (float xu, float yu, int width, int height,
2268 float *res) const;
2269
2300 bool ApplySubpixelGeometryDistortion (float xu, float yu, int width, int height,
2301 float *res) const;
2302
2303 private:
2334 float GetRealFocalLength (const lfLens *lens, float focal);
2335
2336 protected:
2337 /* Prevent user from creating and destroying such objects */
2338 lfModifier () {}
2339 ~lfModifier () {}
2340 #elif defined _MSC_VER
2341 /* Sucks, like always */
2342 void *dummy;
2343 #endif
2344 };
2345
2346 C_TYPEDEF (struct, lfModifier)
2347
2348
2349 LF_EXPORT lfModifier *lf_modifier_new (
2350 const lfLens *lens, float crop, int width, int height);
2351
2353 LF_EXPORT void lf_modifier_destroy (lfModifier *modifier);
2354
2356 LF_EXPORT int lf_modifier_initialize (
2357 lfModifier *modifier, const lfLens *lens, lfPixelFormat format,
2358 float focal, float aperture, float distance, float scale,
2359 lfLensType targeom, int flags, cbool reverse);
2360
2362 LF_EXPORT void lf_modifier_add_coord_callback (
2363 lfModifier *modifier, lfModifyCoordFunc callback, int priority,
2364 void *data, size_t data_size);
2365
2367 LF_EXPORT void lf_modifier_add_subpixel_callback (
2368 lfModifier *modifier, lfSubpixelCoordFunc callback, int priority,
2369 void *data, size_t data_size);
2370
2372 LF_EXPORT void lf_modifier_add_color_callback (
2373 lfModifier *modifier, lfModifyColorFunc callback, int priority,
2374 void *data, size_t data_size);
2375
2377 LF_EXPORT cbool lf_modifier_add_subpixel_callback_TCA (
2378 lfModifier *modifier, lfLensCalibTCA *model, cbool reverse);
2379
2381 LF_EXPORT cbool lf_modifier_add_color_callback_vignetting (
2382 lfModifier *modifier, lfLensCalibVignetting *model,
2383 lfPixelFormat format, cbool reverse);
2384
2386 LF_EXPORT cbool lf_modifier_add_coord_callback_distortion (
2387 lfModifier *modifier, lfLensCalibDistortion *model, cbool reverse);
2388
2390 LF_EXPORT cbool lf_modifier_add_coord_callback_geometry (
2391 lfModifier *modifier, lfLensType from, lfLensType to, float focal);
2392
2394 LF_EXPORT cbool lf_modifier_add_coord_callback_scale (
2395 lfModifier *modifier, float scale, cbool reverse);
2396
2398 LF_EXPORT float lf_modifier_get_auto_scale (
2399 lfModifier *modifier, cbool reverse);
2400
2402 LF_EXPORT cbool lf_modifier_apply_subpixel_distortion (
2403 lfModifier *modifier, float xu, float yu, int width, int height, float *res);
2404
2406 LF_EXPORT cbool lf_modifier_apply_color_modification (
2407 lfModifier *modifier, void *pixels, float x, float y, int width, int height,
2408 int comp_role, int row_stride);
2409
2411 LF_EXPORT cbool lf_modifier_apply_geometry_distortion (
2412 lfModifier *modifier, float xu, float yu, int width, int height, float *res);
2413
2415 LF_EXPORT cbool lf_modifier_apply_subpixel_geometry_distortion (
2416 lfModifier *modifier, float xu, float yu, int width, int height, float *res);
2417
2420 #undef cbool
2421
2422 #ifdef __cplusplus
2423 }
2424 #endif
2425
2426 #endif /* __LENSFUN_H__ */
LF_PANORAMIC
Panoramic (cylindrical)
Definition: lensfun.h:748
lf_db_load_file
lfError lf_db_load_file(lfDatabase *db, const char *filename)
lfDistortionModel
lfDistortionModel
The lensfun library implements several lens distortion models. This enum lists them.
Definition: lensfun.h:448
lfLens::MinAperture
float MinAperture
Definition: lensfun.h:793
lfModifyCoordFunc
void(* lfModifyCoordFunc)(void *data, float *iocoord, int count)
A callback function which modifies the coordinates of a strip of pixels.
Definition: lensfun.h:1851
LF_PF_U16
Definition: lensfun.h:1724
LF_CR_UNKNOWN
Definition: lensfun.h:1753
lf_modifier_apply_subpixel_geometry_distortion
cbool lf_modifier_apply_subpixel_geometry_distortion(lfModifier *modifier, float xu, float yu, int width, int height, float *res)
lf_lens_add_calib_tca
void lf_lens_add_calib_tca(lfLens *lens, const lfLensCalibTCA *tcac)
lf_db_find_cameras
const lfCamera ** lf_db_find_cameras(const lfDatabase *db, const char *maker, const char *model)
lf_lens_add_calib_fov
DEPRECATED void lf_lens_add_calib_fov(lfLens *lens, const lfLensCalibFov *cf)
lfLens::Maker
lfMLstr Maker
Definition: lensfun.h:785
lf_modifier_initialize
int lf_modifier_initialize(lfModifier *modifier, const lfLens *lens, lfPixelFormat format, float focal, float aperture, float distance, float scale, lfLensType targeom, int flags, cbool reverse)
lfLens::CalibDistortion
lfLensCalibDistortion ** CalibDistortion
Definition: lensfun.h:817
lfLensCalibFov::FieldOfView
float FieldOfView
Field of view for given images.
Definition: lensfun.h:678
LF_RECTILINEAR
Rectilinear lens.
Definition: lensfun.h:735
LF_MODIFY_DISTORTION
Definition: lensfun.h:1709
lfLens::Type
lfLensType Type
Definition: lensfun.h:815
LF_SEARCH_SORT_AND_UNIQUIFY
This flag makes LensFun to sort the results by focal length, and remove all double lens names...
Definition: lensfun.h:1320
lfMount::Compat
char ** Compat
Definition: lensfun.h:197
lfLens::CalibVignetting
lfLensCalibVignetting ** CalibVignetting
Definition: lensfun.h:821
lfDatabase::UserUpdatesDir
char * UserUpdatesDir
Home lens database directory for automatic updates (something like "~/.local/share/lensfun/updates") ...
Definition: lensfun.h:1351
LF_NO_CROP
no crop at all
Definition: lensfun.h:627
LF_PF_F64
Definition: lensfun.h:1730
LF_PF_U8
Definition: lensfun.h:1722
LF_DIST_MODEL_POLY5
5th order polynomial model.
Definition: lensfun.h:468
lfError
lfError
Definition: lensfun.h:111
lf_get_distortion_model_desc
const char * lf_get_distortion_model_desc(enum lfDistortionModel model, const char **details, const lfParameter ***params)
lf_lens_guess_parameters
void lf_lens_guess_parameters(lfLens *lens)
lfLens::CenterX
float CenterX
Definition: lensfun.h:807
lfLens::CropFactor
float CropFactor
Definition: lensfun.h:811
lfLensCalibVignetting::Focal
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:610
lfLensCalibTCA
Laterlal chromatic aberrations calibration data.
Definition: lensfun.h:552
lfLensCalibDistortion
Lens distortion calibration data.
Definition: lensfun.h:487
lfSubpixelCoordFunc
void(* lfSubpixelCoordFunc)(void *data, float *iocoord, int count)
A callback function which modifies the separate coordinates for all color components for every pixel ...
Definition: lensfun.h:1810
lf_modifier_add_subpixel_callback
void lf_modifier_add_subpixel_callback(lfModifier *modifier, lfSubpixelCoordFunc callback, int priority, void *data, size_t data_size)
lf_modifier_add_color_callback_vignetting
cbool lf_modifier_add_color_callback_vignetting(lfModifier *modifier, lfLensCalibVignetting *model, lfPixelFormat format, cbool reverse)
lf_modifier_add_coord_callback
void lf_modifier_add_coord_callback(lfModifier *modifier, lfModifyCoordFunc callback, int priority, void *data, size_t data_size)
lf_lens_copy
void lf_lens_copy(lfLens *dest, const lfLens *source)
Copy the data from one lfLens structure into another.
lf_mount_destroy
void lf_mount_destroy(lfMount *mount)
Destroy a lfMount object.
lf_lens_remove_calib_tca
cbool lf_lens_remove_calib_tca(lfLens *lens, int idx)
lf_lens_remove_calib_vignetting
cbool lf_lens_remove_calib_vignetting(lfLens *lens, int idx)
lfLens
Lens data. Unknown fields are set to NULL or 0.
Definition: lensfun.h:782
lf_lens_interpolate_distortion
cbool lf_lens_interpolate_distortion(const lfLens *lens, float focal, lfLensCalibDistortion *res)
lfPixelFormat
lfPixelFormat
A list of pixel formats supported by internal colour callbacks.
Definition: lensfun.h:1719
LF_MODIFY_SCALE
Definition: lensfun.h:1713
lfLens::AspectRatio
float AspectRatio
Definition: lensfun.h:813
lfVignettingModel
lfVignettingModel
The lensfun library supports several models for lens vignetting correction.
Definition: lensfun.h:580
lfLens::CalibTCA
lfLensCalibTCA ** CalibTCA
Definition: lensfun.h:819
lfLens::CenterY
float CenterY
Definition: lensfun.h:809
lf_modifier_add_coord_callback_scale
cbool lf_modifier_add_coord_callback_scale(lfModifier *modifier, float scale, cbool reverse)
lfMount
This structure contains everything specific to a camera mount.
Definition: lensfun.h:188
lfLens::MinFocal
float MinFocal
Definition: lensfun.h:789
lf_db_mount_name
const char * lf_db_mount_name(const lfDatabase *db, const char *mount)
LF_FISHEYE_STEREOGRAPHIC
Stereographic fisheye.
Definition: lensfun.h:759
lfLens::Score
int Score
Definition: lensfun.h:829
LF_TCA_MODEL_LINEAR
Linear lateral chromatic aberrations model.
Definition: lensfun.h:527
LF_TCA_MODEL_POLY3
Third order polynomial.
Definition: lensfun.h:540
LF_MODIFY_GEOMETRY
Definition: lensfun.h:1711
LF_CROP_CIRCLE
use a circular crop, e.g. for circular fisheye images
Definition: lensfun.h:631
cbool
#define cbool
C-compatible bool type; don't bother to define Yet Another Boolean Type.
Definition: lensfun.h:98
lfLens::Model
lfMLstr Model
Definition: lensfun.h:787
lfLensCalibCrop::Focal
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:642
lf_modifier_apply_subpixel_distortion
cbool lf_modifier_apply_subpixel_distortion(lfModifier *modifier, float xu, float yu, int width, int height, float *res)
lf_db_find_lenses_hd
const lfLens ** lf_db_find_lenses_hd(const lfDatabase *db, const lfCamera *camera, const char *maker, const char *lens, int sflags)
lfCamera::Score
int Score
Camera matching score, used while searching: not actually a camera parameter.
Definition: lensfun.h:313
lf_free
void lf_free(void *data)
lf_mount_check
cbool lf_mount_check(lfMount *mount)
lf_modifier_get_auto_scale
float lf_modifier_get_auto_scale(lfModifier *modifier, cbool reverse)
LF_FISHEYE_ORTHOGRAPHIC
Orthographic fisheye.
Definition: lensfun.h:757
lf_db_get_cameras
const lfCamera *const * lf_db_get_cameras(const lfDatabase *db)
lf_modifier_new
lfModifier * lf_modifier_new(const lfLens *lens, float crop, int width, int height)
lfLensType
lfLensType
Lens type. See Change of projection for further information.
Definition: lensfun.h:727
LF_MODIFY_VIGNETTING
Definition: lensfun.h:1706
lf_lens_remove_calib_crop
cbool lf_lens_remove_calib_crop(lfLens *lens, int idx)
lfLensCalibRealFocal::Focal
float Focal
Definition: lensfun.h:690
LF_DIST_MODEL_PTLENS
PTLens model, which is also used by Hugin.
Definition: lensfun.h:476
LF_CR_INTENSITY
Definition: lensfun.h:1755
LF_DIST_MODEL_POLY3
3rd order polynomial model, which is a subset of the PTLens model.
Definition: lensfun.h:459
LF_CROP_RECTANGLE
use a rectangular crop
Definition: lensfun.h:629
lf_get_tca_model_desc
const char * lf_get_tca_model_desc(enum lfTCAModel model, const char **details, const lfParameter ***params)
lf_modifier_add_subpixel_callback_TCA
cbool lf_modifier_add_subpixel_callback_TCA(lfModifier *modifier, lfLensCalibTCA *model, cbool reverse)
lf_db_find_mount
const lfMount * lf_db_find_mount(const lfDatabase *db, const char *mount)
C_TYPEDEF
#define C_TYPEDEF(t, c)
Definition: lensfun.h:30
LF_FISHEYE_EQUISOLID
Equisolid fisheye.
Definition: lensfun.h:761
LF_FISHEYE_THOBY
Fisheye as measured by Thoby (for Nikkor 10.5).
Definition: lensfun.h:767
lf_db_get_mounts
const lfMount *const * lf_db_get_mounts(const lfDatabase *db)
lfLensCalibTCA::Focal
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:557
lf_lens_interpolate_crop
cbool lf_lens_interpolate_crop(const lfLens *lens, float focal, lfLensCalibCrop *res)
LF_CR_RED
Definition: lensfun.h:1757
LF_CR_GREEN
Definition: lensfun.h:1759
LF_EXPORT
#define LF_EXPORT
This macro expands to an appropiate symbol visibility declaration.
Definition: lensfun.h:64
lf_camera_destroy
void lf_camera_destroy(lfCamera *camera)
Destroy a lfCamera object.
lf_lens_new
lfLens * lf_lens_new()
Create a new lens object.
lfParameter::Min
float Min
Minimal value that has sense.
Definition: lensfun.h:715
lfParameter::Max
float Max
Maximal value that has sense.
Definition: lensfun.h:717
LF_UNKNOWN
Unknown lens type.
Definition: lensfun.h:730
lfLensCalibRealFocal
Struct to save real focal length, which can depends on the (nominal) focal length.
Definition: lensfun.h:687
lf_modifier_apply_color_modification
cbool lf_modifier_apply_color_modification(lfModifier *modifier, void *pixels, float x, float y, int width, int height, int comp_role, int row_stride)
lf_db_find_cameras_ext
const lfCamera ** lf_db_find_cameras_ext(const lfDatabase *db, const char *maker, const char *model, int sflags)
lfLensCalibRealFocal::RealFocal
float RealFocal
Real focal length.
Definition: lensfun.h:702
lfModifier
A modifier object contains optimized data required to rectify a image.
Definition: lensfun.h:1932
lf_camera_check
cbool lf_camera_check(lfCamera *camera)
LF_CR_END
Definition: lensfun.h:1744
lfCamera::CropFactor
float CropFactor
Camera crop factor (ex: 1.0). Must be defined.
Definition: lensfun.h:311
lf_mlstr_get
const char * lf_mlstr_get(const lfMLstr str)
Get a string corresponding to current locale from a multi-language string.
lf_camera_copy
void lf_camera_copy(lfCamera *dest, const lfCamera *source)
Copy the data from one lfCamera structure into another.
LF_WRONG_FORMAT
Definition: lensfun.h:116
LF_SEARCH_LOOSE
This flag selects a looser search algorithm resulting in more results (still sorted by score)...
Definition: lensfun.h:1308
lfLensCalibVignetting::Distance
float Distance
Focus distance in meters.
Definition: lensfun.h:614
lf_lens_add_calib_distortion
void lf_lens_add_calib_distortion(lfLens *lens, const lfLensCalibDistortion *dc)
lf_modifier_destroy
void lf_modifier_destroy(lfModifier *modifier)
lfLensCalibVignetting::Aperture
float Aperture
Aperture (f-number) at which this calibration data was taken.
Definition: lensfun.h:612
DEPRECATED
#define DEPRECATED
For marking deprecated functions, see http://stackoverflow.com/a/21265197.
Definition: lensfun.h:91
LF_CR_BLUE
Definition: lensfun.h:1761
lf_modifier_apply_geometry_distortion
cbool lf_modifier_apply_geometry_distortion(lfModifier *modifier, float xu, float yu, int width, int height, float *res)
lf_camera_new
lfCamera * lf_camera_new()
Create a new camera object.
lfLens::MaxFocal
float MaxFocal
Definition: lensfun.h:791
LF_MODIFY_TCA
Definition: lensfun.h:1704
lf_mount_copy
void lf_mount_copy(lfMount *dest, const lfMount *source)
Copy the data from one lfMount structure into another.
lfComponentRole
lfComponentRole
These constants define the role of every pixel component, four bits each. "pixel" refers here to a se...
Definition: lensfun.h:1738
lf_get_lens_type_desc
const char * lf_get_lens_type_desc(enum lfLensType type, const char **details)
lfLens::Mounts
char ** Mounts
Definition: lensfun.h:797
LF_EQUIRECTANGULAR
Equirectangular.
Definition: lensfun.h:755
LF_CR_NEXT
Definition: lensfun.h:1751
lfLensCalibDistortion::Focal
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:492
lfLensCalibFov::Focal
float Focal
Definition: lensfun.h:668
lf_lens_interpolate_tca
cbool lf_lens_interpolate_tca(const lfLens *lens, float focal, lfLensCalibTCA *res)
lf_lens_destroy
void lf_lens_destroy(lfLens *lens)
Destroy a lfLens object.
LF_MODIFY_ALL
Definition: lensfun.h:1715
lf_db_find_lenses
const lfLens ** lf_db_find_lenses(const lfDatabase *db, const lfLens *lens, int sflags)
lf_db_destroy
void lf_db_destroy(lfDatabase *db)
Destroy the database object.
LF_FISHEYE
Equidistant fisheye.
Definition: lensfun.h:741
lf_db_load_data
lfError lf_db_load_data(lfDatabase *db, const char *errcontext, const char *data, size_t data_size)
lf_modifier_add_coord_callback_geometry
cbool lf_modifier_add_coord_callback_geometry(lfModifier *modifier, lfLensType from, lfLensType to, float focal)
lf_modifier_add_color_callback
void lf_modifier_add_color_callback(lfModifier *modifier, lfModifyColorFunc callback, int priority, void *data, size_t data_size)
LF_PF_U32
Definition: lensfun.h:1726
LF_TCA_MODEL_NONE
No TCA correction data is known.
Definition: lensfun.h:515
lfCamera::Model
lfMLstr Model
Model name (ex: "Rolleiflex SL35") – same as in EXIF.
Definition: lensfun.h:305
lf_get_crop_desc
const char * lf_get_crop_desc(enum lfCropMode mode, const char **details, const lfParameter ***params)
lfLens::CalibFov
lfLensCalibFov ** CalibFov
Definition: lensfun.h:825
lfCamera::Maker
lfMLstr Maker
Camera maker (ex: "Rollei") – same as in EXIF.
Definition: lensfun.h:303
lf_lens_remove_calib_fov
DEPRECATED cbool lf_lens_remove_calib_fov(lfLens *lens, int idx)
LF_NO_ERROR
Definition: lensfun.h:114
lf_db_new
lfDatabase * lf_db_new(void)
Create a new empty database object.
lf_lens_check
cbool lf_lens_check(lfLens *lens)
lf_get_vignetting_model_desc
const char * lf_get_vignetting_model_desc(enum lfVignettingModel model, const char **details, const lfParameter ***params)
lfCamera::Mount
char * Mount
Camera mount type (ex: "QBM")
Definition: lensfun.h:309
lfMLstr
char * lfMLstr
Definition: lensfun.h:108
lfDatabase
A lens database object.
Definition: lensfun.h:1345
lf_lens_interpolate_real_focal
cbool lf_lens_interpolate_real_focal(const lfLens *lens, float focal, lfLensCalibRealFocal *res)
lf_lens_add_calib_crop
void lf_lens_add_calib_crop(lfLens *lens, const lfLensCalibCrop *cc)
lf_db_get_lenses
const lfLens *const * lf_db_get_lenses(const lfDatabase *db)
LF_VIGNETTING_MODEL_PA
Pablo D'Angelo vignetting model (which is a more general variant of the law).
Definition: lensfun.h:593
LF_DIST_MODEL_NONE
Distortion parameters are unknown.
Definition: lensfun.h:451
lfMount::Name
lfMLstr Name
Camera mount name.
Definition: lensfun.h:195
lfLensCalibVignetting
Lens vignetting calibration data.
Definition: lensfun.h:605
lf_lens_remove_calib_real_focal
cbool lf_lens_remove_calib_real_focal(lfLens *lens, int idx)
lf_lens_interpolate_fov
DEPRECATED cbool lf_lens_interpolate_fov(const lfLens *lens, float focal, lfLensCalibFov *res)
lf_mlstr_add
lfMLstr lf_mlstr_add(lfMLstr str, const char *lang, const char *trstr)
Add a new translated string to a multi-language string.
LF_VIGNETTING_MODEL_NONE
No vignetting correction data is known.
Definition: lensfun.h:583
lf_lens_add_calib_vignetting
void lf_lens_add_calib_vignetting(lfLens *lens, const lfLensCalibVignetting *vc)
lf_db_save_all
lfError lf_db_save_all(const lfDatabase *db, const char *filename)
lf_lens_interpolate_vignetting
cbool lf_lens_interpolate_vignetting(const lfLens *lens, float focal, float aperture, float distance, lfLensCalibVignetting *res)
lfTCAModel
lfTCAModel
The lensfun library supports several models for lens lateral chromatic aberrations (also called trans...
Definition: lensfun.h:512
lf_modifier_add_coord_callback_distortion
cbool lf_modifier_add_coord_callback_distortion(lfModifier *modifier, lfLensCalibDistortion *model, cbool reverse)
lfParameter::Default
float Default
Default value for the parameter.
Definition: lensfun.h:719
lf_lens_add_calib_real_focal
void lf_lens_add_calib_real_focal(lfLens *lens, const lfLensCalibRealFocal *cf)
lf_mount_new
lfMount * lf_mount_new()
Create a new mount object.
lfCropMode
lfCropMode
Different crop modes.
Definition: lensfun.h:624
lfLensCalibFov
Struct to save calibrated field of view, which can depends on the focal length (DEPRECATED) ...
Definition: lensfun.h:665
lfLens::CalibCrop
lfLensCalibCrop ** CalibCrop
Definition: lensfun.h:823
lfCamera
Camera data. Unknown fields are set to NULL.
Definition: lensfun.h:300
lf_db_save
char * lf_db_save(const lfMount *const *mounts, const lfCamera *const *cameras, const lfLens *const *lenses)
lf_mlstr_dup
lfMLstr lf_mlstr_dup(const lfMLstr str)
Create a complete copy of a multi-language string.
lfCamera::Variant
lfMLstr Variant
Camera variant. Some cameras use same EXIF id for different models.
Definition: lensfun.h:307
lfModifyColorFunc
void(* lfModifyColorFunc)(void *data, float x, float y, void *pixels, int comp_role, int count)
A callback function which modifies the colors of a strip of pixels.
Definition: lensfun.h:1836
lfLensCalibCrop
Struct to save image crop, which can depend on the focal length.
Definition: lensfun.h:639
LF_PF_F32
Definition: lensfun.h:1728
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)
lfParameter::Name
const char * Name
Parameter name (something like 'k', 'k3', 'omega' etc.)
Definition: lensfun.h:713
lfParameter
This structure describes a single parameter for some lens model.
Definition: lensfun.h:710
lf_db_load
lfError lf_db_load(lfDatabase *db)
lf_lens_remove_calib_distortion
cbool lf_lens_remove_calib_distortion(lfLens *lens, int idx)
lfDatabase::HomeDataDir
char * HomeDataDir
Home lens database directory (something like "~/.local/share/lensfun")
Definition: lensfun.h:1348
lfLens::CalibRealFocal
lfLensCalibRealFocal ** CalibRealFocal
Definition: lensfun.h:827
lfLens::MaxAperture
float MaxAperture
Definition: lensfun.h:795