LCP cleanup (#4062)
- Removed `using namespace` - Use real `Cache` - Use `std::shared_ptr<LCPProfile>` - Moved `LCPPersModel` to .cc More could be done...
This commit is contained in:
parent
5656d16e64
commit
d442f7a85b
@ -305,7 +305,7 @@ rtengine::CLUTStore& rtengine::CLUTStore::getInstance()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<rtengine::HaldCLUT> rtengine::CLUTStore::getClut(const Glib::ustring& filename)
|
std::shared_ptr<rtengine::HaldCLUT> rtengine::CLUTStore::getClut(const Glib::ustring& filename) const
|
||||||
{
|
{
|
||||||
std::shared_ptr<rtengine::HaldCLUT> result;
|
std::shared_ptr<rtengine::HaldCLUT> result;
|
||||||
|
|
||||||
|
@ -57,14 +57,14 @@ class CLUTStore final :
|
|||||||
public:
|
public:
|
||||||
static CLUTStore& getInstance();
|
static CLUTStore& getInstance();
|
||||||
|
|
||||||
std::shared_ptr<HaldCLUT> getClut(const Glib::ustring& filename);
|
std::shared_ptr<HaldCLUT> getClut(const Glib::ustring& filename) const;
|
||||||
|
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CLUTStore();
|
CLUTStore();
|
||||||
|
|
||||||
Cache<Glib::ustring, std::shared_ptr<HaldCLUT>> cache;
|
mutable Cache<Glib::ustring, std::shared_ptr<HaldCLUT>> cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1121,7 @@ void ImProcCoordinator::getAutoCrop (double ratio, int &x, int &y, int &w, int &
|
|||||||
LCPMapper *pLCPMap = nullptr;
|
LCPMapper *pLCPMap = nullptr;
|
||||||
|
|
||||||
if (params.lensProf.lcpFile.length() && imgsrc->getMetaData()->getFocalLen() > 0) {
|
if (params.lensProf.lcpFile.length() && imgsrc->getMetaData()->getFocalLen() > 0) {
|
||||||
LCPProfile *pLCPProf = lcpStore->getProfile (params.lensProf.lcpFile);
|
const std::shared_ptr<LCPProfile> pLCPProf = LCPStore::getInstance()->getProfile (params.lensProf.lcpFile);
|
||||||
|
|
||||||
if (pLCPProf) pLCPMap = new LCPMapper (pLCPProf, imgsrc->getMetaData()->getFocalLen(), imgsrc->getMetaData()->getFocalLen35mm(), imgsrc->getMetaData()->getFocusDist(),
|
if (pLCPProf) pLCPMap = new LCPMapper (pLCPProf, imgsrc->getMetaData()->getFocalLen(), imgsrc->getMetaData()->getFocalLen35mm(), imgsrc->getMetaData()->getFocusDist(),
|
||||||
0, false, params.lensProf.useDist, fullw, fullh, params.coarse, imgsrc->getRotateDegree());
|
0, false, params.lensProf.useDist, fullw, fullh, params.coarse, imgsrc->getRotateDegree());
|
||||||
|
@ -313,7 +313,7 @@ void ImProcFunctions::transform (Imagefloat* original, Imagefloat* transformed,
|
|||||||
LCPMapper *pLCPMap = nullptr;
|
LCPMapper *pLCPMap = nullptr;
|
||||||
|
|
||||||
if (needsLCP()) { // don't check focal length to allow distortion correction for lenses without chip
|
if (needsLCP()) { // don't check focal length to allow distortion correction for lenses without chip
|
||||||
LCPProfile *pLCPProf = lcpStore->getProfile (params->lensProf.lcpFile);
|
const std::shared_ptr<LCPProfile> pLCPProf = LCPStore::getInstance()->getProfile (params->lensProf.lcpFile);
|
||||||
|
|
||||||
if (pLCPProf) {
|
if (pLCPProf) {
|
||||||
pLCPMap = new LCPMapper (pLCPProf, focalLen, focalLen35mm,
|
pLCPMap = new LCPMapper (pLCPProf, focalLen, focalLen35mm,
|
||||||
@ -784,7 +784,7 @@ void ImProcFunctions::transformHighQuality (Imagefloat* original, Imagefloat* tr
|
|||||||
double ascale = params->commonTrans.autofill ? getTransformAutoFill (oW, oH, true /*fullImage*/ ? pLCPMap : nullptr) : 1.0;
|
double ascale = params->commonTrans.autofill ? getTransformAutoFill (oW, oH, true /*fullImage*/ ? pLCPMap : nullptr) : 1.0;
|
||||||
|
|
||||||
// smaller crop images are a problem, so only when processing fully
|
// smaller crop images are a problem, so only when processing fully
|
||||||
bool enableLCPCA = pLCPMap && params->lensProf.useCA && fullImage && pLCPMap->enableCA;
|
bool enableLCPCA = pLCPMap && params->lensProf.useCA && fullImage && pLCPMap->isCACorrectionAvailable();
|
||||||
bool enableLCPDist = pLCPMap && params->lensProf.useDist; // && fullImage;
|
bool enableLCPDist = pLCPMap && params->lensProf.useDist; // && fullImage;
|
||||||
|
|
||||||
if (enableLCPCA) {
|
if (enableLCPCA) {
|
||||||
|
1610
rtengine/lcp.cc
1610
rtengine/lcp.cc
File diff suppressed because it is too large
Load Diff
169
rtengine/lcp.h
169
rtengine/lcp.h
@ -21,22 +21,24 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
|
|
||||||
|
#include "cache.h"
|
||||||
#include "imagefloat.h"
|
#include "imagefloat.h"
|
||||||
#include "opthelper.h"
|
#include "opthelper.h"
|
||||||
|
|
||||||
namespace rtengine
|
namespace rtengine
|
||||||
{
|
{
|
||||||
|
|
||||||
enum LCPCorrectionMode {
|
enum class LCPCorrectionMode {
|
||||||
LCP_MODE_VIGNETTE = 0,
|
VIGNETTE,
|
||||||
LCP_MODE_DISTORTION = 1,
|
DISTORTION,
|
||||||
LCP_MODE_CA = 2
|
CA
|
||||||
};
|
};
|
||||||
|
|
||||||
// Perspective model common data, also used for Vignette and Fisheye
|
// Perspective model common data, also used for Vignette and Fisheye
|
||||||
@ -44,10 +46,20 @@ class LCPModelCommon final
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LCPModelCommon();
|
LCPModelCommon();
|
||||||
|
|
||||||
bool empty() const; // is it empty
|
bool empty() const; // is it empty
|
||||||
void print() const; // printf all values
|
void print() const; // printf all values
|
||||||
void merge(const LCPModelCommon& a, const LCPModelCommon& b, float facA);
|
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:
|
//private:
|
||||||
using Param = std::array<float, 5>;
|
using Param = std::array<float, 5>;
|
||||||
@ -72,97 +84,114 @@ public:
|
|||||||
VignParam vign_param;
|
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(LCPCorrectionMode mode) const;
|
|
||||||
void print() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LCPProfile
|
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(LCPCorrectionMode mode, double maxAvgDevFac, int minFramesLeft);
|
|
||||||
|
|
||||||
void handle_text(std::string text);
|
|
||||||
std::ostringstream textbuf;
|
|
||||||
|
|
||||||
public:
|
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
|
// Common data
|
||||||
Glib::ustring profileName, lensPrettyName, cameraPrettyName, lens, camera; // lens/camera(=model) can be auto-matched with DNG
|
Glib::ustring profileName;
|
||||||
bool isRaw, isFisheye;
|
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;
|
float sensorFormatFactor;
|
||||||
int persModelCount;
|
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
|
// 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!
|
LCPPersModel* aPersModel[MaxPersModelCount]; // Do NOT use std::list or something, it's buggy in GCC!
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LCPStore
|
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
|
// Maps file name to profile as cache
|
||||||
std::map<Glib::ustring, LCPProfile*> profileCache;
|
mutable Cache<Glib::ustring, std::shared_ptr<LCPProfile>> cache;
|
||||||
|
|
||||||
public:
|
|
||||||
~LCPStore();
|
|
||||||
Glib::ustring getDefaultCommonDirectory() const;
|
|
||||||
bool isValidLCPFileName(Glib::ustring filename) const;
|
|
||||||
LCPProfile* getProfile(Glib::ustring filename);
|
|
||||||
|
|
||||||
static LCPStore* getInstance();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define lcpStore LCPStore::getInstance()
|
|
||||||
|
|
||||||
|
|
||||||
// Once precalculated class to correct a point
|
// Once precalculated class to correct a point
|
||||||
class LCPMapper
|
class LCPMapper
|
||||||
{
|
{
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
bool isCACorrectionAvailable() const;
|
||||||
|
|
||||||
|
void correctDistortion(double& x, double& y, double scale) const; // MUST be the first stage
|
||||||
|
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 useCADist; // should the distortion in the CA info be used?
|
||||||
bool swapXY;
|
bool swapXY;
|
||||||
LCPModelCommon mc;
|
LCPModelCommon mc;
|
||||||
LCPModelCommon chrom[3]; // in order RedGreen/Green/BlueGreen
|
LCPModelCommon chrom[3]; // in order RedGreen/Green/BlueGreen
|
||||||
bool isFisheye;
|
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, double scale) const; // MUST be the first stage
|
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1855,7 +1855,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le
|
|||||||
|
|
||||||
// Correct vignetting of lens profile
|
// Correct vignetting of lens profile
|
||||||
if (!hasFlatField && lensProf.useVign) {
|
if (!hasFlatField && lensProf.useVign) {
|
||||||
LCPProfile *pLCPProf = lcpStore->getProfile(lensProf.lcpFile);
|
const std::shared_ptr<LCPProfile> pLCPProf = LCPStore::getInstance()->getProfile(lensProf.lcpFile);
|
||||||
|
|
||||||
if (pLCPProf) { // don't check focal length to allow distortion correction for lenses without chip, also pass dummy focal length 1 in case of 0
|
if (pLCPProf) { // don't check focal length to allow distortion correction for lenses without chip, also pass dummy focal length 1 in case of 0
|
||||||
LCPMapper map(pLCPProf, max(idata->getFocalLen(), 1.0), idata->getFocalLen35mm(), idata->getFocusDist(), idata->getFNumber(), true, false, W, H, coarse, -1);
|
LCPMapper map(pLCPProf, max(idata->getFocalLen(), 1.0), idata->getFocalLen35mm(), idata->getFocusDist(), idata->getFNumber(), true, false, W, H, coarse, -1);
|
||||||
|
@ -41,7 +41,7 @@ LensProfilePanel::LensProfilePanel () : FoldableToolPanel(this, "lensprof", M("T
|
|||||||
filterLCP->add_pattern("*.LCP");
|
filterLCP->add_pattern("*.LCP");
|
||||||
fcbLCPFile->add_filter(filterLCP);
|
fcbLCPFile->add_filter(filterLCP);
|
||||||
|
|
||||||
Glib::ustring defDir = lcpStore->getDefaultCommonDirectory();
|
Glib::ustring defDir = LCPStore::getInstance()->getDefaultCommonDirectory();
|
||||||
|
|
||||||
if (!defDir.empty()) {
|
if (!defDir.empty()) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -82,7 +82,7 @@ void LensProfilePanel::read(const rtengine::procparams::ProcParams* pp, const Pa
|
|||||||
disableListener ();
|
disableListener ();
|
||||||
conUseDist.block(true);
|
conUseDist.block(true);
|
||||||
|
|
||||||
if (!pp->lensProf.lcpFile.empty() && lcpStore->isValidLCPFileName(pp->lensProf.lcpFile)) {
|
if (!pp->lensProf.lcpFile.empty() && LCPStore::getInstance()->isValidLCPFileName(pp->lensProf.lcpFile)) {
|
||||||
fcbLCPFile->set_filename (pp->lensProf.lcpFile);
|
fcbLCPFile->set_filename (pp->lensProf.lcpFile);
|
||||||
updateDisabled(true);
|
updateDisabled(true);
|
||||||
} else {
|
} else {
|
||||||
@ -128,7 +128,7 @@ void LensProfilePanel::setRawMeta(bool raw, const rtengine::ImageMetaData* pMeta
|
|||||||
|
|
||||||
void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited)
|
void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited)
|
||||||
{
|
{
|
||||||
if (lcpStore->isValidLCPFileName(fcbLCPFile->get_filename())) {
|
if (LCPStore::getInstance()->isValidLCPFileName(fcbLCPFile->get_filename())) {
|
||||||
pp->lensProf.lcpFile = fcbLCPFile->get_filename();
|
pp->lensProf.lcpFile = fcbLCPFile->get_filename();
|
||||||
} else {
|
} else {
|
||||||
pp->lensProf.lcpFile = "";
|
pp->lensProf.lcpFile = "";
|
||||||
@ -149,7 +149,7 @@ void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited
|
|||||||
void LensProfilePanel::onLCPFileChanged()
|
void LensProfilePanel::onLCPFileChanged()
|
||||||
{
|
{
|
||||||
lcpFileChanged = true;
|
lcpFileChanged = true;
|
||||||
updateDisabled(lcpStore->isValidLCPFileName(fcbLCPFile->get_filename()));
|
updateDisabled(LCPStore::getInstance()->isValidLCPFileName(fcbLCPFile->get_filename()));
|
||||||
|
|
||||||
if (listener) {
|
if (listener) {
|
||||||
listener->panelChanged (EvLCPFile, Glib::path_get_basename(fcbLCPFile->get_filename()));
|
listener->panelChanged (EvLCPFile, Glib::path_get_basename(fcbLCPFile->get_filename()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user