From 512517327ff93d32b0bcce39d8a101ce7332eaac Mon Sep 17 00:00:00 2001 From: Lawrence Date: Thu, 2 Jan 2020 17:10:41 -0800 Subject: [PATCH] Move profiled distortion correction in pipeline Lensfun/LCP distortion correction was applied before automatic scaling and perspective correction in the inverse transformation. This means it was applied after scaling and perspective in the pipeline. It should actually come first. --- rtengine/iptransform.cc | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index af513536e..bc490ce82 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -253,15 +253,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 if (needsPerspective()) { // horizontal perspective transformation @@ -273,6 +266,10 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector &src, y_d *= maxRadius * vpcospt / (maxRadius - y_d * vptanpt); } + if (pLCPMap && params->lensProf.useDist) { + pLCPMap->correctDistortion(x_d, y_d, 0, 0, 1); + } + // rotate double Dx = x_d * cost - y_d * sint; double Dy = x_d * sint + y_d * cost; @@ -935,15 +932,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 if (enablePerspective) { // horizontal perspective transformation @@ -955,6 +945,10 @@ void ImProcFunctions::transformGeneral(bool highQuality, Imagefloat *original, I y_d *= maxRadius * vpcospt / (maxRadius - y_d * vptanpt); } + if (enableLCPDist) { + pLCPMap->correctDistortion(x_d, y_d, w2, h2, 1); // must be first transform + } + // rotate const double Dxc = x_d * cost - y_d * sint; const double Dyc = x_d * sint + y_d * cost;