From patchwork Tue Jan 20 12:26:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 25881 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 1E275BDCBF for ; Tue, 20 Jan 2026 12:26:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CACEF61FD6; Tue, 20 Jan 2026 13:26:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="O+qDJFEh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5EAE361A35 for ; Tue, 20 Jan 2026 13:26:37 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b09a:fcc3:e9a4:a9a8]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 3788A2169; Tue, 20 Jan 2026 13:26:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768911966; bh=eL+k2EL2JfpXoL5X7gV7awPUpsFnyOfOlJ50FdFvmZQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=O+qDJFEhJEmWKVqbOlgjM8mCe2dmmTWasv0xXyYTsrKF5vnad36Am4LFcYKnOUtam lrpDuBTERhrEwreHy95geF/l7bV0po4mjBsq0c264bPURjzGxY1cfBoUlHPQgZFlDP NEOLsqLP51Z/tt7G/GTVi7vXeTILMceyYG7HzRtA= From: Stefan Klug Date: Tue, 20 Jan 2026 13:26:14 +0100 Subject: [PATCH v5 09/15] ipa: rkisp1: lsc: Handle quantization locally MIME-Version: 1.0 Message-Id: <20260120-sklug-lsc-resampling-v2-dev-v5-9-ef5cec7b299f@ideasonboard.com> References: <20260120-sklug-lsc-resampling-v2-dev-v5-0-ef5cec7b299f@ideasonboard.com> In-Reply-To: <20260120-sklug-lsc-resampling-v2-dev-v5-0-ef5cec7b299f@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Mailer: b4 0.14.2 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 quantization functionality in the Interpolator type hinders in writing nice code. Don't use it and implement the functionality directly in the algorithm. While at it, reduce the threshold to half of the quantization step size, otherwise it might happen that we skip a full quantization step. Rename the kColourTemperatureChangeThreshhold to kColourTemperatureQuantization to better express the usecase. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Barnabás Pőcze --- Changes in v4: - Small fix in commit message - Replaced manual std::abs(signed diff) by utils::abs_diff() - Collected tag Changes in v3: - Reduce threshold to quantization step/2 - Drop unnecessary static modifier - Collected tag Changes in v2: - Added this patch --- src/ipa/rkisp1/algorithms/lsc.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp index c42f74557c7364935254d75ee1fb923d176e0dbd..b7c2ebe43dc0de6716a90b50153cc4dee5d717af 100644 --- a/src/ipa/rkisp1/algorithms/lsc.cpp +++ b/src/ipa/rkisp1/algorithms/lsc.cpp @@ -70,7 +70,7 @@ LOG_DEFINE_CATEGORY(RkISP1Lsc) namespace { -constexpr int kColourTemperatureChangeThreshhold = 10; +constexpr int kColourTemperatureQuantization = 10; class LscPolynomialLoader { @@ -308,12 +308,16 @@ std::vector parseSizes(const YamlObject &tuningData, return sizes; } +unsigned int quantize(unsigned int value, unsigned int step) +{ + return std::lround(value / static_cast(step)) * step; +} + } /* namespace */ LensShadingCorrection::LensShadingCorrection() : lastAppliedCt_(0), lastAppliedQuantizedCt_(0) { - sets_.setQuantization(kColourTemperatureChangeThreshhold); } /** @@ -426,17 +430,23 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context, RkISP1Params *params) { uint32_t ct = frameContext.awb.temperatureK; - if (std::abs(static_cast(ct) - static_cast(lastAppliedCt_)) < - kColourTemperatureChangeThreshhold) + unsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization); + + /* + * Add a threshold so that oscillations around a quantization step don't + * lead to constant changes. + */ + if (utils::abs_diff(ct, lastAppliedCt_) < kColourTemperatureQuantization / 2) return; - unsigned int quantizedCt; - const Components &set = sets_.getInterpolated(ct, &quantizedCt); - if (lastAppliedQuantizedCt_ == quantizedCt) + + if (quantizedCt == lastAppliedQuantizedCt_) return; auto config = params->block(); config.setEnabled(true); setParameters(*config); + + const Components &set = sets_.getInterpolated(quantizedCt); copyTable(*config, set); lastAppliedCt_ = ct;