diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index ed19f44f0..99315c20d 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -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 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; } diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h index 207e4e86e..ddc6d885a 100644 --- a/rtengine/rtlensfun.h +++ b/rtengine/rtlensfun.h @@ -90,6 +90,7 @@ public: float getCropFactor() const; bool hasVignettingCorrection() const; bool hasDistortionCorrection() const; + bool hasCACorrection() const; private: friend class LFDatabase; diff --git a/rtgui/lensprofile.cc b/rtgui/lensprofile.cc index 6415c1fce..d158f44f4 100644 --- a/rtgui/lensprofile.cc +++ b/rtgui/lensprofile.cc @@ -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); + } } }