From patchwork Tue Nov 17 14:56:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 28949 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 724F7BDE17 for ; Tue, 17 Nov 2026 14:57:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 18AF06A899; Tue, 17 Nov 2026 15:57:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hv98mpTy"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED7726A7FE for ; Tue, 17 Nov 2026 15:56:58 +0100 (CET) Received: from Monstersaurus.lan (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4E4E4929; Tue, 17 Nov 2026 15:54:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1794927271; bh=Qnf5Z+rafhodbXHVcLK/hNtMPjvJiMm6LS5/qsFHETY=; h=From:To:Cc:Subject:Date:From; b=hv98mpTyfGScSY3a0FJFAgEXqozSe8sDfDgSVfxYFRWzah7xUG0JHfab6SiZDAK6u A2A2hzWbeBbLbZbIgu8gX6sODRegkgIIjbXKsB7NlGfLt1OhcoKXZT/b8o5g7L6+6l uxqvtJ4BSi4+RTk1BnlCJA6QVRJ2aSdRnUAVUlRw= From: Kieran Bingham To: libcamera devel Cc: Kieran Bingham Subject: [PATCH] ipa: simple: Add lux algorithm to the SoftIPA Date: Tue, 17 Nov 2026 14:56:55 +0000 Message-ID: <20261117145655.446350-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.52.0 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" Utilise the lux component of libipa to map in the lux estimate process using the yHistgram of the Soft ISP statistics. Tie this into both the Agc and Awb process calls to make use of the data where possible. Signed-off-by: Kieran Bingham --- Note: Untested / locally compile tested only, and depends on Series:6358 from Barnabas to bring in the libipa lux support. https://patchwork.libcamera.org/project/libcamera/list/?series=6358 src/ipa/softisp/algorithms/agc.cpp | 1 + src/ipa/softisp/algorithms/awb.cpp | 7 +-- src/ipa/softisp/algorithms/lux.cpp | 82 ++++++++++++++++++++++++++ src/ipa/softisp/algorithms/lux.h | 37 ++++++++++++ src/ipa/softisp/algorithms/meson.build | 1 + src/ipa/softisp/ipa_context.h | 5 +- 6 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 src/ipa/softisp/algorithms/lux.cpp create mode 100644 src/ipa/softisp/algorithms/lux.h diff --git a/src/ipa/softisp/algorithms/agc.cpp b/src/ipa/softisp/algorithms/agc.cpp index ea234bc2ae4b..b20cf388cc1b 100644 --- a/src/ipa/softisp/algorithms/agc.cpp +++ b/src/ipa/softisp/algorithms/agc.cpp @@ -99,6 +99,7 @@ void Agc::process(IPAContext &context, .yHist = yHist, .exposure = frameContext.sensor.exposure, .gain = frameContext.sensor.gain, + .lux = frameContext.lux.lux, }}, metadata); } else { agc_.process(context.configuration.agc, context.activeState.agc, frameContext.agc, {}, metadata); diff --git a/src/ipa/softisp/algorithms/awb.cpp b/src/ipa/softisp/algorithms/awb.cpp index fb9bcb06a75e..6c46cd02052d 100644 --- a/src/ipa/softisp/algorithms/awb.cpp +++ b/src/ipa/softisp/algorithms/awb.cpp @@ -19,11 +19,6 @@ LOG_DEFINE_CATEGORY(IPASoftIspAwb) namespace ipa::softisp::algorithms { -/* - * \todo Replace it with a proper Lux algorithm - */ -static constexpr unsigned int kDefaultLux = 500; - class SoftIspAwbStats final : public AwbStats { public: @@ -160,7 +155,7 @@ void Awb::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, SoftIspAwbStats awbStats = calculateRgbMeans(context, stats); awbAlgo_.process(context.activeState.awb, frameContext.awb, awbStats, - kDefaultLux, metadata); + frameContext.lux.lux, metadata); } REGISTER_IPA_ALGORITHM(Awb, "Awb") diff --git a/src/ipa/softisp/algorithms/lux.cpp b/src/ipa/softisp/algorithms/lux.cpp new file mode 100644 index 000000000000..f0c89bcdb8b9 --- /dev/null +++ b/src/ipa/softisp/algorithms/lux.cpp @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Ideas On Board + * + * SoftISP Lux control + */ + +#include "lux.h" + +#include + +#include + +#include "libipa/histogram.h" +#include "libipa/lux.h" + +/** + * \file lux.h + */ + +namespace libcamera { + +namespace ipa::softisp::algorithms { + +/** + * \class Lux + * \brief SoftISP Lux control + * + * The Lux algorithm is responsible for estimating the lux level of the image. + * It doesn't take or generate any controls, but it provides a lux level for + * other algorithms (such as AGC) to use. + */ + +/** + * \copydoc libcamera::ipa::Algorithm::init + */ +int Lux::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData) +{ + return lux_.init(tuningData); +} + +/** + * \copydoc libcamera::ipa::Algorithm::prepare + */ +void Lux::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + [[maybe_unused]] DebayerParams *params) +{ + lux_.prepare(context.activeState.lux, frameContext.lux); +} + +/** + * \copydoc libcamera::ipa::Algorithm::process + */ +void Lux::process(IPAContext &context, + [[maybe_unused]] const uint32_t frame, + IPAFrameContext &frameContext, + const SwIspStats *stats, + ControlList &metadata) +{ + if (!stats) { + lux_.process(context.activeState.lux, frameContext.lux, metadata, {}); + return; + } + + Histogram yHist(stats->yHistogram); + + lux_.process(context.activeState.lux, frameContext.lux, metadata, + { { + .exposureTime = context.configuration.agc.lineDuration * + frameContext.sensor.exposure, + .analogueGain = frameContext.sensor.gain, + .digitalGain = 1, + .yHist = yHist, + } }); +} + +REGISTER_IPA_ALGORITHM(Lux, "Lux") + +} /* namespace ipa::softisp::algorithms */ + +} /* namespace libcamera */ diff --git a/src/ipa/softisp/algorithms/lux.h b/src/ipa/softisp/algorithms/lux.h new file mode 100644 index 000000000000..606ebea52ca0 --- /dev/null +++ b/src/ipa/softisp/algorithms/lux.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2026, Ideas On Board + * + * RkISP1 Lux control + */ + +#pragma once + +#include + +#include "libipa/lux.h" + +#include "algorithm.h" + +namespace libcamera { + +namespace ipa::softisp::algorithms { + +class Lux : public Algorithm +{ +public: + int init(IPAContext &context, const ValueNode &tuningData) override; + void prepare(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + DebayerParams *params) override; + void process(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + const SwIspStats *stats, + ControlList &metadata) override; + +private: + ipa::LuxAlgorithm lux_; +}; + +} /* namespace ipa::softisp::algorithms */ +} /* namespace libcamera */ diff --git a/src/ipa/softisp/algorithms/meson.build b/src/ipa/softisp/algorithms/meson.build index d98f4b1f45d4..0f0d65dcd7b8 100644 --- a/src/ipa/softisp/algorithms/meson.build +++ b/src/ipa/softisp/algorithms/meson.build @@ -7,4 +7,5 @@ softisp_ipa_algorithms = files([ 'blc.cpp', 'ccm.cpp', 'lsc.cpp', + 'lux.cpp', ]) diff --git a/src/ipa/softisp/ipa_context.h b/src/ipa/softisp/ipa_context.h index 62d1ae84b3c8..ab1f55006337 100644 --- a/src/ipa/softisp/ipa_context.h +++ b/src/ipa/softisp/ipa_context.h @@ -22,7 +22,8 @@ #include #include #include -#include "libipa/lsc.h" +#include +#include #include "core_ipa_interface.h" @@ -58,6 +59,7 @@ struct IPAActiveState { } knobs; ipa::lsc::ActiveState lsc; + ipa::lux::ActiveState lux; }; struct IPAFrameContext : public FrameContext { @@ -74,6 +76,7 @@ struct IPAFrameContext : public FrameContext { std::optional contrast; std::optional saturation; ipa::lsc::FrameContext lsc; + ipa::lux::FrameContext lux; }; struct IPAContext {