lensfun  0.3.2.0
lensfun.h
Go to the documentation of this file.
00001 /* -*- mode:c++ -*- */
00002 /*
00003     Lensfun - a library for maintaining a database of photographical lenses,
00004     and providing the means to correct some of the typical lens distortions.
00005     Copyright (C) 2007 by Andrew Zabolotny
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public
00018     License along with this library; if not, write to the Free
00019     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 
00022 #ifndef __LENSFUN_H__
00023 #define __LENSFUN_H__
00024 
00025 #include <stddef.h>
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00030 #  define C_TYPEDEF(t,c)
00031 #else
00032 #  define C_TYPEDEF(t,c) typedef t c c;
00033 #endif
00034 
00040 /*----------------------------------------------------------------------------*/
00041 
00048 
00049 #define LF_VERSION_MAJOR        0
00050 
00051 #define LF_VERSION_MINOR        3
00052 
00053 #define LF_VERSION_MICRO        2
00054 
00055 #define LF_VERSION_BUGFIX       0
00056 
00057 #define LF_VERSION      ((LF_VERSION_MAJOR << 24) | (LF_VERSION_MINOR << 16) | (LF_VERSION_MICRO << 8) | LF_VERSION_BUGFIX)
00058 
00060 #define LF_MAX_DATABASE_VERSION 1
00061 
00062 #if defined CONF_LENSFUN_STATIC
00063 
00064 #   define LF_EXPORT
00065 #else
00066 #   ifdef CONF_SYMBOL_VISIBILITY
00067 #       if defined PLATFORM_WINDOWS
00068 #           define LF_EXPORT    __declspec(dllexport)
00069 #       elif defined CONF_COMPILER_GCC || __clang__
00070 #           define LF_EXPORT    __attribute__((visibility("default")))
00071 #       else
00072 #           error "I don't know how to change symbol visibility for your compiler"
00073 #       endif
00074 #   else
00075 #       if defined PLATFORM_WINDOWS || defined _MSC_VER
00076 #           define LF_EXPORT    __declspec(dllimport)
00077 #       else
00078 #           define LF_EXPORT
00079 #       endif
00080 #   endif
00081 #endif
00082 
00083 #ifndef CONF_LENSFUN_INTERNAL
00084 
00085 #    ifdef __GNUC__
00086 #        define DEPRECATED __attribute__((deprecated))
00087 #    elif defined(_MSC_VER)
00088 #        define DEPRECATED __declspec(deprecated)
00089 #    else
00090 #        pragma message("WARNING: You need to implement DEPRECATED for this compiler")
00091 #        define DEPRECATED
00092 #    endif
00093 #else
00094 #    define DEPRECATED
00095 #endif
00096 
00098 #define cbool int
00099 
00108 typedef char *lfMLstr;
00109 
00111 enum lfError
00112 {
00114     LF_NO_ERROR = 0,
00116     LF_WRONG_FORMAT,
00118     LF_NO_DATABASE
00119 };
00120 
00121 C_TYPEDEF (enum, lfError)
00122 
00123 
00124 typedef unsigned char lf_u8;
00126 typedef unsigned short lf_u16;
00128 typedef unsigned int lf_u32;
00130 typedef float lf_f32;
00132 typedef double lf_f64;
00133 
00142 LF_EXPORT void lf_free (void *data);
00143 
00152 LF_EXPORT const char *lf_mlstr_get (const lfMLstr str);
00153 
00170 LF_EXPORT lfMLstr lf_mlstr_add (lfMLstr str, const char *lang, const char *trstr);
00171 
00180 LF_EXPORT lfMLstr lf_mlstr_dup (const lfMLstr str);
00181 
00184 /*----------------------------------------------------------------------------*/
00185 
00201 struct LF_EXPORT lfMount
00202 {
00208     lfMLstr Name;
00210     char **Compat;
00211 
00212 #ifdef __cplusplus
00213 
00216     lfMount ();
00217 
00221     lfMount &operator = (const lfMount &other);
00222 
00226     ~lfMount ();
00227 
00238     void SetName (const char *val, const char *lang = NULL);
00239 
00245     void AddCompat (const char *val);
00246 
00252     bool Check ();
00253 #endif
00254 };
00255 
00256 C_TYPEDEF (struct, lfMount)
00257 
00258 
00265 LF_EXPORT lfMount *lf_mount_new ();
00266 
00276 LF_EXPORT void lf_mount_destroy (lfMount *mount);
00277 
00287 LF_EXPORT void lf_mount_copy (lfMount *dest, const lfMount *source);
00288 
00290 LF_EXPORT cbool lf_mount_check (lfMount *mount);
00291 
00294 /*----------------------------------------------------------------------------*/
00295 
00313 struct LF_EXPORT lfCamera
00314 {
00316     lfMLstr Maker;
00318     lfMLstr Model;
00320     lfMLstr Variant;
00322     char *Mount;
00324     float CropFactor;
00326     int Score;
00327 
00328 #ifdef __cplusplus
00329 
00332     lfCamera ();
00333 
00337     lfCamera (const lfCamera &other);
00338 
00342     ~lfCamera ();
00343 
00347     lfCamera &operator = (const lfCamera &other);
00348 
00359     void SetMaker (const char *val, const char *lang = NULL);
00360 
00371     void SetModel (const char *val, const char *lang = NULL);
00372 
00383     void SetVariant (const char *val, const char *lang = NULL);
00384 
00390     void SetMount (const char *val);
00391 
00397     bool Check ();
00398 #endif
00399 };
00400 
00401 C_TYPEDEF (struct, lfCamera)
00402 
00403 
00410 LF_EXPORT lfCamera *lf_camera_new ();
00411 
00421 LF_EXPORT void lf_camera_destroy (lfCamera *camera);
00422 
00432 LF_EXPORT void lf_camera_copy (lfCamera *dest, const lfCamera *source);
00433 
00435 LF_EXPORT cbool lf_camera_check (lfCamera *camera);
00436 
00439 /*----------------------------------------------------------------------------*/
00440 
00461 enum lfDistortionModel
00462 {
00464     LF_DIST_MODEL_NONE,
00472     LF_DIST_MODEL_POLY3,
00481     LF_DIST_MODEL_POLY5,
00489     LF_DIST_MODEL_PTLENS,
00490 };
00491 
00492 C_TYPEDEF (enum, lfDistortionModel)
00493 
00494 
00500 struct lfLensCalibDistortion
00501 {
00503     enum lfDistortionModel Model;
00505     float Focal;
00507     float Terms [3];
00508 };
00509 
00510 C_TYPEDEF (struct, lfLensCalibDistortion)
00511 
00512 
00525 enum lfTCAModel
00526 {
00528     LF_TCA_MODEL_NONE,
00540     LF_TCA_MODEL_LINEAR,
00541 
00553     LF_TCA_MODEL_POLY3
00554 };
00555 
00556 C_TYPEDEF (enum, lfTCAModel)
00557 
00558 
00565 struct lfLensCalibTCA
00566 {
00568     enum lfTCAModel Model;
00570     float Focal;
00572     float Terms [6];
00573 };
00574 
00575 C_TYPEDEF (struct, lfLensCalibTCA)
00576 
00577 
00593 enum lfVignettingModel
00594 {
00596     LF_VIGNETTING_MODEL_NONE,
00606     LF_VIGNETTING_MODEL_PA
00607 };
00608 
00609 C_TYPEDEF (enum, lfVignettingModel)
00610 
00611 
00618 struct lfLensCalibVignetting
00619 {
00621     enum lfVignettingModel Model;
00623     float Focal;
00625     float Aperture;
00627     float Distance;
00629     float Terms [3];
00630 };
00631 
00632 C_TYPEDEF (struct, lfLensCalibVignetting)
00633 
00634 
00637 enum lfCropMode
00638 {
00640     LF_NO_CROP,
00642     LF_CROP_RECTANGLE,
00644     LF_CROP_CIRCLE
00645 };
00646 
00647 C_TYPEDEF(enum, lfCropMode)
00648 
00649 
00652 struct lfLensCalibCrop
00653 {
00655     float Focal;
00657     enum lfCropMode CropMode;
00666     float Crop [4];
00667 };
00668 
00669 C_TYPEDEF (struct, lfLensCalibCrop)
00670 
00671 
00678 struct lfLensCalibFov
00679 {
00681     float Focal;
00691     float FieldOfView;
00692 };
00693 
00694 C_TYPEDEF (struct, lfLensCalibFov)
00695 
00696 
00700 struct lfLensCalibRealFocal
00701 {
00703     float Focal;
00715     float RealFocal;
00716 };
00717 
00718 C_TYPEDEF (struct, lfLensCalibRealFocal)
00719 
00720 
00723 struct lfParameter
00724 {
00726     const char *Name;
00728     float Min;
00730     float Max;
00732     float Default;
00733 };
00734 
00735 C_TYPEDEF (struct, lfParameter)
00736 
00737 
00740 enum lfLensType
00741 {
00743     LF_UNKNOWN,
00748     LF_RECTILINEAR,
00754     LF_FISHEYE,
00761     LF_PANORAMIC,
00768     LF_EQUIRECTANGULAR,
00770     LF_FISHEYE_ORTHOGRAPHIC,
00772     LF_FISHEYE_STEREOGRAPHIC,
00774     LF_FISHEYE_EQUISOLID,
00780     LF_FISHEYE_THOBY
00781 };
00782 
00783 C_TYPEDEF (enum, lfLensType)
00784 
00785 
00795 struct LF_EXPORT lfLens
00796 {
00798     lfMLstr Maker;
00800     lfMLstr Model;
00802     float MinFocal;
00804     float MaxFocal;
00806     float MinAperture;
00808     float MaxAperture;
00810     char **Mounts;
00820     float CenterX;
00822     float CenterY;
00824     float CropFactor;
00826     float AspectRatio;
00828     lfLensType Type;
00830     lfLensCalibDistortion **CalibDistortion;
00832     lfLensCalibTCA **CalibTCA;
00834     lfLensCalibVignetting **CalibVignetting;
00836     lfLensCalibCrop **CalibCrop;
00838     lfLensCalibFov **CalibFov;
00840     lfLensCalibRealFocal **CalibRealFocal;
00842     int Score;
00843 
00844 #ifdef __cplusplus
00845 
00848     lfLens ();
00849 
00853     lfLens (const lfLens &other);
00854 
00858     ~lfLens ();
00859 
00863     lfLens &operator = (const lfLens &other);
00864 
00875     void SetMaker (const char *val, const char *lang = NULL);
00876 
00887     void SetModel (const char *val, const char *lang = NULL);
00888 
00896     void AddMount (const char *val);
00897 
00906     void AddCalibDistortion (const lfLensCalibDistortion *dc);
00907 
00913     bool RemoveCalibDistortion (int idx);
00914 
00924     void AddCalibTCA (const lfLensCalibTCA *tcac);
00925 
00931     bool RemoveCalibTCA (int idx);
00932 
00941     void AddCalibVignetting (const lfLensCalibVignetting *vc);
00942 
00948     bool RemoveCalibVignetting (int idx);
00949 
00958     void AddCalibCrop (const lfLensCalibCrop *cc);
00959 
00965     bool RemoveCalibCrop (int idx);
00966 
00978     DEPRECATED void AddCalibFov (const lfLensCalibFov *cf);
00979 
00989     DEPRECATED bool RemoveCalibFov (int idx);
00990 
00999     void AddCalibRealFocal (const lfLensCalibRealFocal *cf);
01000 
01007     bool RemoveCalibRealFocal (int idx);
01008 
01017     void GuessParameters ();
01018 
01024     bool Check ();
01025 
01041     static const char *GetDistortionModelDesc (
01042         lfDistortionModel model, const char **details, const lfParameter ***params);
01058     static const char *GetTCAModelDesc (
01059         lfTCAModel model, const char **details, const lfParameter ***params);
01060 
01076     static const char *GetVignettingModelDesc (
01077         lfVignettingModel model, const char **details, const lfParameter ***params);
01078 
01094     static const char *GetCropDesc (
01095         lfCropMode mode, const char **details, const lfParameter ***params);
01096 
01108     static const char *GetLensTypeDesc (lfLensType type, const char **details);
01109 
01117     bool InterpolateDistortion (float focal, lfLensCalibDistortion &res) const;
01118 
01126     bool InterpolateTCA (float focal, lfLensCalibTCA &res) const;
01127 
01141     bool InterpolateVignetting (
01142         float focal, float aperture, float distance, lfLensCalibVignetting &res) const;
01143 
01151     bool InterpolateCrop (float focal, lfLensCalibCrop &res) const;
01152 
01164     DEPRECATED bool InterpolateFov (float focal, lfLensCalibFov &res) const;
01165 
01177     bool InterpolateRealFocal (float focal, lfLensCalibRealFocal &res) const;
01178 #endif
01179 };
01180 
01181 C_TYPEDEF (struct, lfLens)
01182 
01183 
01190 LF_EXPORT lfLens *lf_lens_new ();
01191 
01201 LF_EXPORT void lf_lens_destroy (lfLens *lens);
01202 
01212 LF_EXPORT void lf_lens_copy (lfLens *dest, const lfLens *source);
01213 
01215 LF_EXPORT cbool lf_lens_check (lfLens *lens);
01216 
01218 LF_EXPORT void lf_lens_guess_parameters (lfLens *lens);
01219 
01221 LF_EXPORT const char *lf_get_distortion_model_desc (
01222     enum lfDistortionModel model, const char **details, const lfParameter ***params);
01223 
01225 LF_EXPORT const char *lf_get_tca_model_desc (
01226     enum lfTCAModel model, const char **details, const lfParameter ***params);
01227 
01229 LF_EXPORT const char *lf_get_vignetting_model_desc (
01230     enum lfVignettingModel model, const char **details, const lfParameter ***params);
01231 
01233 LF_EXPORT const char *lf_get_crop_desc (
01234     enum lfCropMode mode, const char **details, const lfParameter ***params);
01235 
01237 LF_EXPORT const char *lf_get_lens_type_desc (
01238     enum lfLensType type, const char **details);
01239 
01241 LF_EXPORT cbool lf_lens_interpolate_distortion (const lfLens *lens, float focal,
01242     lfLensCalibDistortion *res);
01243 
01245 LF_EXPORT cbool lf_lens_interpolate_tca (const lfLens *lens, float focal, lfLensCalibTCA *res);
01246 
01248 LF_EXPORT cbool lf_lens_interpolate_vignetting (const lfLens *lens, float focal, float aperture,
01249     float distance, lfLensCalibVignetting *res);
01250 
01252 LF_EXPORT cbool lf_lens_interpolate_crop (const lfLens *lens, float focal,
01253     lfLensCalibCrop *res);
01254 
01256 DEPRECATED LF_EXPORT cbool lf_lens_interpolate_fov (const lfLens *lens, float focal,
01257     lfLensCalibFov *res);
01258 
01260 LF_EXPORT cbool lf_lens_interpolate_real_focal (const lfLens *lens, float focal,
01261     lfLensCalibRealFocal *res);
01262 
01264 LF_EXPORT void lf_lens_add_calib_distortion (lfLens *lens, const lfLensCalibDistortion *dc);
01265 
01267 LF_EXPORT cbool lf_lens_remove_calib_distortion (lfLens *lens, int idx);
01268 
01270 LF_EXPORT void lf_lens_add_calib_tca (lfLens *lens, const lfLensCalibTCA *tcac);
01271 
01273 LF_EXPORT cbool lf_lens_remove_calib_tca (lfLens *lens, int idx);
01274 
01276 LF_EXPORT void lf_lens_add_calib_vignetting (lfLens *lens, const lfLensCalibVignetting *vc);
01277 
01279 LF_EXPORT cbool lf_lens_remove_calib_vignetting (lfLens *lens, int idx);
01280 
01282 LF_EXPORT void lf_lens_add_calib_crop (lfLens *lens, const lfLensCalibCrop *cc);
01283 
01285 LF_EXPORT cbool lf_lens_remove_calib_crop (lfLens *lens, int idx);
01286 
01288 DEPRECATED LF_EXPORT void lf_lens_add_calib_fov (lfLens *lens, const lfLensCalibFov *cf);
01289 
01291 DEPRECATED LF_EXPORT cbool lf_lens_remove_calib_fov (lfLens *lens, int idx);
01292 
01294 LF_EXPORT void lf_lens_add_calib_real_focal (lfLens *lens, const lfLensCalibRealFocal *cf);
01295 
01297 LF_EXPORT cbool lf_lens_remove_calib_real_focal (lfLens *lens, int idx);
01298 
01301 /*----------------------------------------------------------------------------*/
01302 
01312 enum
01313 {
01321     LF_SEARCH_LOOSE = 1,
01333     LF_SEARCH_SORT_AND_UNIQUIFY = 2
01334 };
01335 
01358 struct LF_EXPORT lfDatabase
01359 {
01361     char *HomeDataDir;
01364     char *UserUpdatesDir;
01365 
01366 #ifdef __cplusplus
01367     lfDatabase ();
01368     ~lfDatabase ();
01369 
01373     static lfDatabase *Create ();
01374 
01378     void Destroy ();
01379 
01390     bool LoadDirectory (const char *dirname);
01391 
01399     lfError Load ();
01400 
01413     lfError Load (const char *filename);
01414 
01429     lfError Load (const char *errcontext, const char *data, size_t data_size);
01430 
01438     lfError Save (const char *filename) const;
01439 
01453     lfError Save (const char *filename,
01454                   const lfMount *const *mounts,
01455                   const lfCamera *const *cameras,
01456                   const lfLens *const *lenses) const;
01457 
01470     static char *Save (const lfMount *const *mounts,
01471                        const lfCamera *const *cameras,
01472                        const lfLens *const *lenses);
01473 
01498     const lfCamera **FindCameras (const char *maker, const char *model) const;
01499 
01520     const lfCamera **FindCamerasExt (const char *maker, const char *model,
01521                                      int sflags = 0) const;
01522 
01530     const lfCamera *const *GetCameras () const;
01531 
01569     const lfLens **FindLenses (const lfCamera *camera, const char *maker,
01570                                const char *model, int sflags = 0) const;
01571 
01589     const lfLens **FindLenses (const lfLens *lens, int sflags = 0) const;
01590 
01598     const lfLens *const *GetLenses () const;
01599 
01607     const lfMount *FindMount (const char *mount) const;
01608 
01616     const char *MountName (const char *mount) const;
01617 
01625     const lfMount *const *GetMounts () const;
01626 
01632     void AddMount (lfMount *mount);
01633 
01639     void AddCamera (lfCamera *camera);
01640 
01646     void AddLens (lfLens *lens);
01647 
01648 private:
01649 #endif
01650     void *Mounts;
01651     void *Cameras;
01652     void *Lenses;
01653 };
01654 
01655 C_TYPEDEF (struct, lfDatabase)
01656 
01657 
01667 LF_EXPORT lfDatabase *lf_db_new (void);
01668 
01678 LF_EXPORT void lf_db_destroy (lfDatabase *db);
01679 
01681 LF_EXPORT lfError lf_db_load (lfDatabase *db);
01682 
01684 LF_EXPORT lfError lf_db_load_file (lfDatabase *db, const char *filename);
01685 
01687 LF_EXPORT lfError lf_db_load_data (lfDatabase *db, const char *errcontext,
01688                                    const char *data, size_t data_size);
01689 
01691 LF_EXPORT lfError lf_db_save_all (const lfDatabase *db, const char *filename);
01692 
01694 LF_EXPORT lfError lf_db_save_file (const lfDatabase *db, const char *filename,
01695                                    const lfMount *const *mounts,
01696                                    const lfCamera *const *cameras,
01697                                    const lfLens *const *lenses);
01698 
01700 LF_EXPORT char *lf_db_save (const lfMount *const *mounts,
01701                             const lfCamera *const *cameras,
01702                             const lfLens *const *lenses);
01703 
01705 LF_EXPORT const lfCamera **lf_db_find_cameras (
01706     const lfDatabase *db, const char *maker, const char *model);
01707 
01709 LF_EXPORT const lfCamera **lf_db_find_cameras_ext (
01710     const lfDatabase *db, const char *maker, const char *model, int sflags);
01711 
01713 LF_EXPORT const lfCamera *const *lf_db_get_cameras (const lfDatabase *db);
01714 
01716 LF_EXPORT const lfLens **lf_db_find_lenses_hd (
01717     const lfDatabase *db, const lfCamera *camera, const char *maker,
01718     const char *lens, int sflags);
01719 
01721 LF_EXPORT const lfLens **lf_db_find_lenses (
01722     const lfDatabase *db, const lfLens *lens, int sflags);
01723 
01725 LF_EXPORT const lfLens *const *lf_db_get_lenses (const lfDatabase *db);
01726 
01728 LF_EXPORT const lfMount *lf_db_find_mount (const lfDatabase *db, const char *mount);
01729 
01731 LF_EXPORT const char *lf_db_mount_name (const lfDatabase *db, const char *mount);
01732 
01734 LF_EXPORT const lfMount *const *lf_db_get_mounts (const lfDatabase *db);
01735 
01738 /*----------------------------------------------------------------------------*/
01739 
01748 enum
01749 {
01751     LF_MODIFY_TCA        = 0x00000001,
01753     LF_MODIFY_VIGNETTING = 0x00000002,
01754     /* Value 0x00000004 is deprecated. */
01756     LF_MODIFY_DISTORTION = 0x00000008,
01758     LF_MODIFY_GEOMETRY   = 0x00000010,
01760     LF_MODIFY_SCALE      = 0x00000020,
01762     LF_MODIFY_ALL        = ~0
01763 };
01764 
01766 enum lfPixelFormat
01767 {
01769     LF_PF_U8,
01771     LF_PF_U16,
01773     LF_PF_U32,
01775     LF_PF_F32,
01777     LF_PF_F64
01778 };
01779 
01780 C_TYPEDEF (enum, lfPixelFormat)
01781 
01782 
01785 enum lfComponentRole
01786 {
01791     LF_CR_END = 0,
01798     LF_CR_NEXT,
01800     LF_CR_UNKNOWN,
01802     LF_CR_INTENSITY,
01804     LF_CR_RED,
01806     LF_CR_GREEN,
01808     LF_CR_BLUE
01809 };
01810 
01811 C_TYPEDEF (enum, lfComponentRole)
01812 
01813 
01814 #define LF_CR_1(a)              (LF_CR_ ## a)
01815 
01816 #define LF_CR_2(a,b)            ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4))
01817 
01818 #define LF_CR_3(a,b,c)          ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
01819                                  ((LF_CR_ ## c) << 8))
01820 
01821 #define LF_CR_4(a,b,c,d)        ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
01822                                  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12))
01823 
01824 #define LF_CR_5(a,b,c,d,e)      ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
01825                                  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
01826                                  ((LF_CR_ ## e) << 16))
01827 
01828 #define LF_CR_6(a,b,c,d,e,f)    ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
01829                                  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
01830                                  ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20))
01831 
01832 #define LF_CR_7(a,b,c,d,e,f,g)   ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
01833                                  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
01834                                  ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20) | \
01835                                  ((LF_CR_ ## g) << 24))
01836 
01837 #define LF_CR_8(a,b,c,d,e,f,g,h) ((LF_CR_ ## a) | ((LF_CR_ ## b) << 4) | \
01838                                  ((LF_CR_ ## c) << 8) | ((LF_CR_ ## d) << 12) | \
01839                                  ((LF_CR_ ## e) << 16) | ((LF_CR_ ## f) << 20) | \
01840                                  ((LF_CR_ ## g) << 24) | ((LF_CR_ ## h) << 28))
01841 
01857 typedef void (*lfSubpixelCoordFunc) (void *data, float *iocoord, int count);
01858 
01883 typedef void (*lfModifyColorFunc) (void *data, float x, float y,
01884                                    void *pixels, int comp_role, int count);
01885 
01898 typedef void (*lfModifyCoordFunc) (void *data, float *iocoord, int count);
01899 
01900 // @cond
01901     
01903 struct lfCallbackData
01904 {
01905     int priority;
01906     void *data;
01907     size_t data_size;
01908 };
01909 
01910 // A test point in the autoscale algorithm
01911 typedef struct { float angle, dist; } lfPoint;
01912 
01913 // @endcond
01914 
01994 #ifdef __cplusplus
01995 }
01996 #endif
01997 
01998 struct LF_EXPORT lfModifier
01999 {
02000 #ifdef __cplusplus
02001 
02022     lfModifier (const lfLens *lens, float crop, int width, int height);
02023     ~lfModifier ();
02024 
02048     static lfModifier *Create (const lfLens *lens, float crop, int width, int height);
02049 
02095     int Initialize (
02096         const lfLens *lens, lfPixelFormat format, float focal, float aperture,
02097         float distance, float scale, lfLensType targeom, int flags, bool reverse);
02098 
02104     void Destroy ();
02105 
02122     void AddCoordCallback (lfModifyCoordFunc callback, int priority,
02123                            void *data, size_t data_size);
02124 
02142     void AddSubpixelCallback (lfSubpixelCoordFunc callback, int priority,
02143                               void *data, size_t data_size);
02144 
02161     void AddColorCallback (lfModifyColorFunc callback, int priority,
02162                            void *data, size_t data_size);
02163 
02178     bool AddSubpixelCallbackTCA (lfLensCalibTCA &model, bool reverse = false);
02179 
02194     bool AddColorCallbackVignetting (lfLensCalibVignetting &model, lfPixelFormat format,
02195                                      bool reverse = false);
02196 
02210     bool AddCoordCallbackDistortion (lfLensCalibDistortion &model, bool reverse = false);
02211 
02226     bool AddCoordCallbackGeometry (lfLensType from, lfLensType to, float focal);
02227 
02244     bool AddCoordCallbackScale (float scale, bool reverse = false);
02245 
02259     float GetAutoScale (bool reverse);
02260 
02290     bool ApplyColorModification (void *pixels, float x, float y, int width, int height,
02291                                  int comp_role, int row_stride) const;
02292 
02323     bool ApplyGeometryDistortion (float xu, float yu, int width, int height,
02324                                   float *res) const;
02325 
02357     bool ApplySubpixelDistortion (float xu, float yu, int width, int height,
02358                                   float *res) const;
02359 
02390     bool ApplySubpixelGeometryDistortion (float xu, float yu, int width, int height,
02391                                           float *res) const;
02392 
02393 private:
02424     float GetRealFocalLength (const lfLens *lens, float focal);
02425 
02426     void AddCallback (void *arr, lfCallbackData *d,
02427                       int priority, void *data, size_t data_size);
02428 
02442     double AutoscaleResidualDistance (float *coord) const;
02457     float GetTransformedDistance (lfPoint point) const;
02458 
02459     static void ModifyCoord_UnTCA_Linear (void *data, float *iocoord, int count);
02460     static void ModifyCoord_TCA_Linear (void *data, float *iocoord, int count);
02461     static void ModifyCoord_UnTCA_Poly3 (void *data, float *iocoord, int count);
02462     static void ModifyCoord_TCA_Poly3 (void *data, float *iocoord, int count);
02463 
02464     static void ModifyCoord_UnDist_Poly3 (void *data, float *iocoord, int count);
02465     static void ModifyCoord_Dist_Poly3 (void *data, float *iocoord, int count);
02466 #ifdef VECTORIZATION_SSE
02467     static void ModifyCoord_Dist_Poly3_SSE (void *data, float *iocoord, int count);
02468 #endif
02469     static void ModifyCoord_UnDist_Poly5 (void *data, float *iocoord, int count);
02470     static void ModifyCoord_Dist_Poly5 (void *data, float *iocoord, int count);
02471     static void ModifyCoord_UnDist_PTLens (void *data, float *iocoord, int count);
02472     static void ModifyCoord_Dist_PTLens (void *data, float *iocoord, int count);
02473 #ifdef VECTORIZATION_SSE
02474     static void ModifyCoord_UnDist_PTLens_SSE (void *data, float *iocoord, int count);
02475     static void ModifyCoord_Dist_PTLens_SSE (void *data, float *iocoord, int count);
02476 #endif
02477     static void ModifyCoord_Geom_FishEye_Rect (void *data, float *iocoord, int count);
02478     static void ModifyCoord_Geom_Panoramic_Rect (void *data, float *iocoord, int count);
02479     static void ModifyCoord_Geom_ERect_Rect (void *data, float *iocoord, int count);
02480     static void ModifyCoord_Geom_Rect_FishEye (void *data, float *iocoord, int count);
02481     static void ModifyCoord_Geom_Panoramic_FishEye (void *data, float *iocoord, int count);
02482     static void ModifyCoord_Geom_ERect_FishEye (void *data, float *iocoord, int count);
02483     static void ModifyCoord_Geom_Rect_Panoramic (void *data, float *iocoord, int count);
02484     static void ModifyCoord_Geom_FishEye_Panoramic (void *data, float *iocoord, int count);
02485     static void ModifyCoord_Geom_ERect_Panoramic (void *data, float *iocoord, int count);
02486     static void ModifyCoord_Geom_Rect_ERect (void *data, float *iocoord, int count);
02487     static void ModifyCoord_Geom_FishEye_ERect (void *data, float *iocoord, int count);
02488     static void ModifyCoord_Geom_Panoramic_ERect (void *data, float *iocoord, int count);
02489     static void ModifyCoord_Geom_Orthographic_ERect (void *data, float *iocoord, int count);
02490     static void ModifyCoord_Geom_ERect_Orthographic (void *data, float *iocoord, int count);
02491     static void ModifyCoord_Geom_Stereographic_ERect (void *data, float *iocoord, int count);
02492     static void ModifyCoord_Geom_ERect_Stereographic (void *data, float *iocoord, int count);
02493     static void ModifyCoord_Geom_Equisolid_ERect (void *data, float *iocoord, int count);
02494     static void ModifyCoord_Geom_ERect_Equisolid (void *data, float *iocoord, int count);
02495     static void ModifyCoord_Geom_Thoby_ERect (void *data, float *iocoord, int count);
02496     static void ModifyCoord_Geom_ERect_Thoby (void *data, float *iocoord, int count);
02497 #ifdef VECTORIZATION_SSE
02498     static void ModifyColor_DeVignetting_PA_SSE (
02499       void *data, float _x, float _y, lf_f32 *pixels, int comp_role, int count);
02500 #endif
02501 #ifdef VECTORIZATION_SSE2
02502     static void ModifyColor_DeVignetting_PA_SSE2 (
02503       void *data, float _x, float _y, lf_u16 *pixels, int comp_role, int count);
02504 #endif
02505 
02506     template<typename T> static void ModifyColor_Vignetting_PA (
02507         void *data, float x, float y, T *rgb, int comp_role, int count);
02508     template<typename T> static void ModifyColor_DeVignetting_PA (
02509         void *data, float x, float y, T *rgb, int comp_role, int count);
02510 
02511     static void ModifyCoord_Scale (void *data, float *iocoord, int count);
02512 #endif
02513 
02514     int Width, Height;
02516     double CenterX, CenterY;
02518     double NormScale, NormUnScale;
02521     double NormalizedInMillimeters;
02524     double AspectRatioCorrection;
02525 
02527     void *SubpixelCallbacks;
02529     void *ColorCallbacks;
02531     void *CoordCallbacks;
02532 
02534     double MaxX, MaxY;
02535 };
02536 
02537 #ifdef __cplusplus
02538 extern "C" {
02539 #endif
02540 
02541 C_TYPEDEF (struct, lfModifier)
02542 
02543 
02544 LF_EXPORT lfModifier *lf_modifier_new (
02545     const lfLens *lens, float crop, int width, int height);
02546 
02548 LF_EXPORT void lf_modifier_destroy (lfModifier *modifier);
02549 
02551 LF_EXPORT int lf_modifier_initialize (
02552     lfModifier *modifier, const lfLens *lens, lfPixelFormat format,
02553     float focal, float aperture, float distance, float scale,
02554     lfLensType targeom, int flags, cbool reverse);
02555 
02557 LF_EXPORT void lf_modifier_add_coord_callback (
02558     lfModifier *modifier, lfModifyCoordFunc callback, int priority,
02559     void *data, size_t data_size);
02560 
02562 LF_EXPORT void lf_modifier_add_subpixel_callback (
02563     lfModifier *modifier, lfSubpixelCoordFunc callback, int priority,
02564     void *data, size_t data_size);
02565 
02567 LF_EXPORT void lf_modifier_add_color_callback (
02568     lfModifier *modifier, lfModifyColorFunc callback, int priority,
02569     void *data, size_t data_size);
02570 
02572 LF_EXPORT cbool lf_modifier_add_subpixel_callback_TCA (
02573     lfModifier *modifier, lfLensCalibTCA *model, cbool reverse);
02574 
02576 LF_EXPORT cbool lf_modifier_add_color_callback_vignetting (
02577     lfModifier *modifier, lfLensCalibVignetting *model,
02578     lfPixelFormat format, cbool reverse);
02579 
02581 LF_EXPORT cbool lf_modifier_add_coord_callback_distortion (
02582     lfModifier *modifier, lfLensCalibDistortion *model, cbool reverse);
02583 
02585 LF_EXPORT cbool lf_modifier_add_coord_callback_geometry (
02586     lfModifier *modifier, lfLensType from, lfLensType to, float focal);
02587 
02589 LF_EXPORT cbool lf_modifier_add_coord_callback_scale (
02590     lfModifier *modifier, float scale, cbool reverse);
02591 
02593 LF_EXPORT float lf_modifier_get_auto_scale (
02594     lfModifier *modifier, cbool reverse);
02595 
02597 LF_EXPORT cbool lf_modifier_apply_subpixel_distortion (
02598     lfModifier *modifier, float xu, float yu, int width, int height, float *res);
02599 
02601 LF_EXPORT cbool lf_modifier_apply_color_modification (
02602     lfModifier *modifier, void *pixels, float x, float y, int width, int height,
02603     int comp_role, int row_stride);
02604 
02606 LF_EXPORT cbool lf_modifier_apply_geometry_distortion (
02607     lfModifier *modifier, float xu, float yu, int width, int height, float *res);
02608 
02610 LF_EXPORT cbool lf_modifier_apply_subpixel_geometry_distortion (
02611     lfModifier *modifier, float xu, float yu, int width, int height, float *res);
02612 
02615 #undef cbool
02616 
02617 #ifdef __cplusplus
02618 }
02619 #endif
02620 
02621 #endif /* __LENSFUN_H__ */