From patchwork Tue Apr 7 22:01:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 26494 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 F0985C32F9 for ; Tue, 7 Apr 2026 22:03:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4183562DEF; Wed, 8 Apr 2026 00:02:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FB4iUJkg"; 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 E79FD62DAD for ; Wed, 8 Apr 2026 00:02:43 +0200 (CEST) Received: from [192.168.0.204] (ams.linuxembedded.co.uk [209.38.108.23]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 11A151C4D; 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=BEhM5gmAYP5zsWL3XAYTLQ3/oVZz6IBL19P9xUhlFLk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FB4iUJkg9vQU0Jl9+RQxYZ5RPT5R5fvCI2Pfs8lFUCJd+V4ugP99KXOnwYchYofEV 6guYRwj8LYhhweDWcfiQKH2DlB5FLggaC+xXD/csRToIu1sT/dfVnjpTqCiYTuYZ5t 1vxENm6Q5WFAxD+ynrx0uLcGSqFoXYjfUS0TJjUc= From: Kieran Bingham Date: Tue, 07 Apr 2026 23:01:15 +0100 Subject: [PATCH 12/13] ipa: libipa: awb: convert to common queueRequest MIME-Version: 1.0 Message-Id: <20260407-kbingham-awb-split-v1-12-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=8073; i=kieran.bingham@ideasonboard.com; s=20260204; h=from:subject:message-id; bh=BEhM5gmAYP5zsWL3XAYTLQ3/oVZz6IBL19P9xUhlFLk=; b=9yx8t0PgTjf80Ar8+BmoYFl9IlEx/LuUBf7dQWuHqL2mrHz9pxqfOGZAAeHmaLrlQCz0FGxBe c/cmeZbO5rZBvTaqcM4iOVl52mvyifrCYJd42Shkt7IBXrW6vDV5NFz 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 now duplicated implementation for both soft IPA and rkisp1 IPA for managing requests at queue time into the common libipa AWB implementation. Signed-off-by: Kieran Bingham --- src/ipa/libipa/awb.cpp | 59 +++++++++++++++++++++++++++++++++++++++ src/ipa/libipa/awb.h | 5 ++++ src/ipa/rkisp1/algorithms/awb.cpp | 49 ++------------------------------ src/ipa/simple/algorithms/awb.cpp | 52 ++++------------------------------ 4 files changed, 72 insertions(+), 93 deletions(-) diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp index d0c577958caebc0b7e24fe58506da964df2200fe..cac6b4bd206faa4f32680e16c7522685cfd30cac 100644 --- a/src/ipa/libipa/awb.cpp +++ b/src/ipa/libipa/awb.cpp @@ -168,6 +168,65 @@ int AwbAlgorithm::configure(awb::ActiveState &state, awb::Session &session) return 0; } +/** + * \brief Provide control values to the algorithm + * \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 + * \param[in] controls The list of user controls + */ +void AwbAlgorithm::queueRequest(awb::ActiveState &state, + [[maybe_unused]] const uint32_t frame, + awb::FrameContext &frameContext, + const ControlList &controls) +{ + const auto &awbEnable = controls.get(controls::AwbEnable); + if (awbEnable && *awbEnable != state.autoEnabled) { + state.autoEnabled = *awbEnable; + + LOG(Awb, Debug) + << (*awbEnable ? "Enabling" : "Disabling") << " AWB"; + } + + /* Handle controls from subclass algo (Grey or Bayes) */ + handleControls(controls); + + frameContext.autoEnabled = state.autoEnabled; + + /* Todo: Check to see if we should always parse the following controls */ + if (frameContext.autoEnabled) + return; + + const auto &colourGains = controls.get(controls::ColourGains); + const auto &colourTemperature = controls.get(controls::ColourTemperature); + bool update = false; + if (colourGains) { + state.manual.gains.r() = (*colourGains)[0]; + state.manual.gains.b() = (*colourGains)[1]; + /* + * \todo Colour temperature reported in metadata is now + * incorrect, as we can't deduce the temperature from the gains. + * This will be fixed with the bayes AWB algorithm. + */ + update = true; + } else if (colourTemperature) { + state.manual.temperatureK = *colourTemperature; + const auto &gains = gainsFromColourTemperature(*colourTemperature); + if (gains) { + state.manual.gains.r() = gains->r(); + state.manual.gains.b() = gains->b(); + update = true; + } + } + + if (update) + LOG(Awb, Debug) + << "Set colour gains to " << state.manual.gains; + + frameContext.gains = state.manual.gains; + frameContext.temperatureK = state.manual.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 4ceae537686f8f4c93686fab4b9efbc06e112b1d..0256ff8ca3429288c317d3ee940255c4a5391357 100644 --- a/src/ipa/libipa/awb.h +++ b/src/ipa/libipa/awb.h @@ -68,6 +68,11 @@ public: int configure(awb::ActiveState &state, awb::Session &session); + void queueRequest(awb::ActiveState &state, + [[maybe_unused]] const uint32_t frame, + awb::FrameContext &frameContext, + const ControlList &controls); + 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 86d5dfed3e1c2bb587705f05362229db3cdadafd..b91132fc6177650b9338867359583bf5429ea7e5 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -146,55 +146,12 @@ int Awb::configure(IPAContext &context, * \copydoc libcamera::ipa::Algorithm::queueRequest */ void Awb::queueRequest(IPAContext &context, - [[maybe_unused]] const uint32_t frame, + const uint32_t frame, IPAFrameContext &frameContext, const ControlList &controls) { - auto &awb = context.activeState.awb; - - const auto &awbEnable = controls.get(controls::AwbEnable); - if (awbEnable && *awbEnable != awb.autoEnabled) { - awb.autoEnabled = *awbEnable; - - LOG(RkISP1Awb, Debug) - << (*awbEnable ? "Enabling" : "Disabling") << " AWB"; - } - - awbAlgo_->handleControls(controls); - - frameContext.awb.autoEnabled = awb.autoEnabled; - - if (awb.autoEnabled) - return; - - const auto &colourGains = controls.get(controls::ColourGains); - const auto &colourTemperature = controls.get(controls::ColourTemperature); - bool update = false; - if (colourGains) { - awb.manual.gains.r() = (*colourGains)[0]; - awb.manual.gains.b() = (*colourGains)[1]; - /* - * \todo Colour temperature reported in metadata is now - * incorrect, as we can't deduce the temperature from the gains. - * This will be fixed with the bayes AWB algorithm. - */ - update = true; - } else if (colourTemperature) { - awb.manual.temperatureK = *colourTemperature; - const auto &gains = awbAlgo_->gainsFromColourTemperature(*colourTemperature); - if (gains) { - awb.manual.gains.r() = gains->r(); - awb.manual.gains.b() = gains->b(); - update = true; - } - } - - if (update) - LOG(RkISP1Awb, Debug) - << "Set colour gains to " << awb.manual.gains; - - frameContext.awb.gains = awb.manual.gains; - frameContext.awb.temperatureK = awb.manual.temperatureK; + awbAlgo_->queueRequest(context.activeState.awb, frame, frameContext.awb, + controls); } /** diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp index 230b7807075941f086911549066e39c0a04dff5c..d8516871562724fc65ffbb67161ff4fd988c4b1c 100644 --- a/src/ipa/simple/algorithms/awb.cpp +++ b/src/ipa/simple/algorithms/awb.cpp @@ -114,55 +114,13 @@ int Awb::configure(IPAContext &context, * \copydoc libcamera::ipa::Algorithm::queueRequest */ void Awb::queueRequest(IPAContext &context, - [[maybe_unused]] const uint32_t frame, - [[maybe_unused]] IPAFrameContext &frameContext, + const uint32_t frame, + IPAFrameContext &frameContext, const ControlList &controls) { - auto &awb = context.activeState.awb; - - const auto &awbEnable = controls.get(controls::AwbEnable); - if (awbEnable && *awbEnable != awb.autoEnabled) { - awb.autoEnabled = *awbEnable; - - LOG(IPASoftAwb, Debug) - << (*awbEnable ? "Enabling" : "Disabling") << " AWB"; - } - - awbAlgo_->handleControls(controls); - - frameContext.awb.autoEnabled = awb.autoEnabled; - - if (awb.autoEnabled) - return; - - const auto &colourGains = controls.get(controls::ColourGains); - const auto &colourTemperature = controls.get(controls::ColourTemperature); - bool update = false; - if (colourGains) { - awb.manual.gains.r() = (*colourGains)[0]; - awb.manual.gains.b() = (*colourGains)[1]; - /* - * \todo Colour temperature reported in metadata is now - * incorrect, as we can't deduce the temperature from the gains. - * This will be fixed with the bayes AWB algorithm. - */ - update = true; - } else if (colourTemperature) { - awb.manual.temperatureK = *colourTemperature; - const auto &gains = awbAlgo_->gainsFromColourTemperature(*colourTemperature); - if (gains) { - awb.manual.gains.r() = gains->r(); - awb.manual.gains.b() = gains->b(); - update = true; - } - } - - if (update) - LOG(IPASoftAwb, Debug) - << "Set colour gains to " << awb.manual.gains; - - frameContext.awb.gains = awb.manual.gains; - frameContext.awb.temperatureK = awb.manual.temperatureK; + awbAlgo_->queueRequest(context.activeState.awb, + frame, frameContext.awb, + controls); } void Awb::prepare(IPAContext &context,