[{"id":26373,"web_url":"https://patchwork.libcamera.org/comment/26373/","msgid":"<167508482743.42371.13196141218005958056@Monstersaurus>","date":"2023-01-30T13:20:27","subject":"Re: [libcamera-devel] [PATCH v3 1/5] ipa: raspberrypi: Generalise\n\tstatistics","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck via libcamera-devel (2022-12-13 11:48:32)\n> At present, the controller algorithms access the bcm2835_isp_stats structure,\n> which is hardware specific. It would be desirable to abstract out the statistics\n> structure to remove hardware specific headers from the algorithms source files.\n> \n> Define a new templated RegionStats class that encompasses region based\n> statistics generated by the ISP. For the VC4 ISP, this can be used to hold\n> RGB sums and focus FoM values.\n> \n> Define a new Statistics structure that holds all the VC4 ISP statistics output.\n> This includes AGC histograms, AGC/AWB region sums and focus FoM regions.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/ipa/raspberrypi/controller/region_stats.h | 123 ++++++++++++++++++\n>  src/ipa/raspberrypi/statistics.h              |  70 ++++++++++\n>  2 files changed, 193 insertions(+)\n>  create mode 100644 src/ipa/raspberrypi/controller/region_stats.h\n>  create mode 100644 src/ipa/raspberrypi/statistics.h\n> \n> diff --git a/src/ipa/raspberrypi/controller/region_stats.h b/src/ipa/raspberrypi/controller/region_stats.h\n> new file mode 100644\n> index 000000000000..9aaf3a58a6f7\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/region_stats.h\n> @@ -0,0 +1,123 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2022, Raspberry Pi Ltd\n> + *\n> + * region_stats.h - Raspberry Pi region based statistics container\n> + */\n> +#pragma once\n> +\n> +#include <array>\n> +#include <stdint.h>\n> +#include <vector>\n> +\n> +#include <libcamera/geometry.h>\n> +\n> +namespace RPiController {\n> +\n> +template<typename T>\n> +class RegionStats\n> +{\n> +public:\n> +       struct Region {\n> +               T val;\n> +               uint32_t counted;\n> +               uint32_t uncounted;\n> +       };\n> +\n> +       RegionStats()\n> +               : size_({}), numFloating_(0), default_({})\n> +       {\n> +       }\n> +\n> +       void init(const libcamera::Size &size, unsigned int numFloating = 0)\n> +       {\n> +               size_ = size;\n> +               numFloating_ = numFloating;\n> +               regions_.clear();\n> +               regions_.resize(size_.width * size_.height + numFloating_);\n> +       }\n> +\n> +       void init(unsigned int num)\n> +       {\n> +               size_ = libcamera::Size(num, 1);\n> +               numFloating_ = 0;\n> +               regions_.clear();\n> +               regions_.resize(num);\n> +       }\n> +\n> +       unsigned int numRegions() const\n> +       {\n> +               return size_.width * size_.height;\n> +       }\n> +\n> +       unsigned int numFloatingRegions() const\n> +       {\n> +               return numFloating_;\n> +       }\n> +\n> +       libcamera::Size size() const\n> +       {\n> +               return size_;\n> +       }\n> +\n> +       void set(unsigned int index, const Region &region)\n> +       {\n> +               if (index >= numRegions())\n> +                       return;\n> +               set_(index, region);\n> +       }\n> +\n> +       void set(const libcamera::Point &pos, const Region &region)\n> +       {\n> +               set(pos.y * size_.width + pos.x, region);\n> +       }\n> +\n> +       void setFloating(unsigned int index, const Region &region)\n> +       {\n> +               if (index >= numFloatingRegions())\n> +                       return;\n> +               set(numRegions() + index, region);\n> +       }\n> +\n> +       const Region &get(unsigned int index) const\n> +       {\n> +               if (index >= numRegions())\n> +                       return default_;\n> +               return get_(index);\n> +       }\n> +\n> +       const T &get(const libcamera::Point &pos) const\n> +       {\n> +               return get(pos.y * size_.width + pos.x);\n> +       }\n> +\n> +       const T &getFloating(unsigned int index) const\n> +       {\n> +               if (index >= numFloatingRegions())\n> +                       return default_;\n> +               return get_(numRegions() + index);\n> +       }\n> +\n> +       typename std::vector<Region>::iterator begin() { return regions_.begin(); }\n> +       typename std::vector<Region>::iterator end() { return regions_.end(); }\n> +       typename std::vector<Region>::const_iterator begin() const { return regions_.begin(); }\n> +       typename std::vector<Region>::const_iterator end() const { return regions_.end(); }\n> +\n> +private:\n> +       void set_(unsigned int index, const Region &region)\n> +       {\n> +               regions_[index] = region;\n> +       }\n> +\n> +       const Region &get_(unsigned int index) const\n> +       {\n> +               return regions_[index];\n> +       }\n> +\n> +       libcamera::Size size_;\n> +       unsigned int numFloating_;\n> +       std::vector<Region> regions_;\n> +       Region default_;\n> +};\n> +\n> +} /* namespace RPiController */\n> diff --git a/src/ipa/raspberrypi/statistics.h b/src/ipa/raspberrypi/statistics.h\n> new file mode 100644\n> index 000000000000..a762bf3d41aa\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/statistics.h\n> @@ -0,0 +1,70 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2022, Raspberry Pi Ltd\n> + *\n> + * statistics.h - Raspberry Pi generic statistics structure\n> + */\n> +#pragma once\n> +\n> +#include <memory>\n> +#include <stdint.h>\n> +#include <vector>\n> +\n> +#include \"histogram.h\"\n> +#include \"region_stats.h\"\n> +\n> +namespace RPiController {\n> +\n> +struct RgbySums {\n> +       RgbySums(uint64_t _rSum = 0, uint64_t _gSum = 0, uint64_t _bSum = 0, uint64_t _ySum = 0)\n> +               : rSum(_rSum), gSum(_gSum), bSum(_bSum), ySum(_ySum)\n> +       {\n> +       }\n> +       uint64_t rSum;\n> +       uint64_t gSum;\n> +       uint64_t bSum;\n> +       uint64_t ySum;\n> +};\n> +\n> +using RgbyRegions = RegionStats<RgbySums>;\n> +using FocusRegions = RegionStats<uint64_t>;\n> +\n> +struct Statistics {\n> +       /*\n> +        * Positioning of the AGC statistics gathering in the pipeline:\n> +        * Pre-WB correction or post-WB correction.\n> +        * Assume this is post-LSC.\n> +        */\n> +       enum class AgcStatsPos { PreWb, PostWb };\n> +       const AgcStatsPos agcStatsPos;\n> +\n> +       /*\n> +        * Positioning of the AWB/ALSC statistics gathering in the pipeline:\n> +        * Pre-LSC or post-LSC.\n> +        */\n> +       enum class ColourStatsPos { PreLsc, PostLsc };\n> +       const ColourStatsPos colourStatsPos;\n> +\n> +       Statistics(AgcStatsPos a, ColourStatsPos c)\n> +               : agcStatsPos(a), colourStatsPos(c)\n> +       {\n> +       }\n> +\n> +       /* Histogram statistics. Not all histograms may be populated! */\n> +       Histogram rHist;\n> +       Histogram gHist;\n> +       Histogram bHist;\n> +       Histogram yHist;\n> +\n> +       /* Row sums for flicker avoidance. */\n> +       std::vector<RgbySums> rowSums;\n> +\n> +       /* Region based colour sums. */\n> +       RgbyRegions agcRegions;\n> +       RgbyRegions awbRegions;\n> +\n> +       /* Region based focus FoM. */\n> +       FocusRegions focusRegions;\n> +};\n> +\n> +} /* namespace RPiController */\n> -- \n> 2.25.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 956DBBDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 30 Jan 2023 13:33:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F3372625E4;\n\tMon, 30 Jan 2023 14:33:04 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 943D260482\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Jan 2023 14:33:03 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 198128B8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Jan 2023 14:33:03 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1675085585;\n\tbh=qPDBrhUyeElXHQTORaIKW57jrU3GimP+hAm/gDxDJdE=;\n\th=In-Reply-To:References:To:Date:Resent-From:Resent-To:Subject:\n\tList-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:\n\tList-Subscribe:From:Reply-To:Resent-Date:From;\n\tb=xMxB9VRTYEC6B4OPWZ3gYssN8RHvz874j8n5uK/NK1HwBnoVVuw4naRr/waw6Q9gz\n\taEJpZfkk/tSBcA0QWU5Umh9N7HLQVYsxLc68HM/9C8v8f5Ho3AHp3ewaI18Uc1+vzl\n\t9nAQKrVhjgXlRCmn91V06EGneU9El/lV/Gy1CjOtC5+CPxRepLy7phNfNZ0higNmts\n\tzseq7VMSy0b63b/stUWlXGzKZ9sPwMt8Y02/OMj+MEQliX2XGMzaz0l3FUsdUC6ZAh\n\tdQ3A2imU4pU/uKF/H2nGlOZ67UFvR8znVpKNxfQsrgkpPczLhrZCkf1UHFJkd2S6eP\n\t+4GKC/jDKuGXw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1675085583;\n\tbh=qPDBrhUyeElXHQTORaIKW57jrU3GimP+hAm/gDxDJdE=;\n\th=In-Reply-To:References:Subject:From:To:Date:Resent-From:Resent-To:\n\tFrom;\n\tb=ltKal19KFPr7eW+Xr5Z+2CyVyn+1ZTRV4x18dvkwLf1IZNppkBloRiaJOiMORxb7h\n\t3Hta1Rz4cWaKXqJ7rhUv5OLiR45q/ENmP8RZGTvTWtwGU/PBE19oCdVIEJifA7FFG8\n\tXCsOoay58Pqc2oCXE+YS/aqynImlTYdFI+8mDQJM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ltKal19K\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20221213114836.15473-2-naush@raspberrypi.com>","References":"<20221213114836.15473-1-naush@raspberrypi.com>\n\t<20221213114836.15473-2-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 30 Jan 2023 13:20:27 +0000","Message-ID":"<167508482743.42371.13196141218005958056@Monstersaurus>","User-Agent":"alot/0.10","Resent-From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Resent-To":"libcamera-devel@lists.libcamera.org","Subject":"Re: [libcamera-devel] [PATCH v3 1/5] ipa: raspberrypi: Generalise\n\tstatistics","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>","Resent-Message-Id":"<20230130133304.F3372625E4@lancelot.ideasonboard.com>","Resent-Date":"Mon, 30 Jan 2023 14:33:04 +0100 (CET)"}}]