Patch Detail
Show a patch.
GET /api/patches/25368/?format=api
{ "id": 25368, "url": "https://patchwork.libcamera.org/api/patches/25368/?format=api", "web_url": "https://patchwork.libcamera.org/patch/25368/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20251204213744.1110922-2-rui.wang@ideasonboard.com>", "date": "2025-12-04T21:37:43", "name": "[v3,1/2] ipa/rkisp1: refactory DPF parsing and initialization", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "e71f28f8952b17651d3346af2e791c952acf67ff", "submitter": { "id": 241, "url": "https://patchwork.libcamera.org/api/people/241/?format=api", "name": "Rui Wang", "email": "rui.wang@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/25368/mbox/", "series": [ { "id": 5639, "url": "https://patchwork.libcamera.org/api/series/5639/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5639", "date": "2025-12-04T21:37:42", "name": "rebase_dpf_refactory_patch_v3", "version": 3, "mbox": "https://patchwork.libcamera.org/series/5639/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/25368/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/25368/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 B8618BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 4 Dec 2025 21:38:16 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6B01461160;\n\tThu, 4 Dec 2025 22:38:16 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D5FB61145\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 4 Dec 2025 22:38:15 +0100 (CET)", "from localhost.localdomain (unknown [209.216.103.65])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 25428EB7;\n\tThu, 4 Dec 2025 22:35:59 +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=\"S2pw6EpB\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764884159;\n\tbh=quwt/48HxC7Htnr5cBdEcfIhMofqWnP5niiLki4iZGk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=S2pw6EpBMc6Tijhp7x58X5yyN4t91Usj4E1rcnZwmG/fBECF8BD0FN3NpVUoza48c\n\tZLSYwrqMnOP1rfGvW0jc5NgTCfSubYmGVMtSmFTpX+57/yhpn0uLnLN80oT2mvFHUF\n\tauHSwcPC5KpmuJ+wAGkxrVoMO+Re03rI0Cl+N93U=", "From": "Rui Wang <rui.wang@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Rui Wang <rui.wang@ideasonboard.com>", "Subject": "[PATCH v3 1/2] ipa/rkisp1: refactory DPF parsing and initialization", "Date": "Thu, 4 Dec 2025 16:37:43 -0500", "Message-ID": "<20251204213744.1110922-2-rui.wang@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20251204213744.1110922-1-rui.wang@ideasonboard.com>", "References": "<20251204213744.1110922-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": "Split DPF configuration parsing and initialization into clearer,\nself-contained helpers and modernized initialization patterns.\n\nAdd parseConfig, parseModes and loadReductionConfig to factor\nparsing logic and mode lookups.\nIntroduce ModeConfig and store mode entries in\nnoiseReductionModes_ to decouple parsing from runtime selection.\nMove sentinel member initializers into the constructor initializer\nlist (runningMode_) and declare vectors\nwithout in-class initializers for default construction.\nReplace ad-hoc string handling with value_or and const auto\nwhere appropriate for clearer and safer parsing.\nReplace domain/range/strength YAML keys mapping and error returns\n(use filter, nll, strength keys and return false from parse\nhelpers instead of -EINVAL).\nAdd loadReductionConfig to centralize loading of DPF configs for\nreduction modes and preserve logging and failure behavior.\nAdjust queueRequest, prepare, and helpers to use the new\nparsing/initialization flow while preserving existing behavior.\nThis refactor improves separation of concerns, makes parsing easier\nto maintain, and reduces duplicated logic. No functional behaviour is\nintended to be changed.\n\nSigned-off-by: Rui Wang <rui.wang@ideasonboard.com>\n\n---\nchangelog :\n 1. fix config issue and some format\n---\n Makefile | 125 +++++++++++\n src/ipa/rkisp1/algorithms/dpf.cpp | 359 +++++++++++++++++++++++-------\n src/ipa/rkisp1/algorithms/dpf.h | 22 ++\n 3 files changed, 420 insertions(+), 86 deletions(-)\n create mode 100644 Makefile", "diff": "diff --git a/Makefile b/Makefile\nnew file mode 100644\nindex 00000000..07f8f0fb\n--- /dev/null\n+++ b/Makefile\n@@ -0,0 +1,125 @@\n+# Support execution in a docker environment\n+\n+define run-in-docker\n+\t# CONTAINER=$1\n+\t# COMMAND=$2\n+\t# OPTIONS=$3\n+\tdocker run \\\n+\t\t-v \"${PWD}\":\"${PWD}\" \\\n+\t\t-w \"${PWD}\" \\\n+\t\t${3} \\\n+\t\t--rm -i ${1} ${2}\n+\n+\t\t#--privileged=true \\\n+\t\t#--cap-add=SYS_PTRACE \\\n+\t\t#--security-opt seccomp=unconfined \\\n+\t\t#-v \"${HOME}\":\"${HOME}\" \\\n+\t\t#-v /var/run/docker.sock:/var/run/docker.sock \\\n+\n+endef\n+\n+define git-uk-bookworm-arm64-cross\n+\t$(call run-in-docker,git.uk.ideasonboard.com/camera/containers:debian-bookworm-cross-arm64,$1,$2)\n+endef\n+\n+define bookworm-arm64\n+\t$(call run-in-docker,debian-bookworm-cross-arm64,$1,$2)\n+endef\n+\n+# Helper function to run clang-tidy with proper setup\n+# $1 = git command to list files\n+# $2 = output log file\n+define run-tidy\n+\t@echo \"Running clang-tidy and saving to $(2)...\"\n+\t@$(1) > /tmp/tidy-files.txt\n+\t@if [ -s /tmp/tidy-files.txt ]; then \\\n+\t\techo \"Checking files:\"; cat /tmp/tidy-files.txt; \\\n+\t\tcat /tmp/tidy-files.txt | docker run -v \"${PWD}\":\"${PWD}\" -w \"${PWD}\" --rm -i debian-bookworm-cross-arm64 sh -c \"mkdir -p $(RESULTS_DIR) && chmod 777 $(RESULTS_DIR) && xargs -r -I{} clang-tidy {} -p $(BUILD) || true\" > $(2) 2>&1 || touch $(2); \\\n+\t\techo \"Done. Output saved to $(2)\"; \\\n+\t\tpython3 utils/log_to_html.py $(2) $(basename $(2)).html || true; \\\n+\telse \\\n+\t\techo \"No files to check\"; \\\n+\t\ttouch $(2); \\\n+\tfi\n+\t@rm -f /tmp/tidy-files.txt\n+endef\n+\n+BUILD=build/bookworm-arm64\n+RESULTS_DIR=$(BUILD)/clang-tidy-results\n+\n+libcamera: $(BUILD)/build.ninja\n+\t$(call bookworm-arm64,ninja -C $(BUILD))\n+\n+# /usr/share/meson/arm64-cross is provided by the debian-bookworm-cross-arm64 container\n+configure $(BUILD)/build.ninja:\n+\t$(call bookworm-arm64,meson setup $(BUILD) \\\n+\t\t$(RECONFIGURE) \\\n+\t\t--cross-file /usr/share/meson/arm64-cross \\\n+\t\t-Dprefix=/usr \\\n+\t\t-Dpycamera=enabled \\\n+\t\t-Ddocumentation=disabled \\\n+\t\t-Dlibdir=/lib/aarch64-linux-gnu \\\n+\t\t)\n+\n+reconfigure: RECONFIGURE=--reconfigure\n+reconfigure: configure\n+\n+PYTHON_DIST=usr/lib/python3.11/dist-packages\n+PACKAGE_TGZ=libcamera-aarch64.tgz\n+.PHONY: package\n+package:\n+\t$(call bookworm-arm64,rm -rf $(BUILD)/install)\n+\t$(call bookworm-arm64,mkdir -p $(BUILD)/install)\n+\t$(call bookworm-arm64,ninja -C $(BUILD) install,--env DESTDIR=install)\n+\t$(call bookworm-arm64,mkdir -p $(BUILD)/install/$(PYTHON_DIST))\n+# \t$(call bookworm-arm64,mv \\\n+# \t\t$(BUILD)/install/usr/lib/python3/dist-packages/libcamera \\\n+# \t\t$(BUILD)/install/$(PYTHON_DIST))\n+\ttar -C $(BUILD)/install -czf $(PACKAGE_TGZ) ./\n+\n+.PHONY: tmp_install\n+tmp_install:\n+\t$(call bookworm-arm64,rm -rf $(BUILD)/install)\n+\t$(call bookworm-arm64,mkdir -p $(BUILD)/install)\n+\t$(call bookworm-arm64,ninja -C $(BUILD) install,--env DESTDIR=install)\n+\t$(call bookworm-arm64,mkdir -p $(BUILD)/install/$(PYTHON_DIST))\n+\t$(call bookworm-arm64,mv \\\n+\t\t$(BUILD)/install/usr/lib/python3/dist-packages/libcamera \\\n+\t\t$(BUILD)/install/$(PYTHON_DIST))\n+\n+# Directly install on a target\n+kastor kakip debix-som debix-model-A: libcamera tmp_install\n+\trsync --keep-dirlinks -rav --progress build/bookworm-arm64/install/ rui@192.168.31.73:~/libcamera-install/\n+\n+\n+beehive: package\n+\tscp $(PACKAGE_TGZ) rui@192.168.31.73:~/python3-disp/\n+\tssh $@ -tC \"cd / && sudo tar --keep-directory-symlink --no-same-owner -vxhf ~/python3-disp/$(PACKAGE_TGZ)\"\n+rui: package\n+\tscp $(PACKAGE_TGZ) rui@192.168.31.73:/tmp/\n+\tssh rui@192.168.31.73 -tC \"cd / && sudo tar --keep-directory-symlink --no-same-owner -vxhf /tmp/$(PACKAGE_TGZ)\"\n+\n+.PHONY: tidy-diff\n+tidy-diff:\n+\t$(call run-tidy,git diff --name-only -- '*.c' '*.cpp' '*.cc' '*.h',$(RESULTS_DIR)/tidy-diff.log)\n+\n+.PHONY: tidy\n+tidy:\n+\t$(call run-tidy,git ls-files -- '*.c' '*.cpp' '*.cc' '*.h',$(RESULTS_DIR)/tidy.log)\n+\n+.PHONY: tidy-last-commit\n+tidy-last-commit:\n+\t$(call run-tidy,git diff --name-only HEAD~1 HEAD -- '*.c' '*.cpp' '*.cc' '*.h',$(RESULTS_DIR)/tidy-last-commit.log)\n+\n+.PHONY: tidy-branch\n+tidy-branch:\n+\t$(call run-tidy,git diff --name-only master...HEAD -- '*.c' '*.cpp' '*.cc' '*.h',$(RESULTS_DIR)/tidy-branch.log)\n+\n+.PHONY: tidy-staged\n+tidy-staged:\n+\t$(call run-tidy,git diff --name-only --cached -- '*.c' '*.cpp' '*.cc' '*.h',$(RESULTS_DIR)/tidy-staged.log)\n+\n+.PHONY: build-and-check-branch\n+build-and-check-branch:\n+\tgit diff master...HEAD\n+\ndiff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp\nindex 39f3e461..7e2da7b1 100644\n--- a/src/ipa/rkisp1/algorithms/dpf.cpp\n+++ b/src/ipa/rkisp1/algorithms/dpf.cpp\n@@ -37,7 +37,8 @@ namespace ipa::rkisp1::algorithms {\n LOG_DEFINE_CATEGORY(RkISP1Dpf)\n \n Dpf::Dpf()\n-\t: config_({}), strengthConfig_({})\n+\t: config_({}), strengthConfig_({}),\n+\t runningMode_(controls::draft::NoiseReductionModeOff)\n {\n }\n \n@@ -46,6 +47,69 @@ Dpf::Dpf()\n */\n int Dpf::init([[maybe_unused]] IPAContext &context,\n \t const YamlObject &tuningData)\n+{\n+\t/* Parse tuning block. */\n+\tif (!parseConfig(tuningData)) {\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+bool Dpf::parseConfig(const YamlObject &tuningData)\n+{\n+\t/* Parse base config. */\n+\tif (!parseSingleConfig(tuningData, config_, strengthConfig_)) {\n+\t\treturn false;\n+\t}\n+\tif (!parseModes(tuningData)) {\n+\t\treturn false;\n+\t}\n+\treturn true;\n+}\n+\n+bool Dpf::parseModes(const YamlObject &tuningData)\n+{\n+\t/* Parse noise reduction modes. */\n+\tif (!tuningData.contains(\"modes\")) {\n+\t\treturn true;\n+\t}\n+\n+\tnoiseReductionModes_.clear();\n+\tfor (const auto &entry : tuningData[\"modes\"].asList()) {\n+\t\tstd::optional<std::string> typeOpt =\n+\t\t\tentry[\"type\"].get<std::string>();\n+\t\tif (!typeOpt) {\n+\t\t\tLOG(RkISP1Dpf, Error) << \"Modes entry missing type\";\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tint32_t modeValue = controls::draft::NoiseReductionModeOff;\n+\t\tif (*typeOpt == \"minimal\") {\n+\t\t\tmodeValue = controls::draft::NoiseReductionModeMinimal;\n+\t\t} else if (*typeOpt == \"fast\") {\n+\t\t\tmodeValue = controls::draft::NoiseReductionModeFast;\n+\t\t} else if (*typeOpt == \"highquality\") {\n+\t\t\tmodeValue = controls::draft::NoiseReductionModeHighQuality;\n+\t\t} else if (*typeOpt == \"zsl\") {\n+\t\t\tmodeValue = controls::draft::NoiseReductionModeZSL;\n+\t\t} else {\n+\t\t\tLOG(RkISP1Dpf, Error) << \"Unknown mode type: \" << *typeOpt;\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tModeConfig mode{};\n+\t\tmode.modeValue = modeValue;\n+\t\tif (!parseSingleConfig(entry, mode.dpf, mode.strength)) {\n+\t\t\treturn false;\n+\t\t}\n+\t\tnoiseReductionModes_.push_back(mode);\n+\t}\n+\n+\treturn true;\n+}\n+bool Dpf::parseSingleConfig(const YamlObject &tuningData,\n+\t\t\t rkisp1_cif_isp_dpf_config &config,\n+\t\t\t rkisp1_cif_isp_dpf_strength_config &strengthConfig)\n {\n \tstd::vector<uint8_t> values;\n \n@@ -53,7 +117,11 @@ int Dpf::init([[maybe_unused]] IPAContext &context,\n \t * The domain kernel is configured with a 9x9 kernel for the green\n \t * pixels, and a 13x9 or 9x9 kernel for red and blue pixels.\n \t */\n-\tconst YamlObject &dFObject = tuningData[\"DomainFilter\"];\n+\tconst YamlObject &dFObject = tuningData[\"filter\"];\n+\tif (!dFObject) {\n+\t\tLOG(RkISP1Dpf, Error) << \"filter section missing\";\n+\t\treturn false;\n+\t}\n \n \t/*\n \t * For the green component, we have the 9x9 kernel specified\n@@ -75,17 +143,17 @@ int Dpf::init([[maybe_unused]] IPAContext &context,\n \tvalues = dFObject[\"g\"].getList<uint8_t>().value_or(std::vector<uint8_t>{});\n \tif (values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS) {\n \t\tLOG(RkISP1Dpf, Error)\n-\t\t\t<< \"Invalid 'DomainFilter:g': expected \"\n+\t\t\t<< \"Invalid 'filter:g': expected \"\n \t\t\t<< RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n \t\t\t<< \" elements, got \" << values.size();\n-\t\treturn -EINVAL;\n+\t\treturn false;\n \t}\n \n \tstd::copy_n(values.begin(), values.size(),\n-\t\t std::begin(config_.g_flt.spatial_coeff));\n+\t\t std::begin(config.g_flt.spatial_coeff));\n \n-\tconfig_.g_flt.gr_enable = true;\n-\tconfig_.g_flt.gb_enable = true;\n+\tconfig.g_flt.gr_enable = true;\n+\tconfig.g_flt.gb_enable = true;\n \n \t/*\n \t * For the red and blue components, we have the 13x9 kernel specified\n@@ -112,65 +180,155 @@ int Dpf::init([[maybe_unused]] IPAContext &context,\n \tif (values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS &&\n \t values.size() != RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS - 1) {\n \t\tLOG(RkISP1Dpf, Error)\n-\t\t\t<< \"Invalid 'DomainFilter:rb': expected \"\n+\t\t\t<< \"Invalid 'filter:rb': expected \"\n \t\t\t<< RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS - 1\n \t\t\t<< \" or \" << RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n \t\t\t<< \" elements, got \" << values.size();\n-\t\treturn -EINVAL;\n+\t\treturn false;\n \t}\n \n-\tconfig_.rb_flt.fltsize = values.size() == RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n-\t\t\t ? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9\n-\t\t\t : RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9;\n+\tconfig.rb_flt.fltsize = values.size() == RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS\n+\t\t\t\t\t? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9\n+\t\t\t\t\t: RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9;\n \n \tstd::copy_n(values.begin(), values.size(),\n-\t\t std::begin(config_.rb_flt.spatial_coeff));\n+\t\t std::begin(config.rb_flt.spatial_coeff));\n \n-\tconfig_.rb_flt.r_enable = true;\n-\tconfig_.rb_flt.b_enable = true;\n+\tconfig.rb_flt.r_enable = true;\n+\tconfig.rb_flt.b_enable = true;\n \n \t/*\n \t * The range kernel is configured with a noise level lookup table (NLL)\n \t * which stores a piecewise linear function that characterizes the\n \t * sensor noise profile as a noise level function curve (NLF).\n \t */\n-\tconst YamlObject &rFObject = tuningData[\"NoiseLevelFunction\"];\n+\tconst YamlObject &rFObject = tuningData[\"nll\"];\n+\tif (!rFObject) {\n+\t\tLOG(RkISP1Dpf, Error) << \"nll section missing\";\n+\t\treturn false;\n+\t}\n \n-\tstd::vector<uint16_t> nllValues;\n-\tnllValues = rFObject[\"coeff\"].getList<uint16_t>().value_or(std::vector<uint16_t>{});\n+\tconst auto nllValues =\n+\t\trFObject[\"coeff\"].getList<uint16_t>().value_or(std::vector<uint16_t>{});\n \tif (nllValues.size() != RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS) {\n \t\tLOG(RkISP1Dpf, Error)\n-\t\t\t<< \"Invalid 'RangeFilter:coeff': expected \"\n+\t\t\t<< \"Invalid 'nll:coeff': expected \"\n \t\t\t<< RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS\n \t\t\t<< \" elements, got \" << nllValues.size();\n-\t\treturn -EINVAL;\n+\t\treturn false;\n \t}\n \n \tstd::copy_n(nllValues.begin(), nllValues.size(),\n-\t\t std::begin(config_.nll.coeff));\n+\t\t std::begin(config.nll.coeff));\n \n-\tstd::string scaleMode = rFObject[\"scale-mode\"].get<std::string>(\"\");\n+\tconst auto scaleMode = rFObject[\"scale-mode\"].get<std::string>(\"\");\n \tif (scaleMode == \"linear\") {\n-\t\tconfig_.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LINEAR;\n+\t\tconfig.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LINEAR;\n \t} else if (scaleMode == \"logarithmic\") {\n-\t\tconfig_.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC;\n+\t\tconfig.nll.scale_mode = RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC;\n \t} else {\n \t\tLOG(RkISP1Dpf, Error)\n-\t\t\t<< \"Invalid 'RangeFilter:scale-mode': expected \"\n+\t\t\t<< \"Invalid 'nll:scale-mode': expected \"\n \t\t\t<< \"'linear' or 'logarithmic' value, got \"\n \t\t\t<< scaleMode;\n-\t\treturn -EINVAL;\n+\t\treturn false;\n \t}\n \n-\tconst YamlObject &fSObject = tuningData[\"FilterStrength\"];\n+\tconst YamlObject &gObject = tuningData[\"gain\"];\n+\tif (!gObject) {\n+\t\tLOG(RkISP1Dpf, Error) << \"gain section missing\";\n+\t\treturn false;\n+\t}\n \n-\tstrengthConfig_.r = fSObject[\"r\"].get<uint16_t>(64);\n-\tstrengthConfig_.g = fSObject[\"g\"].get<uint16_t>(64);\n-\tstrengthConfig_.b = fSObject[\"b\"].get<uint16_t>(64);\n+\tconfig.gain.mode =\n+\t\tgObject[\"gain_mode\"].get<uint32_t>().value_or(\n+\t\t\tRKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS);\n+\tconfig.gain.nf_r_gain = gObject[\"r\"].get<uint16_t>().value_or(256);\n+\tconfig.gain.nf_b_gain = gObject[\"b\"].get<uint16_t>().value_or(256);\n+\tconfig.gain.nf_gr_gain = gObject[\"gr\"].get<uint16_t>().value_or(256);\n+\tconfig.gain.nf_gb_gain = gObject[\"gb\"].get<uint16_t>().value_or(256);\n+\n+\tconst YamlObject &fSObject = tuningData[\"strength\"];\n+\tif (!fSObject) {\n+\t\tLOG(RkISP1Dpf, Error) << \"strength section missing\";\n+\t\treturn false;\n+\t}\n \n-\treturn 0;\n+\tstrengthConfig.r = fSObject[\"r\"].get<uint8_t>().value_or(64);\n+\tstrengthConfig.g = fSObject[\"g\"].get<uint8_t>().value_or(64);\n+\tstrengthConfig.b = fSObject[\"b\"].get<uint8_t>().value_or(64);\n+\treturn true;\n+}\n+\n+bool Dpf::loadReductionConfig(int32_t mode)\n+{\n+\tauto it = std::find_if(noiseReductionModes_.begin(), noiseReductionModes_.end(),\n+\t\t\t [mode](const ModeConfig &m) {\n+\t\t\t\t return m.modeValue == mode;\n+\t\t\t });\n+\tif (it == noiseReductionModes_.end()) {\n+\t\tLOG(RkISP1Dpf, Warning)\n+\t\t\t<< \"No DPF config for reduction mode \"\n+\t\t\t<< static_cast<int>(mode);\n+\t\treturn false;\n+\t}\n+\n+\tconfig_ = it->dpf;\n+\tstrengthConfig_ = it->strength;\n+\n+\tLOG(RkISP1Dpf, Info)\n+\t\t<< \"DPF mode=Reduction (config loaded)\"\n+\t\t<< \" mode=\" << static_cast<int>(mode);\n+\n+\treturn true;\n }\n+void Dpf::logConfigIfChanged(const IPAFrameContext &frameContext)\n+{\n+\tif (!frameContext.dpf.update) {\n+\t\treturn;\n+\t}\n+\n+\tstd::ostringstream ss;\n+\n+\tss << \"DPF config update: \";\n+\tss << \", control mode=\" << static_cast<int>(runningMode_);\n+\tss << \", denoise=\" << (frameContext.dpf.denoise ? \"enabled\" : \"disabled, \");\n+\n+\tss << \"rb_fltsize=\"\n+\t << (config_.rb_flt.fltsize == RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 ? \"13x9\" : \"9x9\");\n+\tss << \", nll_scale=\"\n+\t << (config_.nll.scale_mode == RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC ? \"log\" : \"linear\");\n+\tss << \", gain_mode=\" << config_.gain.mode;\n+\tss << \", strength=\" << int(strengthConfig_.r) << ',' << int(strengthConfig_.g) << ',' << int(strengthConfig_.b);\n+\n+\tss << \", g=[\";\n+\tfor (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) {\n+\t\tif (i) {\n+\t\t\tss << ',';\n+\t\t}\n+\t\tss << int(config_.g_flt.spatial_coeff[i]);\n+\t}\n+\tss << \"]\";\n \n+\tss << \", rb=[\";\n+\tfor (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) {\n+\t\tif (i) {\n+\t\t\tss << ',';\n+\t\t}\n+\t\tss << int(config_.rb_flt.spatial_coeff[i]);\n+\t}\n+\tss << \"]\";\n+\n+\tss << \", nll=[\";\n+\tfor (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS; ++i) {\n+\t\tif (i) {\n+\t\t\tss << ',';\n+\t\t}\n+\t\tss << int(config_.nll.coeff[i]);\n+\t}\n+\tss << \"]\";\n+\tLOG(RkISP1Dpf, Info) << ss.str();\n+}\n /**\n * \\copydoc libcamera::ipa::Algorithm::queueRequest\n */\n@@ -183,30 +341,34 @@ void Dpf::queueRequest(IPAContext &context,\n \tbool update = false;\n \n \tconst auto &denoise = controls.get(controls::draft::NoiseReductionMode);\n-\tif (denoise) {\n-\t\tLOG(RkISP1Dpf, Debug) << \"Set denoise to \" << *denoise;\n-\n-\t\tswitch (*denoise) {\n-\t\tcase controls::draft::NoiseReductionModeOff:\n-\t\t\tif (dpf.denoise) {\n-\t\t\t\tdpf.denoise = false;\n-\t\t\t\tupdate = true;\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tcase controls::draft::NoiseReductionModeMinimal:\n-\t\tcase controls::draft::NoiseReductionModeHighQuality:\n-\t\tcase controls::draft::NoiseReductionModeFast:\n-\t\t\tif (!dpf.denoise) {\n-\t\t\t\tdpf.denoise = true;\n-\t\t\t\tupdate = true;\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\tLOG(RkISP1Dpf, Error)\n-\t\t\t\t<< \"Unsupported denoise value \"\n-\t\t\t\t<< *denoise;\n-\t\t\tbreak;\n+\tif (!denoise) {\n+\t\treturn;\n+\t}\n+\trunningMode_ = *denoise;\n+\tswitch (runningMode_) {\n+\tcase controls::draft::NoiseReductionModeOff:\n+\t\tif (dpf.denoise) {\n+\t\t\tdpf.denoise = false;\n+\t\t\tupdate = true;\n+\t\t}\n+\t\tbreak;\n+\tcase controls::draft::NoiseReductionModeMinimal:\n+\tcase controls::draft::NoiseReductionModeHighQuality:\n+\tcase controls::draft::NoiseReductionModeFast:\n+\tcase controls::draft::NoiseReductionModeZSL:\n+\t\tif (loadReductionConfig(runningMode_)) {\n+\t\t\tupdate = true;\n+\t\t\tdpf.denoise = true;\n+\t\t} else {\n+\t\t\tdpf.denoise = false;\n+\t\t\tupdate = true;\n \t\t}\n+\t\tbreak;\n+\tdefault:\n+\t\tLOG(RkISP1Dpf, Error)\n+\t\t\t<< \"Unsupported denoise value \"\n+\t\t\t<< *denoise;\n+\t\tbreak;\n \t}\n \n \tframeContext.dpf.denoise = dpf.denoise;\n@@ -219,41 +381,66 @@ void Dpf::queueRequest(IPAContext &context,\n void Dpf::prepare(IPAContext &context, const uint32_t frame,\n \t\t IPAFrameContext &frameContext, RkISP1Params *params)\n {\n-\tif (!frameContext.dpf.update && frame > 0)\n+\tif (!frameContext.dpf.update && frame > 0) {\n \t\treturn;\n+\t}\n+\n+\tif (!frameContext.dpf.denoise) {\n+\t\tprepareDisabledMode(context, frame, frameContext, params);\n+\t\treturn;\n+\t}\n+\n+\tprepareEnabledMode(context, frame, frameContext, params);\n+}\n+\n+void Dpf::prepareDisabledMode([[maybe_unused]] IPAContext &context,\n+\t\t\t [[maybe_unused]] const uint32_t frame,\n+\t\t\t [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t RkISP1Params *params)\n+{\n+\tframeContext.dpf.denoise = false;\n+\tauto dpfConfig = params->block<BlockType::Dpf>();\n+\tdpfConfig.setEnabled(false);\n+\tauto dpfStrength = params->block<BlockType::DpfStrength>();\n+\tdpfStrength.setEnabled(false);\n+}\n+\n+void Dpf::prepareEnabledMode(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n+\t\t\t [[maybe_unused]] IPAFrameContext &frameContext, RkISP1Params *params)\n+{\n+\tauto dpfConfig = params->block<BlockType::Dpf>();\n+\tdpfConfig.setEnabled(true);\n+\t*dpfConfig = config_;\n \n-\tauto config = params->block<BlockType::Dpf>();\n-\tconfig.setEnabled(frameContext.dpf.denoise);\n-\n-\tauto strengthConfig = params->block<BlockType::DpfStrength>();\n-\tstrengthConfig.setEnabled(frameContext.dpf.denoise);\n-\n-\tif (frameContext.dpf.denoise) {\n-\t\t*config = config_;\n-\t\t*strengthConfig = strengthConfig_;\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+\t * The DPF needs to take into account the total amount of\n+\t * digital gain, which comes from the AWB and LSC modules. The\n+\t * DPF hardware can be programmed with a digital gain value\n+\t * manually, but can also use the gains supplied by the AWB and\n+\t * LSC modules automatically when they are enabled. Use that\n+\t * mode of operation as it simplifies control of the DPF.\n+\t */\n+\tconst auto &awb = context.configuration.awb;\n+\tconst auto &lsc = context.configuration.lsc;\n+\tauto &mode = dpfConfig->gain.mode;\n+\n+\tif (awb.enabled && lsc.enabled) {\n+\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS;\n+\t} else if (awb.enabled) {\n+\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS;\n+\t} else if (lsc.enabled) {\n+\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS;\n+\t} else {\n+\t\tmode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED;\n \t}\n+\tconfig_.gain.mode = mode;\n+\n+\tauto dpfStrength = params->block<BlockType::DpfStrength>();\n+\tdpfStrength.setEnabled(true);\n+\n+\t*dpfStrength = strengthConfig_;\n+\n+\tlogConfigIfChanged(frameContext);\n }\n \n REGISTER_IPA_ALGORITHM(Dpf, \"Dpf\")\ndiff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h\nindex 2dd8cd36..d4bfb2dc 100644\n--- a/src/ipa/rkisp1/algorithms/dpf.h\n+++ b/src/ipa/rkisp1/algorithms/dpf.h\n@@ -30,8 +30,30 @@ public:\n \t\t RkISP1Params *params) override;\n \n private:\n+\tstruct ModeConfig {\n+\t\tint32_t modeValue;\n+\t\trkisp1_cif_isp_dpf_config dpf;\n+\t\trkisp1_cif_isp_dpf_strength_config strength;\n+\t};\n+\tbool parseConfig(const YamlObject &tuningData);\n+\tbool parseModes(const YamlObject &tuningData);\n+\tbool parseSingleConfig(const YamlObject &tuningData,\n+\t\t\t rkisp1_cif_isp_dpf_config &config,\n+\t\t\t rkisp1_cif_isp_dpf_strength_config &strengthConfig);\n+\n+\tbool loadReductionConfig(int32_t mode);\n+\tvoid logConfigIfChanged(const IPAFrameContext &frameContext);\n+\n+\tvoid prepareDisabledMode(IPAContext &context, const uint32_t frame,\n+\t\t\t\t IPAFrameContext &frameContext,\n+\t\t\t\t RkISP1Params *params);\n+\tvoid prepareEnabledMode(IPAContext &context, const uint32_t frame,\n+\t\t\t\tIPAFrameContext &frameContext, RkISP1Params *params);\n+\n \tstruct rkisp1_cif_isp_dpf_config config_;\n \tstruct rkisp1_cif_isp_dpf_strength_config strengthConfig_;\n+\tstd::vector<ModeConfig> noiseReductionModes_;\n+\tint32_t runningMode_;\n };\n \n } /* namespace ipa::rkisp1::algorithms */\n", "prefixes": [ "v3", "1/2" ] }