[{"id":31669,"web_url":"https://patchwork.libcamera.org/comment/31669/","msgid":"<172850591375.532453.4892910919335199508@ping.linuxembedded.co.uk>","date":"2024-10-09T20:31:53","subject":"Re: [PATCH v2 06/10] ipa: mali-c55: Add BLC Algorithm","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Daniel Scally (2024-07-09 15:49:46)\n> From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> \n> Add a Black Level Correction algorithm.\n> \n> Acked-by: Nayden Kanchev  <nayden.kanchev@arm.com>\n> Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> ---\n> Changes in v2:\n> \n>         - Use the union rather than reinterpret_cast<>() to abstract the block\n> \n>  src/ipa/mali-c55/algorithms/blc.cpp     | 121 ++++++++++++++++++++++++\n>  src/ipa/mali-c55/algorithms/blc.h       |  40 ++++++++\n>  src/ipa/mali-c55/algorithms/meson.build |   1 +\n>  3 files changed, 162 insertions(+)\n>  create mode 100644 src/ipa/mali-c55/algorithms/blc.cpp\n>  create mode 100644 src/ipa/mali-c55/algorithms/blc.h\n> \n> diff --git a/src/ipa/mali-c55/algorithms/blc.cpp b/src/ipa/mali-c55/algorithms/blc.cpp\n> new file mode 100644\n> index 00000000..aebb9dc4\n> --- /dev/null\n> +++ b/src/ipa/mali-c55/algorithms/blc.cpp\n> @@ -0,0 +1,121 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2021-2022, Ideas On Board\n\nPerhaps a refresh on dates...\n\n> + *\n> + * blc.cpp - Mali-C55 sensor offset (black level) correction\n\nAnd drop blc.cpp\n\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\nWhat's todo here ? Lets do it or remove it...\n\n> + */\n> +\n> +LOG_DEFINE_CATEGORY(MaliC55Blc)\n> +\n> +BlackLevelCorrection::BlackLevelCorrection()\n> +       : tuningParameters_(false)\n> +{\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::init\n> + */\n> +int BlackLevelCorrection::init([[maybe_unused]] IPAContext &context,\n> +                              const YamlObject &tuningData)\n> +{\n> +       offset00 = tuningData[\"offset00\"].get<uint32_t>(256);\n> +       offset01 = tuningData[\"offset01\"].get<uint32_t>(256);\n> +       offset10 = tuningData[\"offset10\"].get<uint32_t>(256);\n> +       offset11 = tuningData[\"offset11\"].get<uint32_t>(256);\n> +\n> +       if (offset00 > kMaxOffset || offset01 > kMaxOffset ||\n> +           offset10 > kMaxOffset || offset11 > kMaxOffset) {\n> +               LOG(MaliC55Blc, Error) << \"Invalid black level offsets\";\n> +               return -EINVAL;\n> +       }\n> +\n\nI think in here we can also check/read a black level from the\nCameraSensorHelper, but take precedence from the tuning file if it's\npresent.\n\n\n> +       tuningParameters_ = true;\n> +\n> +       LOG(MaliC55Blc, Debug)\n> +               << \"Black levels: 00 \" << offset00 << \", 01 \" << offset01\n> +               << \", 10 \" << offset10 << \", 11 \" << offset11;\n> +\n> +       return 0;\n> +}\n> +\n> +/**\n> + * \\copydoc libcamera::ipa::Algorithm::prepare\n> + */\n> +void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,\n> +                                  const uint32_t frame,\n> +                                  [[maybe_unused]] IPAFrameContext &frameContext,\n> +                                  mali_c55_params_buffer *params)\n> +{\n> +       mali_c55_params_block block;\n> +       block.data = &params->data[params->total_size];\n> +\n> +       if (frame > 0)\n> +               return;\n> +\n> +       if (!tuningParameters_)\n> +               return;\n> +\n> +       block.header->type = MALI_C55_PARAM_BLOCK_SENSOR_OFFS;\n> +       block.header->enabled = true;\n> +       block.header->size = sizeof(mali_c55_params_sensor_off_preshading);\n> +\n> +       block.sensor_offs->chan00 = offset00;\n> +       block.sensor_offs->chan01 = offset01;\n> +       block.sensor_offs->chan10 = offset10;\n> +       block.sensor_offs->chan11 = offset11;\n> +\n> +       params->total_size += block.header->size;\n> +}\n> +\n> +void BlackLevelCorrection::process([[maybe_unused]] IPAContext &context,\n> +                                  [[maybe_unused]] const uint32_t frame,\n> +                                  [[maybe_unused]] IPAFrameContext &frameContext,\n> +                                  [[maybe_unused]] const mali_c55_stats_buffer *stats,\n> +                                  ControlList &metadata)\n> +{\n> +       /*\n> +        * Black Level Offsets in tuning data need to be 20-bit, whereas the\n> +        * metadata expects values from a 16-bit range. Right-shift to remove\n> +        * the 4 least significant bits.\n> +        *\n> +        * The black levels should be reported in the order R, Gr, Gb, B. We\n> +        * ignore that here given we're using matching values so far, but it\n> +        * would be safer to check the sensor's bayer order.\n> +        *\n> +        * \\todo Account for bayer order.\n> +        */\n> +       metadata.set(controls::SensorBlackLevels, {\n> +               static_cast<int32_t>(offset00 >> 4),\n> +               static_cast<int32_t>(offset01 >> 4),\n> +               static_cast<int32_t>(offset10 >> 4),\n> +               static_cast<int32_t>(offset11 >> 4),\n> +       });\n> +}\n> +\n> +REGISTER_IPA_ALGORITHM(BlackLevelCorrection, \"BlackLevelCorrection\")\n> +\n> +} /* namespace ipa::mali_c55::algorithms */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/mali-c55/algorithms/blc.h b/src/ipa/mali-c55/algorithms/blc.h\n> new file mode 100644\n> index 00000000..e73056e0\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\nSounds old ;-)\n\n> + *\n> + * blc.h - Mali-C55 sensor offset (black level) correction\n\nI think we've dropped adding filenames perhaps since this was started,\nas they just get out of date, and don't add value.\n\n\nBut otherwise, this is a pretty simplistic algo module.\n\nWith updates where helpful,\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\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> +       BlackLevelCorrection();\n> +       ~BlackLevelCorrection() = default;\n> +\n> +       int init(IPAContext &context, const YamlObject &tuningData) override;\n> +       void prepare(IPAContext &context, const uint32_t frame,\n> +                    IPAFrameContext &frameContext,\n> +                    mali_c55_params_buffer *params) override;\n> +       void process(IPAContext &context, const uint32_t frame,\n> +                    IPAFrameContext &frameContext,\n> +                    const mali_c55_stats_buffer *stats,\n> +                    ControlList &metadata) override;\n> +\n> +private:\n> +       static constexpr uint32_t kMaxOffset = 0xfffff;\n> +\n> +       bool tuningParameters_;\n> +       uint32_t offset00;\n> +       uint32_t offset01;\n> +       uint32_t offset10;\n> +       uint32_t offset11;\n> +};\n> +\n> +} /* namespace ipa::mali_c55::algorithms */\n> +} /* namespace libcamera */\n> diff --git a/src/ipa/mali-c55/algorithms/meson.build b/src/ipa/mali-c55/algorithms/meson.build\n> index 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> -- \n> 2.34.1\n>","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 3D3A0C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  9 Oct 2024 20:32:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 51485618C9;\n\tWed,  9 Oct 2024 22:31:59 +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 62E26618C5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  9 Oct 2024 22:31:57 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 938B52EC;\n\tWed,  9 Oct 2024 22:30:19 +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=\"gzuxb/V1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728505819;\n\tbh=WUXg3yY+WP35Jidp4TIQVvFrL8o9HGW1LyYs99TY0KA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=gzuxb/V1CjGCYk6krC4V7jqPpe9xMsCJe7KDyjUUSdphpexr3CkVqaQ34SWVb9HN8\n\tWC7yga63RUbqqm5N8Aj7dpspVM8BLc3Ga82v+hsLFQNKIvltNAuRFw3iTmcFmy+6G/\n\tSHUJNaiIQj65uqyN05KZcf1qg+pwLnVpbxlzqGlw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240709144950.3277837-7-dan.scally@ideasonboard.com>","References":"<20240709144950.3277837-1-dan.scally@ideasonboard.com>\n\t<20240709144950.3277837-7-dan.scally@ideasonboard.com>","Subject":"Re: [PATCH v2 06/10] ipa: mali-c55: Add BLC Algorithm","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tNayden Kanchev <nayden.kanchev@arm.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 09 Oct 2024 21:31:53 +0100","Message-ID":"<172850591375.532453.4892910919335199508@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]