diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index f2900fdf1..47153c93c 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -491,15 +491,8 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector &src, for (size_t i = 0; i < src.size(); i++) { double x_d = src[i].x, y_d = src[i].y; - if (pLCPMap && params->lensProf.useDist) { - pLCPMap->correctDistortion(x_d, y_d, 0, 0, ascale); - } else { - x_d *= ascale; - y_d *= ascale; - } - - x_d += ascale * (0 - w2); // centering x coord & scale - y_d += ascale * (0 - h2); // centering y coord & scale + y_d = ascale * (y_d - h2); // centering x coord & scale + x_d = ascale * (x_d - w2); // centering x coord & scale switch (perspectiveType) { case PerspType::NONE: @@ -522,6 +515,10 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector &src, break; } + if (pLCPMap && params->lensProf.useDist) { + pLCPMap->correctDistortion(x_d, y_d, 0, 0); + } + // rotate double Dx = x_d * cost - y_d * sint; double Dy = x_d * sint + y_d * cost; @@ -1219,15 +1216,8 @@ void ImProcFunctions::transformGeneral(bool highQuality, Imagefloat *original, I double x_d = x; double y_d = y; - if (enableLCPDist) { - pLCPMap->correctDistortion(x_d, y_d, cx, cy, ascale); // must be first transform - } else { - x_d *= ascale; - y_d *= ascale; - } - - x_d += ascale * centerFactorx; // centering x coord & scale - y_d += ascale * centerFactory; // centering y coord & scale + x_d = ascale * (x_d + centerFactorx); // centering x coord & scale + y_d = ascale * (y_d + centerFactory); // centering y coord & scale switch (perspectiveType) { case PerspType::NONE: @@ -1250,6 +1240,10 @@ void ImProcFunctions::transformGeneral(bool highQuality, Imagefloat *original, I break; } + if (enableLCPDist) { + pLCPMap->correctDistortion(x_d, y_d, w2, h2); + } + // rotate const double Dxc = x_d * cost - y_d * sint; const double Dyc = x_d * sint + y_d * cost; diff --git a/rtengine/lcp.cc b/rtengine/lcp.cc index 1826101e7..8e90a3549 100644 --- a/rtengine/lcp.cc +++ b/rtengine/lcp.cc @@ -990,16 +990,16 @@ bool rtengine::LCPMapper::isCACorrectionAvailable() const return enableCA; } -void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy, double scale) const +void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy) const { x += cx; y += cy; if (isFisheye) { - const double u = x * scale; - const double v = y * scale; - const double u0 = static_cast(mc.x0) * scale; - const double v0 = static_cast(mc.y0) * scale; + const double u = x; + const double v = y; + const double u0 = static_cast(mc.x0); + const double v0 = static_cast(mc.y0); const double du = (u - u0); const double dv = (v - v0); const double fx = mc.fx; @@ -1007,7 +1007,7 @@ void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy const double k1 = mc.param[0]; const double k2 = mc.param[1]; const double r = sqrt(du * du + dv * dv); - const double f = sqrt(fx*fy / (scale * scale)); + const double f = sqrt(fx*fy); const double th = atan2(r, f); const double th2 = th * th; const double cfact = (((k2 * th2 + k1) * th2 + 1) * th) / r; @@ -1017,10 +1017,8 @@ void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy x = ud; y = vd; } else { - x *= scale; - y *= scale; - const double x0 = static_cast(mc.x0) * scale; - const double y0 = static_cast(mc.y0) * scale; + const double x0 = static_cast(mc.x0); + const double y0 = static_cast(mc.y0); const double xd = (x - x0) / static_cast(mc.fx), yd = (y - y0) / static_cast(mc.fy); const auto& aDist = mc.param; @@ -1037,8 +1035,8 @@ void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy y = ynew * static_cast(mc.fy) + y0; } - x -= cx * scale; - y -= cy * scale; + x -= cx; + y -= cy; } void rtengine::LCPMapper::correctCA(double& x, double& y, int cx, int cy, int channel) const diff --git a/rtengine/lcp.h b/rtengine/lcp.h index 4c1e09865..b59cc84c6 100644 --- a/rtengine/lcp.h +++ b/rtengine/lcp.h @@ -166,7 +166,7 @@ private: class LensCorrection { public: virtual ~LensCorrection() {} - virtual void correctDistortion(double &x, double &y, int cx, int cy, double scale) const = 0; + virtual void correctDistortion(double &x, double &y, int cx, int cy) const = 0; virtual bool isCACorrectionAvailable() const = 0; virtual void correctCA(double &x, double &y, int cx, int cy, int channel) const = 0; virtual void processVignette(int width, int height, float** rawData) const = 0; @@ -194,7 +194,7 @@ public: ); - void correctDistortion(double &x, double &y, int cx, int cy, double scale) const override; // MUST be the first stage + void correctDistortion(double &x, double &y, int cx, int cy) const override; bool isCACorrectionAvailable() const override; void correctCA(double& x, double& y, int cx, int cy, int channel) const override; void processVignette(int width, int height, float** rawData) const override; diff --git a/rtengine/rtlensfun.cc b/rtengine/rtlensfun.cc index 7ffb9ad33..363819cf7 100644 --- a/rtengine/rtlensfun.cc +++ b/rtengine/rtlensfun.cc @@ -46,7 +46,7 @@ LFModifier::operator bool() const } -void LFModifier::correctDistortion(double &x, double &y, int cx, int cy, double scale) const +void LFModifier::correctDistortion(double &x, double &y, int cx, int cy) const { if (!data_) { return; @@ -67,8 +67,6 @@ void LFModifier::correctDistortion(double &x, double &y, int cx, int cy, double x -= cx; y -= cy; } - x *= scale; - y *= scale; } diff --git a/rtengine/rtlensfun.h b/rtengine/rtlensfun.h index 2f3e4677d..51212c9b9 100644 --- a/rtengine/rtlensfun.h +++ b/rtengine/rtlensfun.h @@ -53,7 +53,7 @@ public: explicit operator bool() const; - void correctDistortion(double &x, double &y, int cx, int cy, double scale) const override; + void correctDistortion(double &x, double &y, int cx, int cy) const override; bool isCACorrectionAvailable() const override; void correctCA(double &x, double &y, int cx, int cy, int channel) const override; void processVignette(int width, int height, float** rawData) const override;