added support for CA correction via lensfun

Performance could be improved (see the comments marked "agriggio" in iptransform.cc and rtlensfun.cc)
This commit is contained in:
Alberto Griggio 2017-10-26 23:55:52 +02:00
parent a29287eaa0
commit 830fd6fdbb
3 changed files with 44 additions and 2 deletions

View File

@ -72,12 +72,29 @@ void LFModifier::correctDistortion(double &x, double &y, int cx, int cy, double
bool LFModifier::isCACorrectionAvailable() const
{
return false;
return (flags_ & LF_MODIFY_TCA);
}
void LFModifier::correctCA(double &x, double &y, int channel) const
{
assert(channel >= 0 && channel <= 2);
// agriggio: RT currently applies the CA correction per channel, whereas
// lensfun applies it to all the three channels simultaneously. This means
// we do the work 3 times, because each time we discard 2 of the 3
// channels. We could consider caching the info to speed this up
float pos[6];
if (swap_xy_) {
std::swap(x, y);
}
data_->ApplySubpixelDistortion(x, y, 1, 1, pos);
x = pos[2*channel];
y = pos[2*channel+1];
if (swap_xy_) {
std::swap(x, y);
}
}
@ -109,6 +126,11 @@ Glib::ustring LFModifier::getDisplayString() const
ret += "vignetting";
sep = ", ";
}
if (flags_ & LF_MODIFY_TCA) {
ret += sep;
ret += "CA";
sep = ", ";
}
if (flags_ & LF_MODIFY_SCALE) {
ret += sep;
ret += "autoscaling";
@ -245,6 +267,15 @@ bool LFLens::hasDistortionCorrection() const
}
}
bool LFLens::hasCACorrection() const
{
if (data_) {
return data_->CalibTCA;
} else {
return false;
}
}
//-----------------------------------------------------------------------------
// LFDatabase
@ -428,7 +459,7 @@ std::unique_ptr<LFModifier> LFDatabase::getModifier(const LFCamera &camera, cons
if (data_) {
if (camera && lens) {
lfModifier *mod = lfModifier::Create(lens.data_, camera.getCropFactor(), width, height);
int flags = LF_MODIFY_DISTORTION | LF_MODIFY_SCALE;
int flags = LF_MODIFY_DISTORTION | LF_MODIFY_SCALE | LF_MODIFY_TCA;
if (aperture > 0) {
flags |= LF_MODIFY_VIGNETTING;
}

View File

@ -90,6 +90,7 @@ public:
float getCropFactor() const;
bool hasVignettingCorrection() const;
bool hasDistortionCorrection() const;
bool hasCACorrection() const;
private:
friend class LFDatabase;

View File

@ -254,6 +254,16 @@ void LensProfilePanel::updateLensfunWarning()
}
ckbUseVign->set_sensitive(l.hasVignettingCorrection());
ckbUseDist->set_sensitive(l.hasDistortionCorrection());
ckbUseCA->set_sensitive(l.hasCACorrection());
if (!isRaw || !l.hasVignettingCorrection()) {
ckbUseVign->set_active(false);
}
if (!l.hasDistortionCorrection()) {
ckbUseDist->set_active(false);
}
if (!l.hasCACorrection()) {
ckbUseCA->set_active(false);
}
}
}