[{"id":25893,"web_url":"https://patchwork.libcamera.org/comment/25893/","msgid":"<CAHW6GYL3OCJXga1Rus5uagpBN=OkiCYzxpt3o2KxSHxpoYOjjQ@mail.gmail.com>","date":"2022-11-24T12:51:01","subject":"Re: [libcamera-devel] [PATCH v2 1/5] ipa: raspberrypi: Generalise\n\tstatistics","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for the update!\n\nOn Thu, 24 Nov 2022 at 10:38, Naushir Patuck via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\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 hostograms, AGC/AWB region sums and focus FoM regions.\n\ns/hostograms/histograms/\n\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nI think I was happy with this before, and I'm still happy with the new\nversion (typo notwithstanding)!\n\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nThanks\nDavid\n\nDavid\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 51D06BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Nov 2022 12:51:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B20B863313;\n\tThu, 24 Nov 2022 13:51:16 +0100 (CET)","from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com\n\t[IPv6:2607:f8b0:4864:20::42a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 412B9632EA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Nov 2022 13:51:14 +0100 (CET)","by mail-pf1-x42a.google.com with SMTP id d192so1604198pfd.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Nov 2022 04:51:14 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669294276;\n\tbh=CGwMgXoOExZaPnQ+LhhkaRlCnnG0YfY7pu3CxsLWWwY=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=qXeILQAyhwyJfQScfH2O0jrHly/w6A3bvbONkuGyUYOW9qYvkeZsRuGS/H2LAZO2u\n\tuiHDJ2WuogH8DmML4P8DNpilD1SyvkDEyvBoZF6VglujM94Bn7BPMbD8g1N5tEQP45\n\tVmN5YBU+T/94rdge31gu6GOwHx0d/ubdTbSy6ecntv6rpsudXU+gqGBHOb4AMMhruZ\n\tUzUsPHIDo+l5RMvY1n9rCX6S3rmP/giNFGg0M0a7kVFqrYvYY/O0GBYe9bnRtofLma\n\tO+3yuSVAuDzDzFQcJyKwHJyxAULafSMtDod9vSKoGjvE9AOLwSCZqwGz3Od5noIL5d\n\tbnF7wfbKz2Svw==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=ywp1e7caY058j8+XtEVrgHG821UYo+ZqEC0hE+9PlAg=;\n\tb=q9Zfbx9V68r1RKq8D41B5E8RzjeqfJOW18cF5xXardo9zhLR+W2Un1IyO0usG/8Voh\n\t9uVHrUrjQm9H2nDPYw80huRMvFO5MqN4ECIR7wu0a3vmgjpp87mYlCkZOAuSB/OSQ1wQ\n\tZEz+R/Aa37Udr/22qODIAX9DfVxrPltUL8faBC2ONB35VjdrWb4kfimGXRl/25LMUZu5\n\tTXTiz56RzhROW/o10+YkMIYYLXqQAnI5UJdEsChFRKbws1VAH8y4VqxSW3GNQMA3Oi2u\n\tc/UVypT+bNQ/uRW9w48AVbahI6+1XuYCOSxDa2vA75LTUFR/Zr7Svs5tlV6dmLCi+1J9\n\t+11g=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"q9Zfbx9V\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=ywp1e7caY058j8+XtEVrgHG821UYo+ZqEC0hE+9PlAg=;\n\tb=hKxIbXbj0Fpq8tO3F/4OpOyvebKtgfN9kPsGU85FAJwRklgwaiOpktKyWA8C/lbx9p\n\t5S0IDhNr6BNi6s2OiPxFY5lkYUbfRPztIg48wAOdNeI5D5Mfp0WJGewe5qpAlkZnKq0F\n\tLCoby8mIWZGtfWnp0YUU1wPVjOXT6x974hfKf72S0TRg7EMJ5KNNWGof2VazjrTcsiEB\n\t8KDAzhYHsZ3HH1eml8bkaY/khbFT6P1LZMbnyKb2nrJ88zZ7UQY3UZjJ/pwbeb6oj8Ee\n\t22kpytmfz8unXci54IUUEC+70GStfVTYwmWzOXFr/8N323d98+EcET7ayHPKumJu3DfN\n\tqPyQ==","X-Gm-Message-State":"ANoB5pl0Uyq9HIR94HrIEN8o4EdA5HmXM/ns2wuUNxwThBVJEEUbdTmr\n\tUeTmISfT4Ehz1XYGhXVLDcFPOMXp4YWXryz1LZM0Jg==","X-Google-Smtp-Source":"AA0mqf5O9TT0fOtEjunh6VUfPh+Xmaq8RvCinq081zIMZwI9/QCgxP4tl0pwxQ5WqWTm/o6CdxTsfnNdRHsPdkgzH6g=","X-Received":"by 2002:a63:4944:0:b0:46f:ec9f:dcb0 with SMTP id\n\ty4-20020a634944000000b0046fec9fdcb0mr14193007pgk.202.1669294272420;\n\tThu, 24 Nov 2022 04:51:12 -0800 (PST)","MIME-Version":"1.0","References":"<20221124103832.6172-1-naush@raspberrypi.com>\n\t<20221124103832.6172-2-naush@raspberrypi.com>","In-Reply-To":"<20221124103832.6172-2-naush@raspberrypi.com>","Date":"Thu, 24 Nov 2022 12:51:01 +0000","Message-ID":"<CAHW6GYL3OCJXga1Rus5uagpBN=OkiCYzxpt3o2KxSHxpoYOjjQ@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v2 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":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]