[{"id":37660,"web_url":"https://patchwork.libcamera.org/comment/37660/","msgid":"<3c1f7f8f-3a0b-4f23-b2bc-a5b41797f7e8@ideasonboard.com>","date":"2026-01-14T15:37:14","subject":"Re: [PATCH v3 09/15] ipa: rkisp1: lsc: Handle quantization locally","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2026. 01. 14. 12:58 keltezéssel, Stefan Klug írta:\n> The quantization functionality in the Interpolator hinders in writing\n\nIt's a small thing, but I'd add \"the Interpolator >type<\".\n\n\n> nice code. Don't use it and implement the functionality directly in the\n> algorithm.\n> \n> While at it, reduce the threshold to half of the quantization step size,\n> otherwise it might happen that we skip a full quantization step. Rename\n> the kColourTemperatureChangeThreshhold to kColourTemperatureQuantization\n> to better express the usecase.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> ---\n> \n> Changes in v3:\n> - Reduce threshold to quantization step/2\n> - Drop unnecessary static modifier\n> - Collected tag\n> \n> Changes in v2:\n> - Added this patch\n> ---\n>   src/ipa/rkisp1/algorithms/lsc.cpp | 25 ++++++++++++++++++-------\n>   1 file changed, 18 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp\n> index c42f74557c7364935254d75ee1fb923d176e0dbd..77ed0a95209ac13e82f4ee43f7a22095bb5fd65f 100644\n> --- a/src/ipa/rkisp1/algorithms/lsc.cpp\n> +++ b/src/ipa/rkisp1/algorithms/lsc.cpp\n> @@ -70,7 +70,7 @@ LOG_DEFINE_CATEGORY(RkISP1Lsc)\n>   \n>   namespace {\n>   \n> -constexpr int kColourTemperatureChangeThreshhold = 10;\n> +constexpr int kColourTemperatureQuantization = 10;\n>   \n>   class LscPolynomialLoader\n>   {\n> @@ -308,12 +308,16 @@ std::vector<double> parseSizes(const YamlObject &tuningData,\n>   \treturn sizes;\n>   }\n>   \n> +unsigned int quantize(unsigned int value, unsigned int step)\n> +{\n> +\treturn std::lround(value / static_cast<double>(step)) * step;\n> +}\n> +\n>   } /* namespace */\n>   \n>   LensShadingCorrection::LensShadingCorrection()\n>   \t: lastAppliedCt_(0), lastAppliedQuantizedCt_(0)\n>   {\n> -\tsets_.setQuantization(kColourTemperatureChangeThreshhold);\n>   }\n>   \n>   /**\n> @@ -426,17 +430,24 @@ void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,\n>   \t\t\t\t    RkISP1Params *params)\n>   {\n>   \tuint32_t ct = frameContext.awb.temperatureK;\n> -\tif (std::abs(static_cast<int>(ct) - static_cast<int>(lastAppliedCt_)) <\n> -\t    kColourTemperatureChangeThreshhold)\n> +\tunsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization);\n> +\tint ctDiff = static_cast<int>(ct) - static_cast<int>(lastAppliedCt_);\n> +\n> +\t/*\n> +\t * Add a threshold so that oscillations around a quantization step don't\n> +\t * lead to constant changes.\n> +\t */\n> +\tif (std::abs(ctDiff) < kColourTemperatureQuantization / 2)\n\n   utils::abs_diff(ct, lastAppliedCt_)\n\ncould be used here.\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n>   \t\treturn;\n> -\tunsigned int quantizedCt;\n> -\tconst Components &set = sets_.getInterpolated(ct, &quantizedCt);\n> -\tif (lastAppliedQuantizedCt_ == quantizedCt)\n> +\n> +\tif (quantizedCt == lastAppliedQuantizedCt_)\n>   \t\treturn;\n>   \n>   \tauto config = params->block<BlockType::Lsc>();\n>   \tconfig.setEnabled(true);\n>   \tsetParameters(*config);\n> +\n> +\tconst Components &set = sets_.getInterpolated(quantizedCt);\n>   \tcopyTable(*config, set);\n>   \n>   \tlastAppliedCt_ = ct;\n>","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 13B78C3226\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Jan 2026 15:37:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 504C661FBC;\n\tWed, 14 Jan 2026 16:37:19 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 30A4E61F9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Jan 2026 16:37:18 +0100 (CET)","from [192.168.33.18] (185.221.143.114.nat.pool.zt.hu\n\t[185.221.143.114])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2BBD155C;\n\tWed, 14 Jan 2026 16:36:51 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"SLT5x3bC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768405011;\n\tbh=XDUQ0IK95fjW4szkUjLs4zuRbP7N8hrFXw8toRhvxgI=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=SLT5x3bCZHEWfEdFniKbffTu+yBGTekLZdd01lSPdjvWEb3syuCVqlgl6dp90VW/8\n\t4sAX8BaZf5sRoUg1GOZvAxgF2ykjfNSdgww43cZqCeLFbjS2JSxvE+UCwIckO/tJLQ\n\tzxDaOelkunDJ2J0CSvf4Qk2ho4Ymd7oGnHrRz9bo=","Message-ID":"<3c1f7f8f-3a0b-4f23-b2bc-a5b41797f7e8@ideasonboard.com>","Date":"Wed, 14 Jan 2026 16:37:14 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 09/15] ipa: rkisp1: lsc: Handle quantization locally","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>","References":"<20260114-sklug-lsc-resampling-v2-dev-v3-0-80cd24f4dd61@ideasonboard.com>\n\t<20260114-sklug-lsc-resampling-v2-dev-v3-9-80cd24f4dd61@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20260114-sklug-lsc-resampling-v2-dev-v3-9-80cd24f4dd61@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>"}}]