From 841e2ff26f25edc79e47c2aa7ca6ce62b8b60c97 Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Sat, 11 Feb 2023 22:53:23 +0100 Subject: [PATCH] Add de-fishing to ImProcFunctions::transCoord so the source window is correctly estimated when using de-fishing --- rtengine/iptransform.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index d863d3041..301d4b929 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -519,6 +519,21 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector &src, pLCPMap->correctDistortion(x_d, y_d, w2, h2); } + x_d /= params->perspective.camera_scale; + y_d /= params->perspective.camera_scale; + if (true || params->perspective.camera_defish) { + double const focal_source = params->perspective.camera_focal_length * maxRadius*1351.0/5206.416/6.5; + double focal_dst = focal_source; + x_d /= focal_dst; + y_d /= focal_dst; + + double const r = std::sqrt(x_d*x_d + y_d*y_d); + double const factor = focal_source * std::atan(r)/r; + + x_d *= factor; + y_d *= factor; + } + // rotate double Dx = x_d * cost - y_d * sint; double Dy = x_d * sint + y_d * cost; @@ -1497,7 +1512,8 @@ bool ImProcFunctions::needsPerspective () const params->perspective.projection_rotate || params->perspective.projection_shift_horiz || params->perspective.projection_shift_vert || - params->perspective.projection_yaw) ); + params->perspective.projection_yaw || + params->perspective.camera_defish) ); } bool ImProcFunctions::needsGradient () const