From patchwork Thu Nov 20 10:45:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 25095 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 C7DAAC3330 for ; Thu, 20 Nov 2025 10:46:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F69760AB1; Thu, 20 Nov 2025 11:46:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="fsCZUs3s"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5721260A8A for ; Thu, 20 Nov 2025 11:46:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763635586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vVfx98L7QettwdI59zv0fnwQbGjLUrVmHFrOP7RjXBA=; b=fsCZUs3snPqwaAlKcG2qmKp7hP8xha9ZArKDBydEqB9I9UxJ37jEc/byvsKgp3LNRJbSlX AR08Ha3dXSVg96PjiQfqxOXk+QB44LY4TKqFfxyI5CljKy4wWPOSL2E606qM1AnRmFUhXk CDvv5Y2ohqSheNI9CpV2KMjdwkSA8Z8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-134-c_p03WtVM12ZMRe5E7KDhg-1; Thu, 20 Nov 2025 05:46:22 -0500 X-MC-Unique: c_p03WtVM12ZMRe5E7KDhg-1 X-Mimecast-MFC-AGG-ID: c_p03WtVM12ZMRe5E7KDhg_1763635581 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A6DC19560A3; Thu, 20 Nov 2025 10:46:21 +0000 (UTC) Received: from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.34.39]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8CA161800451; Thu, 20 Nov 2025 10:46:19 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , Kieran Bingham , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v2 09/13] libcamera: ipa: simple: Make gamma adjustable Date: Thu, 20 Nov 2025 11:45:44 +0100 Message-ID: <20251120104548.80268-10-mzamazal@redhat.com> In-Reply-To: <20251120104548.80268-1-mzamazal@redhat.com> References: <20251120104548.80268-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bRTtSDe0w5trTb4AYU0VWzZS1XoXce9TkIb49AL1lJE_1763635581 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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" The gamma value is fixed in software ISP. Let's make it adjustable, similarly to contrast and saturation. The default gamma value is changed from 1/2.0 to a more common value 1/2.2, which is used in GPU ISP. Signed-off-by: Milan Zamazal --- src/ipa/simple/algorithms/adjust.cpp | 8 ++++++++ src/ipa/simple/algorithms/adjust.h | 2 ++ src/ipa/simple/algorithms/lut.cpp | 9 ++++++--- src/ipa/simple/ipa_context.h | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ipa/simple/algorithms/adjust.cpp b/src/ipa/simple/algorithms/adjust.cpp index 49fa98c9d..600fd3c7b 100644 --- a/src/ipa/simple/algorithms/adjust.cpp +++ b/src/ipa/simple/algorithms/adjust.cpp @@ -23,6 +23,7 @@ LOG_DEFINE_CATEGORY(IPASoftAdjust) int Adjust::init(IPAContext &context, [[maybe_unused]] const YamlObject &tuningData) { + context.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, kDefaultGamma); context.ctrlMap[&controls::Contrast] = ControlInfo(0.0f, 2.0f, 1.0f); if (context.ccmEnabled) context.ctrlMap[&controls::Saturation] = ControlInfo(0.0f, 2.0f, 1.0f); @@ -32,6 +33,7 @@ int Adjust::init(IPAContext &context, [[maybe_unused]] const YamlObject &tuningD int Adjust::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { + context.activeState.knobs.gamma = std::optional(); context.activeState.knobs.contrast = std::optional(); context.activeState.knobs.saturation = std::optional(); @@ -43,6 +45,12 @@ void Adjust::queueRequest(typename Module::Context &context, [[maybe_unused]] typename Module::FrameContext &frameContext, const ControlList &controls) { + const auto &gamma = controls.get(controls::Gamma); + if (gamma.has_value()) { + context.activeState.knobs.gamma = gamma; + LOG(IPASoftAdjust, Debug) << "Setting gamma to " << gamma.value(); + } + const auto &contrast = controls.get(controls::Contrast); if (contrast.has_value()) { context.activeState.knobs.contrast = contrast; diff --git a/src/ipa/simple/algorithms/adjust.h b/src/ipa/simple/algorithms/adjust.h index c4baa2503..190d2079f 100644 --- a/src/ipa/simple/algorithms/adjust.h +++ b/src/ipa/simple/algorithms/adjust.h @@ -19,6 +19,8 @@ namespace libcamera { namespace ipa::soft::algorithms { +const float kDefaultGamma = 2.2f; + class Adjust : public Algorithm { public: diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp index a4cb14673..a17a24c9e 100644 --- a/src/ipa/simple/algorithms/lut.cpp +++ b/src/ipa/simple/algorithms/lut.cpp @@ -18,6 +18,8 @@ #include "simple/ipa_context.h" +#include "adjust.h" + namespace libcamera { LOG_DEFINE_CATEGORY(IPASoftLut) @@ -27,8 +29,6 @@ namespace ipa::soft::algorithms { int Lut::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { - /* Gamma value is fixed */ - context.configuration.gamma = 0.5; updateGammaTable(context); return 0; @@ -39,6 +39,8 @@ void Lut::updateGammaTable(IPAContext &context) auto &gammaTable = context.activeState.gamma.gammaTable; const auto blackLevel = context.activeState.blc.level; const unsigned int blackIndex = blackLevel * gammaTable.size() / 256; + const auto gamma = + 1.0 / context.activeState.knobs.gamma.value_or(kDefaultGamma); const auto contrast = context.activeState.knobs.contrast.value_or(1.0); const float divisor = gammaTable.size() - blackIndex - 1.0; @@ -52,7 +54,7 @@ void Lut::updateGammaTable(IPAContext &context) else normalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp); gammaTable[i] = UINT8_MAX * - std::pow(normalized, context.configuration.gamma); + std::pow(normalized, gamma); } /* * Due to CCM operations, the table lookup may reach indices below the black @@ -63,6 +65,7 @@ void Lut::updateGammaTable(IPAContext &context) std::fill(gammaTable.begin(), gammaTable.begin() + blackIndex, gammaTable[blackIndex]); + context.activeState.gamma.gamma = gamma; context.activeState.gamma.blackLevel = blackLevel; context.activeState.gamma.contrast = contrast; } diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h index c69d59780..8f56c25bf 100644 --- a/src/ipa/simple/ipa_context.h +++ b/src/ipa/simple/ipa_context.h @@ -57,6 +57,7 @@ struct IPAActiveState { struct { std::array gammaTable; uint8_t blackLevel; + float gamma; double contrast; } gamma; @@ -65,6 +66,7 @@ struct IPAActiveState { bool matrixChanged = false; struct { + std::optional gamma; /* 0..2 range, 1.0 = normal */ std::optional contrast; std::optional saturation; @@ -84,6 +86,7 @@ struct IPAFrameContext : public FrameContext { double blue; } gains; + std::optional gamma; std::optional contrast; std::optional saturation; };