{"id":25774,"url":"https://patchwork.libcamera.org/api/1.1/patches/25774/?format=json","web_url":"https://patchwork.libcamera.org/patch/25774/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260114113016.25162-10-mzamazal@redhat.com>","date":"2026-01-14T11:30:11","name":"[v3,09/14] libcamera: ipa: simple: Make gamma adjustable","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1695f389ffde9419a70341e6d8b35feefebd6429","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/1.1/people/177/?format=json","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25774/mbox/","series":[{"id":5706,"url":"https://patchwork.libcamera.org/api/1.1/series/5706/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5706","date":"2026-01-14T11:30:02","name":"Simple pipeline IPA cleanup","version":3,"mbox":"https://patchwork.libcamera.org/series/5706/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25774/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25774/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 97367C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Jan 2026 11:31:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F55361FC6;\n\tWed, 14 Jan 2026 12:31:03 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9027A61FC6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Jan 2026 12:31:01 +0100 (CET)","from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-213-F0VpMSI_OOChQC9w14xviA-1;\n\tWed, 14 Jan 2026 06:30:56 -0500","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.93])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id F2C1118003FC; Wed, 14 Jan 2026 11:30:55 +0000 (UTC)","from mzamazal-thinkpadp1gen7.tpbc.com (unknown [10.44.32.217])\n\tby mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 5256C1800665; Wed, 14 Jan 2026 11:30:54 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"QYO8Zp83\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1768390260;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=IBQX3gI6o/n48huuNLu3pgz9+U7xLw/KPKHprbM8bJ8=;\n\tb=QYO8Zp83ifjhZjikAeOww/19J0RDcdhlcQl3ldHu0FJmU90EjPApywZHb2GUzac6rixNR6\n\tz5esSdPmma3kWxmRhiU71CsQcjKmDVLW3zJHZ+3zGceyetD9HbVgKVCvNxQQUmRDMYWN5Q\n\tIP57WDeF65rD0PkdjWmbYNDBBBn7vlQ=","X-MC-Unique":"F0VpMSI_OOChQC9w14xviA-1","X-Mimecast-MFC-AGG-ID":"F0VpMSI_OOChQC9w14xviA_1768390256","From":"Milan Zamazal <mzamazal@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<barnabas.pocze@ideasonboard.com>","Subject":"[PATCH v3 09/14] libcamera: ipa: simple: Make gamma adjustable","Date":"Wed, 14 Jan 2026 12:30:11 +0100","Message-ID":"<20260114113016.25162-10-mzamazal@redhat.com>","In-Reply-To":"<20260114113016.25162-1-mzamazal@redhat.com>","References":"<20260114113016.25162-1-mzamazal@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"YuVWsza5DuW78UgBtA1aBjTpwYO_B3czZRb8jV59OOw_1768390256","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","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":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The gamma value is fixed in software ISP.  Let's make it adjustable,\nsimilarly to contrast and saturation.\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n src/ipa/simple/algorithms/adjust.cpp |  8 ++++++++\n src/ipa/simple/algorithms/adjust.h   |  2 ++\n src/ipa/simple/algorithms/lut.cpp    | 12 +++++++-----\n src/ipa/simple/ipa_context.h         |  4 +++-\n 4 files changed, 20 insertions(+), 6 deletions(-)","diff":"diff --git a/src/ipa/simple/algorithms/adjust.cpp b/src/ipa/simple/algorithms/adjust.cpp\nindex 27ae2a53a..cfbc39610 100644\n--- a/src/ipa/simple/algorithms/adjust.cpp\n+++ b/src/ipa/simple/algorithms/adjust.cpp\n@@ -23,6 +23,7 @@ LOG_DEFINE_CATEGORY(IPASoftAdjust)\n \n int Adjust::init(IPAContext &context, [[maybe_unused]] const YamlObject &tuningData)\n {\n+\tcontext.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, kDefaultGamma);\n \tcontext.ctrlMap[&controls::Contrast] = ControlInfo(0.0f, 2.0f, 1.0f);\n \tif (context.ccmEnabled)\n \t\tcontext.ctrlMap[&controls::Saturation] = ControlInfo(0.0f, 2.0f, 1.0f);\n@@ -32,6 +33,7 @@ int Adjust::init(IPAContext &context, [[maybe_unused]] const YamlObject &tuningD\n int Adjust::configure(IPAContext &context,\n \t\t      [[maybe_unused]] const IPAConfigInfo &configInfo)\n {\n+\tcontext.activeState.knobs.gamma = std::optional<double>();\n \tcontext.activeState.knobs.contrast = std::optional<double>();\n \tcontext.activeState.knobs.saturation = std::optional<double>();\n \n@@ -43,6 +45,12 @@ void Adjust::queueRequest(typename Module::Context &context,\n \t\t\t  [[maybe_unused]] typename Module::FrameContext &frameContext,\n \t\t\t  const ControlList &controls)\n {\n+\tconst auto &gamma = controls.get(controls::Gamma);\n+\tif (gamma.has_value()) {\n+\t\tcontext.activeState.knobs.gamma = gamma;\n+\t\tLOG(IPASoftAdjust, Debug) << \"Setting gamma to \" << gamma.value();\n+\t}\n+\n \tconst auto &contrast = controls.get(controls::Contrast);\n \tif (contrast.has_value()) {\n \t\tcontext.activeState.knobs.contrast = contrast;\ndiff --git a/src/ipa/simple/algorithms/adjust.h b/src/ipa/simple/algorithms/adjust.h\nindex c4baa2503..190d2079f 100644\n--- a/src/ipa/simple/algorithms/adjust.h\n+++ b/src/ipa/simple/algorithms/adjust.h\n@@ -19,6 +19,8 @@ namespace libcamera {\n \n namespace ipa::soft::algorithms {\n \n+const float kDefaultGamma = 2.2f;\n+\n class Adjust : public Algorithm\n {\n public:\ndiff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\nindex 3a00bf4ee..25b188b91 100644\n--- a/src/ipa/simple/algorithms/lut.cpp\n+++ b/src/ipa/simple/algorithms/lut.cpp\n@@ -18,6 +18,8 @@\n \n #include \"simple/ipa_context.h\"\n \n+#include \"adjust.h\"\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPASoftLut)\n@@ -27,8 +29,6 @@ namespace ipa::soft::algorithms {\n int Lut::configure(IPAContext &context,\n \t\t   [[maybe_unused]] const IPAConfigInfo &configInfo)\n {\n-\t/* Gamma value is fixed */\n-\tcontext.configuration.gamma = 1.0 / 2.2;\n \tupdateGammaTable(context);\n \n \treturn 0;\n@@ -37,6 +37,8 @@ int Lut::configure(IPAContext &context,\n void Lut::updateGammaTable(IPAContext &context)\n {\n \tconst auto blackLevel = context.activeState.blc.level;\n+\tconst auto gamma =\n+\t\t1.0 / context.activeState.knobs.gamma.value_or(kDefaultGamma);\n \tconst auto contrast = context.activeState.knobs.contrast.value_or(1.0);\n \t/* Convert 0..2 to 0..infinity; avoid actual inifinity at tan(pi/2) */\n \tdouble contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001));\n@@ -52,8 +54,7 @@ void Lut::updateGammaTable(IPAContext &context)\n \t\t\t\tnormalized = 0.5 * std::pow(normalized / 0.5, contrastExp);\n \t\t\telse\n \t\t\t\tnormalized = 1.0 - 0.5 * std::pow((1.0 - normalized) / 0.5, contrastExp);\n-\t\t\tgammaTable[i] = UINT8_MAX *\n-\t\t\t\t\tstd::pow(normalized, context.configuration.gamma);\n+\t\t\tgammaTable[i] = UINT8_MAX * std::pow(normalized, gamma);\n \t\t}\n \t\t/*\n \t\t * Due to CCM operations, the table lookup may reach indices below the black\n@@ -65,6 +66,7 @@ void Lut::updateGammaTable(IPAContext &context)\n \t\t\t  gammaTable[blackIndex]);\n \t}\n \n+\tcontext.activeState.gamma.gamma = gamma;\n \tcontext.activeState.gamma.blackLevel = blackLevel;\n \tcontext.activeState.gamma.contrastExp = contrastExp;\n }\n@@ -131,7 +133,7 @@ void Lut::prepare(IPAContext &context,\n \t\tcontext.activeState.matrixChanged = false;\n \t}\n \n-\tparams->gamma = context.configuration.gamma;\n+\tparams->gamma = context.activeState.gamma.gamma;\n \tparams->contrastExp = context.activeState.gamma.contrastExp;\n }\n \ndiff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h\nindex 58dcad290..680b72eb9 100644\n--- a/src/ipa/simple/ipa_context.h\n+++ b/src/ipa/simple/ipa_context.h\n@@ -25,7 +25,6 @@ namespace libcamera {\n namespace ipa::soft {\n \n struct IPASessionConfiguration {\n-\tfloat gamma;\n \tstruct {\n \t\tint32_t exposureMin, exposureMax;\n \t\tdouble againMin, againMax, again10, againMinStep;\n@@ -58,6 +57,7 @@ struct IPAActiveState {\n \tstruct {\n \t\tstd::array<double, kGammaLookupSize> gammaTable;\n \t\tuint8_t blackLevel;\n+\t\tfloat gamma;\n \t\tdouble contrast;\n \t\tdouble contrastExp;\n \t} gamma;\n@@ -67,6 +67,7 @@ struct IPAActiveState {\n \tbool matrixChanged = false;\n \n \tstruct {\n+\t\tstd::optional<float> gamma;\n \t\t/* 0..2 range, 1.0 = normal */\n \t\tstd::optional<double> contrast;\n \t\tstd::optional<float> saturation;\n@@ -86,6 +87,7 @@ struct IPAFrameContext : public FrameContext {\n \t\tdouble blue;\n \t} gains;\n \n+\tstd::optional<float> gamma;\n \tstd::optional<double> contrast;\n \tstd::optional<float> saturation;\n };\n","prefixes":["v3","09/14"]}