From patchwork Tue Jun 25 19:04:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 20388 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BA86ABDB1D for ; Tue, 25 Jun 2024 19:04:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE893654AC; Tue, 25 Jun 2024 21:04:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TVDuC2vG"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E9BF654A1 for ; Tue, 25 Jun 2024 21:04:36 +0200 (CEST) Received: from localhost.localdomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB4EC512; Tue, 25 Jun 2024 21:04:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1719342254; bh=IBll4eALAwqey4L4XUudogs8XGInIa4oRRqbXq9kUQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TVDuC2vGq7SCnH2FMAYhf8/2wrmlcZQxA4mgLKmTdAUXCGA4iXsJMM763HVn98/LR a0mIj/ZJKAVI6UhNk13ZAn0xsvu1aLYcePELXE53J4n67dGIqfg/uwGlrfg4/q+eHC Lg0BSCoww0ZdZ9X8t23M2jUtM3Ef3/opE8WJMW6Q= From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi Subject: [PATCH v2 2/6] libcamera: mali-c55: Limit ISP input size Date: Tue, 25 Jun 2024 21:04:15 +0200 Message-ID: <20240625190423.291429-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240625190423.291429-1-jacopo.mondi@ideasonboard.com> References: <20240625190423.291429-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- src/libcamera/pipeline/mali-c55/mali-c55.cpp | 37 ++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp index 1c1fef2337f0..91f2ebd6fd26 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 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::max(); Size bestSize; - for (const Size &size : rawSizes) { + for (const Size &sz : rawSizes) { uint16_t dist = std::abs(static_cast(rawSize.width) - - static_cast(size.width)) + + static_cast(sz.width)) + std::abs(static_cast(rawSize.height) - - static_cast(size.height)); + static_cast(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(&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; } @@ -431,13 +440,13 @@ CameraConfiguration::Status MaliC55CameraConfiguration::validate() 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(maxYuvSize.width) - + uint16_t dist = std::abs(static_cast(minSensorSize.width) - static_cast(size.width)) + - std::abs(static_cast(maxYuvSize.height) - + std::abs(static_cast(minSensorSize.height) - static_cast(size.height)); if (dist < distance) { dist = distance;