From 1dcf9957a47fb54fce4fbae9daec0b587e52562e Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Mon, 9 Feb 2026 12:28:14 +0100 Subject: [PATCH] libcamera: converter: converter_dw100_vertexmap: Fix dewarp parameter p2 handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The lens dewarp implementation done in commit 1784e08be3a6 ("libcamera: dw100_vertexmap: Implement parametric dewarping") handles the dewarp parameter p2 incorrectly because it uses the already dewarped x value as input for the calculation of the y value. Fix that by using separate variables for the output value. Do so for x and y to keep the code symmetric even if it is only strictly required for y. Fixes: 1784e08be3a6 ("libcamera: dw100_vertexmap: Implement parametric dewarping") Signed-off-by: Stefan Klug Reviewed-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- src/libcamera/converter/converter_dw100_vertexmap.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp index 2cdfe976..6e238736 100644 --- a/src/libcamera/converter/converter_dw100_vertexmap.cpp +++ b/src/libcamera/converter/converter_dw100_vertexmap.cpp @@ -628,6 +628,7 @@ int Dw100VertexMap::setDewarpParams(const Matrix &cm, Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p) { double x, y; + double xout, yout; double k1 = dewarpCoeffs_[0]; double k2 = dewarpCoeffs_[1]; double p1 = dewarpCoeffs_[2]; @@ -647,11 +648,11 @@ Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p) double r2 = x * x + y * y; double d = (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2) / (1 + k4 * r2 + k5 * r2 * r2 + k6 * r2 * r2 * r2); - x = x * d + 2 * p1 * x * y + p2 * (r2 + 2 * x * x) + s1 * r2 + s2 * r2 * r2; - y = y * d + 2 * p2 * x * y + p1 * (r2 + 2 * y * y) + s3 * r2 + s4 * r2 * r2; + xout = x * d + 2 * p1 * x * y + p2 * (r2 + 2 * x * x) + s1 * r2 + s2 * r2 * r2; + yout = y * d + 2 * p2 * x * y + p1 * (r2 + 2 * y * y) + s3 * r2 + s4 * r2 * r2; - return { { x * dewarpM_[0][0] + y * dewarpM_[0][1] + dewarpM_[0][2], - y * dewarpM_[1][1] + dewarpM_[1][2] } }; + return { { xout * dewarpM_[0][0] + yout * dewarpM_[0][1] + dewarpM_[0][2], + yout * dewarpM_[1][1] + dewarpM_[1][2] } }; } } /* namespace libcamera */