From 0c0f3d146d00a9bb26d0f385203bc198d5257e0d Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Sat, 9 Sep 2017 18:41:47 +0200 Subject: [PATCH] lensfun: take the focal length from the lens (if a prime) when there is no exif info about it --- rtengine/rtlensfun.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index 78e07d2c9..c90de08d9 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -306,10 +306,14 @@ LFModifier *LFDatabase::getModifier(const LFCamera &camera, const LFLens &lens, int width, int height, bool swap_xy) const { LFModifier *ret = nullptr; - if (data_ && focalLen > 0) { + if (data_) { if (camera.ok() && lens.ok()) { lfModifier *mod = lfModifier::Create(lens.data_, camera.getCropFactor(), width, height); - int flags = mod->Initialize(lens.data_, LF_PF_F32, focalLen, aperture, focusDist > 0 ? focusDist : 1000, 0.0, LF_RECTILINEAR, LF_MODIFY_VIGNETTING | LF_MODIFY_DISTORTION | LF_MODIFY_SCALE, false); + int flags = LF_MODIFY_DISTORTION | LF_MODIFY_SCALE; + if (aperture > 0) { + flags |= LF_MODIFY_VIGNETTING; + } + flags = mod->Initialize(lens.data_, LF_PF_F32, focalLen, aperture, focusDist > 0 ? focusDist : 1000, 0.0, LF_RECTILINEAR, flags, false); ret = new LFModifier(mod, swap_xy, flags); } } @@ -321,7 +325,11 @@ LFModifier *LFDatabase::findModifier(const LensProfParams &lensProf, const Image { const LFDatabase *db = getInstance(); Glib::ustring make, model, lens; + float focallen = idata->getFocalLen(); if (lensProf.lfAutoMatch) { + if (focallen <= 0) { + return nullptr; + } make = idata->getMake(); model = idata->getModel(); lens = idata->getLens(); @@ -332,6 +340,12 @@ LFModifier *LFDatabase::findModifier(const LensProfParams &lensProf, const Image } LFCamera c = db->findCamera(make, model); LFLens l = db->findLens(lensProf.lfAutoMatch ? c : LFCamera(), lens); + if (focallen <= 0 && l.data_ && l.data_->MinFocal == l.data_->MaxFocal) { + focallen = l.data_->MinFocal; + } + if (focallen <= 0) { + return nullptr; + } bool swap_xy = false; if (rawRotationDeg >= 0) { int rot = (coarse.rotate + rawRotationDeg) % 360; @@ -343,7 +357,6 @@ LFModifier *LFDatabase::findModifier(const LensProfParams &lensProf, const Image LFModifier *ret = db->getModifier(c, l, idata->getFocalLen(), idata->getFNumber(), idata->getFocusDist(), width, height, swap_xy); - if (settings->verbose) { std::cout << "LENSFUN:\n" << " camera: " << c.getDisplayString() << "\n"