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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@ -57,14 +57,14 @@ class CLUTStore final :
|
||||
public:
|
||||
static CLUTStore& getInstance();
|
||||
|
||||
std::shared_ptr<HaldCLUT> getClut(const Glib::ustring& filename);
|
||||
std::shared_ptr<HaldCLUT> getClut(const Glib::ustring& filename) const;
|
||||
|
||||
void clearCache();
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
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(),
|
||||
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;
|
||||
|
||||
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) {
|
||||
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;
|
||||
|
||||
// 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;
|
||||
|
||||
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 <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 LCPCorrectionMode {
|
||||
LCP_MODE_VIGNETTE = 0,
|
||||
LCP_MODE_DISTORTION = 1,
|
||||
LCP_MODE_CA = 2
|
||||
enum class LCPCorrectionMode {
|
||||
VIGNETTE,
|
||||
DISTORTION,
|
||||
CA
|
||||
};
|
||||
|
||||
// Perspective model common data, also used for Vignette and Fisheye
|
||||
@ -44,10 +46,20 @@ 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>;
|
||||
@ -72,97 +84,114 @@ 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(LCPCorrectionMode 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(LCPCorrectionMode mode, 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(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
|
||||
{
|
||||
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()
|
||||
|
||||
|
||||
// Once precalculated class to correct a point
|
||||
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 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, 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
|
||||
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
|
||||
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");
|
||||
fcbLCPFile->add_filter(filterLCP);
|
||||
|
||||
Glib::ustring defDir = lcpStore->getDefaultCommonDirectory();
|
||||
Glib::ustring defDir = LCPStore::getInstance()->getDefaultCommonDirectory();
|
||||
|
||||
if (!defDir.empty()) {
|
||||
#ifdef WIN32
|
||||
@ -82,7 +82,7 @@ void LensProfilePanel::read(const rtengine::procparams::ProcParams* pp, const Pa
|
||||
disableListener ();
|
||||
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);
|
||||
updateDisabled(true);
|
||||
} else {
|
||||
@ -128,7 +128,7 @@ void LensProfilePanel::setRawMeta(bool raw, const rtengine::ImageMetaData* pMeta
|
||||
|
||||
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();
|
||||
} else {
|
||||
pp->lensProf.lcpFile = "";
|
||||
@ -149,7 +149,7 @@ void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited
|
||||
void LensProfilePanel::onLCPFileChanged()
|
||||
{
|
||||
lcpFileChanged = true;
|
||||
updateDisabled(lcpStore->isValidLCPFileName(fcbLCPFile->get_filename()));
|
||||
updateDisabled(LCPStore::getInstance()->isValidLCPFileName(fcbLCPFile->get_filename()));
|
||||
|
||||
if (listener) {
|
||||
listener->panelChanged (EvLCPFile, Glib::path_get_basename(fcbLCPFile->get_filename()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user