From patchwork Tue Jun 23 13:55:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 27017 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 DD46AC330F for ; Tue, 23 Jun 2026 13:55:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1DA9F65863; Tue, 23 Jun 2026 15:55:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="LiTfTBwz"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A4EE565798 for ; Tue, 23 Jun 2026 15:55:11 +0200 (CEST) Received: from [192.168.1.7] (net-93-65-100-155.cust.vodafonedsl.it [93.65.100.155]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F318E1D25; Tue, 23 Jun 2026 15:54:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782222873; bh=dASPJFs4t8sbP5bExYA9VZ7t5mvDky0iz+Ow4tjWnWw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LiTfTBwzXcJITJ9HTtkp8bBlvJA1kMCKNG8tkv8IDJ8QcgIsuAVHuDZ6cIHIfTvm1 nybPTZ/aRMdJSdJhj5dsNy+rpGkTU3oY6t8pex/37C5KhvnYswC/HfNtQtTSySvEbR zL5BsXcxx4M7EqsK/R4LBJ8EWEiYnDxkFvOQnLSA= From: Jacopo Mondi Date: Tue, 23 Jun 2026 15:55:01 +0200 Subject: [PATCH v2 06/11] ipa: simple: Use libipa CcmAlgorithm MIME-Version: 1.0 Message-Id: <20260623-libipa-algorithms-v2-6-f97433f12e4e@ideasonboard.com> References: <20260623-libipa-algorithms-v2-0-f97433f12e4e@ideasonboard.com> In-Reply-To: <20260623-libipa-algorithms-v2-0-f97433f12e4e@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Kieran Bingham X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=5853; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=X6T5HwcgH94HKIRAMTHwUanm5Aq0DIzW+XF+X5nD8DY=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBqOpA7ZGPmKfjl268APAyVDsCl9Ge9e9NxOhoWD 4yHQ+q+iL6JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCajqQOwAKCRByNAaPFqFW POSLD/4r2tT/bAqDqrRCDxWxKBWXZA9FVWzrMON1jeYY5dkelSF61wCM2Qoik9ZFN3vbo9mX81y BQhAFlw0ySWQrbHpLXWSwgm6Kcb3GJ6lVXLUChPRsH6VL04SarW82FEqOzd6Np3fQmqAHYnDGLr BCbp4suZ5a9bW1QTjep71wWWC3cdJCVyDt6swJ8GjhszduSQixuYWGx0oJzuT+c4y4GSX7mjyJI UfffKmPtIMxVBmccuF/waglacduWhlXcxOH2S3zurcIdeYq40u0Vck0KrUtTuxyh/aFADSBzUgi fZ8aO/EKkv19pHOo13x1VgrYge+6bg5GlHjDpjr1wggS7ja0bIfH9BU+nYKm/Xmq5wZaLyPXJN5 KIF9GVjd64uAtgvJMRiE2OtWfoIwHAFw7h2TkUO7+HxnuW/b/gArHqwZtjUrOscftSONl0/AbGi 7pcNRzCZ0OmEmlD/Pv3e1DVT3FSaGpaigqLN8iE9+chqnoJ2lwzQVhO4JJjqXXu6ENOktbhHu6w SIgEHPEdE/8MadiXblpch9/B0KnSY5HoMHlp2actg4Fccaf4nLH5BMVmQzbvvn+46AHr9PJI0g7 MJKi6ZvzLB2XYCqzkAKe7SbRN3fNjK/kxBJcg014ka4wt9ugkYvRWUnBpprkNyonFJoWBWjpf2s +SlGvWmS5P3hGNg== 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 --- src/ipa/simple/algorithms/ccm.cpp | 69 +++++++++++++++++++++------------------ src/ipa/simple/algorithms/ccm.h | 23 ++++++++----- src/ipa/simple/ipa_context.h | 5 +-- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp index ff37c718c6e4..6cf55bd93db0 100644 --- a/src/ipa/simple/algorithms/ccm.cpp +++ b/src/ipa/simple/algorithms/ccm.cpp @@ -8,54 +8,61 @@ #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) +/** + * \copydoc libcamera::ipa::Algorithm::init + */ int Ccm::init([[maybe_unused]] 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; - } + return ccmAlgo_.init(tuningData, context.ctrlMap); +} + +/** + * \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.temperatureK); +} - context.ccmEnabled = true; +/** + * \copydoc libcamera::ipa::Algorithm::queueRequest + */ +void Ccm::queueRequest(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) +{ + /* Nothing to do here, the ccm will be calculated in prepare() */ + if (frameContext.awb.autoEnabled) + return; - return 0; + ccmAlgo_.queueRequest(context.activeState.ccm, frameContext.ccm, controls); } void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params) { - const unsigned int ct = frameContext.awb.temperatureK; - - /* Change CCM only on bigger temperature changes. */ - if (!currentCcm_ || - utils::abs_diff(ct, lastCt_) >= kTemperatureThreshold) { - currentCcm_ = ccm_.getInterpolated(ct); - lastCt_ = ct; - } - + if (frameContext.awb.autoEnabled) + ccmAlgo_.prepare(context.activeState.ccm, frameContext.ccm, + frame, frameContext.awb.temperatureK); + + /* + * \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 +71,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..0d35347ea583 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,15 @@ 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, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + const ControlList &controls) override; + void prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, @@ -36,9 +43,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;