Patch Detail
Show a patch.
GET /api/patches/16856/?format=api
{ "id": 16856, "url": "https://patchwork.libcamera.org/api/patches/16856/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16856/", "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": "<20220727222149.30627-9-laurent.pinchart@ideasonboard.com>", "date": "2022-07-27T22:21:48", "name": "[libcamera-devel,v5,8/9] ipa: rkisp1: Add support of Filter control", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "44214eaed1700bce610c47f2f51f2b85c395c87d", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16856/mbox/", "series": [ { "id": 3338, "url": "https://patchwork.libcamera.org/api/series/3338/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3338", "date": "2022-07-27T22:21:40", "name": "ipa: rkisp1: Add GSL, LSC, DPCC, Filter and CProc algorithms", "version": 5, "mbox": "https://patchwork.libcamera.org/series/3338/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16856/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16856/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 B8E68BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Jul 2022 22:22:10 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6D7B363319;\n\tThu, 28 Jul 2022 00:22:10 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EAA3F6331B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jul 2022 00:22:01 +0200 (CEST)", "from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7DB846D4;\n\tThu, 28 Jul 2022 00:22:01 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658960530;\n\tbh=OBjZfxqJWpfHceVIGKjHiunRgGcei3sD/pKUn8Dk0ws=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=iNJABq8OiaS/bI2t/VFJ1uWgKIahuplJhOF+B4sTLByQVB7OPcthk4xIi4BKMkDD0\n\tna+1nmuYAtis6cwcbJAJQGsfA3OKBx9rldp2r+RZHZ0DU9GpHqlaZBQSwqL1FuMTVA\n\tk3fFJp/Re2qGxavjVpHVPaJ9pr2cVlxISlCRBOxH1R7TPdlQUQujQa+GVcGLnNtQko\n\t9a45JMFk8+yi1DzQ8p522XN0Lal2MWRqIYybUSTthfvlWUCrS8UO3dw0mJqs0o2xLr\n\tS27xhjXq0yVZFFNB4dsPFGomA8BAQtp6wyT8Hw5R+hsPPor2Jh2AMgbmPA4Icx9Xnk\n\t0IrCUrFughbIQ==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1658960521;\n\tbh=OBjZfxqJWpfHceVIGKjHiunRgGcei3sD/pKUn8Dk0ws=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=v7GGXrirKy7/GA1HwY50zuq1Er8l74yVcdSE3ivh6SLHigOhvUkhvjRjGkp7GDOpN\n\tEb8P0lI2LFO7qJbRpJx8WncpwX+/+SRrM93tFEo+TEmD/S+GXrpZ0AKRKYMPHg77zN\n\tTMF2DMbTgN42+04YKR5OAV4ZBwJwLojrCCLsWzKg=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"v7GGXrir\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 28 Jul 2022 01:21:48 +0300", "Message-Id": "<20220727222149.30627-9-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.35.1", "In-Reply-To": "<20220727222149.30627-1-laurent.pinchart@ideasonboard.com>", "References": "<20220727222149.30627-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 8/9] ipa: rkisp1: Add support of Filter\n\tcontrol", "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>", "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Florian Sylvestre <fsylvestre@baylibre.com>\n\nDenoise and Sharpness filters will be applied by RkISP1 during the\ndemosaicing step. The denoise filter is responsible for removing noise from\nthe image, while the sharpness filter will enhance its acutance.\n\nAdd filter algorithm with denoise and sharpness values based on user controls.\n\nSigned-off-by: Florian Sylvestre <fsylvestre@baylibre.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/algorithms/filter.cpp | 201 +++++++++++++++++++++++\n src/ipa/rkisp1/algorithms/filter.h | 30 ++++\n src/ipa/rkisp1/algorithms/meson.build | 1 +\n src/ipa/rkisp1/data/ov5640.yaml | 1 +\n src/ipa/rkisp1/ipa_context.cpp | 14 ++\n src/ipa/rkisp1/ipa_context.h | 6 +\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 8 +\n 7 files changed, 261 insertions(+)\n create mode 100644 src/ipa/rkisp1/algorithms/filter.cpp\n create mode 100644 src/ipa/rkisp1/algorithms/filter.h", "diff": "diff --git a/src/ipa/rkisp1/algorithms/filter.cpp b/src/ipa/rkisp1/algorithms/filter.cpp\nnew file mode 100644\nindex 000000000000..8ca10fd1ee9d\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/filter.cpp\n@@ -0,0 +1,201 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * filter.cpp - RkISP1 Filter control\n+ */\n+\n+#include \"filter.h\"\n+\n+#include <cmath>\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/control_ids.h>\n+\n+/**\n+ * \\file filter.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+/**\n+ * \\class Filter\n+ * \\brief RkISP1 Filter control\n+ *\n+ * Denoise and Sharpness filters will be applied by RkISP1 during the\n+ * demosaicing step. The denoise filter is responsible for removing noise from\n+ * the image, while the sharpness filter will enhance its acutance.\n+ *\n+ * \\todo In current version the denoise and sharpness control is based on user\n+ * controls. In a future version it should be controlled automatically by the\n+ * algorithm.\n+ */\n+\n+LOG_DEFINE_CATEGORY(RkISP1Filter)\n+\n+static constexpr uint32_t kFiltLumWeightDefault = 0x00022040;\n+static constexpr uint32_t kFiltModeDefault = 0x000004f2;\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::queueRequest\n+ */\n+void Filter::queueRequest(IPAContext &context,\n+\t\t\t [[maybe_unused]] const uint32_t frame,\n+\t\t\t const ControlList &controls)\n+{\n+\tauto &filter = context.frameContext.filter;\n+\n+\tconst auto &sharpness = controls.get(controls::Sharpness);\n+\tif (sharpness) {\n+\t\tfilter.sharpness = std::round(std::clamp(*sharpness, 0.0f, 10.0f));\n+\t\tfilter.updateParams = true;\n+\n+\t\tLOG(RkISP1Filter, Debug) << \"Set sharpness to \" << *sharpness;\n+\t}\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\tfilter.denoise = 0;\n+\t\t\tfilter.updateParams = true;\n+\t\t\tbreak;\n+\t\tcase controls::draft::NoiseReductionModeMinimal:\n+\t\t\tfilter.denoise = 1;\n+\t\t\tfilter.updateParams = true;\n+\t\t\tbreak;\n+\t\tcase controls::draft::NoiseReductionModeHighQuality:\n+\t\tcase controls::draft::NoiseReductionModeFast:\n+\t\t\tfilter.denoise = 3;\n+\t\t\tfilter.updateParams = true;\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tLOG(RkISP1Filter, Error)\n+\t\t\t\t<< \"Unsupported denoise value \"\n+\t\t\t\t<< *denoise;\n+\t\t}\n+\t}\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void Filter::prepare(IPAContext &context, rkisp1_params_cfg *params)\n+{\n+\tauto &filter = context.frameContext.filter;\n+\n+\t/* Check if the algorithm configuration has been updated. */\n+\tif (!filter.updateParams)\n+\t\treturn;\n+\n+\tfilter.updateParams = false;\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 = filter.denoise;\n+\tuint8_t sharpness = filter.sharpness;\n+\tauto &flt_config = params->others.flt_config;\n+\n+\tflt_config.fac_sh0 = filt_fac_sh0[sharpness];\n+\tflt_config.fac_sh1 = filt_fac_sh1[sharpness];\n+\tflt_config.fac_mid = filt_fac_mid[sharpness];\n+\tflt_config.fac_bl0 = filt_fac_bl0[sharpness];\n+\tflt_config.fac_bl1 = filt_fac_bl1[sharpness];\n+\n+\tflt_config.lum_weight = kFiltLumWeightDefault;\n+\tflt_config.mode = kFiltModeDefault;\n+\tflt_config.thresh_sh0 = filt_thresh_sh0[denoise];\n+\tflt_config.thresh_sh1 = filt_thresh_sh1[denoise];\n+\tflt_config.thresh_bl0 = filt_thresh_bl0[denoise];\n+\tflt_config.thresh_bl1 = filt_thresh_bl1[denoise];\n+\tflt_config.grn_stage1 = stage1_select[denoise];\n+\tflt_config.chr_v_mode = filt_chr_v_mode[denoise];\n+\tflt_config.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\tflt_config.grn_stage1 = 2;\n+\t} else if (denoise == 10) {\n+\t\tif (sharpness > 5)\n+\t\t\tflt_config.grn_stage1 = 2;\n+\t\telse if (sharpness > 3)\n+\t\t\tflt_config.grn_stage1 = 1;\n+\t}\n+\n+\tif (denoise > 7) {\n+\t\tif (sharpness > 7) {\n+\t\t\tflt_config.fac_bl0 /= 2;\n+\t\t\tflt_config.fac_bl1 /= 4;\n+\t\t} else if (sharpness > 4) {\n+\t\t\tflt_config.fac_bl0 = flt_config.fac_bl0 * 3 / 4;\n+\t\t\tflt_config.fac_bl1 /= 2;\n+\t\t}\n+\t}\n+\n+\tparams->module_en_update |= RKISP1_CIF_ISP_MODULE_FLT;\n+\tparams->module_ens |= RKISP1_CIF_ISP_MODULE_FLT;\n+\tparams->module_cfg_update |= RKISP1_CIF_ISP_MODULE_FLT;\n+}\n+\n+REGISTER_IPA_ALGORITHM(Filter, \"Filter\")\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/filter.h b/src/ipa/rkisp1/algorithms/filter.h\nnew file mode 100644\nindex 000000000000..9eb170eb7da1\n--- /dev/null\n+++ b/src/ipa/rkisp1/algorithms/filter.h\n@@ -0,0 +1,30 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * filter.h - RkISP1 Filter control\n+ */\n+\n+#pragma once\n+\n+#include <sys/types.h>\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::rkisp1::algorithms {\n+\n+class Filter : public Algorithm\n+{\n+public:\n+\tFilter() = default;\n+\t~Filter() = default;\n+\n+\tvoid queueRequest(IPAContext &context, const uint32_t frame,\n+\t\t\t const ControlList &controls) override;\n+\tvoid prepare(IPAContext &context, rkisp1_params_cfg *params) override;\n+};\n+\n+} /* namespace ipa::rkisp1::algorithms */\n+} /* namespace libcamera */\ndiff --git a/src/ipa/rkisp1/algorithms/meson.build b/src/ipa/rkisp1/algorithms/meson.build\nindex 870074939d6a..dcd24fe07d23 100644\n--- a/src/ipa/rkisp1/algorithms/meson.build\n+++ b/src/ipa/rkisp1/algorithms/meson.build\n@@ -5,6 +5,7 @@ rkisp1_ipa_algorithms = files([\n 'awb.cpp',\n 'blc.cpp',\n 'dpcc.cpp',\n+ 'filter.cpp',\n 'gsl.cpp',\n 'lsc.cpp',\n ])\ndiff --git a/src/ipa/rkisp1/data/ov5640.yaml b/src/ipa/rkisp1/data/ov5640.yaml\nindex 2315ec437f77..99529481f593 100644\n--- a/src/ipa/rkisp1/data/ov5640.yaml\n+++ b/src/ipa/rkisp1/data/ov5640.yaml\n@@ -155,4 +155,5 @@ algorithms:\n rnd-offsets:\n green: 2\n red-blue: 2\n+ - Filter:\n ...\ndiff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp\nindex 30bb87a967bd..4b1171865f1f 100644\n--- a/src/ipa/rkisp1/ipa_context.cpp\n+++ b/src/ipa/rkisp1/ipa_context.cpp\n@@ -136,6 +136,20 @@ namespace libcamera::ipa::rkisp1 {\n * \\brief Estimated color temperature\n */\n \n+/**\n+ * \\var IPAFrameContext::filter\n+ * \\brief Context for the Filter algorithm\n+ *\n+ * \\struct IPAFrameContext::filter.denoise\n+ * \\brief Denoising level\n+ *\n+ * \\var IPAFrameContext::filter.sharpness\n+ * \\brief Sharpness level\n+ *\n+ * \\var IPAFrameContext::filter.updateParams\n+ * \\brief Indicates if ISP parameters need to be updated\n+ */\n+\n /**\n * \\var IPAFrameContext::sensor\n * \\brief Effective sensor values\ndiff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h\nindex 3bfb262c8eb3..3b2f6af1276f 100644\n--- a/src/ipa/rkisp1/ipa_context.h\n+++ b/src/ipa/rkisp1/ipa_context.h\n@@ -57,6 +57,12 @@ struct IPAFrameContext {\n \t\tdouble temperatureK;\n \t} awb;\n \n+\tstruct {\n+\t\tuint8_t denoise;\n+\t\tuint8_t sharpness;\n+\t\tbool updateParams;\n+\t} filter;\n+\n \tstruct {\n \t\tuint32_t exposure;\n \t\tdouble gain;\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 99eecd444f95..4e000d3122fb 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -968,6 +968,14 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n \t\t\t\t\t\t hasSelfPath_ ? &selfPath_ : nullptr);\n \n \tControlInfoMap::Map ctrls;\n+\tctrls.emplace(std::piecewise_construct,\n+\t\t std::forward_as_tuple(&controls::Sharpness),\n+\t\t std::forward_as_tuple(0.0f, 10.0f, 1.0f));\n+\n+\tctrls.emplace(std::piecewise_construct,\n+\t\t std::forward_as_tuple(&controls::draft::NoiseReductionMode),\n+\t\t std::forward_as_tuple(controls::draft::NoiseReductionModeValues));\n+\n \tctrls.emplace(std::piecewise_construct,\n \t\t std::forward_as_tuple(&controls::AeEnable),\n \t\t std::forward_as_tuple(false, true));\n", "prefixes": [ "libcamera-devel", "v5", "8/9" ] }