From patchwork Tue Aug 27 01:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 21041 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 E6145C32D8 for ; Tue, 27 Aug 2024 01:41:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 733E363439; Tue, 27 Aug 2024 03:41:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P4CGnhaF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3962B61E4F for ; Tue, 27 Aug 2024 03:41:02 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D6621583; Tue, 27 Aug 2024 03:39:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1724722795; bh=SQid8fA6gluHknPa2Oqd0f7G0vhc3KABTHpb6YoeIio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4CGnhaF9ehHfQxuDu7IYkeTlwjzx2H4ENQFsmVdC/1DWdPsrEdBhsp3crqYBUqcX nspr3xwCiOys1lY/NByRQ/CJqfF83562QPdlQ3H638a4/SAreALZk9LhFRXvNtYqG6 1+ky7HVilSaWErWAi608iI/4wt4gIJWTdpvgnTgE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH v4 9/9] ipa: rkisp1: blc: Add support for BLS in compand Date: Tue, 27 Aug 2024 04:40:43 +0300 Message-ID: <20240827014044.24673-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240827014044.24673-1-laurent.pinchart@ideasonboard.com> References: <20240827014044.24673-1-laurent.pinchart@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" From: Paul Elder Extend the RkISP1 BLC algorithm to use the ISP 'companding' block for versions of the ISP (such as the one on the i.MX8MP) that lack the dedicated BLS block but implement BLS as part of the companding block. As access to the companding block requires the extensible parameters format, disable BLC when using the legacy parameters format on i.MX8MP to avoid crashes at runtime with older kernels. Signed-off-by: Paul Elder Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Stefan Klug --- Changes since v3: - Disable BLC on i.MX8MP if using the legacy parameters format --- src/ipa/rkisp1/algorithms/blc.cpp | 57 ++++++++++++++++++++++++------- src/ipa/rkisp1/algorithms/blc.h | 5 ++- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp index c93f7ead62cf..98cb7145e164 100644 --- a/src/ipa/rkisp1/algorithms/blc.cpp +++ b/src/ipa/rkisp1/algorithms/blc.cpp @@ -7,6 +7,8 @@ #include "blc.h" +#include + #include #include @@ -38,7 +40,6 @@ namespace ipa::rkisp1::algorithms { LOG_DEFINE_CATEGORY(RkISP1Blc) BlackLevelCorrection::BlackLevelCorrection() - : tuningParameters_(false) { /* * This is a bit of a hack. In raw mode no black level correction @@ -96,8 +97,6 @@ int BlackLevelCorrection::init(IPAContext &context, const YamlObject &tuningData blackLevelBlue_ = *blackLevel; } - tuningParameters_ = true; - LOG(RkISP1Blc, Debug) << "Black levels: red " << blackLevelRed_ << ", green (red) " << blackLevelGreenR_ @@ -107,10 +106,27 @@ int BlackLevelCorrection::init(IPAContext &context, const YamlObject &tuningData return 0; } +int BlackLevelCorrection::configure(IPAContext &context, + [[maybe_unused]] const IPACameraSensorInfo &configInfo) +{ + /* + * BLC on ISP versions that include the companding block requires usage + * of the extensible parameters format. + */ + supported_ = context.configuration.paramFormat == V4L2_META_FMT_RK_ISP1_EXT_PARAMS || + !context.hw->compand; + + if (!supported_) + LOG(RkISP1Blc, Warning) + << "BLC in companding block requires extensible parameters"; + + return 0; +} + /** * \copydoc libcamera::ipa::Algorithm::prepare */ -void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, +void BlackLevelCorrection::prepare(IPAContext &context, const uint32_t frame, [[maybe_unused]] IPAFrameContext &frameContext, RkISP1Params *params) @@ -121,18 +137,33 @@ void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context, if (frame > 0) return; - if (!tuningParameters_) + if (!supported_) return; - auto config = params->block(); - config.setEnabled(true); + if (context.hw->compand) { + auto config = params->block(); + config.setEnabled(true); - config->enable_auto = 0; - /* The rkisp1 uses 12bit based black levels. Scale down accordingly. */ - config->fixed_val.r = blackLevelRed_ >> 4; - config->fixed_val.gr = blackLevelGreenR_ >> 4; - config->fixed_val.gb = blackLevelGreenB_ >> 4; - config->fixed_val.b = blackLevelBlue_ >> 4; + /* + * Scale up to the 20-bit black levels used by the companding + * block. + */ + config->r = blackLevelRed_ << 4; + config->gr = blackLevelGreenR_ << 4; + config->gb = blackLevelGreenB_ << 4; + config->b = blackLevelBlue_ << 4; + } else { + auto config = params->block(); + config.setEnabled(true); + + config->enable_auto = 0; + + /* Scale down to the 12-bit black levels used by the BLS block. */ + config->fixed_val.r = blackLevelRed_ >> 4; + config->fixed_val.gr = blackLevelGreenR_ >> 4; + config->fixed_val.gb = blackLevelGreenB_ >> 4; + config->fixed_val.b = blackLevelBlue_ >> 4; + } } /** diff --git a/src/ipa/rkisp1/algorithms/blc.h b/src/ipa/rkisp1/algorithms/blc.h index 372f6f7d00cc..f797ae44d639 100644 --- a/src/ipa/rkisp1/algorithms/blc.h +++ b/src/ipa/rkisp1/algorithms/blc.h @@ -20,6 +20,8 @@ public: ~BlackLevelCorrection() = default; int init(IPAContext &context, const YamlObject &tuningData) override; + int configure(IPAContext &context, + const IPACameraSensorInfo &configInfo) override; void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, RkISP1Params *params) override; @@ -29,7 +31,8 @@ public: ControlList &metadata) override; private: - bool tuningParameters_; + bool supported_; + int16_t blackLevelRed_; int16_t blackLevelGreenR_; int16_t blackLevelGreenB_;