libcamera: dw100_vertexmap: Fix dewarp parameter p2 handling
diff mbox series

Message ID 20260209112818.854064-1-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • libcamera: dw100_vertexmap: Fix dewarp parameter p2 handling
Related show

Commit Message

Stefan Klug Feb. 9, 2026, 11:28 a.m. UTC
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 <stefan.klug@ideasonboard.com>
---
 src/libcamera/converter/converter_dw100_vertexmap.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Barnabás Pőcze Feb. 9, 2026, 12:40 p.m. UTC | #1
2026. 02. 09. 12:28 keltezéssel, Stefan Klug írta:
> 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 <stefan.klug@ideasonboard.com>
> ---

Looks ok to me.

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


>   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 2cdfe9767a9f..6e238736c435 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<double, 3, 3> &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 */
> --
> 2.51.0
>
Kieran Bingham Feb. 9, 2026, 2:58 p.m. UTC | #2
Quoting Stefan Klug (2026-02-09 11:28:14)
> 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 <stefan.klug@ideasonboard.com>
> ---
>  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 2cdfe9767a9f..6e238736c435 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<double, 3, 3> &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] } };

Looks sane,

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

>  }
>  
>  } /* namespace libcamera */
> -- 
> 2.51.0
>

Patch
diff mbox series

diff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp
index 2cdfe9767a9f..6e238736c435 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<double, 3, 3> &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 */