[v2,34/35] DNI libcamera: rkisp1: Implement dw100 specific features
diff mbox series

Message ID 20251023144841.403689-35-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
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>

---

Changes in v2:
- Marked as DoNotIntegrate because the puplic interface needs further
  discussions
- Added Dw100EffectiveScale metadata
---
 .../converter/converter_dw100_vertexmap.h     |  2 +-
 src/libcamera/control_ids_draft.yaml          | 45 ++++++++++++++++++
 src/libcamera/pipeline/rkisp1/rkisp1.cpp      | 46 ++++++++++++++++---
 3 files changed, 86 insertions(+), 7 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/converter/converter_dw100_vertexmap.h b/include/libcamera/internal/converter/converter_dw100_vertexmap.h
index b05ed8338a23..5fa46452f9ef 100644
--- a/include/libcamera/internal/converter/converter_dw100_vertexmap.h
+++ b/include/libcamera/internal/converter/converter_dw100_vertexmap.h
@@ -47,7 +47,7 @@  public:
 	const Transform &transform() const { return transform_; }
 
 	void setScale(const float scale) { scale_ = scale; }
-	float effectiveScale() const { return (effectiveScaleX_ + effectiveScaleY_) * 0.5; }
+	std::array<float, 2> effectiveScale() const { return { static_cast<float>(effectiveScaleX_), static_cast<float>(effectiveScaleY_) }; }
 
 	void setRotation(const float rotation) { rotation_ = rotation; }
 	float rotation() const { return rotation_; }
diff --git a/src/libcamera/control_ids_draft.yaml b/src/libcamera/control_ids_draft.yaml
index 03309eeac34f..30c832e32159 100644
--- a/src/libcamera/control_ids_draft.yaml
+++ b/src/libcamera/control_ids_draft.yaml
@@ -206,6 +206,51 @@  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 is 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. Scaling happens centered around the center of the ScalerCrop +
+        Dw10Offset.
+  - Dw100Rotation:
+      type: float
+      direction: inout
+      description: |
+        Rotates the image by the given angle in degrees in clockwise direction
+        around the center of ScalerCrop + Dw100Offset
+  - Dw100Offset:
+      type: Point
+      direction: inout
+      description: |
+        Moves the image by the given values in x and y direction in sensor
+        coordinate space. This is clamped, so that all output pixels contain
+        valid data. The offset is therefore ignored when the Dw100Scale value is
+        too small.
+  - Dw100EffectiveScale:
+      type: float
+      direction: out
+      description: |
+        Effective scale
+      size: [2]
 
   - FaceDetectMode:
       type: int32_t
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
index 9a156d4a01f2..6538fbcc9698 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp
@@ -1500,13 +1500,18 @@  int PipelineHandlerRkISP1::updateControls(RkISP1CameraData *data)
 								      maxCrop);
 		}
 
-		if (data->dewarpParams_.has_value()) {
-			if (dewarper_->supportsRequests())
+		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);
+
+			if (data->dewarpParams_.has_value())
 				controls[&controls::LensDewarpEnable] = ControlInfo(false, true, true);
-			else
-				LOG(RkISP1, Warning)
-					<< "dw100 kernel driver has no requests support."
-					   " No dynamic configuration possible.";
+		} else {
+			LOG(RkISP1, Warning)
+				<< "dw100 kernel driver has no requests support."
+				   " No dynamic configuration possible.";
 		}
 	}
 
@@ -1784,6 +1789,30 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 	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;
+	}
+
 	const auto &lensDewarpEnable = request->controls().get(controls::LensDewarpEnable);
 	if (lensDewarpEnable) {
 		vertexMap.setLensDewarpEnable(*lensDewarpEnable);
@@ -1836,6 +1865,11 @@  void PipelineHandlerRkISP1::imageBufferReady(FrameBuffer *buffer)
 	}
 
 	auto &meta = request->metadata();
+	std::array<float, 2> effectiveScale = vertexMap.effectiveScale();
+	meta.set(controls::draft::Dw100EffectiveScale, effectiveScale);
+	meta.set(controls::draft::Dw100Scale, (effectiveScale[0] + effectiveScale[1]) / 2.0);
+	meta.set(controls::draft::Dw100Rotation, vertexMap.rotation());
+	meta.set(controls::draft::Dw100Offset, vertexMap.effectiveOffset());
 	meta.set(controls::ScalerCrop, vertexMap.effectiveScalerCrop());
 
 	if (vertexMap.dewarpParamsValid())