{"id":25175,"url":"https://patchwork.libcamera.org/api/1.1/patches/25175/?format=json","web_url":"https://patchwork.libcamera.org/patch/25175/","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":"<20251125000848.4103786-9-rui.wang@ideasonboard.com>","date":"2025-11-25T00:08:45","name":"[v1,08/11] ipa: rkisp1: algorithms: dpf: apply DPF overrides","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"34e251252732c5fb403ad94ef9e19e9cd436d9b0","submitter":{"id":241,"url":"https://patchwork.libcamera.org/api/1.1/people/241/?format=json","name":"Rui Wang","email":"rui.wang@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25175/mbox/","series":[{"id":5612,"url":"https://patchwork.libcamera.org/api/1.1/series/5612/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5612","date":"2025-11-25T00:08:37","name":"ipa: rkisp1: DPF refactor and tuning improvements","version":1,"mbox":"https://patchwork.libcamera.org/series/5612/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25175/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25175/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 373E9C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Nov 2025 00:09:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0C87B60AB5;\n\tTue, 25 Nov 2025 01:09:20 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D2C13608CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Nov 2025 01:09:16 +0100 (CET)","from rui-Precision-7560.local (unknown\n\t[IPv6:2607:fea8:935b:7220:cb34:a7b8:53d:5466])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 097E41785;\n\tTue, 25 Nov 2025 01:07:07 +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=\"gPIAQ+jE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764029228;\n\tbh=VJCQePz+9Lhqe9GTyMtTSklznvMT0HOuuL/2HWrfeb0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=gPIAQ+jEIytSkbJHJnmZBG7Q6mznviTKWWg7QjvCDvoyKq3gbDuWNSKYkzwacfEHe\n\t9peEkrCLB9cvy9KFbAtaFZwYNkO77hHE2umbEfnX3HoAWzQuZEi2SxiQQRQJk16Tu7\n\tHDmotj3EDnfNmdmhyO+bgN513/qu4+SqwOFhTgfQ=","From":"Rui Wang <rui.wang@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Rui Wang <rui.wang@ideasonboard.com>","Subject":"[PATCH v1 08/11] ipa: rkisp1: algorithms: dpf: apply DPF overrides","Date":"Mon, 24 Nov 2025 19:08:45 -0500","Message-ID":"<20251125000848.4103786-9-rui.wang@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20251125000848.4103786-1-rui.wang@ideasonboard.com>","References":"<20251125000848.4103786-1-rui.wang@ideasonboard.com>","MIME-Version":"1.0","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>"},"content":"Implement applyOverridesTo() to merge manual overrides into hardware state\nand add logConfigIfChanged() to make configuration updates visible in logs\nfor debugging.\n\napplyOverridesTo() applies all collected manual overrides to the DPF\nconfiguration in manual mode:\n- Channel strengths (R/G/B)\n- Spatial coefficients (green and RB)\n- RB filter size\n- NLL coefficients and scale mode\n\nlogConfigIfChanged() provides detailed logging of configuration changes,\nincluding all coefficients, strength values, gain band selection, and\ncontrol mode. Uses static state tracking to log only when changes occur.\n\nSigned-off-by: Rui Wang <rui.wang@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/dpf.cpp | 135 ++++++++++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/dpf.h   |   9 +-\n 2 files changed, 142 insertions(+), 2 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp\nindex 91bcd503..c88f5c69 100644\n--- a/src/ipa/rkisp1/algorithms/dpf.cpp\n+++ b/src/ipa/rkisp1/algorithms/dpf.cpp\n@@ -9,6 +9,7 @@\n \n #include <algorithm>\n #include <array>\n+#include <sstream>\n #include <string>\n #include <vector>\n \n@@ -555,6 +556,140 @@ bool Dpf::processModeChange(const ControlList &controls, [[maybe_unused]] uint32\n \treturn (currentMode != getRunningMode());\n }\n \n+void Dpf::applyOverridesTo(rkisp1_cif_isp_dpf_config &config,\n+\t\t\t   rkisp1_cif_isp_dpf_strength_config &strengthConfig,\n+\t\t\t   bool &anyOverride)\n+{\n+\tif (getRunningMode() != controls::rkisp1::DenoiseModeManual)\n+\t\treturn;\n+\t/* only apply overrides in manual mode */\n+\tif (overrides_.strength) {\n+\t\tstrengthConfig.r = overrides_.strength->r;\n+\t\tstrengthConfig.g = overrides_.strength->g;\n+\t\tstrengthConfig.b = overrides_.strength->b;\n+\t\tanyOverride = true;\n+\t}\n+\tif (overrides_.spatialGreen) {\n+\t\tstd::copy(overrides_.spatialGreen->coeffs.begin(), overrides_.spatialGreen->coeffs.end(),\n+\t\t\t  config.g_flt.spatial_coeff);\n+\t\tanyOverride = true;\n+\t}\n+\tif (overrides_.spatialRb) {\n+\t\tstd::copy(overrides_.spatialRb->coeffs.begin(), overrides_.spatialRb->coeffs.end(),\n+\t\t\t  config.rb_flt.spatial_coeff);\n+\t\tanyOverride = true;\n+\t\tconfig.rb_flt.fltsize = *overrides_.rbSize\n+\t\t\t\t\t\t? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9\n+\t\t\t\t\t\t: RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9;\n+\t\tanyOverride = true;\n+\t}\n+\tif (overrides_.nll) {\n+\t\tstd::copy(overrides_.nll->coeffs.begin(), overrides_.nll->coeffs.end(),\n+\t\t\t  config.nll.coeff);\n+\t\tconfig.nll.scale_mode = overrides_.nll->scaleMode\n+\t\t\t\t\t\t? RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC\n+\t\t\t\t\t\t: RKISP1_CIF_ISP_NLL_SCALE_LINEAR;\n+\t\tanyOverride = true;\n+\t}\n+\tif (!anyOverride)\n+\t\treturn;\n+\t/* Log applied overrides */\n+\tconfig_ = config;\n+\tstrengthConfig_ = strengthConfig;\n+\tLOG(RkISP1Dpf, Info)\n+\t\t<< \"DPF manual overrides applied: strength=\"\n+\t\t<< (int)strengthConfig_.r << \",\"\n+\t\t<< (int)strengthConfig_.g << \",\"\n+\t\t<< (int)strengthConfig_.b\n+\t\t<< (overrides_.spatialGreen ? \" gKernel\" : \"\")\n+\t\t<< (overrides_.spatialRb ? \" rbKernel\" : \"\")\n+\t\t<< (overrides_.rbSize ? \" rbSize\" : \"\")\n+\t\t<< (overrides_.nll ? \" nll\" : \"\");\n+}\n+\n+void Dpf::logConfigIfChanged(uint32_t exposureGainIndex,\n+\t\t\t     int32_t exposureBandIndex,\n+\t\t\t     bool anyOverride,\n+\t\t\t     const IPAFrameContext &frameContext)\n+{\n+\tstatic rkisp1_cif_isp_dpf_config lastCfg{};\n+\tstatic rkisp1_cif_isp_dpf_strength_config lastStr{};\n+\tstatic bool haveLast = false;\n+\n+\t/* Check if the DPF configuration or strength settings have changed since the last log */\n+\t/* Use memcmp for byte-wise comparison of the C structs (no operator== defined) */\n+\tbool cfgChanged = !haveLast || memcmp(&lastCfg, &config_, sizeof(config_)) != 0;\n+\tbool strChanged = !haveLast || memcmp(&lastStr, &strengthConfig_, sizeof(strengthConfig_)) != 0;\n+\n+\tif (!cfgChanged && !strChanged)\n+\t\treturn;\n+\n+\tstd::string gCoeffsStr = \"[\";\n+\tfor (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) {\n+\t\tif (i > 0)\n+\t\t\tgCoeffsStr += \",\";\n+\t\tgCoeffsStr += std::to_string(static_cast<int>(config_.g_flt.spatial_coeff[i]));\n+\t}\n+\tgCoeffsStr += \"]\";\n+\n+\tstd::string rbCoeffsStr = \"[\";\n+\tfor (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) {\n+\t\tif (i > 0)\n+\t\t\trbCoeffsStr += \",\";\n+\t\trbCoeffsStr += std::to_string(static_cast<int>(config_.rb_flt.spatial_coeff[i]));\n+\t}\n+\trbCoeffsStr += \"]\";\n+\n+\tstd::string nllCoeffsStr = \"[\";\n+\tfor (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS; ++i) {\n+\t\tif (i > 0)\n+\t\t\tnllCoeffsStr += \",\";\n+\t\tnllCoeffsStr += std::to_string(config_.nll.coeff[i]);\n+\t}\n+\tnllCoeffsStr += \"]\";\n+\n+\tstd::string rbFilterSizeStr =\n+\t\tconfig_.rb_flt.fltsize == RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9\n+\t\t\t? \"13x9\"\n+\t\t\t: \"9x9\";\n+\tstd::string nllScaleStr =\n+\t\tconfig_.nll.scale_mode == RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC\n+\t\t\t? \"log\"\n+\t\t\t: \"linear\";\n+\tstd::string denoiseStr = (frameContext.dpf.denoise ? \"enabled\" : \"disabled\");\n+\tstd::string overrideStr = (anyOverride ? \" (overrides applied)\" : \"\");\n+\n+\tstd::string exposureIndexBandStr;\n+\tif (useExposureIndexLevels_ && exposureBandIndex >= 0) {\n+\t\texposureIndexBandStr =\n+\t\t\t\", exposureIndex_band=\" + std::to_string(exposureBandIndex);\n+\t\tif (lastExposureGainIndex_ != exposureBandIndex) {\n+\t\t\texposureIndexBandStr += \"(new)\";\n+\t\t}\n+\t}\n+\n+\tLOG(RkISP1Dpf, Info)\n+\t\t<< \"DPF config update: rb_fltsize=\" << rbFilterSizeStr\n+\t\t<< \", nll_scale=\" << nllScaleStr\n+\t\t<< \", gain_mode=\" << config_.gain.mode\n+\t\t<< \", strength=\" << (int)strengthConfig_.r << \",\"\n+\t\t<< (int)strengthConfig_.g << \",\"\n+\t\t<< (int)strengthConfig_.b\n+\t\t<< \", g=\" << gCoeffsStr\n+\t\t<< \", rb=\" << rbCoeffsStr\n+\t\t<< \", nll=\" << nllCoeffsStr\n+\t\t<< \", exposureIndex=\" << exposureGainIndex\n+\t\t<< exposureIndexBandStr\n+\t\t<< \", control mode=\" << static_cast<int>(getRunningMode())\n+\t\t<< \", reduction mode=\" << static_cast<int>(currentReductionMode_)\n+\t\t<< \", denoise=\" << denoiseStr\n+\t\t<< overrideStr;\n+\n+\tlastCfg = config_;\n+\tlastStr = strengthConfig_;\n+\thaveLast = true;\n+}\n+\n /**\n  * \\copydoc libcamera::ipa::Algorithm::queueRequest\n  */\ndiff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h\nindex c63d1558..abcdf8ee 100644\n--- a/src/ipa/rkisp1/algorithms/dpf.h\n+++ b/src/ipa/rkisp1/algorithms/dpf.h\n@@ -88,10 +88,15 @@ private:\n \t\t\t       rkisp1_cif_isp_dpf_strength_config &strengthConfig);\n \n \tbool processModeChange(const ControlList &controls, uint32_t currentFrame) override;\n-\n \tvoid snapshotCurrentToOverrides() override;\n-\n \tvoid restoreAutoConfig(IPAContext &context, IPAFrameContext &frameContext) override;\n+\tvoid applyOverridesTo(rkisp1_cif_isp_dpf_config &config,\n+\t\t\t      rkisp1_cif_isp_dpf_strength_config &strengthConfig,\n+\t\t\t      bool &anyOverride);\n+\tvoid logConfigIfChanged(uint32_t exposureGainIndex,\n+\t\t\t\tint32_t exposureBandIndex,\n+\t\t\t\tbool anyOverride,\n+\t\t\t\tconst IPAFrameContext &frameContext);\n };\n \n } /* namespace ipa::rkisp1::algorithms */\n","prefixes":["v1","08/11"]}