lensfun  0.3.2.0
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 2
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 2
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 
112 {
119 };
120 
121 C_TYPEDEF (enum, lfError)
122 
123 
124 typedef unsigned char lf_u8;
126 typedef unsigned short lf_u16;
128 typedef unsigned int lf_u32;
130 typedef float lf_f32;
132 typedef double lf_f64;
133 
142 LF_EXPORT void lf_free (void *data);
143 
152 LF_EXPORT const char *lf_mlstr_get (const lfMLstr str);
153 
170 LF_EXPORT lfMLstr lf_mlstr_add (lfMLstr str, const char *lang, const char *trstr);
171 
180 LF_EXPORT lfMLstr lf_mlstr_dup (const lfMLstr str);
181 
184 /*----------------------------------------------------------------------------*/
185 
202 {
208  lfMLstr Name;
210  char **Compat;
211 
212 #ifdef __cplusplus
213 
216  lfMount ();
217 
221  lfMount (const lfMount &other);
222 
226  lfMount &operator = (const lfMount &other);
227 
231  ~lfMount ();
232 
243  void SetName (const char *val, const char *lang = NULL);
244 
250  void AddCompat (const char *val);
251 
257  bool Check ();
258 #endif
259 };
260 
261 C_TYPEDEF (struct, lfMount)
262 
263 
271 
281 LF_EXPORT void lf_mount_destroy (lfMount *mount);
282 
292 LF_EXPORT void lf_mount_copy (lfMount *dest, const lfMount *source);
293 
296 
299 /*----------------------------------------------------------------------------*/
300 
319 {
321  lfMLstr Maker;
323  lfMLstr Model;
325  lfMLstr Variant;
327  char *Mount;
329  float CropFactor;
331  int Score;
332 
333 #ifdef __cplusplus
334 
337  lfCamera ();
338 
342  lfCamera (const lfCamera &other);
343 
347  ~lfCamera ();
348 
352  lfCamera &operator = (const lfCamera &other);
353 
364  void SetMaker (const char *val, const char *lang = NULL);
365 
376  void SetModel (const char *val, const char *lang = NULL);
377 
388  void SetVariant (const char *val, const char *lang = NULL);
389 
395  void SetMount (const char *val);
396 
402  bool Check ();
403 #endif
404 };
405 
406 C_TYPEDEF (struct, lfCamera)
407 
408 
416 
426 LF_EXPORT void lf_camera_destroy (lfCamera *camera);
427 
437 LF_EXPORT void lf_camera_copy (lfCamera *dest, const lfCamera *source);
438 
441 
444 /*----------------------------------------------------------------------------*/
445 
467 {
512 };
513 
515 
516 
523 {
525  enum lfDistortionModel Model;
527  float Focal;
529  float Terms [5];
530 };
531 
533 
534 
548 {
603 };
604 
605 C_TYPEDEF (enum, lfTCAModel)
606 
607 
615 {
617  enum lfTCAModel Model;
619  float Focal;
621  float Terms [12];
622 };
623 
624 C_TYPEDEF (struct, lfLensCalibTCA)
625 
626 
643 {
667 };
668 
670 
671 
679 {
681  enum lfVignettingModel Model;
683  float Focal;
685  float Aperture;
687  float Distance;
689  float Terms [3];
690 };
691 
693 
694 
698 {
705 };
706 
707 C_TYPEDEF(enum, lfCropMode)
708 
709 
713 {
715  float Focal;
717  enum lfCropMode CropMode;
726  float Crop [4];
727 };
728 
729 C_TYPEDEF (struct, lfLensCalibCrop)
730 
731 
739 {
741  float Focal;
751  float FieldOfView;
752 };
753 
754 C_TYPEDEF (struct, lfLensCalibFov)
755 
756 
761 {
763  float Focal;
775  float RealFocal;
776 };
777 
779 
780 
784 {
786  const char *Name;
788  float Min;
790  float Max;
792  float Default;
793 };
794 
795 C_TYPEDEF (struct, lfParameter)
796 
797 
801 {
841 };
842 
843 C_TYPEDEF (enum, lfLensType)
844 
845 
855 {
857  lfMLstr Maker;
859  lfMLstr Model;
861  float MinFocal;
863  float MaxFocal;
865  float MinAperture;
867  float MaxAperture;
869  char **Mounts;
879  float CenterX;
881  float CenterY;
883  float CropFactor;
885  float AspectRatio;
901  int Score;
902 
903 #ifdef __cplusplus
904 
907  lfLens ();
908 
912  lfLens (const lfLens &other);
913 
917  ~lfLens ();
918 
922  lfLens &operator = (const lfLens &other);
923 
934  void SetMaker (const char *val, const char *lang = NULL);
935 
946  void SetModel (const char *val, const char *lang = NULL);
947 
955  void AddMount (const char *val);
956 
965  void AddCalibDistortion (const lfLensCalibDistortion *dc);
966 
972  bool RemoveCalibDistortion (int idx);
973 
983  void AddCalibTCA (const lfLensCalibTCA *tcac);
984 
990  bool RemoveCalibTCA (int idx);
991 
1000  void AddCalibVignetting (const lfLensCalibVignetting *vc);
1001 
1007  bool RemoveCalibVignetting (int idx);
1008 
1017  void AddCalibCrop (const lfLensCalibCrop *cc);
1018 
1024  bool RemoveCalibCrop (int idx);
1025 
1037  DEPRECATED void AddCalibFov (const lfLensCalibFov *cf);
1038 
1048  DEPRECATED bool RemoveCalibFov (int idx);
1049 
1058  void AddCalibRealFocal (const lfLensCalibRealFocal *cf);
1059 
1066  bool RemoveCalibRealFocal (int idx);
1067 
1076  void GuessParameters ();
1077 
1083  bool Check ();
1084 
1100  static const char *GetDistortionModelDesc (
1101  lfDistortionModel model, const char **details, const lfParameter ***params);
1117  static const char *GetTCAModelDesc (
1118  lfTCAModel model, const char **details, const lfParameter ***params);
1119 
1135  static const char *GetVignettingModelDesc (
1136  lfVignettingModel model, const char **details, const lfParameter ***params);
1137 
1153  static const char *GetCropDesc (
1154  lfCropMode mode, const char **details, const lfParameter ***params);
1155 
1167  static const char *GetLensTypeDesc (lfLensType type, const char **details);
1168 
1176  bool InterpolateDistortion (float focal, lfLensCalibDistortion &res) const;
1177 
1185  bool InterpolateTCA (float focal, lfLensCalibTCA &res) const;
1186 
1200  bool InterpolateVignetting (
1201  float focal, float aperture, float distance, lfLensCalibVignetting &res) const;
1202 
1210  bool InterpolateCrop (float focal, lfLensCalibCrop &res) const;
1211 
1223  DEPRECATED bool InterpolateFov (float focal, lfLensCalibFov &res) const;
1224 
1236  bool InterpolateRealFocal (float focal, lfLensCalibRealFocal &res) const;
1237 #endif
1238 };
1239 
1240 C_TYPEDEF (struct, lfLens)
1241 
1242 
1250 
1260 LF_EXPORT void lf_lens_destroy (lfLens *lens);
1261 
1271 LF_EXPORT void lf_lens_copy (lfLens *dest, const lfLens *source);
1272 
1275 
1278 
1281  enum lfDistortionModel model, const char **details, const lfParameter ***params);
1282 
1284 LF_EXPORT const char *lf_get_tca_model_desc (
1285  enum lfTCAModel model, const char **details, const lfParameter ***params);
1286 
1289  enum lfVignettingModel model, const char **details, const lfParameter ***params);
1290 
1292 LF_EXPORT const char *lf_get_crop_desc (
1293  enum lfCropMode mode, const char **details, const lfParameter ***params);
1294 
1296 LF_EXPORT const char *lf_get_lens_type_desc (
1297  enum lfLensType type, const char **details);
1298 
1300 LF_EXPORT cbool lf_lens_interpolate_distortion (const lfLens *lens, float focal,
1301  lfLensCalibDistortion *res);
1302 
1304 LF_EXPORT cbool lf_lens_interpolate_tca (const lfLens *lens, float focal, lfLensCalibTCA *res);
1305 
1307 LF_EXPORT cbool lf_lens_interpolate_vignetting (const lfLens *lens, float focal, float aperture,
1308  float distance, lfLensCalibVignetting *res);
1309 
1311 LF_EXPORT cbool lf_lens_interpolate_crop (const lfLens *lens, float focal,
1312  lfLensCalibCrop *res);
1313 
1315 DEPRECATED LF_EXPORT cbool lf_lens_interpolate_fov (const lfLens *lens, float focal,
1316  lfLensCalibFov *res);
1317 
1319 LF_EXPORT cbool lf_lens_interpolate_real_focal (const lfLens *lens, float focal,
1320  lfLensCalibRealFocal *res);
1321 
1324 
1327 
1329 LF_EXPORT void lf_lens_add_calib_tca (lfLens *lens, const lfLensCalibTCA *tcac);
1330 
1333 
1336 
1339 
1341 LF_EXPORT void lf_lens_add_calib_crop (lfLens *lens, const lfLensCalibCrop *cc);
1342 
1345 
1348 
1351 
1354 
1357 
1360 /*----------------------------------------------------------------------------*/
1361 
1371 enum
1372 {
1393 };
1394 
1415 {
1421 
1422 #ifdef __cplusplus
1423  lfDatabase ();
1424  ~lfDatabase ();
1425 
1430  DEPRECATED static lfDatabase *Create ();
1431 
1438  DEPRECATED void Destroy ();
1439 
1450  bool LoadDirectory (const char *dirname);
1451 
1460  lfError Load ();
1461 
1474  lfError Load (const char *filename);
1475 
1490  lfError Load (const char *errcontext, const char *data, size_t data_size);
1491 
1499  lfError Save (const char *filename) const;
1500 
1514  lfError Save (const char *filename,
1515  const lfMount *const *mounts,
1516  const lfCamera *const *cameras,
1517  const lfLens *const *lenses) const;
1518 
1531  static char *Save (const lfMount *const *mounts,
1532  const lfCamera *const *cameras,
1533  const lfLens *const *lenses);
1534 
1559  const lfCamera **FindCameras (const char *maker, const char *model) const;
1560 
1581  const lfCamera **FindCamerasExt (const char *maker, const char *model,
1582  int sflags = 0) const;
1583 
1591  const lfCamera *const *GetCameras () const;
1592 
1630  const lfLens **FindLenses (const lfCamera *camera, const char *maker,
1631  const char *model, int sflags = 0) const;
1632 
1650  const lfLens **FindLenses (const lfLens *lens, int sflags = 0) const;
1651 
1659  const lfLens *const *GetLenses () const;
1660 
1668  const lfMount *FindMount (const char *mount) const;
1669 
1677  const char *MountName (const char *mount) const;
1678 
1686  const lfMount *const *GetMounts () const;
1687 
1693  void AddMount (lfMount *mount);
1694 
1700  void AddCamera (lfCamera *camera);
1701 
1707  void AddLens (lfLens *lens);
1708 
1709 private:
1710 #endif
1711  void *Mounts;
1712  void *Cameras;
1713  void *Lenses;
1714 };
1715 
1716 C_TYPEDEF (struct, lfDatabase)
1717 
1718 
1729 
1740 
1743 
1745 LF_EXPORT lfError lf_db_load_file (lfDatabase *db, const char *filename);
1746 
1748 LF_EXPORT cbool lf_db_load_directory (lfDatabase *db, const char *dirname);
1749 
1751 LF_EXPORT lfError lf_db_load_data (lfDatabase *db, const char *errcontext,
1752  const char *data, size_t data_size);
1753 
1755 LF_EXPORT lfError lf_db_save_all (const lfDatabase *db, const char *filename);
1756 
1758 LF_EXPORT lfError lf_db_save_file (const lfDatabase *db, const char *filename,
1759  const lfMount *const *mounts,
1760  const lfCamera *const *cameras,
1761  const lfLens *const *lenses);
1762 
1764 LF_EXPORT char *lf_db_save (const lfMount *const *mounts,
1765  const lfCamera *const *cameras,
1766  const lfLens *const *lenses);
1767 
1770  const lfDatabase *db, const char *maker, const char *model);
1771 
1774  const lfDatabase *db, const char *maker, const char *model, int sflags);
1775 
1777 LF_EXPORT const lfCamera *const *lf_db_get_cameras (const lfDatabase *db);
1778 
1781  const lfDatabase *db, const lfCamera *camera, const char *maker,
1782  const char *lens, int sflags);
1783 
1786  const lfDatabase *db, const lfLens *lens, int sflags);
1787 
1789 LF_EXPORT const lfLens *const *lf_db_get_lenses (const lfDatabase *db);
1790 
1792 LF_EXPORT const lfMount *lf_db_find_mount (const lfDatabase *db, const char *mount);
1793 
1795 LF_EXPORT const char *lf_db_mount_name (const lfDatabase *db, const char *mount);
1796 
1798 LF_EXPORT const lfMount *const *lf_db_get_mounts (const lfDatabase *db);
1799 
1802 /*----------------------------------------------------------------------------*/
1803 
1812 enum
1813 {
1815  LF_MODIFY_TCA = 0x00000001,
1817  LF_MODIFY_VIGNETTING = 0x00000002,
1818  /* Value 0x00000004 is deprecated. */
1820  LF_MODIFY_DISTORTION = 0x00000008,
1822  LF_MODIFY_GEOMETRY = 0x00000010,
1824  LF_MODIFY_SCALE = 0x00000020,
1827 };
1828 
1831 {
1842 };
1843 
1844 C_TYPEDEF (enum, lfPixelFormat)
1845 
1846 
1850 {
1873 };
1874 
1875 C_TYPEDEF (enum, lfComponentRole)
1876 
1877 
1878 #define LF_CR_1(a) (LF_CR_ ## a)
1879 
1880 #define LF_CR_2(a,b) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4))
1881 
1882 #define LF_CR_3(a,b,c) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1883  ((LF_CR_ ## c) << 8))
1884 
1885 #define LF_CR_4(a,b,c,d) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1886  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12))
1887 
1888 #define LF_CR_5(a,b,c,d,e) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1889  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1890  ((LF_CR_ ## e) << 16))
1891 
1892 #define LF_CR_6(a,b,c,d,e,f) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1893  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1894  ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20))
1895 
1896 #define LF_CR_7(a,b,c,d,e,f,g) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1897  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1898  ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20) | \
1899  ((LF_CR_ ## g) << 24))
1900 
1901 #define LF_CR_8(a,b,c,d,e,f,g,h) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
1902  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
1903  ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20) | \
1904  ((LF_CR_ ## g) << 24) | ((LF_CR_ ## h) << 28))
1905 
1921 typedef void (*lfSubpixelCoordFunc) (void *data, float *iocoord, int count);
1922 
1947 typedef void (*lfModifyColorFunc) (void *data, float x, float y,
1948  void *pixels, int comp_role, int count);
1949 
1962 typedef void (*lfModifyCoordFunc) (void *data, float *iocoord, int count);
1963 
1964 // @cond
1965 
1967 struct lfCallbackData
1968 {
1969  int priority;
1970  void *data;
1971  size_t data_size;
1972 };
1973 
1974 // A test point in the autoscale algorithm
1975 typedef struct { float angle, dist; } lfPoint;
1976 
1977 // @endcond
1978 
2060 #ifdef __cplusplus
2061 }
2062 #endif
2063 
2065 {
2066 #ifdef __cplusplus
2067 
2088  lfModifier (const lfLens *lens, float crop, int width, int height);
2089  ~lfModifier ();
2090 
2117  DEPRECATED static lfModifier *Create (const lfLens *lens, float crop, int width, int height);
2118 
2164  int Initialize (
2165  const lfLens *lens, lfPixelFormat format, float focal, float aperture,
2166  float distance, float scale, lfLensType targeom, int flags, bool reverse);
2167 
2195  cbool EnableScaleRotateShift (
2196  float scale, float angle, float shift_x, float shift_y);
2197 
2204  DEPRECATED void Destroy ();
2205 
2222  void AddCoordCallback (lfModifyCoordFunc callback, int priority,
2223  void *data, size_t data_size);
2224 
2242  void AddSubpixelCallback (lfSubpixelCoordFunc callback, int priority,
2243  void *data, size_t data_size);
2244 
2261  void AddColorCallback (lfModifyColorFunc callback, int priority,
2262  void *data, size_t data_size);
2263 
2278  bool AddSubpixelCallbackTCA (lfLensCalibTCA &model, bool reverse = false);
2279 
2294  bool AddColorCallbackVignetting (lfLensCalibVignetting &model, lfPixelFormat format,
2295  bool reverse = false);
2296 
2310  bool AddCoordCallbackDistortion (lfLensCalibDistortion &model, bool reverse = false);
2311 
2326  bool AddCoordCallbackGeometry (lfLensType from, lfLensType to, float focal = 0);
2327 
2344  bool AddCoordCallbackScale (float scale, bool reverse = false);
2345 
2359  float GetAutoScale (bool reverse);
2360 
2390  bool ApplyColorModification (void *pixels, float x, float y, int width, int height,
2391  int comp_role, int row_stride) const;
2392 
2423  bool ApplyGeometryDistortion (float xu, float yu, int width, int height,
2424  float *res) const;
2425 
2457  bool ApplySubpixelDistortion (float xu, float yu, int width, int height,
2458  float *res) const;
2459 
2490  bool ApplySubpixelGeometryDistortion (float xu, float yu, int width, int height,
2491  float *res) const;
2492 
2493 private:
2524  float GetRealFocalLength (const lfLens *lens, float focal);
2525 
2526  void AddCallback (void *arr, lfCallbackData *d,
2527  int priority, void *data, size_t data_size);
2528 
2542  double AutoscaleResidualDistance (float *coord) const;
2557  float GetTransformedDistance (lfPoint point) const;
2558 
2559  static void ModifyCoord_UnTCA_Linear (void *data, float *iocoord, int count);
2560  static void ModifyCoord_TCA_Linear (void *data, float *iocoord, int count);
2561  static void ModifyCoord_UnTCA_Poly3 (void *data, float *iocoord, int count);
2562  static void ModifyCoord_TCA_Poly3 (void *data, float *iocoord, int count);
2563  static void ModifyCoord_TCA_ACM (void *data, float *iocoord, int count);
2564 
2565  static void ModifyCoord_UnDist_Poly3 (void *data, float *iocoord, int count);
2566  static void ModifyCoord_Dist_Poly3 (void *data, float *iocoord, int count);
2567 #ifdef VECTORIZATION_SSE
2568  static void ModifyCoord_Dist_Poly3_SSE (void *data, float *iocoord, int count);
2569 #endif
2570  static void ModifyCoord_UnDist_Poly5 (void *data, float *iocoord, int count);
2571  static void ModifyCoord_Dist_Poly5 (void *data, float *iocoord, int count);
2572  static void ModifyCoord_UnDist_PTLens (void *data, float *iocoord, int count);
2573  static void ModifyCoord_Dist_PTLens (void *data, float *iocoord, int count);
2574 #ifdef VECTORIZATION_SSE
2575  static void ModifyCoord_UnDist_PTLens_SSE (void *data, float *iocoord, int count);
2576  static void ModifyCoord_Dist_PTLens_SSE (void *data, float *iocoord, int count);
2577 #endif
2578  static void ModifyCoord_Dist_ACM (void *data, float *iocoord, int count);
2579  static void ModifyCoord_Geom_FishEye_Rect (void *data, float *iocoord, int count);
2580  static void ModifyCoord_Geom_Panoramic_Rect (void *data, float *iocoord, int count);
2581  static void ModifyCoord_Geom_ERect_Rect (void *data, float *iocoord, int count);
2582  static void ModifyCoord_Geom_Rect_FishEye (void *data, float *iocoord, int count);
2583  static void ModifyCoord_Geom_Panoramic_FishEye (void *data, float *iocoord, int count);
2584  static void ModifyCoord_Geom_ERect_FishEye (void *data, float *iocoord, int count);
2585  static void ModifyCoord_Geom_Rect_Panoramic (void *data, float *iocoord, int count);
2586  static void ModifyCoord_Geom_FishEye_Panoramic (void *data, float *iocoord, int count);
2587  static void ModifyCoord_Geom_ERect_Panoramic (void *data, float *iocoord, int count);
2588  static void ModifyCoord_Geom_Rect_ERect (void *data, float *iocoord, int count);
2589  static void ModifyCoord_Geom_FishEye_ERect (void *data, float *iocoord, int count);
2590  static void ModifyCoord_Geom_Panoramic_ERect (void *data, float *iocoord, int count);
2591  static void ModifyCoord_Geom_Orthographic_ERect (void *data, float *iocoord, int count);
2592  static void ModifyCoord_Geom_ERect_Orthographic (void *data, float *iocoord, int count);
2593  static void ModifyCoord_Geom_Stereographic_ERect (void *data, float *iocoord, int count);
2594  static void ModifyCoord_Geom_ERect_Stereographic (void *data, float *iocoord, int count);
2595  static void ModifyCoord_Geom_Equisolid_ERect (void *data, float *iocoord, int count);
2596  static void ModifyCoord_Geom_ERect_Equisolid (void *data, float *iocoord, int count);
2597  static void ModifyCoord_Geom_Thoby_ERect (void *data, float *iocoord, int count);
2598  static void ModifyCoord_Geom_ERect_Thoby (void *data, float *iocoord, int count);
2599 #ifdef VECTORIZATION_SSE
2600  static void ModifyColor_DeVignetting_PA_SSE (
2601  void *data, float _x, float _y, lf_f32 *pixels, int comp_role, int count);
2602 #endif
2603 #ifdef VECTORIZATION_SSE2
2604  static void ModifyColor_DeVignetting_PA_SSE2 (
2605  void *data, float _x, float _y, lf_u16 *pixels, int comp_role, int count);
2606 #endif
2607 
2608  template<typename T> static void ModifyColor_Vignetting_PA (
2609  void *data, float x, float y, T *rgb, int comp_role, int count);
2610  template<typename T> static void ModifyColor_DeVignetting_PA (
2611  void *data, float x, float y, T *rgb, int comp_role, int count);
2612 
2613  static void ModifyCoord_Scale (void *data, float *iocoord, int count);
2614  static void ModifyCoord_LinearMap (void *data, float *iocoord, int count);
2615  static void ModifyCoord_Affinity (void *data, float *iocoord, int count);
2616 #endif
2617  double Width, Height;
2621  double CenterX, CenterY;
2623  double NormScale, NormUnScale;
2627  double NormalizedInMillimeters;
2630  double NormalizedInFocalLengths;
2633  double AspectRatioCorrection;
2634 
2636  void *SubpixelCallbacks;
2638  void *ColorCallbacks;
2640  void *CoordCallbacks;
2641 
2643  double MaxX, MaxY;
2645  bool Reverse;
2646  // Crop factor of the sensor (not any calibration)
2647  float Crop;
2648 };
2649 
2650 #ifdef __cplusplus
2651 extern "C" {
2652 #endif
2653 
2654 C_TYPEDEF (struct, lfModifier)
2655 
2656 
2658  const lfLens *lens, float crop, int width, int height);
2659 
2661 LF_EXPORT void lf_modifier_destroy (lfModifier *modifier);
2662 
2665  lfModifier *modifier, const lfLens *lens, lfPixelFormat format,
2666  float focal, float aperture, float distance, float scale,
2667  lfLensType targeom, int flags, cbool reverse);
2668 
2671  lfModifier *modifier, lfModifyCoordFunc callback, int priority,
2672  void *data, size_t data_size);
2673 
2676  lfModifier *modifier, lfSubpixelCoordFunc callback, int priority,
2677  void *data, size_t data_size);
2678 
2681  lfModifier *modifier, lfModifyColorFunc callback, int priority,
2682  void *data, size_t data_size);
2683 
2686  lfModifier *modifier, lfLensCalibTCA *model, cbool reverse);
2687 
2690  lfModifier *modifier, lfLensCalibVignetting *model,
2691  lfPixelFormat format, cbool reverse);
2692 
2695  lfModifier *modifier, lfLensCalibDistortion *model, cbool reverse);
2696 
2699  lfModifier *modifier, lfLensType from, lfLensType to);
2700 
2703  lfModifier *modifier, float scale, cbool reverse);
2704 
2707  lfModifier *modifier, cbool reverse);
2708 
2711  lfModifier *modifier, float xu, float yu, int width, int height, float *res);
2712 
2715  lfModifier *modifier, void *pixels, float x, float y, int width, int height,
2716  int comp_role, int row_stride);
2717 
2720  lfModifier *modifier, float xu, float yu, int width, int height, float *res);
2721 
2724  lfModifier *modifier, float xu, float yu, int width, int height, float *res);
2725 
2728 #undef cbool
2729 
2730 #ifdef __cplusplus
2731 }
2732 #endif
2733 
2734 #endif /* __LENSFUN_H__ */
Panoramic (cylindrical)
Definition: lensfun.h:821
lfError lf_db_load_file(lfDatabase *db, const char *filename)
lfDistortionModel
The Lensfun library implements several lens distortion models. This enum lists them.
Definition: lensfun.h:466
float MinAperture
Definition: lensfun.h:865
Definition: lensfun.h:1835
Definition: lensfun.h:1864
cbool lf_modifier_apply_subpixel_geometry_distortion(lfModifier *modifier, float xu, float yu, int width, int height, float *res)
Adobe Camera Model. The coordinate system is different here. Everything is measured in units of the f...
Definition: lensfun.h:511
unsigned int lf_u32
Definition: lensfun.h:128
void lf_lens_add_calib_tca(lfLens *lens, const lfLensCalibTCA *tcac)
const lfCamera ** lf_db_find_cameras(const lfDatabase *db, const char *maker, const char *model)
DEPRECATED void lf_lens_add_calib_fov(lfLens *lens, const lfLensCalibFov *cf)
lfMLstr Maker
Definition: lensfun.h:857
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)
lfLensCalibDistortion ** CalibDistortion
Definition: lensfun.h:889
float FieldOfView
Field of view for given images.
Definition: lensfun.h:751
Rectilinear lens.
Definition: lensfun.h:808
Definition: lensfun.h:1820
lfLensType Type
Definition: lensfun.h:887
This flag makes Lensfun to sort the results by focal length, and remove all double lens names...
Definition: lensfun.h:1392
char ** Compat
Definition: lensfun.h:210
lfLensCalibVignetting ** CalibVignetting
Definition: lensfun.h:893
char * UserUpdatesDir
Home lens database directory for automatic updates (something like "~/.local/share/lensfun/updates") ...
Definition: lensfun.h:1420
no crop at all
Definition: lensfun.h:700
Definition: lensfun.h:1841
Definition: lensfun.h:1833
5th order polynomial model.
Definition: lensfun.h:486
lfError
Definition: lensfun.h:111
const char * lf_get_distortion_model_desc(enum lfDistortionModel model, const char **details, const lfParameter ***params)
void lf_lens_guess_parameters(lfLens *lens)
float CenterX
Definition: lensfun.h:879
float CropFactor
Definition: lensfun.h:883
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:683
Laterlal chromatic aberrations calibration data.
Definition: lensfun.h:614
Definition: lensfun.h:118
Lens distortion calibration data.
Definition: lensfun.h:522
void lf_modifier_add_subpixel_callback(lfModifier *modifier, lfSubpixelCoordFunc callback, int priority, void *data, size_t data_size)
double lf_f64
Definition: lensfun.h:132
cbool lf_modifier_add_color_callback_vignetting(lfModifier *modifier, lfLensCalibVignetting *model, lfPixelFormat format, cbool reverse)
void lf_modifier_add_coord_callback(lfModifier *modifier, lfModifyCoordFunc callback, int priority, void *data, size_t data_size)
void lf_lens_copy(lfLens *dest, const lfLens *source)
Copy the data from one lfLens structure into another.
void lf_mount_destroy(lfMount *mount)
Destroy a lfMount object.
cbool lf_lens_remove_calib_tca(lfLens *lens, int idx)
cbool lf_lens_remove_calib_vignetting(lfLens *lens, int idx)
Lens data. Unknown fields are set to NULL or 0.
Definition: lensfun.h:854
cbool lf_lens_interpolate_distortion(const lfLens *lens, float focal, lfLensCalibDistortion *res)
lfPixelFormat
A list of pixel formats supported by internal colour callbacks.
Definition: lensfun.h:1830
Definition: lensfun.h:1824
float AspectRatio
Definition: lensfun.h:885
lfVignettingModel
The Lensfun library supports several models for lens vignetting correction.
Definition: lensfun.h:642
lfLensCalibTCA ** CalibTCA
Definition: lensfun.h:891
float CenterY
Definition: lensfun.h:881
Adobe camera model for TCA. The coordinate system is different here. Everything is measured in units ...
Definition: lensfun.h:602
cbool lf_modifier_add_coord_callback_scale(lfModifier *modifier, float scale, cbool reverse)
This structure contains everything specific to a camera mount.
Definition: lensfun.h:201
float MinFocal
Definition: lensfun.h:861
const char * lf_db_mount_name(const lfDatabase *db, const char *mount)
Stereographic fisheye.
Definition: lensfun.h:832
int Score
Definition: lensfun.h:901
Linear lateral chromatic aberrations model.
Definition: lensfun.h:562
Third order polynomial.
Definition: lensfun.h:574
Definition: lensfun.h:1822
use a circular crop, e.g. for circular fisheye images
Definition: lensfun.h:704
#define cbool
C-compatible bool type; don't bother to define Yet Another Boolean Type.
Definition: lensfun.h:98
lfMLstr Model
Definition: lensfun.h:859
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:715
cbool lf_modifier_apply_subpixel_distortion(lfModifier *modifier, float xu, float yu, int width, int height, float *res)
const lfLens ** lf_db_find_lenses_hd(const lfDatabase *db, const lfCamera *camera, const char *maker, const char *lens, int sflags)
int Score
Camera matching score, used while searching: not actually a camera parameter.
Definition: lensfun.h:331
void lf_free(void *data)
cbool lf_mount_check(lfMount *mount)
float lf_modifier_get_auto_scale(lfModifier *modifier, cbool reverse)
Orthographic fisheye.
Definition: lensfun.h:830
const lfCamera *const * lf_db_get_cameras(const lfDatabase *db)
lfModifier * lf_modifier_new(const lfLens *lens, float crop, int width, int height)
lfLensType
Lens type. See Change of projection for further information.
Definition: lensfun.h:800
Definition: lensfun.h:1817
cbool lf_lens_remove_calib_crop(lfLens *lens, int idx)
float Focal
Definition: lensfun.h:763
PTLens model, which is also used by Hugin.
Definition: lensfun.h:494
Definition: lensfun.h:1866
3rd order polynomial model, which is a subset of the PTLens model.
Definition: lensfun.h:477
use a rectangular crop
Definition: lensfun.h:702
const char * lf_get_tca_model_desc(enum lfTCAModel model, const char **details, const lfParameter ***params)
cbool lf_modifier_add_subpixel_callback_TCA(lfModifier *modifier, lfLensCalibTCA *model, cbool reverse)
const lfMount * lf_db_find_mount(const lfDatabase *db, const char *mount)
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:1921
#define C_TYPEDEF(t, c)
Definition: lensfun.h:30
Equisolid fisheye.
Definition: lensfun.h:834
Fisheye as measured by Thoby (for Nikkor 10.5).
Definition: lensfun.h:840
const lfMount *const * lf_db_get_mounts(const lfDatabase *db)
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:619
cbool lf_lens_interpolate_crop(const lfLens *lens, float focal, lfLensCalibCrop *res)
Definition: lensfun.h:1868
unsigned char lf_u8
Definition: lensfun.h:124
Definition: lensfun.h:1870
#define LF_EXPORT
This macro expands to an appropiate symbol visibility declaration.
Definition: lensfun.h:64
void lf_camera_destroy(lfCamera *camera)
Destroy a lfCamera object.
lfLens * lf_lens_new()
Create a new lens object.
float Min
Minimal value that has sense.
Definition: lensfun.h:788
float Max
Maximal value that has sense.
Definition: lensfun.h:790
Unknown lens type.
Definition: lensfun.h:803
Struct to save real focal length, which can depends on the (nominal) focal length.
Definition: lensfun.h:760
cbool lf_modifier_apply_color_modification(lfModifier *modifier, void *pixels, float x, float y, int width, int height, int comp_role, int row_stride)
const lfCamera ** lf_db_find_cameras_ext(const lfDatabase *db, const char *maker, const char *model, int sflags)
float RealFocal
Real focal length.
Definition: lensfun.h:775
A modifier object contains optimized data required to rectify a image.
Definition: lensfun.h:2064
cbool lf_camera_check(lfCamera *camera)
Definition: lensfun.h:1855
float CropFactor
Camera crop factor (ex: 1.0). Must be defined.
Definition: lensfun.h:329
const char * lf_mlstr_get(const lfMLstr str)
Get a string corresponding to current locale from a multi-language string.
void lf_camera_copy(lfCamera *dest, const lfCamera *source)
Copy the data from one lfCamera structure into another.
Definition: lensfun.h:116
This flag selects a looser search algorithm resulting in more results (still sorted by score)...
Definition: lensfun.h:1380
float Distance
Focus distance in meters.
Definition: lensfun.h:687
void lf_lens_add_calib_distortion(lfLens *lens, const lfLensCalibDistortion *dc)
void lf_modifier_destroy(lfModifier *modifier)
float Aperture
Aperture (f-number) at which this calibration data was taken.
Definition: lensfun.h:685
#define DEPRECATED
For marking deprecated functions, see http://stackoverflow.com/a/21265197.
Definition: lensfun.h:91
Definition: lensfun.h:1872
cbool lf_modifier_apply_geometry_distortion(lfModifier *modifier, float xu, float yu, int width, int height, float *res)
lfCamera * lf_camera_new()
Create a new camera object.
float MaxFocal
Definition: lensfun.h:863
Definition: lensfun.h:1815
void lf_mount_copy(lfMount *dest, const lfMount *source)
Copy the data from one lfMount structure into another.
unsigned short lf_u16
Definition: lensfun.h:126
lfComponentRole
These constants define the role of every pixel component, four bits each. "pixel" refers here to a se...
Definition: lensfun.h:1849
const char * lf_get_lens_type_desc(enum lfLensType type, const char **details)
char ** Mounts
Definition: lensfun.h:869
Equirectangular.
Definition: lensfun.h:828
Definition: lensfun.h:1862
float Focal
Focal length in mm at which this calibration data was taken.
Definition: lensfun.h:527
float Focal
Definition: lensfun.h:741
cbool lf_lens_interpolate_tca(const lfLens *lens, float focal, lfLensCalibTCA *res)
void lf_lens_destroy(lfLens *lens)
Destroy a lfLens object.
Definition: lensfun.h:1826
const lfLens ** lf_db_find_lenses(const lfDatabase *db, const lfLens *lens, int sflags)
void lf_db_destroy(lfDatabase *db)
Destroy the database object.
Equidistant fisheye.
Definition: lensfun.h:814
lfError lf_db_load_data(lfDatabase *db, const char *errcontext, const char *data, size_t data_size)
void lf_modifier_add_color_callback(lfModifier *modifier, lfModifyColorFunc callback, int priority, void *data, size_t data_size)
Definition: lensfun.h:1837
No TCA correction data is known.
Definition: lensfun.h:550
lfMLstr Model
Model name (ex: "Rolleiflex SL35") – same as in EXIF.
Definition: lensfun.h:323
const char * lf_get_crop_desc(enum lfCropMode mode, const char **details, const lfParameter ***params)
lfLensCalibFov ** CalibFov
Definition: lensfun.h:897
lfMLstr Maker
Camera maker (ex: "Rollei") – same as in EXIF.
Definition: lensfun.h:321
DEPRECATED cbool lf_lens_remove_calib_fov(lfLens *lens, int idx)
Definition: lensfun.h:114
lfDatabase * lf_db_new(void)
Create a new empty database object.
cbool lf_lens_check(lfLens *lens)
const char * lf_get_vignetting_model_desc(enum lfVignettingModel model, const char **details, const lfParameter ***params)
char * Mount
Camera mount type (ex: "QBM")
Definition: lensfun.h:327
char * lfMLstr
Definition: lensfun.h:108
A lens database object.
Definition: lensfun.h:1414
cbool lf_lens_interpolate_real_focal(const lfLens *lens, float focal, lfLensCalibRealFocal *res)
void lf_lens_add_calib_crop(lfLens *lens, const lfLensCalibCrop *cc)
const lfLens *const * lf_db_get_lenses(const lfDatabase *db)
Pablo D'Angelo vignetting model (which is a more general variant of the law).
Definition: lensfun.h:655
Distortion parameters are unknown.
Definition: lensfun.h:469
lfMLstr Name
Camera mount name.
Definition: lensfun.h:208
Lens vignetting calibration data.
Definition: lensfun.h:678
cbool lf_lens_remove_calib_real_focal(lfLens *lens, int idx)
float lf_f32
Definition: lensfun.h:130
DEPRECATED cbool lf_lens_interpolate_fov(const lfLens *lens, float focal, lfLensCalibFov *res)
lfMLstr lf_mlstr_add(lfMLstr str, const char *lang, const char *trstr)
Add a new translated string to a multi-language string.
No vignetting correction data is known.
Definition: lensfun.h:645
void lf_lens_add_calib_vignetting(lfLens *lens, const lfLensCalibVignetting *vc)
lfError lf_db_save_all(const lfDatabase *db, const char *filename)
cbool lf_lens_interpolate_vignetting(const lfLens *lens, float focal, float aperture, float distance, lfLensCalibVignetting *res)
lfTCAModel
The Lensfun library supports several models for lens lateral chromatic aberrations (also called trans...
Definition: lensfun.h:547
cbool lf_modifier_add_coord_callback_distortion(lfModifier *modifier, lfLensCalibDistortion *model, cbool reverse)
float Default
Default value for the parameter.
Definition: lensfun.h:792
Adobe's vignetting model. It differs from D'Angelo's model only in the coordinate system...
Definition: lensfun.h:666
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:1947
void lf_lens_add_calib_real_focal(lfLens *lens, const lfLensCalibRealFocal *cf)
lfMount * lf_mount_new()
Create a new mount object.
lfCropMode
Different crop modes.
Definition: lensfun.h:697
Struct to save calibrated field of view, which can depends on the focal length (DEPRECATED) ...
Definition: lensfun.h:738
lfLensCalibCrop ** CalibCrop
Definition: lensfun.h:895
Camera data. Unknown fields are set to NULL.
Definition: lensfun.h:318
char * lf_db_save(const lfMount *const *mounts, const lfCamera *const *cameras, const lfLens *const *lenses)
lfMLstr lf_mlstr_dup(const lfMLstr str)
Create a complete copy of a multi-language string.
lfMLstr Variant
Camera variant. Some cameras use same EXIF id for different models.
Definition: lensfun.h:325
void(* lfModifyCoordFunc)(void *data, float *iocoord, int count)
A callback function which modifies the coordinates of a strip of pixels.
Definition: lensfun.h:1962
Struct to save image crop, which can depend on the focal length.
Definition: lensfun.h:712
cbool lf_modifier_add_coord_callback_geometry(lfModifier *modifier, lfLensType from, lfLensType to)
Definition: lensfun.h:1839
lfError lf_db_save_file(const lfDatabase *db, const char *filename, const lfMount *const *mounts, const lfCamera *const *cameras, const lfLens *const *lenses)
const char * Name
Parameter name (something like 'k', 'k3', 'omega' etc.)
Definition: lensfun.h:786
This structure describes a single parameter for some lens model.
Definition: lensfun.h:783
lfError lf_db_load(lfDatabase *db)
cbool lf_lens_remove_calib_distortion(lfLens *lens, int idx)
char * HomeDataDir
Home lens database directory (something like "~/.local/share/lensfun")
Definition: lensfun.h:1417
cbool lf_db_load_directory(lfDatabase *db, const char *dirname)
lfLensCalibRealFocal ** CalibRealFocal
Definition: lensfun.h:899
float MaxAperture
Definition: lensfun.h:867