{"id":20294,"url":"https://patchwork.libcamera.org/api/1.1/patches/20294/?format=json","web_url":"https://patchwork.libcamera.org/patch/20294/","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":"<20240613132602.1021721-7-dan.scally@ideasonboard.com>","date":"2024-06-13T13:25:58","name":"[06/10] ipa: mali-c55: Add BLC Algorithm","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"716dfa3b3070398ae9af5e0d588c3b92884cdf59","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/1.1/people/156/?format=json","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20294/mbox/","series":[{"id":4388,"url":"https://patchwork.libcamera.org/api/1.1/series/4388/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4388","date":"2024-06-13T13:25:52","name":"Add Mali-C55 IPA Module and Algorithms","version":1,"mbox":"https://patchwork.libcamera.org/series/4388/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20294/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20294/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 6AE0DC3293\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Jun 2024 13:26:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 24A7A65499;\n\tThu, 13 Jun 2024 15:26:43 +0200 (CEST)","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 6F52F6549C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2024 15:26:30 +0200 (CEST)","from mail.ideasonboard.com\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 57B5CBEB;\n\tThu, 13 Jun 2024 15:26:16 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kPpwxlO7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1718285176;\n\tbh=bTrtVzi2UpxfZ1yg9kD9dKgSLeK48cAppu3RB9yXOC8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=kPpwxlO7tW6w5b4kgF/lrjsqi2dwdeDRpy7IIXFCY2b7XH0RqSavN4ba7AuhGslm6\n\t8o2Tb7Qd2s8s7RQ1qf9GiKkaBpcV1XLS+gjUI4DKPx75hUqhX/EnoCXmbNpnATtN8O\n\t5uicfEEUeMGZ4JnJ8/Qdz17Jjr1j9Ys6oS6AkEvo=","From":"Daniel Scally <dan.scally@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"dan.scally@ideasonboard.com, nayden.kanchev@arm.com,\n\tjacopo.mondi@ideasonboard.com","Subject":"[PATCH 06/10] ipa: mali-c55: Add BLC Algorithm","Date":"Thu, 13 Jun 2024 14:25:58 +0100","Message-Id":"<20240613132602.1021721-7-dan.scally@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20240613132602.1021721-1-dan.scally@ideasonboard.com>","References":"<20240613132602.1021721-1-dan.scally@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":"From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nAdd a Black Level Correction algorithm.\n\nAcked-by: Nayden Kanchev  <nayden.kanchev@arm.com>\nJacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/ipa/mali-c55/algorithms/blc.cpp     | 119 ++++++++++++++++++++++++\n src/ipa/mali-c55/algorithms/blc.h       |  40 ++++++++\n src/ipa/mali-c55/algorithms/meson.build |   1 +\n 3 files changed, 160 insertions(+)\n create mode 100644 src/ipa/mali-c55/algorithms/blc.cpp\n create mode 100644 src/ipa/mali-c55/algorithms/blc.h","diff":"diff --git a/src/ipa/mali-c55/algorithms/blc.cpp b/src/ipa/mali-c55/algorithms/blc.cpp\nnew file mode 100644\nindex 00000000..c8590d8a\n--- /dev/null\n+++ b/src/ipa/mali-c55/algorithms/blc.cpp\n@@ -0,0 +1,119 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * blc.cpp - Mali-C55 sensor offset (black level) correction\n+ */\n+\n+#include \"blc.h\"\n+\n+#include <libcamera/base/log.h>\n+#include <libcamera/control_ids.h>\n+\n+#include \"libcamera/internal/yaml_parser.h\"\n+\n+/**\n+ * \\file blc.h\n+ */\n+\n+namespace libcamera {\n+\n+namespace ipa::mali_c55::algorithms {\n+\n+/**\n+ * \\class BlackLevelCorrection\n+ * \\brief MaliC55 Black Level Correction control\n+ *\n+ * todo\n+ */\n+\n+LOG_DEFINE_CATEGORY(MaliC55Blc)\n+\n+BlackLevelCorrection::BlackLevelCorrection()\n+\t: tuningParameters_(false)\n+{\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::init\n+ */\n+int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context,\n+\t\t\t       const YamlObject &tuningData)\n+{\n+\toffset00 = tuningData[\"offset00\"].get<uint32_t>(256);\n+\toffset01 = tuningData[\"offset01\"].get<uint32_t>(256);\n+\toffset10 = tuningData[\"offset10\"].get<uint32_t>(256);\n+\toffset11 = tuningData[\"offset11\"].get<uint32_t>(256);\n+\n+\tif (offset00 > kMaxOffset || offset01 > kMaxOffset ||\n+\t    offset10 > kMaxOffset || offset11 > kMaxOffset) {\n+\t\tLOG(MaliC55Blc, Error) << \"Invalid black level offsets\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\ttuningParameters_ = true;\n+\n+\tLOG(MaliC55Blc, Debug)\n+\t\t<< \"Black levels: 00 \" << offset00 << \", 01 \" << offset01\n+\t\t<< \", 10 \" << offset10 << \", 11 \" << offset11;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\copydoc libcamera::ipa::Algorithm::prepare\n+ */\n+void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,\n+\t\t\t\t   const uint32_t frame,\n+\t\t\t\t   [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t\t   mali_c55_params_block_header *block)\n+{\n+\tif (frame > 0)\n+\t\treturn;\n+\n+\tif (!tuningParameters_)\n+\t\treturn;\n+\n+\tblock->type = MALI_C55_PARAM_BLOCK_SENSOR_OFFS;\n+\tblock->enabled = true;\n+\tblock->size = sizeof(mali_c55_params_sensor_off_preshading);\n+\n+\tstruct mali_c55_params_sensor_off_preshading *sensor_offs =\n+\t\treinterpret_cast<mali_c55_params_sensor_off_preshading *>(block);\n+\n+\tsensor_offs->chan00 = offset00;\n+\tsensor_offs->chan01 = offset01;\n+\tsensor_offs->chan10 = offset10;\n+\tsensor_offs->chan11 = offset11;\n+}\n+\n+void BlackLevelCorrection::process([[maybe_unused]] IPAContext &context,\n+\t\t\t\t   [[maybe_unused]] const uint32_t frame,\n+\t\t\t\t   [[maybe_unused]] IPAFrameContext &frameContext,\n+\t\t\t\t   [[maybe_unused]] const mali_c55_stats_buffer *stats,\n+\t\t\t\t   ControlList &metadata)\n+{\n+\t/*\n+\t * Black Level Offsets in tuning data need to be 20-bit, whereas the\n+\t * metadata expects values from a 16-bit range. Right-shift to remove\n+\t * the 4 least significant bits.\n+\t *\n+\t * The black levels should be reported in the order R, Gr, Gb, B. We\n+\t * ignore that here given we're using matching values so far, but it\n+\t * would be safer to check the sensor's bayer order.\n+\t *\n+\t * \\todo Account for bayer order.\n+\t */\n+\tmetadata.set(controls::SensorBlackLevels, {\n+\t\tstatic_cast<int32_t>(offset00 >> 4),\n+\t\tstatic_cast<int32_t>(offset01 >> 4),\n+\t\tstatic_cast<int32_t>(offset10 >> 4),\n+\t\tstatic_cast<int32_t>(offset11 >> 4),\n+\t});\n+}\n+\n+REGISTER_IPA_ALGORITHM(BlackLevelCorrection, \"BlackLevelCorrection\")\n+\n+} /* namespace ipa::mali_c55::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/mali-c55/algorithms/blc.h b/src/ipa/mali-c55/algorithms/blc.h\nnew file mode 100644\nindex 00000000..34d5a3ac\n--- /dev/null\n+++ b/src/ipa/mali-c55/algorithms/blc.h\n@@ -0,0 +1,40 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021-2022, Ideas On Board\n+ *\n+ * blc.h - Mali-C55 sensor offset (black level) correction\n+ */\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::mali_c55::algorithms {\n+\n+class BlackLevelCorrection : public Algorithm\n+{\n+public:\n+\tBlackLevelCorrection();\n+\t~BlackLevelCorrection() = default;\n+\n+\tint init(IPAContext &context, const YamlObject &tuningData) override;\n+\tvoid prepare(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     mali_c55_params_block_header *block) override;\n+\tvoid process(IPAContext &context, const uint32_t frame,\n+\t\t     IPAFrameContext &frameContext,\n+\t\t     const mali_c55_stats_buffer *stats,\n+\t\t     ControlList &metadata) override;\n+\n+private:\n+\tstatic constexpr uint32_t kMaxOffset = 0xfffff;\n+\n+\tbool tuningParameters_;\n+\tuint32_t offset00;\n+\tuint32_t offset01;\n+\tuint32_t offset10;\n+\tuint32_t offset11;\n+};\n+\n+} /* namespace ipa::mali_c55::algorithms */\n+} /* namespace libcamera */\ndiff --git a/src/ipa/mali-c55/algorithms/meson.build b/src/ipa/mali-c55/algorithms/meson.build\nindex f2203b15..d84432b9 100644\n--- a/src/ipa/mali-c55/algorithms/meson.build\n+++ b/src/ipa/mali-c55/algorithms/meson.build\n@@ -1,4 +1,5 @@\n # SPDX-License-Identifier: CC0-1.0\n \n mali_c55_ipa_algorithms = files([\n+    'blc.cpp',\n ])\n","prefixes":["06/10"]}