Patch Detail
Show a patch.
GET /api/1.1/patches/21858/?format=api
{ "id": 21858, "url": "https://patchwork.libcamera.org/api/1.1/patches/21858/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21858/", "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": "<20241107114819.57599-9-dan.scally@ideasonboard.com>", "date": "2024-11-07T11:48:16", "name": "[v3,08/11] ipa: mali-c55: Add BLC Algorithm", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "13a649a8cb7f2a622774ff9ce07465eef175305d", "submitter": { "id": 156, "url": "https://patchwork.libcamera.org/api/1.1/people/156/?format=api", "name": "Dan Scally", "email": "dan.scally@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21858/mbox/", "series": [ { "id": 4777, "url": "https://patchwork.libcamera.org/api/1.1/series/4777/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4777", "date": "2024-11-07T11:48:08", "name": "Add Mali-C55 IPA Module and Algorithms", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4777/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21858/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21858/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 CDBB0C32CE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 7 Nov 2024 11:48:46 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F3E2B654A1;\n\tThu, 7 Nov 2024 12:48:45 +0100 (CET)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D165D6546F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 7 Nov 2024 12:48:29 +0100 (CET)", "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 D10DE1648;\n\tThu, 7 Nov 2024 12:48:20 +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=\"H+1fwQWh\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1730980101;\n\tbh=bFpULsPcQwU3+mnKOuemBS4R1zAV03fjri05l6xSKYA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=H+1fwQWhqjRh6QOLREt95aHkRmDmHrhByoOSXjQBv/Otic6Hu3WBU9B6ztdxItijM\n\tfHWLNn8EgCbnSPclDETaNRchTR+V4BTqW35mAXV9692ffjmX9HnjgpwniRFTNMNm85\n\tKWURQPBwAwMhAA63F7LhvwdPe8ZmmaCEX7ooBshc=", "From": "Daniel Scally <dan.scally@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Anthony.McGivern@arm.com, Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>,\n\tNayden Kanchev <nayden.kanchev@arm.com>", "Subject": "[PATCH v3 08/11] ipa: mali-c55: Add BLC Algorithm", "Date": "Thu, 7 Nov 2024 11:48:16 +0000", "Message-Id": "<20241107114819.57599-9-dan.scally@ideasonboard.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20241107114819.57599-1-dan.scally@ideasonboard.com>", "References": "<20241107114819.57599-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\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\nAcked-by: Nayden Kanchev <nayden.kanchev@arm.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\nChanges in v3:\n\n\t- Corrected copyright dates\n\t- Checked for black levels in CameraSensorHelper\n\nChanges in v2:\n\n\t- Use the union rather than reinterpret_cast<>() to abstract the block\n\n src/ipa/mali-c55/algorithms/blc.cpp | 140 ++++++++++++++++++++++++\n src/ipa/mali-c55/algorithms/blc.h | 42 +++++++\n src/ipa/mali-c55/algorithms/meson.build | 1 +\n src/ipa/mali-c55/ipa_context.h | 1 +\n src/ipa/mali-c55/mali-c55.cpp | 10 ++\n 5 files changed, 194 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..2a54c86a\n--- /dev/null\n+++ b/src/ipa/mali-c55/algorithms/blc.cpp\n@@ -0,0 +1,140 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * 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+\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>(0);\n+\toffset01 = tuningData[\"offset01\"].get<uint32_t>(0);\n+\toffset10 = tuningData[\"offset10\"].get<uint32_t>(0);\n+\toffset11 = tuningData[\"offset11\"].get<uint32_t>(0);\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::configure\n+ */\n+int BlackLevelCorrection::configure(IPAContext &context,\n+\t\t\t\t [[maybe_unused]] const IPACameraSensorInfo &configInfo)\n+{\n+\t/*\n+\t * If no Black Levels were passed in through tuning data then we could\n+\t * use the value from the CameraSensorHelper if one is available.\n+\t */\n+\tif (context.configuration.sensor.blackLevel &&\n+\t !(offset00 + offset01 + offset10 + offset11)) {\n+\t\toffset00 = context.configuration.sensor.blackLevel;\n+\t\toffset01 = context.configuration.sensor.blackLevel;\n+\t\toffset10 = context.configuration.sensor.blackLevel;\n+\t\toffset11 = context.configuration.sensor.blackLevel;\n+\t}\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_buffer *params)\n+{\n+\tmali_c55_params_block block;\n+\tblock.data = ¶ms->data[params->total_size];\n+\n+\tif (frame > 0)\n+\t\treturn;\n+\n+\tif (!tuningParameters_)\n+\t\treturn;\n+\n+\tblock.header->type = MALI_C55_PARAM_BLOCK_SENSOR_OFFS;\n+\tblock.header->flags = MALI_C55_PARAM_BLOCK_FL_NONE;\n+\tblock.header->size = sizeof(mali_c55_params_sensor_off_preshading);\n+\n+\tblock.sensor_offs->chan00 = offset00;\n+\tblock.sensor_offs->chan01 = offset01;\n+\tblock.sensor_offs->chan10 = offset10;\n+\tblock.sensor_offs->chan11 = offset11;\n+\n+\tparams->total_size += block.header->size;\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..9696e8e9\n--- /dev/null\n+++ b/src/ipa/mali-c55/algorithms/blc.h\n@@ -0,0 +1,42 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Ideas On Board\n+ *\n+ * 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+\tint configure(IPAContext &context,\n+\t\t const IPACameraSensorInfo &configInfo) override;\n+\tvoid prepare(IPAContext &context, const uint32_t frame,\n+\t\t IPAFrameContext &frameContext,\n+\t\t mali_c55_params_buffer *params) 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 3c872888..96808431 100644\n--- a/src/ipa/mali-c55/algorithms/meson.build\n+++ b/src/ipa/mali-c55/algorithms/meson.build\n@@ -2,4 +2,5 @@\n \n mali_c55_ipa_algorithms = files([\n 'agc.cpp',\n+ 'blc.cpp',\n ])\ndiff --git a/src/ipa/mali-c55/ipa_context.h b/src/ipa/mali-c55/ipa_context.h\nindex 73a7cd78..766acc42 100644\n--- a/src/ipa/mali-c55/ipa_context.h\n+++ b/src/ipa/mali-c55/ipa_context.h\n@@ -30,6 +30,7 @@ struct IPASessionConfiguration {\n \tstruct {\n \t\tBayerFormat::Order bayerOrder;\n \t\tutils::Duration lineDuration;\n+\t\tuint32_t blackLevel;\n \t} sensor;\n };\n \ndiff --git a/src/ipa/mali-c55/mali-c55.cpp b/src/ipa/mali-c55/mali-c55.cpp\nindex 55ef7b87..57ddec18 100644\n--- a/src/ipa/mali-c55/mali-c55.cpp\n+++ b/src/ipa/mali-c55/mali-c55.cpp\n@@ -193,6 +193,16 @@ void IPAMaliC55::updateSessionConfiguration(const IPACameraSensorInfo &info,\n \tcontext_.configuration.agc.defaultExposure = defExposure;\n \tcontext_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);\n \tcontext_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);\n+\n+\tif (camHelper_->blackLevel().has_value()) {\n+\t\t/*\n+\t\t * The black level from CameraSensorHelper is a 16-bit value.\n+\t\t * The Mali-C55 ISP expects 20-bit settings, so we shift it to\n+\t\t * the appropriate width\n+\t\t */\n+\t\tcontext_.configuration.sensor.blackLevel =\n+\t\t\tcamHelper_->blackLevel().value() << 4;\n+\t}\n }\n \n void IPAMaliC55::updateControls(const IPACameraSensorInfo &sensorInfo,\n", "prefixes": [ "v3", "08/11" ] }