From patchwork Tue Jun 16 06:41:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 26899 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 E7C1BC3303 for ; Tue, 16 Jun 2026 06:42:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 77239625B2; Tue, 16 Jun 2026 08:41:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Gc6e3V5I"; 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 8D92961E76 for ; Tue, 16 Jun 2026 08:41:50 +0200 (CEST) Received: from [127.0.1.1] (chfd-03-b2-v4wan-176392-cust229.vm15.cable.virginm.net [82.19.20.230]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4E48D166C; Tue, 16 Jun 2026 08:41:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1781592077; bh=ESK//rvtSLlKOvKdItZX6TsAh8BUgChpDfTIaQMnrjQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Gc6e3V5IsVZZyDd0FK+Pg+uuO6a4yDy0I01HV3QIX35ZAXoLekQB/ER2EKY3E5IdB KSbpcQoTWSHMcfK0mqWhXHt+P2mE1lgJWpGX1VA7E8Yr5QKN0Wj/ut+T8dZTar2D9u n5Ccg/GK3QC/gadoX2SA6kTamA2GOMtw6IbV4PJU= From: Daniel Scally Date: Tue, 16 Jun 2026 07:41:42 +0100 Subject: [PATCH 08/10] ipa: rkisp1: goc: Re-work to use GammaAlgorithm class MIME-Version: 1.0 Message-Id: <20260616-ipu3-libipa-rework-v1-8-d4448b54f1d8@ideasonboard.com> References: <20260616-ipu3-libipa-rework-v1-0-d4448b54f1d8@ideasonboard.com> In-Reply-To: <20260616-ipu3-libipa-rework-v1-0-d4448b54f1d8@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5638; i=dan.scally@ideasonboard.com; h=from:subject:message-id; bh=ESK//rvtSLlKOvKdItZX6TsAh8BUgChpDfTIaQMnrjQ=; b=owEBbQKS/ZANAwAKAchJV3psRXUyAcsmYgBqMPAq4Nb9WiPbeVxnUeGsKmpurxIJ4586okxI9 LDbidSvLyWJAjMEAAEKAB0WIQQqyuwyDnZdb+mxmm/ISVd6bEV1MgUCajDwKgAKCRDISVd6bEV1 MvHPD/9nTmMvcZUxDlC5wAgSKSbcSj50YohnY4Ic2QefXn3IdEUjfn6Y1oQLIbLksm+fhWFOfkq wZWbtVY/6DFqaY7GN321xFIZsQORxAJRMUj1I10VbXusdAo68yEgY4HYnP4UIdnpKIe3hZS69yR IIm0WlVaWBx3u7DZB6k+44KHCyo34MtWTI4TzPcQJfepZ8aSH8C7o/VYHCdikWOhRAtIGGI+20B ciIOHOoZ+6L6sjza+0swff7DKQ+yt/sSmZbCPmhXcVGR9BWF80DS1UQ22F6DAAuhby+ODBNCnE+ iXgXSQpltrIo9NhGOEMTyXM3EWTyxCoFG5gsgnOB6GAYxAH22pB0wqbJX7GF07gpI+L2oeEZHkc yNKhTc/qQ/8RPkAAv+rhxIw+OC23Tv2nRGyjvjpqQ9QMmpTzba9zeF3XbyMzuASNgLGkH33t11U QcM7WTBeRgKkMFsckZ1/ZJYSzvHA+NrOTfp+xO47vW4xH1MvT6oKrWxYVIAgk+wDHqtYZ9mvk+y MvnIX/aIap+1SsLZowKGrvFkyKV52Q5po4zchfrkSRsOs6HsKMER/gGF3dkucXOcF6iC+QQ9zKc Nu1Lfuc0LPSdEEnH9KjuG6bSJzbxN13RdsCbgTqA1oTP+Gv9oTGzh+mfyUQ5QwyiyXMZgDd05iO jDb1++CMSES2URg== X-Developer-Key: i=dan.scally@ideasonboard.com; a=openpgp; fpr=EEC699ACA1B7CB5D31330C0BBD501C2A3546CCF6 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" Re-work the RkISP1 Gamma Out Correction algorithm to use the new GammaAlgorithm class from libipa, which allows us to share an implementation with the other IPAs. Signed-off-by: Daniel Scally --- src/ipa/rkisp1/algorithms/goc.cpp | 49 +++++++++++---------------------------- src/ipa/rkisp1/algorithms/goc.h | 5 +++- src/ipa/rkisp1/ipa_context.h | 10 +++----- 3 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/goc.cpp b/src/ipa/rkisp1/algorithms/goc.cpp index e8f64bf3d5e028c2013d37b7ef9fe90b737fad5f..1afd7fb9538d85f771c5b743b856a4963ec8665c 100644 --- a/src/ipa/rkisp1/algorithms/goc.cpp +++ b/src/ipa/rkisp1/algorithms/goc.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include @@ -44,6 +44,7 @@ namespace ipa::rkisp1::algorithms { LOG_DEFINE_CATEGORY(RkISP1Gamma) const float kDefaultGamma = 2.2f; +static constexpr unsigned int kNumLutSegments = RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 - 1; /** * \copydoc libcamera::ipa::Algorithm::init @@ -57,10 +58,12 @@ int GammaOutCorrection::init(IPAContext &context, const ValueNode &tuningData) return -EINVAL; } - defaultGamma_ = tuningData["gamma"].get(kDefaultGamma); - context.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, defaultGamma_); + std::array segments = { + 64, 64, 64, 64, 128, 128, 128, 128, + 256, 256, 256, 512, 512, 512, 512, 512 + }; - return 0; + return gammaAlgo_.init(context.ctrlMap, tuningData, segments); } /** @@ -69,7 +72,7 @@ int GammaOutCorrection::init(IPAContext &context, const ValueNode &tuningData) int GammaOutCorrection::configure(IPAContext &context, [[maybe_unused]] const IPACameraSensorInfo &configInfo) { - context.activeState.goc.gamma = defaultGamma_; + gammaAlgo_.configure(context.activeState.gamma); return 0; } @@ -80,17 +83,8 @@ void GammaOutCorrection::queueRequest(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, const ControlList &controls) { - if (frame == 0) - frameContext.goc.update = true; - - const auto &gamma = controls.get(controls::Gamma); - if (gamma) { - context.activeState.goc.gamma = *gamma; - frameContext.goc.update = true; - LOG(RkISP1Gamma, Debug) << "Set gamma to " << *gamma; - } - - frameContext.goc.gamma = context.activeState.goc.gamma; + gammaAlgo_.queueRequest(context.activeState.gamma, frame, + frameContext.gamma, controls); } /** @@ -104,29 +98,14 @@ void GammaOutCorrection::prepare(IPAContext &context, ASSERT(context.hw.numGammaOutSamples == RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10); - if (!frameContext.goc.update) + if (!frameContext.gamma.update) return; - /* - * The logarithmic segments as specified in the reference. - * Plus an additional 0 to make the loop easier - */ - static constexpr std::array segments = { - 64, 64, 64, 64, 128, 128, 128, 128, 256, - 256, 256, 512, 512, 512, 512, 512, 0 - }; - auto config = params->block(); config.setEnabled(true); - __u16 *gamma_y = config->gamma_y; - - unsigned x = 0; - for (const auto [i, size] : utils::enumerate(segments)) { - gamma_y[i] = std::pow(x / 4096.0, 1.0 / frameContext.goc.gamma) * 1023.0; - x += size; - } - + Span lut{ config->gamma_y }; + gammaAlgo_.prepare(frameContext.gamma, lut); config->mode = RKISP1_CIF_ISP_GOC_MODE_LOGARITHMIC; } @@ -139,7 +118,7 @@ void GammaOutCorrection::process([[maybe_unused]] IPAContext &context, [[maybe_unused]] const rkisp1_stat_buffer *stats, ControlList &metadata) { - metadata.set(controls::Gamma, frameContext.goc.gamma); + gammaAlgo_.process(frameContext.gamma, metadata); } REGISTER_IPA_ALGORITHM(GammaOutCorrection, "GammaOutCorrection") diff --git a/src/ipa/rkisp1/algorithms/goc.h b/src/ipa/rkisp1/algorithms/goc.h index bd79fe19cc86b8aefa2603e98e9d7130b44105d9..f7059d206c935fa72195f36091cf953e5f2413e1 100644 --- a/src/ipa/rkisp1/algorithms/goc.h +++ b/src/ipa/rkisp1/algorithms/goc.h @@ -9,6 +9,9 @@ #include "algorithm.h" +#include +#include + namespace libcamera { namespace ipa::rkisp1::algorithms { @@ -35,7 +38,7 @@ public: ControlList &metadata) override; private: - float defaultGamma_; + GammaAlgorithm> gammaAlgo_; }; } /* namespace ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h index 005f4102b4f6d465fd370c20060331a4f3b3a943..03be79085052d5161ec57d97fe9600f4bf7e93c4 100644 --- a/src/ipa/rkisp1/ipa_context.h +++ b/src/ipa/rkisp1/ipa_context.h @@ -30,6 +30,7 @@ #include "libipa/ccm.h" #include "libipa/fc_queue.h" #include "libipa/fixedpoint.h" +#include "libipa/gamma.h" #include "libipa/lsc.h" namespace libcamera { @@ -124,9 +125,7 @@ struct IPAActiveState { uint8_t sharpness; } filter; - struct { - double gamma; - } goc; + ipa::gamma::ActiveState gamma; struct { double lux; @@ -190,10 +189,7 @@ struct IPAFrameContext : public FrameContext { bool update; } filter; - struct { - double gamma; - bool update; - } goc; + ipa::gamma::FrameContext gamma; struct { uint32_t exposure;