[v2,32/35] libcamera: Add and implement LensDewarpEnable control
diff mbox series

Message ID 20251023144841.403689-33-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Full dewarper support on imx8mp
Related show

Commit Message

Stefan Klug Oct. 23, 2025, 2:48 p.m. UTC
Add a LensDewarpEnable control to enable or disable lens dewarping if it
is configured. Implement it for the dw100 converter.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

---

Changes in v2:
- Merged control definition and usage into one patch
- Improved control description
- Fixed actual handling of LensDewarpEnable control that got lost in a
  previous rebase
---
 src/libcamera/control_ids_core.yaml      |  7 +++++++
 src/libcamera/pipeline/rkisp1/rkisp1.cpp | 26 ++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

Comments

Paul Elder Nov. 7, 2025, 10:02 a.m. UTC | #1
Quoting Stefan Klug (2025-10-23 23:48:33)
> Add a LensDewarpEnable control to enable or disable lens dewarping if it
> is configured. Implement it for the dw100 converter.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> 
> ---
> 
> Changes in v2:
> - Merged control definition and usage into one patch
> - Improved control description
> - Fixed actual handling of LensDewarpEnable control that got lost in a
>   previous rebase
> ---
>  src/libcamera/control_ids_core.yaml      |  7 +++++++
>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 26 ++++++++++++++++++++++--
>  2 files changed, 31 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/control_ids_core.yaml b/src/libcamera/control_ids_core.yaml
> index f781865859ac..3bcb475fd102 100644
> --- a/src/libcamera/control_ids_core.yaml
> +++ b/src/libcamera/control_ids_core.yaml
> @@ -1346,4 +1346,11 @@ controls:
>          reduces the WdrExposureValue until the amount of pixels that are close
>          to saturation is lower than this value.
>  
> +  - LensDewarpEnable:
> +      type: bool
> +      direction: inout
> +      description: |
> +        Enable or disable lens dewarping. This control is only available if lens
> +        dewarp parameters are configured in the tuning file.
> +
>  ...
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> index 2280a5554f5a..da3cfc0ffdeb 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> @@ -1492,6 +1492,14 @@ int PipelineHandlerRkISP1::updateControls(RkISP1CameraData *data)
>                                                                       maxCrop);
>                 }
>  
> +               if (data->dewarpParams_.has_value()) {
> +                       if (dewarper_->supportsRequests())
> +                               controls[&controls::LensDewarpEnable] = ControlInfo(false, true, true);
> +                       else
> +                               LOG(RkISP1, Warning)
> +                                       << "dw100 kernel driver has no requests support."
> +                                          " No dynamic configuration possible.";
> +               }
>         }
>  
>         /* Add the IPA registered controls to list of camera controls. */
> @@ -1765,8 +1773,15 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
>                 availableDewarpRequests_.pop();
>         }
>  
> +       bool update = false;
>         auto &vertexMap = dewarper_->vertexMap(&data->mainPathStream_);
>  
> +       const auto &lensDewarpEnable = request->controls().get(controls::LensDewarpEnable);
> +       if (lensDewarpEnable) {
> +               vertexMap.setLensDewarpEnable(*lensDewarpEnable);
> +               update = true;
> +       }
> +
>         /* Handle scaler crop control. */
>         const auto &crop = request->controls().get(controls::ScalerCrop);
>         if (crop) {
> @@ -1775,9 +1790,12 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
>                                 << "Dynamically setting ScalerCrop requires a "
>                                    "dw100 driver with requests support";
>                 vertexMap.setScalerCrop(*crop);
> -               dewarper_->applyVertexMap(&data->mainPathStream_, dewarpRequest);
> +               update = true;
>         }
>  
> +       if (update)
> +               dewarper_->applyVertexMap(&data->mainPathStream_, dewarpRequest);
> +
>         /*
>          * Queue input and output buffers to the dewarper. The output
>          * buffers for the dewarper are the buffers of the request, supplied
> @@ -1809,7 +1827,11 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
>                 }
>         }
>  
> -       request->metadata().set(controls::ScalerCrop, vertexMap.effectiveScalerCrop());
> +       auto &meta = request->metadata();
> +       meta.set(controls::ScalerCrop, vertexMap.effectiveScalerCrop());
> +
> +       if (vertexMap.dewarpParamsValid())
> +               meta.set(controls::LensDewarpEnable, vertexMap.lensDewarpEnable());
>  }
>  
>  void PipelineHandlerRkISP1::dewarpRequestReady(V4L2Request *request)
> -- 
> 2.48.1
>

Patch
diff mbox series

diff --git a/src/libcamera/control_ids_core.yaml b/src/libcamera/control_ids_core.yaml
index f781865859ac..3bcb475fd102 100644
--- a/src/libcamera/control_ids_core.yaml
+++ b/src/libcamera/control_ids_core.yaml
@@ -1346,4 +1346,11 @@  controls:
         reduces the WdrExposureValue until the amount of pixels that are close
         to saturation is lower than this value.
 
+  - LensDewarpEnable:
+      type: bool
+      direction: inout
+      description: |
+        Enable or disable lens dewarping. This control is only available if lens
+        dewarp parameters are configured in the tuning file.
+
 ...
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 2280a5554f5a..da3cfc0ffdeb 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -1492,6 +1492,14 @@  int PipelineHandlerRkISP1::updateControls(RkISP1CameraData *data)
 								      maxCrop);
 		}
 
+		if (data->dewarpParams_.has_value()) {
+			if (dewarper_->supportsRequests())
+				controls[&controls::LensDewarpEnable] = ControlInfo(false, true, true);
+			else
+				LOG(RkISP1, Warning)
+					<< "dw100 kernel driver has no requests support."
+					   " No dynamic configuration possible.";
+		}
 	}
 
 	/* Add the IPA registered controls to list of camera controls. */
@@ -1765,8 +1773,15 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 		availableDewarpRequests_.pop();
 	}
 
+	bool update = false;
 	auto &vertexMap = dewarper_->vertexMap(&data->mainPathStream_);
 
+	const auto &lensDewarpEnable = request->controls().get(controls::LensDewarpEnable);
+	if (lensDewarpEnable) {
+		vertexMap.setLensDewarpEnable(*lensDewarpEnable);
+		update = true;
+	}
+
 	/* Handle scaler crop control. */
 	const auto &crop = request->controls().get(controls::ScalerCrop);
 	if (crop) {
@@ -1775,9 +1790,12 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 				<< "Dynamically setting ScalerCrop requires a "
 				   "dw100 driver with requests support";
 		vertexMap.setScalerCrop(*crop);
-		dewarper_->applyVertexMap(&data->mainPathStream_, dewarpRequest);
+		update = true;
 	}
 
+	if (update)
+		dewarper_->applyVertexMap(&data->mainPathStream_, dewarpRequest);
+
 	/*
 	 * Queue input and output buffers to the dewarper. The output
 	 * buffers for the dewarper are the buffers of the request, supplied
@@ -1809,7 +1827,11 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 		}
 	}
 
-	request->metadata().set(controls::ScalerCrop, vertexMap.effectiveScalerCrop());
+	auto &meta = request->metadata();
+	meta.set(controls::ScalerCrop, vertexMap.effectiveScalerCrop());
+
+	if (vertexMap.dewarpParamsValid())
+		meta.set(controls::LensDewarpEnable, vertexMap.lensDewarpEnable());
 }
 
 void PipelineHandlerRkISP1::dewarpRequestReady(V4L2Request *request)