From patchwork Sat Sep 26 23:12:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Alexander X-Patchwork-Id: 28385 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 E7A6FC324E for ; Sat, 26 Sep 2026 23:12:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4599A689CE; Sun, 27 Sep 2026 01:12:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=inspiredexperts.com header.i=@inspiredexperts.com header.b="skEkyGMZ"; dkim-atps=neutral Received: from s1.inspiredexperts.com (s1.inspiredexperts.com [162.243.156.162]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7B9CF68983 for ; Sun, 27 Sep 2026 01:12:07 +0200 (CEST) Received: from poshta.inspiredexperts.com (s1.inspiredexperts.com [127.0.0.1]) by s1.inspiredexperts.com (Postfix) with ESMTPSA id EB07FD2D689; Sat, 26 Sep 2026 17:12:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inspiredexperts.com; s=default; t=1790464325; bh=hDqcDe9SwmGl2WFIozDr9bE/rKn2Lqj+8w2D+jXe5jI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=skEkyGMZH5mf984WgurAKhcGiwGU8XBfcGZqCyeLbc9hm8aP+0zNX53lRIbnftPRj lVuEQmb6zccDwzDP9SK/cDg6eHz5DVAyaDnd0+30YtcMnCQo2CkmGW5NCOxDhTJvWr 7ZQmwTIkm9pPQ6kF9wFpXsbQO6XBJhfC0cSGAWSs= MIME-Version: 1.0 Date: Sat, 26 Sep 2026 17:12:04 -0600 From: James Alexander To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal , =?utf-8?b?QmFybmFiw6FzIFDFkWN6?= =?utf-8?q?e?= , Jacopo Mondi , Kieran Bingham Subject: [PATCH v3] ipa: softisp: adjust: Read default contrast from tuning In-Reply-To: References: <20260816204259.2845517-2-opensource@inspiredexperts.com> <20260916192754.312240-1-opensource@inspiredexperts.com> Message-ID: <6f68162366f6bcb48dea57054c5733d5@inspiredexperts.com> X-Sender: opensource@inspiredexperts.com X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on s1.inspiredexperts.com 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" SoftISP tuning files can enable the Adjust algorithm, but they cannot select the default Contrast control value. This forces applications to supply the control on every request when a sensor needs a non-neutral default. Read an optional defaultContrast value from the Adjust tuning section, validate it against the advertised control range, and use it as both the control default and initial state. Tuning files that omit the value retain the existing neutral default, and per-request controls remain authoritative. Since contrast now always has an initial value, make its active and per-frame state non-optional and remove the fallback paths. Signed-off-by: James Alexander --- Changes in v3: - Rename the tuning key to defaultContrast. - Make the active and per-frame contrast state non-optional. - Drop the standalone Adjust test pending a common IPA algorithm test structure. Tested with a simple-pipeline/softisp build and all seven existing IPA tests on x86_64. Changes in v2: - Rebase the change from the simple IPA onto the current softisp Adjust algorithm. - Limit the tuning option to contrast. Gamma is being moved to the common libipa GammaAlgorithm, and saturation remains tied to CCM behavior. - Reject malformed and out-of-range values instead of clamping them. - Add focused tests for fallback, tuning, request override, and validation. src/ipa/softisp/algorithms/adjust.cpp | 33 ++++++++++++++++++++++++++------- src/ipa/softisp/algorithms/adjust.h | 3 +++ src/ipa/softisp/ipa_context.h | 4 ++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/ipa/softisp/algorithms/adjust.cpp b/src/ipa/softisp/algorithms/adjust.cpp index 56e2cf0e8..6e6010bc4 100644 --- a/src/ipa/softisp/algorithms/adjust.cpp +++ b/src/ipa/softisp/algorithms/adjust.cpp @@ -8,6 +8,8 @@ #include "adjust.h" +#include + #include #include @@ -19,17 +21,34 @@ namespace libcamera { namespace ipa::softisp::algorithms { -constexpr float kDefaultContrast = 1.0f; constexpr float kDefaultSaturation = 1.0f; +constexpr float kMinContrast = 0.0f; +constexpr float kMaxContrast = 2.0f; + LOG_DEFINE_CATEGORY(IPASoftIspAdjust) -int Adjust::init(IPAContext &context, [[maybe_unused]] const ValueNode &tuningData) +int Adjust::init(IPAContext &context, const ValueNode &tuningData) { + const ValueNode &contrastNode = tuningData["defaultContrast"]; + const std::optional contrast = contrastNode.get(); + if (contrastNode && !contrast) { + LOG(IPASoftIspAdjust, Error) << "Failed to parse defaultContrast"; + return -EINVAL; + } + + defaultContrast_ = contrast.value_or(kDefaultContrast); + if (defaultContrast_ < kMinContrast || defaultContrast_ > kMaxContrast) { + LOG(IPASoftIspAdjust, Error) + << "defaultContrast must be in the range [" << kMinContrast + << ", " << kMaxContrast << "]"; + return -EINVAL; + } + context.ctrlMap[&controls::Gamma] = ControlInfo(0.1f, 10.0f, kDefaultGamma); context.ctrlMap[&controls::Contrast] = - ControlInfo(0.0f, 2.0f, kDefaultContrast); + ControlInfo(kMinContrast, kMaxContrast, defaultContrast_); if (context.ccmEnabled) context.ctrlMap[&controls::Saturation] = ControlInfo(0.0f, 2.0f, kDefaultSaturation); @@ -40,7 +59,7 @@ int Adjust::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo) { context.activeState.knobs.gamma = kDefaultGamma; - context.activeState.knobs.contrast = std::optional(); + context.activeState.knobs.contrast = defaultContrast_; context.activeState.knobs.saturation = std::optional(); return 0; @@ -59,7 +78,7 @@ void Adjust::queueRequest(typename Module::Context &context, const auto &contrast = controls.get(controls::Contrast); if (contrast.has_value()) { - context.activeState.knobs.contrast = contrast; + context.activeState.knobs.contrast = contrast.value(); LOG(IPASoftIspAdjust, Debug) << "Setting contrast to " << contrast.value(); } @@ -107,7 +126,7 @@ void Adjust::prepare(IPAContext &context, } params->gamma = 1.0 / context.activeState.knobs.gamma; - const float contrast = context.activeState.knobs.contrast.value_or(kDefaultContrast); + const float contrast = context.activeState.knobs.contrast; params->contrastExp = tan(std::clamp(contrast * M_PI_4, 0.0, M_PI_2 - 0.00001)); } @@ -121,7 +140,7 @@ void Adjust::process([[maybe_unused]] IPAContext &context, metadata.set(controls::Gamma, gamma); const auto &contrast = frameContext.contrast; - metadata.set(controls::Contrast, contrast.value_or(kDefaultContrast)); + metadata.set(controls::Contrast, contrast); const auto &saturation = frameContext.saturation; metadata.set(controls::Saturation, saturation.value_or(kDefaultSaturation)); diff --git a/src/ipa/softisp/algorithms/adjust.h b/src/ipa/softisp/algorithms/adjust.h index 1acf7cdf1..726e24cfc 100644 --- a/src/ipa/softisp/algorithms/adjust.h +++ b/src/ipa/softisp/algorithms/adjust.h @@ -18,6 +18,7 @@ namespace libcamera { namespace ipa::softisp::algorithms { constexpr float kDefaultGamma = 2.2f; +constexpr float kDefaultContrast = 1.0f; class Adjust : public Algorithm { @@ -43,6 +44,8 @@ public: private: void applySaturation(Matrix &ccm, float saturation); + + float defaultContrast_ = kDefaultContrast; }; } /* namespace ipa::softisp::algorithms */ diff --git a/src/ipa/softisp/ipa_context.h b/src/ipa/softisp/ipa_context.h index 397e6c99b..6c1a517d1 100644 --- a/src/ipa/softisp/ipa_context.h +++ b/src/ipa/softisp/ipa_context.h @@ -52,7 +52,7 @@ struct IPAActiveState { struct { float gamma; /* 0..2 range, 1.0 = normal */ - std::optional contrast; + float contrast; std::optional saturation; } knobs; }; @@ -68,7 +68,7 @@ struct IPAFrameContext : public FrameContext { } sensor; float gamma; - std::optional contrast; + float contrast; std::optional saturation; };