From patchwork Tue Apr 7 22:01:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 26496 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 94F90C32FA for ; Tue, 7 Apr 2026 22:03:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 55FA162E07; Wed, 8 Apr 2026 00:02:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ekxKGIOd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2622562DA7 for ; Wed, 8 Apr 2026 00:02:44 +0200 (CEST) Received: from [192.168.0.204] (ams.linuxembedded.co.uk [209.38.108.23]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5123725B7; Wed, 8 Apr 2026 00:01:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1775599276; bh=5JfiMzRudcttUvGqI+sxwQvMjSY3DKrSpztYaCa7ooo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ekxKGIOdKJsdEOWjgwx0iQS2TqsaysAy/V8oPVisT+KodfmPBtIqC/2ajxphJHdm4 ueOYMlDr0EcU3dNnp+Eol/eMxLRE0rbRhHdsOJBd/miESX9lqIzQLHnP2qE2jnKXqF 04EGMpIOQGCZ187DRqL0CgMgbRieG9B+FWFQ/Jfk= From: Kieran Bingham Date: Tue, 07 Apr 2026 23:01:16 +0100 Subject: [PATCH 13/13] ipa: libipa: awb: factor out common prepare MIME-Version: 1.0 Message-Id: <20260407-kbingham-awb-split-v1-13-a39af3f4dc20@ideasonboard.com> References: <20260407-kbingham-awb-split-v1-0-a39af3f4dc20@ideasonboard.com> In-Reply-To: <20260407-kbingham-awb-split-v1-0-a39af3f4dc20@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775599360; l=4270; i=kieran.bingham@ideasonboard.com; s=20260204; h=from:subject:message-id; bh=5JfiMzRudcttUvGqI+sxwQvMjSY3DKrSpztYaCa7ooo=; b=HGzGuZlj5Vhg3l1F0ilZUj99PFgK7adjPqpiy0DN+k72pPcv2n5VDbFBtmGxDSWpBf40EQZ3Q Jajqiz1A51tD+yKhg5cmgQxH56LYA80TNMGDVRbGKmfL8I/SojpUF8o X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=IOxS2C6nWHNjLfkDR71Iesk904i6wJDfEERqV7hDBdY= 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" Move the common duplicated code from both the simple and rkisp1 IPA modules and add these to the prepare function of libipa awb module. Signed-off-by: Kieran Bingham --- src/ipa/libipa/awb.cpp | 20 ++++++++++++++++++++ src/ipa/libipa/awb.h | 4 ++++ src/ipa/rkisp1/algorithms/awb.cpp | 11 ++--------- src/ipa/simple/algorithms/awb.cpp | 12 +++--------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp index cac6b4bd206faa4f32680e16c7522685cfd30cac..b079a9c24b0d2d1e11b8da1087023af715765e31 100644 --- a/src/ipa/libipa/awb.cpp +++ b/src/ipa/libipa/awb.cpp @@ -227,6 +227,26 @@ void AwbAlgorithm::queueRequest(awb::ActiveState &state, frameContext.temperatureK = state.manual.temperatureK; } +/** + * \brief Prepare the AWB frame context ready for usage + * \param[in] state The AWB specific active state shared across frames + * \param[in] frame The frame number to apply the control values + * \param[in] frameContext The current frame's AWB specific context + */ +void AwbAlgorithm::prepare(awb::ActiveState &state, + [[maybe_unused]] const uint32_t frame, + awb::FrameContext &frameContext) +{ + /* + * When AutoAWB is enabled, this is the latest opportunity to take + * the most recent and up to date desired AWB gains. + */ + if (frameContext.autoEnabled) { + frameContext.gains = state.automatic.gains; + frameContext.temperatureK = state.automatic.temperatureK; + } +} + /** * \fn AwbAlgorithm::calculateAwb() * \brief Calculate AWB data from the given statistics diff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h index 0256ff8ca3429288c317d3ee940255c4a5391357..ae061f4082ed947c5b8df95bd33566be6777849f 100644 --- a/src/ipa/libipa/awb.h +++ b/src/ipa/libipa/awb.h @@ -73,6 +73,10 @@ public: awb::FrameContext &frameContext, const ControlList &controls); + void prepare(awb::ActiveState &state, + [[maybe_unused]] const uint32_t frame, + awb::FrameContext &frameContext); + virtual AwbResult calculateAwb(const AwbStats &stats, unsigned int lux) = 0; virtual std::optional> gainsFromColourTemperature(double colourTemperature) = 0; diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index b91132fc6177650b9338867359583bf5429ea7e5..9aacb0cff0e747dba588e45434c108d592742701 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -160,15 +160,8 @@ void Awb::queueRequest(IPAContext &context, void Awb::prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, RkISP1Params *params) { - /* - * This is the latest time we can read the active state. This is the - * most up-to-date automatic values we can read. - */ - if (frameContext.awb.autoEnabled) { - const auto &awb = context.activeState.awb; - frameContext.awb.gains = awb.automatic.gains; - frameContext.awb.temperatureK = awb.automatic.temperatureK; - } + awbAlgo_->prepare(context.activeState.awb, + frame, frameContext.awb); auto gainConfig = params->block(); gainConfig.setEnabled(true); diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp index d8516871562724fc65ffbb67161ff4fd988c4b1c..6ce1ed340a5338e25f44145942de95f7f4f6c637 100644 --- a/src/ipa/simple/algorithms/awb.cpp +++ b/src/ipa/simple/algorithms/awb.cpp @@ -124,18 +124,12 @@ void Awb::queueRequest(IPAContext &context, } void Awb::prepare(IPAContext &context, - [[maybe_unused]] const uint32_t frame, + const uint32_t frame, IPAFrameContext &frameContext, DebayerParams *params) { - /* - * When AutoAWB is enabled, this is the latest opportunity to take - * the most recent and up to date desired AWB gains. - */ - if (frameContext.awb.autoEnabled) { - frameContext.awb.gains = context.activeState.awb.automatic.gains; - frameContext.awb.temperatureK = context.activeState.awb.automatic.temperatureK; - } + awbAlgo_->prepare(context.activeState.awb, + frame, frameContext.awb); params->gains = frameContext.awb.gains; }