[v3,2/9] libcamera: mali-c55: Limit ISP input size
diff mbox series

Message ID 20240626140309.50052-3-jacopo.mondi@ideasonboard.com
State Superseded
Headers show
Series
  • Miscellaneous Mali-C55 Pipeline Fixes
Related show

Commit Message

Jacopo Mondi June 26, 2024, 2:02 p.m. UTC
The Mali-C55 ISP has an input size limit of 640x480.

Filter out resolutions smaller than this when selecting the
sensor format. While at it, rename 'maxYuvSize' to a more
appropriate 'minSensorSize'.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/libcamera/pipeline/mali-c55/mali-c55.cpp | 38 ++++++++++++--------
 1 file changed, 23 insertions(+), 15 deletions(-)

Comments

Umang Jain June 29, 2024, 6:44 a.m. UTC | #1
Hi Jacopo,

Thank you for the patch

On 26/06/24 7:32 pm, Jacopo Mondi wrote:
> The Mali-C55 ISP has an input size limit of 640x480.

s/input/minimum input/

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
>
> Filter out resolutions smaller than this when selecting the
> sensor format. While at it, rename 'maxYuvSize' to a more
> appropriate 'minSensorSize'.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>   src/libcamera/pipeline/mali-c55/mali-c55.cpp | 38 ++++++++++++--------
>   1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> index 1c1fef2337f0..d1ae1a61d5a9 100644
> --- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> +++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> @@ -79,6 +79,7 @@ const std::map<libcamera::PixelFormat, unsigned int> maliC55FmtToCode = {
>   	{ formats::SGRBG16, MEDIA_BUS_FMT_SGRBG16_1X16 },
>   };
>   
> +constexpr Size kMaliC55MinInputSize = { 640, 480 };
>   constexpr Size kMaliC55MinSize = { 128, 128 };
>   constexpr Size kMaliC55MaxSize = { 8192, 8192 };
>   constexpr unsigned int kMaliC55ISPInternalFormat = MEDIA_BUS_FMT_RGB121212_1X36;
> @@ -265,13 +266,16 @@ PixelFormat MaliC55CameraData::adjustRawFormat(const PixelFormat &rawFmt) const
>   	return rawFmt;
>   }
>   
> -Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &rawSize) const
> +Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &size) const
>   {
>   	/* Just make sure the format is supported. */
>   	auto it = maliC55FmtToCode.find(rawFmt);
>   	if (it == maliC55FmtToCode.end())
>   		return {};
>   
> +	/* Expand the RAW size to the minimum ISP input size. */
> +	Size rawSize = size.expandedTo(kMaliC55MinInputSize);
> +
>   	/* Check if the size is natively supported. */
>   	unsigned int rawCode = it->second;
>   	const auto rawSizes = sizes(rawCode);
> @@ -282,14 +286,14 @@ Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &ra
>   	/* Or adjust it to the closest supported size. */
>   	uint16_t distance = std::numeric_limits<uint16_t>::max();
>   	Size bestSize;
> -	for (const Size &size : rawSizes) {
> +	for (const Size &sz : rawSizes) {
>   		uint16_t dist = std::abs(static_cast<int>(rawSize.width) -
> -					 static_cast<int>(size.width)) +
> +					 static_cast<int>(sz.width)) +
>   				std::abs(static_cast<int>(rawSize.height) -
> -					 static_cast<int>(size.height));
> +					 static_cast<int>(sz.height));
>   		if (dist < distance) {
>   			dist = distance;
> -			bestSize = size;
> +			bestSize = sz;
>   		}
>   	}
>   
> @@ -376,8 +380,13 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   		frPipeAvailable = false;
>   	}
>   
> -	/* Adjust processed streams. */
> -	Size maxYuvSize;
> +	/*
> +	 * Adjust processed streams.
> +	 *
> +	 * Compute the minimum sensor size to be later used to select the
> +	 * sensor configuration.
> +	 */
> +	Size minSensorSize = kMaliC55MinInputSize;
>   	for (StreamConfiguration &config : config_) {
>   		if (isFormatRaw(config.pixelFormat))
>   			continue;
> @@ -399,8 +408,8 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   			status = Adjusted;
>   		}
>   
> -		if (maxYuvSize < size)
> -			maxYuvSize = size;
> +		if (minSensorSize < size)
> +			minSensorSize = size;
>   
>   		if (frPipeAvailable) {
>   			config.setStream(const_cast<Stream *>(&data_->frStream_));
> @@ -416,7 +425,7 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   	if (rawConfig) {
>   		const auto it = maliC55FmtToCode.find(rawConfig->pixelFormat);
>   		sensorFormat_.code = it->second;
> -		sensorFormat_.size = rawConfig->size;
> +		sensorFormat_.size = rawConfig->size.expandedTo(minSensorSize);
>   
>   		return status;
>   	}
> @@ -430,14 +439,13 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   	const auto sizes = data_->sizes(it->second);
>   	Size bestSize;
>   	for (const auto &size : sizes) {
> -		/* Skip sensor sizes that are smaller than the max YUV size. */
> -		if (maxYuvSize.width > size.width ||
> -		    maxYuvSize.height > size.height)
> +		if (minSensorSize.width > size.width ||
> +		    minSensorSize.height > size.height)
>   			continue;
>   
> -		uint16_t dist = std::abs(static_cast<int>(maxYuvSize.width) -
> +		uint16_t dist = std::abs(static_cast<int>(minSensorSize.width) -
>   					 static_cast<int>(size.width)) +
> -				std::abs(static_cast<int>(maxYuvSize.height) -
> +				std::abs(static_cast<int>(minSensorSize.height) -
>   					 static_cast<int>(size.height));
>   		if (dist < distance) {
>   			dist = distance;
Dan Scally July 8, 2024, 11:40 a.m. UTC | #2
Hi Jacopo

On 26/06/2024 15:02, Jacopo Mondi wrote:
> The Mali-C55 ISP has an input size limit of 640x480.
>
> Filter out resolutions smaller than this when selecting the
> sensor format. While at it, rename 'maxYuvSize' to a more
> appropriate 'minSensorSize'.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---

Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
>   src/libcamera/pipeline/mali-c55/mali-c55.cpp | 38 ++++++++++++--------
>   1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> index 1c1fef2337f0..d1ae1a61d5a9 100644
> --- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> +++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
> @@ -79,6 +79,7 @@ const std::map<libcamera::PixelFormat, unsigned int> maliC55FmtToCode = {
>   	{ formats::SGRBG16, MEDIA_BUS_FMT_SGRBG16_1X16 },
>   };
>   
> +constexpr Size kMaliC55MinInputSize = { 640, 480 };
>   constexpr Size kMaliC55MinSize = { 128, 128 };
>   constexpr Size kMaliC55MaxSize = { 8192, 8192 };
>   constexpr unsigned int kMaliC55ISPInternalFormat = MEDIA_BUS_FMT_RGB121212_1X36;
> @@ -265,13 +266,16 @@ PixelFormat MaliC55CameraData::adjustRawFormat(const PixelFormat &rawFmt) const
>   	return rawFmt;
>   }
>   
> -Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &rawSize) const
> +Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &size) const
>   {
>   	/* Just make sure the format is supported. */
>   	auto it = maliC55FmtToCode.find(rawFmt);
>   	if (it == maliC55FmtToCode.end())
>   		return {};
>   
> +	/* Expand the RAW size to the minimum ISP input size. */
> +	Size rawSize = size.expandedTo(kMaliC55MinInputSize);
> +
>   	/* Check if the size is natively supported. */
>   	unsigned int rawCode = it->second;
>   	const auto rawSizes = sizes(rawCode);
> @@ -282,14 +286,14 @@ Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &ra
>   	/* Or adjust it to the closest supported size. */
>   	uint16_t distance = std::numeric_limits<uint16_t>::max();
>   	Size bestSize;
> -	for (const Size &size : rawSizes) {
> +	for (const Size &sz : rawSizes) {
>   		uint16_t dist = std::abs(static_cast<int>(rawSize.width) -
> -					 static_cast<int>(size.width)) +
> +					 static_cast<int>(sz.width)) +
>   				std::abs(static_cast<int>(rawSize.height) -
> -					 static_cast<int>(size.height));
> +					 static_cast<int>(sz.height));
>   		if (dist < distance) {
>   			dist = distance;
> -			bestSize = size;
> +			bestSize = sz;
>   		}
>   	}
>   
> @@ -376,8 +380,13 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   		frPipeAvailable = false;
>   	}
>   
> -	/* Adjust processed streams. */
> -	Size maxYuvSize;
> +	/*
> +	 * Adjust processed streams.
> +	 *
> +	 * Compute the minimum sensor size to be later used to select the
> +	 * sensor configuration.
> +	 */
> +	Size minSensorSize = kMaliC55MinInputSize;
>   	for (StreamConfiguration &config : config_) {
>   		if (isFormatRaw(config.pixelFormat))
>   			continue;
> @@ -399,8 +408,8 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   			status = Adjusted;
>   		}
>   
> -		if (maxYuvSize < size)
> -			maxYuvSize = size;
> +		if (minSensorSize < size)
> +			minSensorSize = size;
>   
>   		if (frPipeAvailable) {
>   			config.setStream(const_cast<Stream *>(&data_->frStream_));
> @@ -416,7 +425,7 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   	if (rawConfig) {
>   		const auto it = maliC55FmtToCode.find(rawConfig->pixelFormat);
>   		sensorFormat_.code = it->second;
> -		sensorFormat_.size = rawConfig->size;
> +		sensorFormat_.size = rawConfig->size.expandedTo(minSensorSize);
>   
>   		return status;
>   	}
> @@ -430,14 +439,13 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate()
>   	const auto sizes = data_->sizes(it->second);
>   	Size bestSize;
>   	for (const auto &size : sizes) {
> -		/* Skip sensor sizes that are smaller than the max YUV size. */
> -		if (maxYuvSize.width > size.width ||
> -		    maxYuvSize.height > size.height)
> +		if (minSensorSize.width > size.width ||
> +		    minSensorSize.height > size.height)
>   			continue;
>   
> -		uint16_t dist = std::abs(static_cast<int>(maxYuvSize.width) -
> +		uint16_t dist = std::abs(static_cast<int>(minSensorSize.width) -
>   					 static_cast<int>(size.width)) +
> -				std::abs(static_cast<int>(maxYuvSize.height) -
> +				std::abs(static_cast<int>(minSensorSize.height) -
>   					 static_cast<int>(size.height));
>   		if (dist < distance) {
>   			dist = distance;

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 1c1fef2337f0..d1ae1a61d5a9 100644
--- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp
+++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp
@@ -79,6 +79,7 @@  const std::map<libcamera::PixelFormat, unsigned int> maliC55FmtToCode = {
 	{ formats::SGRBG16, MEDIA_BUS_FMT_SGRBG16_1X16 },
 };
 
+constexpr Size kMaliC55MinInputSize = { 640, 480 };
 constexpr Size kMaliC55MinSize = { 128, 128 };
 constexpr Size kMaliC55MaxSize = { 8192, 8192 };
 constexpr unsigned int kMaliC55ISPInternalFormat = MEDIA_BUS_FMT_RGB121212_1X36;
@@ -265,13 +266,16 @@  PixelFormat MaliC55CameraData::adjustRawFormat(const PixelFormat &rawFmt) const
 	return rawFmt;
 }
 
-Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &rawSize) const
+Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &size) const
 {
 	/* Just make sure the format is supported. */
 	auto it = maliC55FmtToCode.find(rawFmt);
 	if (it == maliC55FmtToCode.end())
 		return {};
 
+	/* Expand the RAW size to the minimum ISP input size. */
+	Size rawSize = size.expandedTo(kMaliC55MinInputSize);
+
 	/* Check if the size is natively supported. */
 	unsigned int rawCode = it->second;
 	const auto rawSizes = sizes(rawCode);
@@ -282,14 +286,14 @@  Size MaliC55CameraData::adjustRawSizes(const PixelFormat &rawFmt, const Size &ra
 	/* Or adjust it to the closest supported size. */
 	uint16_t distance = std::numeric_limits<uint16_t>::max();
 	Size bestSize;
-	for (const Size &size : rawSizes) {
+	for (const Size &sz : rawSizes) {
 		uint16_t dist = std::abs(static_cast<int>(rawSize.width) -
-					 static_cast<int>(size.width)) +
+					 static_cast<int>(sz.width)) +
 				std::abs(static_cast<int>(rawSize.height) -
-					 static_cast<int>(size.height));
+					 static_cast<int>(sz.height));
 		if (dist < distance) {
 			dist = distance;
-			bestSize = size;
+			bestSize = sz;
 		}
 	}
 
@@ -376,8 +380,13 @@  CameraConfiguration::Status MaliC55CameraConfiguration::validate()
 		frPipeAvailable = false;
 	}
 
-	/* Adjust processed streams. */
-	Size maxYuvSize;
+	/*
+	 * Adjust processed streams.
+	 *
+	 * Compute the minimum sensor size to be later used to select the
+	 * sensor configuration.
+	 */
+	Size minSensorSize = kMaliC55MinInputSize;
 	for (StreamConfiguration &config : config_) {
 		if (isFormatRaw(config.pixelFormat))
 			continue;
@@ -399,8 +408,8 @@  CameraConfiguration::Status MaliC55CameraConfiguration::validate()
 			status = Adjusted;
 		}
 
-		if (maxYuvSize < size)
-			maxYuvSize = size;
+		if (minSensorSize < size)
+			minSensorSize = size;
 
 		if (frPipeAvailable) {
 			config.setStream(const_cast<Stream *>(&data_->frStream_));
@@ -416,7 +425,7 @@  CameraConfiguration::Status MaliC55CameraConfiguration::validate()
 	if (rawConfig) {
 		const auto it = maliC55FmtToCode.find(rawConfig->pixelFormat);
 		sensorFormat_.code = it->second;
-		sensorFormat_.size = rawConfig->size;
+		sensorFormat_.size = rawConfig->size.expandedTo(minSensorSize);
 
 		return status;
 	}
@@ -430,14 +439,13 @@  CameraConfiguration::Status MaliC55CameraConfiguration::validate()
 	const auto sizes = data_->sizes(it->second);
 	Size bestSize;
 	for (const auto &size : sizes) {
-		/* Skip sensor sizes that are smaller than the max YUV size. */
-		if (maxYuvSize.width > size.width ||
-		    maxYuvSize.height > size.height)
+		if (minSensorSize.width > size.width ||
+		    minSensorSize.height > size.height)
 			continue;
 
-		uint16_t dist = std::abs(static_cast<int>(maxYuvSize.width) -
+		uint16_t dist = std::abs(static_cast<int>(minSensorSize.width) -
 					 static_cast<int>(size.width)) +
-				std::abs(static_cast<int>(maxYuvSize.height) -
+				std::abs(static_cast<int>(minSensorSize.height) -
 					 static_cast<int>(size.height));
 		if (dist < distance) {
 			dist = distance;