[v1,23/33] libcamera: rkisp1: Implement dw100 specific features
diff mbox series

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

Commit Message

Stefan Klug Sept. 30, 2025, 12:26 p.m. UTC
The dw100 allows more features implemented in the dw100 vertex map.
Implement these features for the rkisp1 pipeline.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/libcamera/control_ids_draft.yaml     | 39 ++++++++++++++++++-
 src/libcamera/pipeline/rkisp1/rkisp1.cpp | 48 +++++++++++++++++++++++-
 2 files changed, 85 insertions(+), 2 deletions(-)

Comments

Barnabás Pőcze Sept. 30, 2025, 1:52 p.m. UTC | #1
Hi

2025. 09. 30. 14:26 keltezéssel, Stefan Klug írta:
> The dw100 allows more features implemented in the dw100 vertex map.
> Implement these features for the rkisp1 pipeline.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>   src/libcamera/control_ids_draft.yaml     | 39 ++++++++++++++++++-
>   src/libcamera/pipeline/rkisp1/rkisp1.cpp | 48 +++++++++++++++++++++++-
>   2 files changed, 85 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/control_ids_draft.yaml b/src/libcamera/control_ids_draft.yaml
> index 03309eeac34f..10ee68db6d8c 100644
> --- a/src/libcamera/control_ids_draft.yaml
> +++ b/src/libcamera/control_ids_draft.yaml
> @@ -206,7 +206,44 @@ controls:
>               available only on this camera device are at least this numeric
>               value. All of the custom test patterns will be static (that is the
>               raw image must not vary from frame to frame).
> -
> +  - Dw100ScaleMode:
> +      type: int32_t
> +      direction: inout
> +      description: |
> +        Scale mode of the dewarper.
> +      enum:

Wrt. https://patchwork.libcamera.org/patch/24496/ could you prefix the
names of the enumerators with exactly the name of the control?


Regards,
Barnabás Pőcze


> +        - name: Fill
> +          value: 0
> +          description: |
> +            Fills the given output size with the largest rectangle possible.
> +            Aspect ratio is not preserved. Dw100Scale and Dw100Offset are
> +            ignored.
> +        - name: Crop
> +          value: 1
> +          description: |
> +            Crops to the given output size. The scale factor can be specified
> +            using Dw100Scale. Aspect ratio is preserved.
> +  - Dw100Scale:
> +      type: float
> +      direction: inout
> +      description: |
> +        Scale factor applied to the image when Dw100ScaleMode is set to Crop.
> +        This value is clamped, so that all pixels have valid input data.
> +        Therefore a value of 0 always provides the largest possible field of
> +        view.
> +  - Dw100Rotation:
> +      type: float
> +      direction: inout
> +      description: |
> +        Rotates the image by the given angle in degrees.
> +  - Dw100Offset:
> +      type: Point
> +      direction: inout
> +      description: |
> +        Moves the image by the given values in x and y direction in output
> +        coordinate space. This is clamped, so that all output pixels contain
> +        valid data. The offset is therefore ignored when Dw100ScaleMode is set
> +        to 'Fit' or the Dw100Scale value is too small.
>     - FaceDetectMode:
>         type: int32_t
>         direction: inout
> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> index 8b78c7f213f6..740791ac9c02 100644
> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
> @@ -1364,6 +1364,17 @@ int PipelineHandlerRkISP1::updateControls(RkISP1CameraData *data)
>   							      scalerMaxCrop_);
>   		data->properties_.set(properties::ScalerCropMaximum, scalerMaxCrop_);
>   		activeCrop_ = scalerMaxCrop_;
> +
> +		if (dewarper_->supportsRequests()) {
> +			controls[&controls::draft::Dw100Scale] = ControlInfo(0.2f, 8.0f, 1.0f);
> +			controls[&controls::draft::Dw100Rotation] = ControlInfo(-180.0f, 180.0f, 0.0f);
> +			controls[&controls::draft::Dw100Offset] = ControlInfo(Point(-10000, -10000), Point(10000, 10000), Point(0, 0));
> +			controls[&controls::draft::Dw100ScaleMode] = ControlInfo(controls::draft::Dw100ScaleModeValues, controls::draft::Fill);
> +		} 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. */
> @@ -1637,6 +1648,37 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
>   		availableDewarpRequests_.pop();
>   	}
> 
> +	bool update = false;
> +	auto &vertexMap = dewarper_->vertexMap(&data->mainPathStream_);
> +
> +	const auto &scale = request->controls().get(controls::draft::Dw100Scale);
> +	if (scale) {
> +		vertexMap.setScale(*scale);
> +		update = true;
> +	}
> +
> +	const auto &rotation = request->controls().get(controls::draft::Dw100Rotation);
> +	if (rotation) {
> +		vertexMap.setRotation(*rotation);
> +		update = true;
> +	}
> +
> +	const auto &offset = request->controls().get(controls::draft::Dw100Offset);
> +	if (offset) {
> +		vertexMap.setOffset(*offset);
> +		update = true;
> +	}
> +
> +	const auto &scaleMode = request->controls().get(controls::draft::Dw100ScaleMode);
> +	if (scaleMode) {
> +		vertexMap.setMode(static_cast<Dw100VertexMap::ScaleMode>(*scaleMode));
> +		update = true;
> +	}
> +
> +	if (update || info->frame == 0) {
> +		dewarper_->applyVertexMap(&data->mainPathStream_, dewarpRequest);
> +	}
> +
>   	/* Handle scaler crop control. */
>   	const auto &crop = request->controls().get(controls::ScalerCrop);
>   	if (crop) {
> @@ -1700,7 +1742,11 @@ void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
>   		}
>   	}
> 
> -	request->metadata().set(controls::ScalerCrop, activeCrop_.value());
> +	auto &meta = request->metadata();
> +	meta.set(controls::draft::Dw100Scale, vertexMap.effectiveScale());
> +	meta.set(controls::draft::Dw100Rotation, vertexMap.rotation());
> +	meta.set(controls::draft::Dw100Offset, vertexMap.effectiveOffset());
> +	meta.set(controls::ScalerCrop, activeCrop_.value());
>   }
> 
>   void PipelineHandlerRkISP1::dewarpRequestReady(V4L2Request *request)
> --
> 2.48.1
>

Patch
diff mbox series

diff --git a/src/libcamera/control_ids_draft.yaml b/src/libcamera/control_ids_draft.yaml
index 03309eeac34f..10ee68db6d8c 100644
--- a/src/libcamera/control_ids_draft.yaml
+++ b/src/libcamera/control_ids_draft.yaml
@@ -206,7 +206,44 @@  controls:
             available only on this camera device are at least this numeric
             value. All of the custom test patterns will be static (that is the
             raw image must not vary from frame to frame).
-
+  - Dw100ScaleMode:
+      type: int32_t
+      direction: inout
+      description: |
+        Scale mode of the dewarper.
+      enum:
+        - name: Fill
+          value: 0
+          description: |
+            Fills the given output size with the largest rectangle possible. 
+            Aspect ratio is not preserved. Dw100Scale and Dw100Offset are 
+            ignored.
+        - name: Crop
+          value: 1
+          description: |
+            Crops to the given output size. The scale factor can be specified 
+            using Dw100Scale. Aspect ratio is preserved.
+  - Dw100Scale:
+      type: float
+      direction: inout
+      description: |
+        Scale factor applied to the image when Dw100ScaleMode is set to Crop. 
+        This value is clamped, so that all pixels have valid input data. 
+        Therefore a value of 0 always provides the largest possible field of 
+        view.
+  - Dw100Rotation:
+      type: float
+      direction: inout
+      description: |
+        Rotates the image by the given angle in degrees.
+  - Dw100Offset:
+      type: Point
+      direction: inout
+      description: |
+        Moves the image by the given values in x and y direction in output 
+        coordinate space. This is clamped, so that all output pixels contain 
+        valid data. The offset is therefore ignored when Dw100ScaleMode is set 
+        to 'Fit' or the Dw100Scale value is too small.
   - FaceDetectMode:
       type: int32_t
       direction: inout
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 8b78c7f213f6..740791ac9c02 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -1364,6 +1364,17 @@  int PipelineHandlerRkISP1::updateControls(RkISP1CameraData *data)
 							      scalerMaxCrop_);
 		data->properties_.set(properties::ScalerCropMaximum, scalerMaxCrop_);
 		activeCrop_ = scalerMaxCrop_;
+
+		if (dewarper_->supportsRequests()) {
+			controls[&controls::draft::Dw100Scale] = ControlInfo(0.2f, 8.0f, 1.0f);
+			controls[&controls::draft::Dw100Rotation] = ControlInfo(-180.0f, 180.0f, 0.0f);
+			controls[&controls::draft::Dw100Offset] = ControlInfo(Point(-10000, -10000), Point(10000, 10000), Point(0, 0));
+			controls[&controls::draft::Dw100ScaleMode] = ControlInfo(controls::draft::Dw100ScaleModeValues, controls::draft::Fill);
+		} 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. */
@@ -1637,6 +1648,37 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 		availableDewarpRequests_.pop();
 	}
 
+	bool update = false;
+	auto &vertexMap = dewarper_->vertexMap(&data->mainPathStream_);
+
+	const auto &scale = request->controls().get(controls::draft::Dw100Scale);
+	if (scale) {
+		vertexMap.setScale(*scale);
+		update = true;
+	}
+
+	const auto &rotation = request->controls().get(controls::draft::Dw100Rotation);
+	if (rotation) {
+		vertexMap.setRotation(*rotation);
+		update = true;
+	}
+
+	const auto &offset = request->controls().get(controls::draft::Dw100Offset);
+	if (offset) {
+		vertexMap.setOffset(*offset);
+		update = true;
+	}
+
+	const auto &scaleMode = request->controls().get(controls::draft::Dw100ScaleMode);
+	if (scaleMode) {
+		vertexMap.setMode(static_cast<Dw100VertexMap::ScaleMode>(*scaleMode));
+		update = true;
+	}
+
+	if (update || info->frame == 0) {
+		dewarper_->applyVertexMap(&data->mainPathStream_, dewarpRequest);
+	}
+
 	/* Handle scaler crop control. */
 	const auto &crop = request->controls().get(controls::ScalerCrop);
 	if (crop) {
@@ -1700,7 +1742,11 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 		}
 	}
 
-	request->metadata().set(controls::ScalerCrop, activeCrop_.value());
+	auto &meta = request->metadata();
+	meta.set(controls::draft::Dw100Scale, vertexMap.effectiveScale());
+	meta.set(controls::draft::Dw100Rotation, vertexMap.rotation());
+	meta.set(controls::draft::Dw100Offset, vertexMap.effectiveOffset());
+	meta.set(controls::ScalerCrop, activeCrop_.value());
 }
 
 void PipelineHandlerRkISP1::dewarpRequestReady(V4L2Request *request)