Merge branch 'lenscorrectiongui' into dev

This commit is contained in:
heckflosse 2017-09-16 19:18:04 +02:00
commit 597c4fbaa1
12 changed files with 122 additions and 99 deletions

View File

@ -1083,9 +1083,7 @@ bool check_need_larger_crop_for_lcp_distortion (int fw, int fh, int x, int y, in
return false;
}
return (params.lensProf.useDist &&
(params.lensProf.useLensfun ||
params.lensProf.lcpFile.length() > 0));
return (params.lensProf.useDist && (params.lensProf.useLensfun() || params.lensProf.useLcp()));
}
} // namespace

View File

@ -1120,7 +1120,7 @@ void ImProcCoordinator::getAutoCrop (double ratio, int &x, int &y, int &w, int &
LensCorrection *pLCPMap = nullptr;
if (params.lensProf.lcpFile.length() && imgsrc->getMetaData()->getFocalLen() > 0) {
if (params.lensProf.useLcp() && imgsrc->getMetaData()->getFocalLen() > 0) {
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(),

View File

@ -1015,12 +1015,12 @@ bool ImProcFunctions::needsVignetting ()
bool ImProcFunctions::needsLCP ()
{
return params->lensProf.lcpFile.length() > 0 && !needsLensfun();
return params->lensProf.useLcp();
}
bool ImProcFunctions::needsLensfun()
{
return params->lensProf.useLensfun;
return params->lensProf.useLensfun();
}
bool ImProcFunctions::needsTransform ()

View File

@ -52,6 +52,7 @@ const int br = (int) options.rtSettings.bot_right;
const int tl = (int) options.rtSettings.top_left;
const int bl = (int) options.rtSettings.bot_left;
const char *LensProfParams::methodstring[static_cast<size_t>(LensProfParams::eLcMode::LC_LCP) + 1u] = {"none", "lfauto", "lfmanual", "lcp"};
const char *RAWParams::BayerSensor::methodstring[RAWParams::BayerSensor::numMethods] = {"amaze", "igv", "lmmse", "eahd", "hphd", "vng4", "dcb", "ahd", "fast", "mono", "none", "pixelshift" };
const char *RAWParams::XTransSensor::methodstring[RAWParams::XTransSensor::numMethods] = {"3-pass (best)", "1-pass (medium)", "fast", "mono", "none" };
@ -919,11 +920,10 @@ void ToneCurveParams::setDefaults()
void LensProfParams::setDefaults()
{
lcMode = eLcMode::LC_NOCORRECTION;
lcpFile = "";
useDist = useVign = true;
useCA = false;
useLensfun = false;
lfAutoMatch = true;
lfCameraMake = "";
lfCameraModel = "";
lfLens = "";
@ -2554,6 +2554,10 @@ int ProcParams::save (const Glib::ustring &fname, const Glib::ustring &fname2, b
}
// lens profile
if (!pedited || pedited->lensProf.lcMode) {
keyFile.set_string ("LensProfile", "LcMode", lensProf.getMethodString (lensProf.lcMode));
}
if (!pedited || pedited->lensProf.lcpFile) {
keyFile.set_string ("LensProfile", "LCPFile", relativePathIfInside (fname, fnameAbsolute, lensProf.lcpFile));
}
@ -2570,12 +2574,6 @@ int ProcParams::save (const Glib::ustring &fname, const Glib::ustring &fname2, b
keyFile.set_boolean ("LensProfile", "UseCA", lensProf.useCA);
}
if (!pedited || pedited->lensProf.useLensfun) {
keyFile.set_boolean("LensProfile", "UseLensfun", lensProf.useLensfun);
}
if (!pedited || pedited->lensProf.lfAutoMatch) {
keyFile.set_boolean("LensProfile", "LFAutoMatch", lensProf.lfAutoMatch);
}
if (!pedited || pedited->lensProf.lfCameraMake) {
keyFile.set_string("LensProfile", "LFCameraMake", lensProf.lfCameraMake);
}
@ -5822,12 +5820,24 @@ int ProcParams::load (const Glib::ustring &fname, ParamsEdited* pedited)
// lens profile
if (keyFile.has_group ("LensProfile")) {
if (keyFile.has_key ("LensProfile", "LcMode")) {
lensProf.lcMode = lensProf.getMethodNumber (keyFile.get_string ("LensProfile", "LcMode"));
if (pedited) {
pedited->lensProf.lcMode = true;
}
}
if (keyFile.has_key ("LensProfile", "LCPFile")) {
lensProf.lcpFile = expandRelativePath (fname, "", keyFile.get_string ("LensProfile", "LCPFile"));
if (pedited) {
pedited->lensProf.lcpFile = true;
}
if(ppVersion < 327 && !lensProf.lcpFile.empty()) {
lensProf.lcMode = LensProfParams::eLcMode::LC_LCP;
}
}
if (keyFile.has_key ("LensProfile", "UseDistortion")) {
@ -5854,20 +5864,6 @@ int ProcParams::load (const Glib::ustring &fname, ParamsEdited* pedited)
}
}
if (keyFile.has_key("LensProfile", "UseLensfun")) {
lensProf.useLensfun = keyFile.get_boolean("LensProfile", "UseLensfun");
if (pedited) {
pedited->lensProf.useLensfun = true;
}
}
if (keyFile.has_key("LensProfile", "LFAutoMatch")) {
lensProf.lfAutoMatch = keyFile.get_boolean("LensProfile", "LFAutoMatch");
if (pedited) {
pedited->lensProf.lfAutoMatch = true;
}
}
if (keyFile.has_key("LensProfile", "LFCameraMake")) {
lensProf.lfCameraMake = keyFile.get_string("LensProfile", "LFCameraMake");
if (pedited) {
@ -8484,12 +8480,11 @@ bool ProcParams::operator== (const ProcParams& other)
&& rotate.degree == other.rotate.degree
&& commonTrans.autofill == other.commonTrans.autofill
&& distortion.amount == other.distortion.amount
&& lensProf.lcMode == other.lensProf.lcMode
&& lensProf.lcpFile == other.lensProf.lcpFile
&& lensProf.useDist == other.lensProf.useDist
&& lensProf.useVign == other.lensProf.useVign
&& lensProf.useCA == other.lensProf.useCA
&& lensProf.useLensfun == other.lensProf.useLensfun
&& lensProf.lfAutoMatch == other.lensProf.lfAutoMatch
&& lensProf.lfCameraMake == other.lensProf.lfCameraMake
&& lensProf.lfCameraModel == other.lensProf.lfCameraModel
&& lensProf.lfLens == other.lensProf.lfLens

View File

@ -829,10 +829,17 @@ class LensProfParams
{
public:
enum class eLcMode {
LC_NOCORRECTION, // No lens correction
LC_LENSFUNAUTOMATCH, // Lens correction using auto matched lensfun database entry
LC_LENSFUNMANUAL, // Lens correction using manually selected lensfun database entry
LC_LCP // Lens correction using lcp file
};
static const char *methodstring[static_cast<size_t>(eLcMode::LC_LCP) + 1u];
eLcMode lcMode;
Glib::ustring lcpFile;
bool useDist, useVign, useCA;
bool useLensfun;
bool lfAutoMatch;
Glib::ustring lfCameraMake;
Glib::ustring lfCameraModel;
Glib::ustring lfLens;
@ -842,6 +849,41 @@ public:
setDefaults();
}
void setDefaults();
bool useLensfun() const
{
return lcMode == eLcMode::LC_LENSFUNAUTOMATCH || lcMode == eLcMode::LC_LENSFUNMANUAL;
}
bool lfAutoMatch() const
{
return lcMode == eLcMode::LC_LENSFUNAUTOMATCH;
}
bool useLcp() const
{
return lcMode == eLcMode::LC_LCP && lcpFile.length() > 0;
}
bool lfManual() const
{
return lcMode == eLcMode::LC_LENSFUNMANUAL;
}
Glib::ustring getMethodString(eLcMode mode) const
{
return methodstring[static_cast<size_t>(mode)];
}
eLcMode getMethodNumber(const Glib::ustring &mode) const
{
for(size_t i = 0; i < static_cast<size_t>(eLcMode::LC_LCP); ++i) {
if(methodstring[i] == mode) {
return static_cast<eLcMode>(i);
}
}
return eLcMode::LC_NOCORRECTION;
}
};

View File

@ -1857,7 +1857,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le
// Correct vignetting of lens profile
if (!hasFlatField && lensProf.useVign) {
std::unique_ptr<LensCorrection> pmap;
if (lensProf.useLensfun) {
if (lensProf.useLensfun()) {
pmap = std::move(LFDatabase::findModifier(lensProf, idata, W, H, coarse, -1));
} else {
const std::shared_ptr<LCPProfile> pLCPProf = LCPStore::getInstance()->getProfile(lensProf.lcpFile);

View File

@ -437,7 +437,7 @@ std::unique_ptr<LFModifier> LFDatabase::findModifier(const LensProfParams &lensP
const LFDatabase *db = getInstance();
Glib::ustring make, model, lens;
float focallen = idata->getFocalLen();
if (lensProf.lfAutoMatch) {
if (lensProf.lfAutoMatch()) {
if (focallen <= 0) {
return nullptr;
}
@ -450,7 +450,7 @@ std::unique_ptr<LFModifier> LFDatabase::findModifier(const LensProfParams &lensP
lens = lensProf.lfLens;
}
LFCamera c = db->findCamera(make, model);
LFLens l = db->findLens(lensProf.lfAutoMatch ? c : LFCamera(), lens);
LFLens l = db->findLens(lensProf.lfAutoMatch() ? c : LFCamera(), lens);
if (focallen <= 0 && l.data_ && l.data_->MinFocal == l.data_->MaxFocal) {
focallen = l.data_->MinFocal;
}

View File

@ -33,6 +33,7 @@ LensProfilePanel::LFDbHelper *LensProfilePanel::lf(nullptr);
LensProfilePanel::LensProfilePanel () :
FoldableToolPanel(this, "lensprof", M("TP_LENSPROFILE_LABEL")),
lcModeChanged(false),
lcpFileChanged(false),
useDistChanged(false),
useVignChanged(false),
@ -122,10 +123,6 @@ LensProfilePanel::LensProfilePanel () :
hbLCPFile->pack_start(*fcbLCPFile);
btnReset = Gtk::manage(new Gtk::Button());
btnReset->set_image (*Gtk::manage(new RTImage ("gtk-cancel.png")));
hbLCPFile->pack_start(*btnReset, Gtk::PACK_SHRINK, 4);
pack_start(*hbLCPFile, Gtk::PACK_SHRINK, 4);
ckbUseDist = Gtk::manage (new Gtk::CheckButton (M("TP_LENSPROFILE_USEDIST")));
@ -136,7 +133,6 @@ LensProfilePanel::LensProfilePanel () :
pack_start (*ckbUseCA, Gtk::PACK_SHRINK, 4);
conLCPFile = fcbLCPFile->signal_file_set().connect( sigc::mem_fun(*this, &LensProfilePanel::onLCPFileChanged), true);
btnReset->signal_clicked().connect( sigc::mem_fun(*this, &LensProfilePanel::onLCPFileReset), true);
conUseDist = ckbUseDist->signal_toggled().connect( sigc::mem_fun(*this, &LensProfilePanel::onUseDistChanged) );
ckbUseVign->signal_toggled().connect( sigc::mem_fun(*this, &LensProfilePanel::onUseVignChanged) );
ckbUseCA->signal_toggled().connect( sigc::mem_fun(*this, &LensProfilePanel::onUseCAChanged) );
@ -163,32 +159,33 @@ void LensProfilePanel::read(const rtengine::procparams::ProcParams* pp, const Pa
}
corrLensfunAuto->set_sensitive(true);
if (pp->lensProf.useLensfun) {
if (pp->lensProf.lfAutoMatch) {
switch(pp->lensProf.lcMode) {
case procparams::LensProfParams::eLcMode::LC_LCP :
corrLcpFile->set_active(true);
break;
case procparams::LensProfParams::eLcMode::LC_LENSFUNAUTOMATCH :
corrLensfunAuto->set_active(true);
} else {
break;
case procparams::LensProfParams::eLcMode::LC_LENSFUNMANUAL :
corrLensfunManual->set_active(true);
}
} else if (!pp->lensProf.lcpFile.empty() && LCPStore::getInstance()->isValidLCPFileName(pp->lensProf.lcpFile)) {
corrLcpFile->set_active(true);
break;
case procparams::LensProfParams::eLcMode::LC_NOCORRECTION :
corrOff->set_active(true);
}
if (pp->lensProf.lcpFile.empty()) {
Glib::ustring lastFolder = fcbLCPFile->get_current_folder();
fcbLCPFile->set_current_folder(lastFolder);
fcbLCPFile->set_filename(lastFolder + "/.");
bindCurrentFolder(*fcbLCPFile, options.lastLensProfileDir);
updateDisabled(false);
} else if (LCPStore::getInstance()->isValidLCPFileName(pp->lensProf.lcpFile)) {
fcbLCPFile->set_filename (pp->lensProf.lcpFile);
updateDisabled(true);
} else {
Glib::ustring fname = fcbLCPFile->get_filename();
if (!pp->lensProf.lcpFile.empty()) {
fcbLCPFile->unselect_filename(fname);
} else {
Glib::ustring lastFolder = fcbLCPFile->get_current_folder();
fcbLCPFile->set_current_folder(lastFolder);
fcbLCPFile->set_filename(lastFolder + "/.");
bindCurrentFolder(*fcbLCPFile, options.lastLensProfileDir);
}
fcbLCPFile->unselect_filename(fcbLCPFile->get_filename());
updateDisabled(false);
corrOff->set_active(true);
}
ckbUseDist->set_active (pp->lensProf.useDist);
@ -203,14 +200,14 @@ void LensProfilePanel::read(const rtengine::procparams::ProcParams* pp, const Pa
l = db->findLens(c, metadata->getLens());
}
if (!setLensfunCamera(pp->lensProf.lfCameraMake, pp->lensProf.lfCameraModel) && pp->lensProf.lfAutoMatch) {
if (!setLensfunCamera(pp->lensProf.lfCameraMake, pp->lensProf.lfCameraModel) && !pp->lensProf.lfManual()) {
setLensfunCamera(c.getMake(), c.getModel());
}
if (!setLensfunLens(pp->lensProf.lfLens) && pp->lensProf.lfAutoMatch) {
if (!setLensfunLens(pp->lensProf.lfLens) && !pp->lensProf.lfManual()) {
setLensfunLens(l.getLens());
}
lcpFileChanged = useDistChanged = useVignChanged = useCAChanged = false;
lcModeChanged = lcpFileChanged = useDistChanged = useVignChanged = useCAChanged = false;
useLensfunChanged = lensfunAutoChanged = lensfunCameraChanged = lensfunLensChanged = false;
if (!batchMode && !checkLensfunCanCorrect(true)) {
@ -276,7 +273,17 @@ void LensProfilePanel::setRawMeta(bool raw, const rtengine::ImageMetaData* pMeta
void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited* pedited)
{
if (corrLcpFile->get_active() && LCPStore::getInstance()->isValidLCPFileName(fcbLCPFile->get_filename())) {
if (corrLcpFile->get_active()) {
pp->lensProf.lcMode = procparams::LensProfParams::eLcMode::LC_LCP;
} else if(corrLensfunManual->get_active()) {
pp->lensProf.lcMode = procparams::LensProfParams::eLcMode::LC_LENSFUNMANUAL;
} else if(corrLensfunAuto->get_active()) {
pp->lensProf.lcMode = procparams::LensProfParams::eLcMode::LC_LENSFUNAUTOMATCH;
} else if(corrOff->get_active()) {
pp->lensProf.lcMode = procparams::LensProfParams::eLcMode::LC_NOCORRECTION;
}
if (LCPStore::getInstance()->isValidLCPFileName(fcbLCPFile->get_filename())) {
pp->lensProf.lcpFile = fcbLCPFile->get_filename();
} else {
pp->lensProf.lcpFile = "";
@ -286,8 +293,6 @@ void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited
pp->lensProf.useVign = ckbUseVign->get_active();
pp->lensProf.useCA = ckbUseCA->get_active();
pp->lensProf.useLensfun = corrLensfunAuto->get_active() || corrLensfunManual->get_active();
pp->lensProf.lfAutoMatch = corrLensfunAuto->get_active();
auto itc = lensfunCameras->get_active();
if (itc) {
pp->lensProf.lfCameraMake = (*itc)[lf->lensfunModelCam.make];
@ -304,6 +309,7 @@ void LensProfilePanel::write( rtengine::procparams::ProcParams* pp, ParamsEdited
}
if (pedited) {
pedited->lensProf.lcMode = lcModeChanged;
pedited->lensProf.lcpFile = lcpFileChanged;
pedited->lensProf.useDist = useDistChanged;
pedited->lensProf.useVign = useVignChanged;
@ -332,22 +338,6 @@ void LensProfilePanel::onLCPFileChanged()
}
}
void LensProfilePanel::onLCPFileReset()
{
lcpFileChanged = true;
fcbLCPFile->unselect_filename(fcbLCPFile->get_filename());
updateDisabled(false);
if (listener) {
disableListener();
corrOff->set_active(true);
enableListener();
listener->panelChanged (EvLCPFile, M("GENERAL_NONE"));
}
}
void LensProfilePanel::onUseDistChanged()
{
useDistChanged = true;
@ -563,7 +553,7 @@ void LensProfilePanel::onCorrModeChanged()
mode = M("GENERAL_UNCHANGED");
}
lcModeChanged = true;
updateLensfunWarning();
if (listener) {
@ -579,7 +569,6 @@ bool LensProfilePanel::checkLensfunCanCorrect(bool automatch)
}
rtengine::procparams::ProcParams lpp;
write(&lpp);
lpp.lensProf.lfAutoMatch = automatch;
std::unique_ptr<LFModifier> mod(LFDatabase::findModifier(lpp.lensProf, metadata, 100, 100, lpp.coarse, -1));
return mod.get() != nullptr;
}

View File

@ -32,9 +32,8 @@ protected:
MyFileChooserButton *fcbLCPFile;
Gtk::CheckButton *ckbUseDist, *ckbUseVign, *ckbUseCA;
Gtk::HBox *hbLCPFile;
Gtk::Button *btnReset;
Gtk::Label *lLCPFileHead;
bool lcpFileChanged, useDistChanged, useVignChanged, useCAChanged;
bool lcModeChanged, lcpFileChanged, useDistChanged, useVignChanged, useCAChanged;
sigc::connection conLCPFile, conUseDist, conUseVign, conUseCA;
void updateDisabled(bool enable);
bool allowFocusDep;
@ -98,7 +97,6 @@ public:
void setRawMeta (bool raw, const rtengine::ImageMetaData* pMeta);
void onLCPFileChanged ();
void onLCPFileReset ();
void onUseDistChanged();
void onUseVignChanged();
void onUseCAChanged();

View File

@ -287,6 +287,7 @@ void ParamsEdited::set (bool v)
commonTrans.autofill = v;
rotate.degree = v;
distortion.amount = v;
lensProf.lcMode = v;
lensProf.lcpFile = v;
lensProf.useDist = v;
lensProf.useVign = v;
@ -826,12 +827,13 @@ void ParamsEdited::initFrom (const std::vector<rtengine::procparams::ProcParams>
commonTrans.autofill = commonTrans.autofill && p.commonTrans.autofill == other.commonTrans.autofill;
rotate.degree = rotate.degree && p.rotate.degree == other.rotate.degree;
distortion.amount = distortion.amount && p.distortion.amount == other.distortion.amount;
lensProf.lcMode = lensProf.lcMode && p.lensProf.lcMode == other.lensProf.lcMode;
lensProf.lcpFile = lensProf.lcpFile && p.lensProf.lcpFile == other.lensProf.lcpFile;
lensProf.useDist = lensProf.useDist && p.lensProf.useDist == other.lensProf.useDist;
lensProf.useVign = lensProf.useVign && p.lensProf.useVign == other.lensProf.useVign;
lensProf.useCA = lensProf.useCA && p.lensProf.useCA == other.lensProf.useCA;
lensProf.useLensfun = lensProf.useLensfun && p.lensProf.useLensfun == other.lensProf.useLensfun;
lensProf.lfAutoMatch = lensProf.lfAutoMatch && p.lensProf.lfAutoMatch == other.lensProf.lfAutoMatch;
lensProf.useLensfun = lensProf.useLensfun && p.lensProf.useLensfun() == other.lensProf.useLensfun();
lensProf.lfAutoMatch = lensProf.lfAutoMatch && p.lensProf.lfAutoMatch() == other.lensProf.lfAutoMatch();
lensProf.lfCameraMake = lensProf.lfCameraMake && p.lensProf.lfCameraMake == other.lensProf.lfCameraMake;
lensProf.lfCameraModel = lensProf.lfCameraModel && p.lensProf.lfCameraModel == other.lensProf.lfCameraModel;
lensProf.lfLens = lensProf.lfLens && p.lensProf.lfLens == other.lensProf.lfLens;
@ -2062,6 +2064,10 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten
toEdit.distortion.amount = dontforceSet && options.baBehav[ADDSET_DIST_AMOUNT] ? toEdit.distortion.amount + mods.distortion.amount : mods.distortion.amount;
}
if (lensProf.lcMode) {
toEdit.lensProf.lcMode = mods.lensProf.lcMode;
}
if (lensProf.lcpFile) {
toEdit.lensProf.lcpFile = mods.lensProf.lcpFile;
}
@ -2078,14 +2084,6 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten
toEdit.lensProf.useCA = mods.lensProf.useCA;
}
if (lensProf.useLensfun) {
toEdit.lensProf.useLensfun = mods.lensProf.useLensfun;
}
if (lensProf.lfAutoMatch) {
toEdit.lensProf.lfAutoMatch = mods.lensProf.lfAutoMatch;
}
if (lensProf.lfCameraMake) {
toEdit.lensProf.lfCameraMake = mods.lensProf.lfCameraMake;
}
@ -3053,7 +3051,7 @@ bool RAWParamsEdited::isUnchanged() const
bool LensProfParamsEdited::isUnchanged() const
{
return lcpFile && useVign && lfLens;
return lcMode && lcpFile && useVign && lfLens;
}
bool RetinexParamsEdited::isUnchanged() const

View File

@ -429,6 +429,7 @@ class LensProfParamsEdited
public:
bool lcpFile, useDist, useVign, useCA;
bool useLensfun, lfAutoMatch, lfCameraMake, lfCameraModel, lfLens;
bool lcMode;
bool isUnchanged() const;
};

View File

@ -2,11 +2,13 @@
#define _PPVERSION_
// This number has to be incremented whenever the PP3 file format is modified or the behaviour of a tool changes
#define PPVERSION 326
#define PPVERSION 327
#define PPVERSION_AEXP 301 //value of PPVERSION when auto exposure algorithm was modified
/*
Log of version changes
327 2017-09-15
[Profiles Lens Correction] Added Lensfun
326 2015-07-26
[Exposure] Added 'Perceptual' tone curve mode
325 2015-07-23