From patchwork Mon Jul 20 14:59:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 27398 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 6C4B2C32FE for ; Mon, 20 Jul 2026 14:59:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DD8467E77; Mon, 20 Jul 2026 16:59:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ntoqqIH2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8400767E42 for ; Mon, 20 Jul 2026 16:59:44 +0200 (CEST) Received: from [192.168.1.106] (mob-5-90-63-152.net.vodafone.it [5.90.63.152]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 90B8F15CD; Mon, 20 Jul 2026 16:58:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1784559526; bh=PZjf6FQi9gCzmouGinDVKkg+erELkT3B1ZUh0u8Sa2k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ntoqqIH2T+Of2hQHUWKmN0Mb2V8+Rqx09VLpLygZ/kvRrra0H4K2klHVx5tkF25TU Qn40jj5n58ue0noiQBjH148ImEZ2QtJzmI9dI4624yBknxOOwzc0AhtqU4Hl4jfOak 074OBz6aykqKaGK215a9AZWRcX2Kyjbtib5ywYoI= From: Jacopo Mondi Date: Mon, 20 Jul 2026 16:59:24 +0200 Subject: [PATCH v6 06/31] ipa: simple: Port to use libipa CcmAlgorithm MIME-Version: 1.0 Message-Id: <20260720-libipa-algorithms-v6-6-ececb73f97cb@ideasonboard.com> References: <20260720-libipa-algorithms-v6-0-ececb73f97cb@ideasonboard.com> In-Reply-To: <20260720-libipa-algorithms-v6-0-ececb73f97cb@ideasonboard.com> To: libcamera-devel@lists.libcamera.org, Stefan Klug , Milan Zamazal Cc: Jacopo Mondi , Kieran Bingham , Robert Mader X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6404; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=f2e+ElLswiS5th0nFoFYfobTzlHF8UV7oPYZ1lTpAwc=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBqXjfTcI+Orur590ej8FILbmo+zRgIORC8FkBhM Cgvg6iaR7uJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCal430wAKCRByNAaPFqFW PJuKD/9lgwVEwZaVsoRVUyJTMU2F1OdxdD6f7085wRnioksVrXSIox293sn2ci7c7chfiuh7uHw eIRv4gjqHyarDFR4DIRlHNy5xDIjvw6csMaC6Ac4gr6orvgn+4SxT8AQpAUElqJm+zOcrAg/8CP mI0a/xLgN9LfpA4D2eE7S2KBGDdBZuxq2P8KlSCtJ55zgf/1o/6Wi/uJ9VrTLwP82a2lRfrFrMD xRSlvsfyz/eGCamLUil3oIE1lyesqY/vCuAeEjSFYY0MyY1/i4tDpuaY3YlaQvGGPpsAj5ickxV fRw0CKFPdmej3MWiZ31IA1GN1JePBs9CP1hD4QG9IrENEIykK0hEMwfxvJ66YrWXU/jT7z9wm0T Oq5pOygJQmZRdolDzEj5aGFdNG4zp289fMTLWyd0qQOrLADj8qP8yjYDVgatoE3uP7Z7VNIVaH+ Wj69bwDfTJkuG6KYjXsHhpqqUdV43v01DurAhGgsyvbox2pHhLGcX8nFTzIDzWapTp4LYfQ7FNO nBAKUUO/sxDcVxIGv1dhvgVWzIr/sum0D/95mdY1H4d4bDysZshSfwlblMpBrvlR4aPWjqt6V3c kLikM0LsfZc54RcdkHweeJxfl9qmgniw6zyt6UYsa3LZQ4eil1J5WpQvh3W1mQ4mTjTHVPxhexo yjAkO2MAFS2VBig== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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: Kieran Bingham Now that libipa provides a common CCM algorithm implementation, replace the custom handling with the common Ccm. Signed-off-by: Kieran Bingham Signed-off-by: Jacopo Mondi Tested-by: Robert Mader Reviewed-by: Milan Zamazal Tested-by: Milan Zamazal --- v5->v6: - Remove a few [[maybe_unused]] - Add Milan's tag - Reword title to match other patches in the series --- src/ipa/simple/algorithms/ccm.cpp | 74 ++++++++++++++++++++++----------------- src/ipa/simple/algorithms/ccm.h | 22 +++++++----- src/ipa/simple/ipa_context.h | 5 +-- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp index 1174784edc7e..8b6da543a719 100644 --- a/src/ipa/simple/algorithms/ccm.cpp +++ b/src/ipa/simple/algorithms/ccm.cpp @@ -8,54 +8,64 @@ #include "ccm.h" -#include -#include - -#include - #include "libcamera/internal/matrix.h" -namespace { - -constexpr unsigned int kTemperatureThreshold = 100; - -} - namespace libcamera { namespace ipa::soft::algorithms { LOG_DEFINE_CATEGORY(IPASoftCcm) -int Ccm::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData) +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Ccm::init(IPAContext &context, const ValueNode &tuningData) { - int ret = ccm_.readYaml(tuningData["ccms"], "ct", "ccm"); - if (ret < 0) { - LOG(IPASoftCcm, Error) - << "Failed to parse 'ccm' parameter from tuning file."; - return ret; - } - + /* Informs the 'adjust' component that CCM is available to apply Saturation */ context.ccmEnabled = true; - return 0; + return ccmAlgo_.init(tuningData, context.ctrlMap); } -void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, - IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params) +/** + * \copydoc libcamera::ipa::Algorithm::configure + */ +int Ccm::configure(IPAContext &context, + [[maybe_unused]] const IPAConfigInfo &configInfo) +{ + return ccmAlgo_.configure(context.activeState.ccm, + context.activeState.awb.automatic.colourTemperature); +} + +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Ccm::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) { - const unsigned int ct = frameContext.awb.colourTemperature; + /* Nothing to do here, the ccm will be calculated in prepare() */ + if (frameContext.awb.autoEnabled) + return; - /* Change CCM only on bigger temperature changes. */ - if (!currentCcm_ || - utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold) { - currentCcm_ = ccm_.getInterpolated(ct); - lastCt_ = ct; - } + ccmAlgo_.queueRequest(context.activeState.ccm, frameContext.ccm, controls); +} +void Ccm::prepare(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params) +{ + if (frameContext.awb.autoEnabled) + ccmAlgo_.prepare(context.activeState.ccm, frameContext.ccm, + frame, frameContext.awb.colourTemperature); + + /* + * \todo: Split out combined matrix into individual parameters in + * DebayerParams and perform any pre-multiplication combination in the + * SoftISP component directly. + */ context.activeState.combinedMatrix = - currentCcm_.value() * context.activeState.combinedMatrix; - frameContext.ccm = currentCcm_.value(); + frameContext.ccm.ccm * context.activeState.combinedMatrix; } void Ccm::process([[maybe_unused]] IPAContext &context, @@ -64,7 +74,7 @@ void Ccm::process([[maybe_unused]] IPAContext &context, [[maybe_unused]] const SwIspStats *stats, ControlList &metadata) { - metadata.set(controls::ColourCorrectionMatrix, frameContext.ccm.data()); + ccmAlgo_.process(frameContext.ccm, metadata); } REGISTER_IPA_ALGORITHM(Ccm, "Ccm") diff --git a/src/ipa/simple/algorithms/ccm.h b/src/ipa/simple/algorithms/ccm.h index b20a7da8aa33..27f11bcbd6e9 100644 --- a/src/ipa/simple/algorithms/ccm.h +++ b/src/ipa/simple/algorithms/ccm.h @@ -7,13 +7,15 @@ #pragma once -#include +#include -#include "libcamera/internal/matrix.h" +#include "libcamera/internal/value_node.h" -#include +#include "libipa/ccm.h" +#include "libipa/fixedpoint.h" #include "algorithm.h" +#include "ipa_context.h" namespace libcamera { @@ -22,10 +24,14 @@ namespace ipa::soft::algorithms { class Ccm : public Algorithm { public: - Ccm() = default; - ~Ccm() = default; - int init(IPAContext &context, const ValueNode &tuningData) override; + + int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; + + void queueRequest(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) override; + void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, @@ -36,9 +42,7 @@ public: ControlList &metadata) override; private: - unsigned int lastCt_; - Interpolator> ccm_; - std::optional> currentCcm_; + CcmAlgorithm> ccmAlgo_; }; } /* namespace ipa::soft::algorithms */ diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index 29643a655ce1..ff312ae8f4e7 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -17,6 +17,7 @@ #include "libcamera/internal/vector.h" #include +#include #include #include "core_ipa_interface.h" @@ -38,6 +39,7 @@ struct IPASessionConfiguration { struct IPAActiveState { ipa::awb::ActiveState awb; + ipa::ccm::ActiveState ccm; struct { int32_t exposure; @@ -63,8 +65,7 @@ struct IPAActiveState { struct IPAFrameContext : public FrameContext { ipa::awb::FrameContext awb; - - Matrix ccm; + ipa::ccm::FrameContext ccm; struct { int32_t exposure;