Show a patch.

GET /api/1.1/patches/25828/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 25828,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/25828/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/25828/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20260118202953.1554892-4-rui.wang@ideasonboard.com>",
    "date": "2026-01-18T20:29:52",
    "name": "[v1,3/4] ipa: rkisp1: algorithms: filter: Integrate mode switching with prepare()",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "e77e2acb422fb18571e6150302fa7f1dd2bc601a",
    "submitter": {
        "id": 241,
        "url": "https://patchwork.libcamera.org/api/1.1/people/241/?format=api",
        "name": "Rui Wang",
        "email": "rui.wang@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/25828/mbox/",
    "series": [
        {
            "id": 5712,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5712/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5712",
            "date": "2026-01-18T20:29:49",
            "name": "Filter algorithm refactoring and mode switching",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/5712/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/25828/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/25828/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 06AEEBDCBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 18 Jan 2026 20:30:52 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C5ED261FB9;\n\tSun, 18 Jan 2026 21:30:51 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D5D7761FC9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 18 Jan 2026 21:30:49 +0100 (CET)",
            "from rui-Precision-7560.local (unknown [209.216.103.65])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A7CE41BA;\n\tSun, 18 Jan 2026 21:30:19 +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=\"lvucb774\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1768768220;\n\tbh=EaKrU4DDAVryp1VaFb9jsIVpm/dzFkU8FuDyKZsQ46E=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=lvucb7746qs/f3BaKpxqKi3WndFswOeVWZbscDPzmjVX6kPnJ5A6dBj4jHF7sPhPG\n\tJ5MqKJhaMv0FymdD/zCLn6tsgplK3R7BJ+LuKN4bavXTgZQOzKCnNpuzcvndSwfmlC\n\tye3cS/JMkIlK/R0YxXmB/4njY/jqHjSr0b+69hFE=",
        "From": "Rui Wang <rui.wang@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Rui Wang <rui.wang@ideasonboard.com>",
        "Subject": "[PATCH v1 3/4] ipa: rkisp1: algorithms: filter: Integrate mode\n\tswitching with prepare()",
        "Date": "Sun, 18 Jan 2026 15:29:52 -0500",
        "Message-ID": "<20260118202953.1554892-4-rui.wang@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20260118202953.1554892-1-rui.wang@ideasonboard.com>",
        "References": "<20260118202953.1554892-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": "Refactor the Filter algorithm's prepare() function to use the new mode\nswitching infrastructure instead of hardcoded lookup tables.\n\nKey changes:\n- Replace hardcoded denoise/sharpness lookup tables with mode-based\n  configuration loaded from tuning data via loadConfig().\n- Refactor prepare() to delegate to prepareDisabledMode() and\n  prepareEnabledMode() helper functions for better code organization.\n- Change filter.denoise from uint8_t to bool in IPAFrameContext to\n  reflect its actual usage as an enable/disable flag.\n- Update queueRequest() to call loadConfig() for noise reduction mode\n  selection, enabling runtime mode switching.\n- Apply sharpness as an override on top of the base noise reduction\n  mode configuration using kSharpnessPresets.\n- Add bounds checking for sharpness level to prevent array overflow.\n- Support sharpness-only operation when no noise reduction mode is\n  configured (activeMode_ == end()).\n\nThe new implementation allows filter parameters to be fully configured\nvia YAML tuning files while maintaining backward compatibility through\nthe sharpness preset system.\n\nSigned-off-by: Rui Wang <rui.wang@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/filter.cpp | 146 ++++++++-------------------\n src/ipa/rkisp1/ipa_context.h         |   2 +-\n 2 files changed, 41 insertions(+), 107 deletions(-)",
    "diff": "diff --git a/src/ipa/rkisp1/algorithms/filter.cpp b/src/ipa/rkisp1/algorithms/filter.cpp\nindex eb4049fd..404ecd90 100644\n--- a/src/ipa/rkisp1/algorithms/filter.cpp\n+++ b/src/ipa/rkisp1/algorithms/filter.cpp\n@@ -82,7 +82,6 @@ static constexpr SharpnessPreset kSharpnessPresets[] = {\n };\n } /* namespace */\n \n-\n /**\n  * \\class Filter\n  * \\brief RkISP1 Filter control\n@@ -245,26 +244,20 @@ void Filter::queueRequest(IPAContext &context,\n \n \tconst auto &denoise = controls.get(controls::draft::NoiseReductionMode);\n \tif (denoise) {\n-\t\tLOG(RkISP1Filter, Debug) << \"Set denoise to \" << *denoise;\n-\n \t\tswitch (*denoise) {\n \t\tcase controls::draft::NoiseReductionModeOff:\n-\t\t\tif (filter.denoise != 0) {\n-\t\t\t\tfilter.denoise = 0;\n+\t\t\tif (filter.denoise) {\n+\t\t\t\tfilter.denoise = false;\n \t\t\t\tupdate = true;\n \t\t\t}\n \t\t\tbreak;\n \t\tcase controls::draft::NoiseReductionModeMinimal:\n-\t\t\tif (filter.denoise != 1) {\n-\t\t\t\tfilter.denoise = 1;\n-\t\t\t\tupdate = true;\n-\t\t\t}\n-\t\t\tbreak;\n \t\tcase controls::draft::NoiseReductionModeHighQuality:\n \t\tcase controls::draft::NoiseReductionModeFast:\n-\t\t\tif (filter.denoise != 3) {\n-\t\t\t\tfilter.denoise = 3;\n+\t\tcase controls::draft::NoiseReductionModeZSL:\n+\t\t\tif (loadConfig(*denoise)) {\n \t\t\t\tupdate = true;\n+\t\t\t\tfilter.denoise = true;\n \t\t\t}\n \t\t\tbreak;\n \t\tdefault:\n@@ -273,6 +266,8 @@ void Filter::queueRequest(IPAContext &context,\n \t\t\t\t<< *denoise;\n \t\t\tbreak;\n \t\t}\n+\t\tif (update)\n+\t\t\tLOG(RkISP1Filter, Debug) << \"Set denoise to \" << modeName(*denoise);\n \t}\n \n \tframeContext.filter.denoise = filter.denoise;\n@@ -284,108 +279,19 @@ void Filter::queueRequest(IPAContext &context,\n  * \\copydoc libcamera::ipa::Algorithm::prepare\n  */\n void Filter::prepare([[maybe_unused]] IPAContext &context,\n-\t\t     [[maybe_unused]] const uint32_t frame,\n+\t\t     const uint32_t frame,\n \t\t     IPAFrameContext &frameContext, RkISP1Params *params)\n {\n \t/* Check if the algorithm configuration has been updated. */\n \tif (!frameContext.filter.update)\n \t\treturn;\n \n-\tstatic constexpr uint16_t filt_fac_sh0[] = {\n-\t\t0x04, 0x07, 0x0a, 0x0c, 0x10, 0x14, 0x1a, 0x1e, 0x24, 0x2a, 0x30\n-\t};\n-\n-\tstatic constexpr uint16_t filt_fac_sh1[] = {\n-\t\t0x04, 0x08, 0x0c, 0x10, 0x16, 0x1b, 0x20, 0x26, 0x2c, 0x30, 0x3f\n-\t};\n-\n-\tstatic constexpr uint16_t filt_fac_mid[] = {\n-\t\t0x04, 0x06, 0x08, 0x0a, 0x0c, 0x10, 0x13, 0x17, 0x1d, 0x22, 0x28\n-\t};\n-\n-\tstatic constexpr uint16_t filt_fac_bl0[] = {\n-\t\t0x02, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x10, 0x15, 0x1a, 0x24\n-\t};\n-\n-\tstatic constexpr uint16_t filt_fac_bl1[] = {\n-\t\t0x00, 0x00, 0x00, 0x02, 0x04, 0x04, 0x06, 0x08, 0x0d, 0x14, 0x20\n-\t};\n-\n-\tstatic constexpr uint16_t filt_thresh_sh0[] = {\n-\t\t0, 18, 26, 36, 41, 75, 90, 120, 170, 250, 1023\n-\t};\n-\n-\tstatic constexpr uint16_t filt_thresh_sh1[] = {\n-\t\t0, 33, 44, 51, 67, 100, 120, 150, 200, 300, 1023\n-\t};\n-\n-\tstatic constexpr uint16_t filt_thresh_bl0[] = {\n-\t\t0, 8, 13, 23, 26, 50, 60, 80, 140, 180, 1023\n-\t};\n-\n-\tstatic constexpr uint16_t filt_thresh_bl1[] = {\n-\t\t0, 2, 5, 10, 15, 20, 26, 51, 100, 150, 1023\n-\t};\n-\n-\tstatic constexpr uint16_t stage1_select[] = {\n-\t\t6, 6, 4, 4, 3, 3, 2, 2, 2, 1, 0\n-\t};\n-\n-\tstatic constexpr uint16_t filt_chr_v_mode[] = {\n-\t\t1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3\n-\t};\n-\n-\tstatic constexpr uint16_t filt_chr_h_mode[] = {\n-\t\t0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3\n-\t};\n-\n-\tuint8_t denoise = frameContext.filter.denoise;\n-\tuint8_t sharpness = frameContext.filter.sharpness;\n-\n-\tauto config = params->block<BlockType::Flt>();\n-\tconfig.setEnabled(true);\n-\n-\tconfig->fac_sh0 = filt_fac_sh0[sharpness];\n-\tconfig->fac_sh1 = filt_fac_sh1[sharpness];\n-\tconfig->fac_mid = filt_fac_mid[sharpness];\n-\tconfig->fac_bl0 = filt_fac_bl0[sharpness];\n-\tconfig->fac_bl1 = filt_fac_bl1[sharpness];\n-\n-\tconfig->lum_weight = kFiltLumWeightDefault;\n-\tconfig->mode = kFiltModeDefault;\n-\tconfig->thresh_sh0 = filt_thresh_sh0[denoise];\n-\tconfig->thresh_sh1 = filt_thresh_sh1[denoise];\n-\tconfig->thresh_bl0 = filt_thresh_bl0[denoise];\n-\tconfig->thresh_bl1 = filt_thresh_bl1[denoise];\n-\tconfig->grn_stage1 = stage1_select[denoise];\n-\tconfig->chr_v_mode = filt_chr_v_mode[denoise];\n-\tconfig->chr_h_mode = filt_chr_h_mode[denoise];\n-\n-\t/*\n-\t * Combined high denoising and high sharpening requires some\n-\t * adjustments to the configuration of the filters. A first stage\n-\t * filter with a lower strength must be selected, and the blur factors\n-\t * must be decreased.\n-\t */\n-\tif (denoise == 9) {\n-\t\tif (sharpness > 3)\n-\t\t\tconfig->grn_stage1 = 2;\n-\t} else if (denoise == 10) {\n-\t\tif (sharpness > 5)\n-\t\t\tconfig->grn_stage1 = 2;\n-\t\telse if (sharpness > 3)\n-\t\t\tconfig->grn_stage1 = 1;\n+\tif (!frameContext.filter.denoise && !frameContext.filter.sharpness) {\n+\t\tprepareDisabledMode(params);\n+\t\treturn;\n \t}\n \n-\tif (denoise > 7) {\n-\t\tif (sharpness > 7) {\n-\t\t\tconfig->fac_bl0 /= 2;\n-\t\t\tconfig->fac_bl1 /= 4;\n-\t\t} else if (sharpness > 4) {\n-\t\t\tconfig->fac_bl0 = config->fac_bl0 * 3 / 4;\n-\t\t\tconfig->fac_bl1 /= 2;\n-\t\t}\n-\t}\n+\tprepareEnabledMode(frame, frameContext, params);\n }\n \n void Filter::prepareDisabledMode(RkISP1Params *params)\n@@ -398,9 +304,37 @@ void Filter::prepareEnabledMode(const uint32_t frame,\n \t\t\t\tIPAFrameContext &frameContext,\n \t\t\t\tRkISP1Params *params)\n {\n+\t/* Ensure we have a valid mode configuration */\n+\tif (activeMode_ == noiseReductionModes_.end() && frameContext.filter.sharpness == 0)\n+\t\treturn;\n+\n+\tconst ModeConfig &modeConfig = *activeMode_;\n+\n \tauto config = params->block<BlockType::Flt>();\n \tconfig.setEnabled(true);\n \n+\t/* Load the base configuration from the active noise reduction mode */\n+\t*config = modeConfig.config;\n+\n+\t/*\n+\t * Apply sharpness override if configured.\n+\t * Sharpness control modulates the sharpening factors on top of\n+\t * the base noise reduction mode configuration.\n+\t */\n+\tuint8_t sharpness = frameContext.filter.sharpness;\n+\tif (sharpness > 0 && sharpness < std::size(kSharpnessPresets)) {\n+\t\tconst SharpnessPreset &preset = kSharpnessPresets[sharpness];\n+\t\tconfig->fac_sh0 = preset.fac_sh0;\n+\t\tconfig->fac_sh1 = preset.fac_sh1;\n+\t\tconfig->fac_mid = preset.fac_mid;\n+\t\tconfig->fac_bl0 = preset.fac_bl0;\n+\t\tconfig->fac_bl1 = preset.fac_bl1;\n+\n+\t\t/* Set mode to default if no active mode is configured */\n+\t\tif (activeMode_ == noiseReductionModes_.end())\n+\t\t\tconfig->mode = kFiltModeDefault;\n+\t}\n+\n \tif (frameContext.filter.update || frame == 0)\n \t\tlogConfig(*config);\n }\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex b257cee5..4554f69b 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -190,7 +190,7 @@ struct IPAFrameContext : public FrameContext {\n \t} dpf;\n \n \tstruct {\n-\t\tuint8_t denoise;\n+\t\tbool denoise;\n \t\tuint8_t sharpness;\n \t\tbool update;\n \t} filter;\n",
    "prefixes": [
        "v1",
        "3/4"
    ]
}