handle coarse rotation in lensfun distortion correction
This commit is contained in:
parent
18f3bd6f45
commit
940577ce45
@ -322,26 +322,7 @@ void ImProcFunctions::transform (Imagefloat* original, Imagefloat* transformed,
|
|||||||
LensCorrection *pLCPMap = nullptr;
|
LensCorrection *pLCPMap = nullptr;
|
||||||
|
|
||||||
if (needsLensfun()) {
|
if (needsLensfun()) {
|
||||||
const LFDatabase *db = LFDatabase::getInstance();
|
pLCPMap = LFDatabase::findModifier(params->lensProf, metadata, fW, fH, params->coarse, rawRotationDeg);
|
||||||
Glib::ustring make, model, lens;
|
|
||||||
if (params->lensProf.lfAutoMatch) {
|
|
||||||
make = metadata->getMake();
|
|
||||||
model = metadata->getModel();
|
|
||||||
lens = metadata->getLens();
|
|
||||||
} else {
|
|
||||||
make = params->lensProf.lfCameraMake;
|
|
||||||
model = params->lensProf.lfCameraModel;
|
|
||||||
lens = params->lensProf.lfLens;
|
|
||||||
}
|
|
||||||
LFCamera c = db->findCamera(make, model);
|
|
||||||
LFLens l = db->findLens(c, lens);
|
|
||||||
pLCPMap = db->getModifier(c, l, fW, fH, focalLen, fNumber, focusDist);
|
|
||||||
|
|
||||||
std::cout << "LENSFUN:\n"
|
|
||||||
<< " camera: " << c.getDisplayString() << "\n"
|
|
||||||
<< " lens: " << l.getDisplayString() << "\n"
|
|
||||||
<< " correction? " << (pLCPMap ? "yes" : "no") << std::endl;
|
|
||||||
|
|
||||||
} else if (needsLCP()) { // don't check focal length to allow distortion correction for lenses without chip
|
} else if (needsLCP()) { // don't check focal length to allow distortion correction for lenses without chip
|
||||||
LCPProfile *pLCPProf = lcpStore->getProfile (params->lensProf.lcpFile);
|
LCPProfile *pLCPProf = lcpStore->getProfile (params->lensProf.lcpFile);
|
||||||
|
|
||||||
|
@ -1858,20 +1858,7 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le
|
|||||||
if (!hasFlatField && lensProf.useVign) {
|
if (!hasFlatField && lensProf.useVign) {
|
||||||
std::unique_ptr<LensCorrection> pmap;
|
std::unique_ptr<LensCorrection> pmap;
|
||||||
if (lensProf.useLensfun) {
|
if (lensProf.useLensfun) {
|
||||||
const LFDatabase *db = LFDatabase::getInstance();
|
pmap.reset(LFDatabase::findModifier(lensProf, idata, W, H, coarse, -1));
|
||||||
Glib::ustring make, model, lens;
|
|
||||||
if (lensProf.lfAutoMatch) {
|
|
||||||
make = idata->getMake();
|
|
||||||
model = idata->getModel();
|
|
||||||
lens = idata->getLens();
|
|
||||||
} else {
|
|
||||||
make = lensProf.lfCameraMake;
|
|
||||||
model = lensProf.lfCameraModel;
|
|
||||||
lens = lensProf.lfLens;
|
|
||||||
}
|
|
||||||
LFCamera c = db->findCamera(make, model);
|
|
||||||
LFLens l = db->findLens(c, lens);
|
|
||||||
pmap.reset(db->getModifier(c, l, W, H, idata->getFocalLen(), idata->getFNumber(), idata->getFocusDist()));
|
|
||||||
} else {
|
} else {
|
||||||
LCPProfile *pLCPProf = lcpStore->getProfile(lensProf.lcpFile);
|
LCPProfile *pLCPProf = lcpStore->getProfile(lensProf.lcpFile);
|
||||||
|
|
||||||
|
@ -19,15 +19,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "rtlensfun.h"
|
#include "rtlensfun.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace rtengine {
|
namespace rtengine {
|
||||||
|
|
||||||
|
extern const Settings *settings;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// LFModifier
|
// LFModifier
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
LFModifier::LFModifier(lfModifier *m):
|
LFModifier::LFModifier(lfModifier *m, bool swap_xy):
|
||||||
data_(m)
|
data_(m),
|
||||||
|
swap_xy_(swap_xy)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,9 +57,17 @@ void LFModifier::correctDistortion(double &x, double &y, int cx, int cy, double
|
|||||||
}
|
}
|
||||||
|
|
||||||
float pos[2];
|
float pos[2];
|
||||||
if (data_->ApplyGeometryDistortion(x+cx, y+cy, 1, 1, pos)) {
|
float xx = x + cx;
|
||||||
|
float yy = y + cy;
|
||||||
|
if (swap_xy_) {
|
||||||
|
std::swap(xx, yy);
|
||||||
|
}
|
||||||
|
if (data_->ApplyGeometryDistortion(xx, yy, 1, 1, pos)) {
|
||||||
x = pos[0] - cx;
|
x = pos[0] - cx;
|
||||||
y = pos[1] - cy;
|
y = pos[1] - cy;
|
||||||
|
if (swap_xy_) {
|
||||||
|
std::swap(x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,19 +270,57 @@ LFLens LFDatabase::findLens(const LFCamera &camera, const Glib::ustring &name) c
|
|||||||
|
|
||||||
|
|
||||||
LFModifier *LFDatabase::getModifier(const LFCamera &camera, const LFLens &lens,
|
LFModifier *LFDatabase::getModifier(const LFCamera &camera, const LFLens &lens,
|
||||||
int width, int height, float focalLen,
|
float focalLen, float aperture, float focusDist,
|
||||||
float aperture, float focusDist) const
|
int width, int height, bool swap_xy) const
|
||||||
{
|
{
|
||||||
LFModifier *ret = nullptr;
|
LFModifier *ret = nullptr;
|
||||||
if (data_) {
|
if (data_) {
|
||||||
if (camera.ok() && lens.ok()) {
|
if (camera.ok() && lens.ok()) {
|
||||||
lfModifier *mod = lfModifier::Create(lens.data_, camera.getCropFactor(), width, height);
|
lfModifier *mod = lfModifier::Create(lens.data_, camera.getCropFactor(), width, height);
|
||||||
mod->Initialize(lens.data_, LF_PF_F32, focalLen, aperture, focusDist > 0 ? focusDist : 1000, 0.0, LF_RECTILINEAR, LF_MODIFY_VIGNETTING | LF_MODIFY_DISTORTION, false);
|
mod->Initialize(lens.data_, LF_PF_F32, focalLen, aperture, focusDist > 0 ? focusDist : 1000, 0.0, LF_RECTILINEAR, LF_MODIFY_VIGNETTING | LF_MODIFY_DISTORTION, false);
|
||||||
ret = new LFModifier(mod);
|
ret = new LFModifier(mod, swap_xy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LFModifier *LFDatabase::findModifier(const LensProfParams &lensProf, const ImageMetaData *idata, int width, int height, const CoarseTransformParams &coarse, int rawRotationDeg)
|
||||||
|
{
|
||||||
|
const LFDatabase *db = getInstance();
|
||||||
|
Glib::ustring make, model, lens;
|
||||||
|
if (lensProf.lfAutoMatch) {
|
||||||
|
make = idata->getMake();
|
||||||
|
model = idata->getModel();
|
||||||
|
lens = idata->getLens();
|
||||||
|
} else {
|
||||||
|
make = lensProf.lfCameraMake;
|
||||||
|
model = lensProf.lfCameraModel;
|
||||||
|
lens = lensProf.lfLens;
|
||||||
|
}
|
||||||
|
LFCamera c = db->findCamera(make, model);
|
||||||
|
LFLens l = db->findLens(c, lens);
|
||||||
|
bool swap_xy = false;
|
||||||
|
if (rawRotationDeg >= 0) {
|
||||||
|
int rot = (coarse.rotate + rawRotationDeg) % 360;
|
||||||
|
swap_xy = (rot == 90 || rot == 270);
|
||||||
|
if (swap_xy) {
|
||||||
|
std::swap(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
<< " lens: " << l.getDisplayString() << "\n"
|
||||||
|
<< " correction? " << (ret ? "yes" : "no") << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace rtengine
|
} // namespace rtengine
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "lcp.h"
|
#include "lcp.h"
|
||||||
|
#include "procparams.h"
|
||||||
|
|
||||||
namespace rtengine {
|
namespace rtengine {
|
||||||
|
|
||||||
@ -40,12 +41,13 @@ public:
|
|||||||
void processVignetteLine3Channels(int width, int y, float *line) const;
|
void processVignetteLine3Channels(int width, int y, float *line) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit LFModifier(lfModifier *m);
|
explicit LFModifier(lfModifier *m, bool rotateXY);
|
||||||
LFModifier(const LFModifier &);
|
LFModifier(const LFModifier &);
|
||||||
LFModifier &operator=(const LFModifier &);
|
LFModifier &operator=(const LFModifier &);
|
||||||
|
|
||||||
friend class LFDatabase;
|
friend class LFDatabase;
|
||||||
lfModifier *data_;
|
lfModifier *data_;
|
||||||
|
bool swap_xy_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LFCamera {
|
class LFCamera {
|
||||||
@ -87,8 +89,10 @@ public:
|
|||||||
LFCamera findCamera(const Glib::ustring &make, const Glib::ustring &model) const;
|
LFCamera findCamera(const Glib::ustring &make, const Glib::ustring &model) const;
|
||||||
LFLens findLens(const LFCamera &camera, const Glib::ustring &name) const;
|
LFLens findLens(const LFCamera &camera, const Glib::ustring &name) const;
|
||||||
LFModifier *getModifier(const LFCamera &camera, const LFLens &lens,
|
LFModifier *getModifier(const LFCamera &camera, const LFLens &lens,
|
||||||
int width, int height,
|
float focalLen, float aperture, float focusDist,
|
||||||
float focalLen, float aperture, float focusDist) const;
|
int width, int height, bool swap_xy) const;
|
||||||
|
|
||||||
|
static LFModifier *findModifier(const LensProfParams &lensProf, const ImageMetaData *idata, int width, int height, const CoarseTransformParams &coarse, int rawRotationDeg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LFDatabase();
|
LFDatabase();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user