[v4,12/13] libcamera: mali-c55: Enable usage of scaler
diff mbox series

Message ID 20240709143913.3276983-13-dan.scally@ideasonboard.com
State Superseded
Headers show
Series
  • Miscellaneous Mali-C55 Pipeline Fixes
Related show

Commit Message

Dan Scally July 9, 2024, 2:39 p.m. UTC
From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

The Mali C55 ISP has a resizing pipeline that allows to crop and scale
images.

So far the mali-c55 pipeline has only supported cropping without using
the scaling functionalities.

Now that the kernel has gained support for the scaling operations, make
the libcamera pipeline use it by combining it with a first cropping step
to align the input and output images FOV ratio, and then scale to the
desired output size.

Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
 src/libcamera/pipeline/mali-c55/mali-c55.cpp | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Comments

Kieran Bingham Oct. 9, 2024, 3:03 p.m. UTC | #1
Quoting Daniel Scally (2024-07-09 15:39:12)
> From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
> The Mali C55 ISP has a resizing pipeline that allows to crop and scale
> images.
> 
> So far the mali-c55 pipeline has only supported cropping without using
> the scaling functionalities.
> 
> Now that the kernel has gained support for the scaling operations, make
> the libcamera pipeline use it by combining it with a first cropping step
> to align the input and output images FOV ratio, and then scale to the
> desired output size.
> 
> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
> ---
>  src/libcamera/pipeline/mali-c55/mali-c55.cpp | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> index 512a7489..f5ca2ca4 100644
> --- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> +++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> @@ -747,16 +747,28 @@ int PipelineHandlerMaliC55::configureProcessedStream(MaliC55CameraData *data,
>         if (ret)
>                 return ret;
>  
> -       /* \todo Configure the resizer crop/compose rectangles. */
> -       Rectangle ispCrop = { 0, 0, config.size };
> +       /*
> +        * Compute the scaler-in to scaler-out ratio: first center-crop to align
> +        * the FOV to the desired resolution, then scale to the desired size.
> +        */
> +       Size scalerIn = subdevFormat.size.boundedToAspectRatio(config.size);
> +       int xCrop = (subdevFormat.size.width - scalerIn.width) / 2;
> +       int yCrop = (subdevFormat.size.height - scalerIn.height) / 2;

Seeing open-coding for centering makes me think we're missing some
helper in geometry.h ... but it looks correct.

> +       Rectangle ispCrop = { xCrop, yCrop, scalerIn };

I think we should be reporting this as ScalerCrop in the metadata to
tell applications exactly what region they are getting from the Sensor.

Of course implementing ScalerCrop as a control will be good to come
later too ;-)

Do we have a request/metadata we can access here in this function to
report this already?

If not - I think we can deal with it when ScalerCrop is actually
implemented anyway.

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

>         ret = pipe->resizer->setSelection(0, V4L2_SEL_TGT_CROP, &ispCrop);
>         if (ret)
>                 return ret;
>  
> -       ret = pipe->resizer->setSelection(0, V4L2_SEL_TGT_COMPOSE, &ispCrop);
> +       Rectangle ispCompose = { 0, 0, config.size };
> +       ret = pipe->resizer->setSelection(0, V4L2_SEL_TGT_COMPOSE, &ispCompose);
>         if (ret)
>                 return ret;
>  
> +       /*
> +        * The source pad format size comes directly from the sink
> +        * compose rectangle.
> +        */
> +       subdevFormat.size = ispCompose.size();
>         subdevFormat.code = maliC55FmtToCode.find(config.pixelFormat)->second;
>         return pipe->resizer->setFormat(1, &subdevFormat);
>  }
> -- 
> 2.34.1
>

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
index 512a7489..f5ca2ca4 100644
--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp
+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
@@ -747,16 +747,28 @@  int PipelineHandlerMaliC55::configureProcessedStream(MaliC55CameraData *data,
 	if (ret)
 		return ret;
 
-	/* \todo Configure the resizer crop/compose rectangles. */
-	Rectangle ispCrop = { 0, 0, config.size };
+	/*
+	 * Compute the scaler-in to scaler-out ratio: first center-crop to align
+	 * the FOV to the desired resolution, then scale to the desired size.
+	 */
+	Size scalerIn = subdevFormat.size.boundedToAspectRatio(config.size);
+	int xCrop = (subdevFormat.size.width - scalerIn.width) / 2;
+	int yCrop = (subdevFormat.size.height - scalerIn.height) / 2;
+	Rectangle ispCrop = { xCrop, yCrop, scalerIn };
 	ret = pipe->resizer->setSelection(0, V4L2_SEL_TGT_CROP, &ispCrop);
 	if (ret)
 		return ret;
 
-	ret = pipe->resizer->setSelection(0, V4L2_SEL_TGT_COMPOSE, &ispCrop);
+	Rectangle ispCompose = { 0, 0, config.size };
+	ret = pipe->resizer->setSelection(0, V4L2_SEL_TGT_COMPOSE, &ispCompose);
 	if (ret)
 		return ret;
 
+	/*
+	 * The source pad format size comes directly from the sink
+	 * compose rectangle.
+	 */
+	subdevFormat.size = ispCompose.size();
 	subdevFormat.code = maliC55FmtToCode.find(config.pixelFormat)->second;
 	return pipe->resizer->setFormat(1, &subdevFormat);
 }