{"id":24884,"url":"https://patchwork.libcamera.org/api/patches/24884/?format=json","web_url":"https://patchwork.libcamera.org/patch/24884/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20251028211751.2761420-14-rui.wang@ideasonboard.com>","date":"2025-10-28T21:17:47","name":"[v1,14/17] ipa: rkisp1: algorithms: dpf: refactor DPF prepare flow","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"1c60b0dc5dff5fe6ba9a21e571111af2912de6e2","submitter":{"id":241,"url":"https://patchwork.libcamera.org/api/people/241/?format=json","name":"Rui Wang","email":"rui.wang@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24884/mbox/","series":[{"id":5542,"url":"https://patchwork.libcamera.org/api/series/5542/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5542","date":"2025-10-28T21:17:34","name":"[v1,01/17] ipa: rkisp1: algorithms: add Denoise base class shell","version":1,"mbox":"https://patchwork.libcamera.org/series/5542/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24884/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24884/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 CAE96BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Oct 2025 21:18:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7DAFC6089B;\n\tTue, 28 Oct 2025 22:18:57 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 999A760887\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Oct 2025 22:18:53 +0100 (CET)","from rui-Precision-7560.local (unknown [209.216.122.90])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 712861864;\n\tTue, 28 Oct 2025 22:17:04 +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=\"cdL9ZeCA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761686225;\n\tbh=1nrA08DwgiY3jQFsCGYM5LlwqCP9ZaNyZYYHOzYXTe4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=cdL9ZeCA3W3v4kTd132T1dE5gfRW8xKIwLAut7cJ7+5cYhzQIV82FBF4yasAGFM3O\n\toZ3zVQkFpBgS33Ib/QPwDC/mnhNkImz5TXeSZ08YogeZ09lMchr57nHlmATuy+ibih\n\tXEmiev+4J5jgfhLb+4XwztAcTC9eyqOfVN48MyaM=","From":"Rui Wang <rui.wang@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Rui Wang <rui.wang@ideasonboard.com>","Subject":"[PATCH v1 14/17] ipa: rkisp1: algorithms: dpf: refactor DPF prepare\n\tflow","Date":"Tue, 28 Oct 2025 17:17:47 -0400","Message-ID":"<20251028211751.2761420-14-rui.wang@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20251028211751.2761420-1-rui.wang@ideasonboard.com>","References":"<20251028211751.2761420-1-rui.wang@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","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":"Split prepare() into explicit auto and manual mode branches. The auto\npath selects ISO bands and disables processing at high light levels,\nwhile the manual path applies user overrides before programming hardware.\n\nKey changes:\n- prepare() now branches to prepareAutoMode or prepareManualMode\n- prepareAutoMode(): Handles ISO band selection, disables DPF at ISO≤100,\n  programs hardware with selected config\n- prepareManualMode(): Programs base config then applies manual overrides\n  via applyOverridesTo()\n- Both modes call logConfigIfChanged() for visibility\n- Added debug logging to queueRequest()\n\nThe refactor removes the old AWB/LSC gain mode logic, now relying on\ngain_mode from tuning configuration.\n\nSigned-off-by: Rui Wang <rui.wang@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/denoise.h |   6 ++\n src/ipa/rkisp1/algorithms/dpf.cpp   | 113 ++++++++++++++++++++--------\n src/ipa/rkisp1/algorithms/dpf.h     |   6 ++\n 3 files changed, 92 insertions(+), 33 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/algorithms/denoise.h b/src/ipa/rkisp1/algorithms/denoise.h\nindex c4b5b0af..e2bedc41 100644\n--- a/src/ipa/rkisp1/algorithms/denoise.h\n+++ b/src/ipa/rkisp1/algorithms/denoise.h\n@@ -54,6 +54,12 @@ protected:\n \n \tvirtual void restoreAutoConfig(IPAContext &context, IPAFrameContext &frameContext) = 0;\n \n+\tvirtual void prepareAutoMode(IPAContext &context, const uint32_t frame,\n+\t\t\t\t     IPAFrameContext &frameContext, RkISP1Params *params) = 0;\n+\n+\tvirtual void prepareManualMode(IPAContext &context, const uint32_t frame,\n+\t\t\t\t       IPAFrameContext &frameContext, RkISP1Params *params) = 0;\n+\n private:\n \tbool manualMode_ = false; /**< Current manual/auto mode state */\n \tbool devMode_ = false; /**< Developer mode state for advanced controls */\ndiff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp\nindex 75e083eb..c4597932 100644\n--- a/src/ipa/rkisp1/algorithms/dpf.cpp\n+++ b/src/ipa/rkisp1/algorithms/dpf.cpp\n@@ -542,6 +542,11 @@ void Dpf::queueRequest(IPAContext &context,\n \t\t\tframeContext.dpf.update = true;\n \t\t}\n \t}\n+\n+\tLOG(RkISP1Dpf, Debug) << \"queueRequest: denoise=\" << frameContext.dpf.denoise\n+\t\t\t      << \", update=\" << frameContext.dpf.update\n+\t\t\t      << (enableDpf_ ? \"\" : \" (DPF disabled)\")\n+\t\t\t      << (modeChanged ? \" (mode change)\" : \"\");\n }\n \n /**\n@@ -550,42 +555,84 @@ void Dpf::queueRequest(IPAContext &context,\n void Dpf::prepare(IPAContext &context, const uint32_t frame,\n \t\t  IPAFrameContext &frameContext, RkISP1Params *params)\n {\n+\t// check if master denoise toggle on\n+\tif (!frameContext.dpf.denoise) {\n+\t\tauto cfg = params->block<BlockType::Dpf>();\n+\t\tcfg.setEnabled(false);\n+\t\tauto str = params->block<BlockType::DpfStrength>();\n+\t\tstr.setEnabled(false);\n+\t\treturn;\n+\t}\n+\n+\tif (isManualMode())\n+\t\tprepareManualMode(context, frame, frameContext, params);\n+\telse\n+\t\tprepareAutoMode(context, frame, frameContext, params);\n+}\n+\n+void Dpf::prepareAutoMode(IPAContext &context, const uint32_t frame,\n+\t\t\t  IPAFrameContext &frameContext, RkISP1Params *params)\n+{\n+\tunsigned iso = computeIso(context, frameContext);\n+\tbool baseIsoSkip = iso <= 100;\n+\n+\t// Select different dpf config determined by iso Level\n+\tif (useIsoLevels_) {\n+\t\tint idx = DenoiseBaseAlgorithm::selectIsoBand(iso, isoLevels_);\n+\t\tif (idx >= 0 && idx != lastIsoIndex_) {\n+\t\t\tconfig_ = isoLevels_[idx].dpf;\n+\t\t\tstrengthConfig_ = isoLevels_[idx].strength;\n+\t\t\tframeContext.dpf.update = true;\n+\t\t\tlastIsoIndex_ = idx;\n+\t\t}\n+\t}\n+\t// Disable dpf denoise due to high light\n+\tif (baseIsoSkip) {\n+\t\tauto cfg = params->block<BlockType::Dpf>();\n+\t\tcfg.setEnabled(false);\n+\t\tauto str = params->block<BlockType::DpfStrength>();\n+\t\tstr.setEnabled(false);\n+\t\treturn;\n+\t}\n+\n \tif (!frameContext.dpf.update && frame > 0)\n \t\treturn;\n \n-\tauto config = params->block<BlockType::Dpf>();\n-\tconfig.setEnabled(frameContext.dpf.denoise);\n-\n-\tif (frameContext.dpf.denoise) {\n-\t\t*config = config_;\n-\n-\t\tconst auto &awb = context.configuration.awb;\n-\t\tconst auto &lsc = context.configuration.lsc;\n-\n-\t\tauto &mode = config->gain.mode;\n-\n-\t\t/*\n-\t\t * The DPF needs to take into account the total amount of\n-\t\t * digital gain, which comes from the AWB and LSC modules. The\n-\t\t * DPF hardware can be programmed with a digital gain value\n-\t\t * manually, but can also use the gains supplied by the AWB and\n-\t\t * LSC modules automatically when they are enabled. Use that\n-\t\t * mode of operation as it simplifies control of the DPF.\n-\t\t */\n-\t\tif (awb.enabled && lsc.enabled)\n-\t\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS;\n-\t\telse if (awb.enabled)\n-\t\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS;\n-\t\telse if (lsc.enabled)\n-\t\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS;\n-\t\telse\n-\t\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED;\n-\t}\n-\n-\tif (frame == 0) {\n-\t\tauto strengthConfig = params->block<BlockType::DpfStrength>();\n-\t\tstrengthConfig.setEnabled(true);\n-\t\t*strengthConfig = strengthConfig_;\n+\tauto cfgBlock = params->block<BlockType::Dpf>();\n+\tcfgBlock.setEnabled(true);\n+\t*cfgBlock = config_;\n+\n+\tcfgBlock->gain.mode = config_.gain.mode;\n+\n+\tif (frameContext.dpf.update) {\n+\t\tauto strBlock = params->block<BlockType::DpfStrength>();\n+\t\tstrBlock.setEnabled(true);\n+\t\t*strBlock = strengthConfig_;\n+\t\tlogConfigIfChanged(iso, lastIsoIndex_, false, frameContext);\n+\t}\n+}\n+\n+void Dpf::prepareManualMode(IPAContext &context, const uint32_t frame,\n+\t\t\t    IPAFrameContext &frameContext, RkISP1Params *params)\n+{\n+\tunsigned iso = computeIso(context, frameContext);\n+\n+\tif (!frameContext.dpf.update && frame > 0)\n+\t\treturn;\n+\n+\tauto cfgBlock = params->block<BlockType::Dpf>();\n+\tcfgBlock.setEnabled(true);\n+\t*cfgBlock = config_;\n+\n+\tcfgBlock->gain.mode = config_.gain.mode;\n+\n+\tif (frame == 0 || frameContext.dpf.update) {\n+\t\tauto strBlock = params->block<BlockType::DpfStrength>();\n+\t\tstrBlock.setEnabled(true);\n+\t\t*strBlock = strengthConfig_;\n+\t\tbool anyOverride = false;\n+\t\tapplyOverridesTo(*cfgBlock, *strBlock, anyOverride);\n+\t\tlogConfigIfChanged(iso, lastIsoIndex_, anyOverride, frameContext);\n \t}\n }\n \ndiff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h\nindex 8c34abcf..d84ba45f 100644\n--- a/src/ipa/rkisp1/algorithms/dpf.h\n+++ b/src/ipa/rkisp1/algorithms/dpf.h\n@@ -105,6 +105,12 @@ private:\n \tvoid applyOverridesTo(rkisp1_cif_isp_dpf_config &cfg, rkisp1_cif_isp_dpf_strength_config &str, bool &anyOverride);\n \n \tvoid logConfigIfChanged(unsigned iso, int isoIndex, bool anyOverride, const IPAFrameContext &frameContext);\n+\n+\tvoid prepareAutoMode(IPAContext &context, const uint32_t frame,\n+\t\t\t     IPAFrameContext &frameContext, RkISP1Params *params) override;\n+\n+\tvoid prepareManualMode(IPAContext &context, const uint32_t frame,\n+\t\t\t       IPAFrameContext &frameContext, RkISP1Params *params) override;\n };\n \n } /* namespace ipa::rkisp1::algorithms */\n","prefixes":["v1","14/17"]}