merge with lcp-vignetting-issue4062
This commit is contained in:
170
rtengine/lcp.h
170
rtengine/lcp.h
@@ -21,27 +21,45 @@
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include <glibmm.h>
|
||||
#include <expat.h>
|
||||
|
||||
#include "cache.h"
|
||||
#include "imagefloat.h"
|
||||
#include "opthelper.h"
|
||||
|
||||
namespace rtengine
|
||||
{
|
||||
|
||||
enum class LCPCorrectionMode {
|
||||
VIGNETTE,
|
||||
DISTORTION,
|
||||
CA
|
||||
};
|
||||
|
||||
// Perspective model common data, also used for Vignette and Fisheye
|
||||
class LCPModelCommon final
|
||||
{
|
||||
public:
|
||||
LCPModelCommon();
|
||||
|
||||
bool empty() const; // is it empty
|
||||
void print() const; // printf all values
|
||||
void merge(const LCPModelCommon& a, const LCPModelCommon& b, float facA);
|
||||
void prepareParams(int fullWidth, int fullHeight, float focalLength, float focalLength35mm, float sensorFormatFactor, bool swapXY, bool mirrorX, bool mirrorY);
|
||||
void prepareParams(
|
||||
int fullWidth,
|
||||
int fullHeight,
|
||||
float focalLength,
|
||||
float focalLength35mm,
|
||||
float sensorFormatFactor,
|
||||
bool swapXY,
|
||||
bool mirrorX,
|
||||
bool mirrorY
|
||||
);
|
||||
|
||||
//private:
|
||||
using Param = std::array<float, 5>;
|
||||
@@ -66,81 +84,86 @@ public:
|
||||
VignParam vign_param;
|
||||
};
|
||||
|
||||
class LCPPersModel
|
||||
{
|
||||
public:
|
||||
float focLen, focDist, aperture; // this is what it refers to
|
||||
|
||||
LCPModelCommon base; // base perspective correction
|
||||
LCPModelCommon chromRG, chromG, chromBG; // red/green, green, blue/green (may be empty)
|
||||
LCPModelCommon vignette; // vignette (may be empty)
|
||||
|
||||
LCPPersModel();
|
||||
bool hasModeData(int mode) const;
|
||||
void print() const;
|
||||
};
|
||||
|
||||
|
||||
class LCPProfile
|
||||
{
|
||||
// Temporary data for parsing
|
||||
bool inCamProfiles, firstLIDone, inPerspect, inAlternateLensID, inAlternateLensNames;
|
||||
char lastTag[256], inInvalidTag[256];
|
||||
LCPPersModel* pCurPersModel;
|
||||
LCPModelCommon* pCurCommon;
|
||||
|
||||
static void XMLCALL XmlStartHandler(void *pLCPProfile, const char *el, const char **attr);
|
||||
static void XMLCALL XmlTextHandler (void *pLCPProfile, const XML_Char *s, int len);
|
||||
static void XMLCALL XmlEndHandler (void *pLCPProfile, const char *el);
|
||||
|
||||
int filterBadFrames(double maxAvgDevFac, int minFramesLeft);
|
||||
|
||||
void handle_text(std::string text);
|
||||
std::ostringstream textbuf;
|
||||
|
||||
public:
|
||||
explicit LCPProfile(const Glib::ustring& fname);
|
||||
~LCPProfile();
|
||||
|
||||
void calcParams(
|
||||
LCPCorrectionMode mode,
|
||||
float focalLength,
|
||||
float focusDist,
|
||||
float aperture,
|
||||
LCPModelCommon* pCorr1,
|
||||
LCPModelCommon* pCorr2,
|
||||
LCPModelCommon *pCorr3
|
||||
) const; // Interpolates between the persModels frames
|
||||
|
||||
void print() const;
|
||||
|
||||
//private:
|
||||
// Common data
|
||||
Glib::ustring profileName, lensPrettyName, cameraPrettyName, lens, camera; // lens/camera(=model) can be auto-matched with DNG
|
||||
bool isRaw, isFisheye;
|
||||
Glib::ustring profileName;
|
||||
Glib::ustring lensPrettyName;
|
||||
Glib::ustring cameraPrettyName;
|
||||
Glib::ustring lens;
|
||||
Glib::ustring camera; // lens/camera(=model) can be auto-matched with DNG
|
||||
bool isRaw;
|
||||
bool isFisheye;
|
||||
float sensorFormatFactor;
|
||||
int persModelCount;
|
||||
|
||||
private:
|
||||
class LCPPersModel;
|
||||
|
||||
int filterBadFrames(LCPCorrectionMode mode, double maxAvgDevFac, int minFramesLeft);
|
||||
|
||||
void handle_text(const std::string& text);
|
||||
|
||||
static void XMLCALL XmlStartHandler(void* pLCPProfile, const char* el, const char** attr);
|
||||
static void XMLCALL XmlTextHandler(void* pLCPProfile, const XML_Char* s, int len);
|
||||
static void XMLCALL XmlEndHandler(void* pLCPProfile, const char* el);
|
||||
|
||||
// Temporary data for parsing
|
||||
bool inCamProfiles;
|
||||
bool firstLIDone;
|
||||
bool inPerspect;
|
||||
bool inAlternateLensID;
|
||||
bool inAlternateLensNames;
|
||||
char lastTag[256];
|
||||
char inInvalidTag[256];
|
||||
LCPPersModel* pCurPersModel;
|
||||
LCPModelCommon* pCurCommon;
|
||||
|
||||
std::ostringstream textbuf;
|
||||
|
||||
// The correction frames
|
||||
static const int MaxPersModelCount = 3000;
|
||||
static constexpr int MaxPersModelCount = 3000;
|
||||
LCPPersModel* aPersModel[MaxPersModelCount]; // Do NOT use std::list or something, it's buggy in GCC!
|
||||
|
||||
explicit LCPProfile(const Glib::ustring &fname);
|
||||
~LCPProfile();
|
||||
|
||||
void calcParams(int mode, float focalLength, float focusDist, float aperture, LCPModelCommon *pCorr1, LCPModelCommon *pCorr2, LCPModelCommon *pCorr3) const; // Interpolates between the persModels frames
|
||||
|
||||
void print() const;
|
||||
};
|
||||
|
||||
class LCPStore
|
||||
{
|
||||
MyMutex mtx;
|
||||
public:
|
||||
static LCPStore* getInstance();
|
||||
|
||||
bool isValidLCPFileName(const Glib::ustring& filename) const;
|
||||
std::shared_ptr<LCPProfile> getProfile(const Glib::ustring& filename) const;
|
||||
Glib::ustring getDefaultCommonDirectory() const;
|
||||
|
||||
private:
|
||||
LCPStore(unsigned int _cache_size = 32);
|
||||
|
||||
// Maps file name to profile as cache
|
||||
std::map<Glib::ustring, LCPProfile*> profileCache;
|
||||
|
||||
public:
|
||||
~LCPStore();
|
||||
Glib::ustring getDefaultCommonDirectory() const;
|
||||
bool isValidLCPFileName(Glib::ustring filename) const;
|
||||
LCPProfile* getProfile(Glib::ustring filename);
|
||||
|
||||
static LCPStore* getInstance();
|
||||
mutable Cache<Glib::ustring, std::shared_ptr<LCPProfile>> cache;
|
||||
};
|
||||
|
||||
#define lcpStore LCPStore::getInstance()
|
||||
|
||||
|
||||
class LensCorrection {
|
||||
public:
|
||||
virtual ~LensCorrection() {}
|
||||
virtual void correctDistortion(double &x, double &y, int cx, int cy, double scale) const = 0;
|
||||
virtual bool supportsCA() const = 0;
|
||||
virtual bool isCACorrectionAvailable() const = 0;
|
||||
virtual void correctCA(double &x, double &y, int channel) const = 0;
|
||||
virtual void processVignetteLine(int width, int y, float *line) const = 0;
|
||||
virtual void processVignetteLine3Channels(int width, int y, float *line) const = 0;
|
||||
@@ -150,25 +173,36 @@ public:
|
||||
// Once precalculated class to correct a point
|
||||
class LCPMapper: public LensCorrection
|
||||
{
|
||||
public:
|
||||
// Precalculates the mapper
|
||||
LCPMapper(
|
||||
const std::shared_ptr<LCPProfile>& pProf,
|
||||
float focalLength,
|
||||
float focalLength35mm,
|
||||
float focusDist,
|
||||
float aperture,
|
||||
bool vignette,
|
||||
bool useCADistP,
|
||||
int fullWidth,
|
||||
int fullHeight,
|
||||
const CoarseTransformParams& coarse,
|
||||
int rawRotationDeg
|
||||
);
|
||||
|
||||
|
||||
void correctDistortion(double &x, double &y, int cx, int cy, double scale) const; // MUST be the first stage
|
||||
bool isCACorrectionAvailable() const;
|
||||
void correctCA(double& x, double& y, int channel) const;
|
||||
void processVignetteLine(int width, int y, float* line) const;
|
||||
void processVignetteLine3Channels(int width, int y, float* line) const;
|
||||
|
||||
private:
|
||||
bool enableCA; // is the mapper capable if CA correction?
|
||||
bool useCADist; // should the distortion in the CA info be used?
|
||||
bool swapXY;
|
||||
LCPModelCommon mc;
|
||||
LCPModelCommon chrom[3]; // in order RedGreen/Green/BlueGreen
|
||||
bool isFisheye;
|
||||
|
||||
public:
|
||||
bool enableCA; // is the mapper capable if CA correction?
|
||||
|
||||
// precalculates the mapper.
|
||||
LCPMapper(LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP, int fullWidth, int fullHeight,
|
||||
const CoarseTransformParams& coarse, int rawRotationDeg);
|
||||
|
||||
void correctDistortion(double &x, double &y, int cx, int cy, double scale) const; // MUST be the first stage
|
||||
bool supportsCA() const { return enableCA; }
|
||||
void correctCA(double& x, double& y, int channel) const;
|
||||
void processVignetteLine(int width, int y, float *line) const;
|
||||
void processVignetteLine3Channels(int width, int y, float *line) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user