{"id":17996,"url":"https://patchwork.libcamera.org/api/1.1/patches/17996/?format=json","web_url":"https://patchwork.libcamera.org/patch/17996/","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":"<20221213114836.15473-2-naush@raspberrypi.com>","date":"2022-12-13T11:48:32","name":"[libcamera-devel,v3,1/5] ipa: raspberrypi: Generalise statistics","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"82408ecd3a724d09b9e2c13f5fcd096c9929ce6d","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17996/mbox/","series":[{"id":3670,"url":"https://patchwork.libcamera.org/api/1.1/series/3670/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3670","date":"2022-12-13T11:48:31","name":"Raspberry Pi: Generalise statistics","version":3,"mbox":"https://patchwork.libcamera.org/series/3670/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17996/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17996/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 B8A91C328D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Dec 2022 11:48:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A809963360;\n\tTue, 13 Dec 2022 12:48:50 +0100 (CET)","from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com\n\t[IPv6:2a00:1450:4864:20::42f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 66F3B63354\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Dec 2022 12:48:48 +0100 (CET)","by mail-wr1-x42f.google.com with SMTP id o5so15333346wrm.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Dec 2022 03:48:48 -0800 (PST)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tj8-20020a5d4528000000b0024287d9d4a8sm11574541wra.74.2022.12.13.03.48.47\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 13 Dec 2022 03:48:47 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1670932130;\n\tbh=VUsG/0hDy7HJda57ZvAicpnKqWLEc8nGuOSYSLpEzLQ=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=s8SmKqwyG2NuSlwsFyTGcGzfwY2XCfp+gMFxoTo+bOYPmF2Tx7twkX63/N/XljQs3\n\tHWBQdrGY2M9pwl42FhCDSJ0kIrwasRmD+fqSxuKhTfpZP9JHWlYAOr+oHfBNxa3cC1\n\tPC8PizSIuCmsDAt7m2AIHeJSRIpf0c2t8BJM8o+5vJMS0Bz/1IGFhUOqyFfEi6xQTl\n\tz5+XWf2BEWSfrbgFyY3j0ZtXjJ27YxQHGgdMlLeVj2KxmTueVFL8yBVOnilox6NTCH\n\t5DBHezje+TReU2TFu52FKAcI7agvwUqgO4aMFOpjnrKg0ya6DjQpASMMLmgCceMuWf\n\tnNJ9Dr/IYaHZQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=UzGll8qwMNu1ew3kASktX78GxzRx0n9eVyC6tPz+/7A=;\n\tb=j1thFQVnggX0tyOFdDiaD67k8ZG0YCXNMI/LGLjcGMqRTEdQNkKKE9XhUgRplST+q/\n\ttVjavjlb8Y8K8fOsLqKbRSXNk5tZ+vUkC2B/CfoFLiwD/GQP9JUo+T0tKJcGr5xFkEtA\n\tczomtR1jLZo3sX96ifn/pIXKKEfGIYPWNe/18bjopHubvyHUHiVLFB4XYZSGmfJqO1L/\n\tWmj36YxqzHJWnDVwwVE4637frXlg2R1p1eFo6a8huJR5rXD5MLrluEzbd+dLSUZfyg+/\n\t3YzkTkNBfEZbMRtVKlLq80++xxq7oJXo1IN9NkxKIea40su8UUuKNCC4Jwc7k0Il74CJ\n\tI3LA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"j1thFQVn\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=UzGll8qwMNu1ew3kASktX78GxzRx0n9eVyC6tPz+/7A=;\n\tb=4lQgn9PT1mvKwL5D+joWorLFo5cXnGiWgu4L5Apqj640KB1X355HkHMvMeywSIEDBJ\n\t3V8EOn9fR7G6rYh6TqnQmQUoUEpmubIo7GWDayOcnUi8OLIsvOaZ8tcwrSFrEn4PgtJy\n\tbSTZnXmWYPmuy+0nUTU80wtHcXiL+6wumHRvBIoIqsMuCTKy2eHYRarb21+9ncninsdb\n\t0S1FCvwL+6dICjfhri94+YV5ruGkSWOYIk0EZkPbqV1dn5mmmxT8lxQ3Zdku/STrrEbK\n\tjGSmc1JRT75BzEKpT5Cd99ZY8zraQTcty2bn45LLIUncIB+S2y3vItvc0M7wxTTRsPog\n\tBFpQ==","X-Gm-Message-State":"ANoB5plpXkqB4nLt76isgJ4m1hGCPY2hFCfa/r2Yo7sFdgABVc0sTzlN\n\tNFVqiTCYSsQRpqMLRMtPfw9nUvrPIabPKncO","X-Google-Smtp-Source":"AA0mqf4kdmOCIXI25SGf8+96JF5RuIQmuhCRCPO4Bh6mpZ/uPEEnrXp6jJBPAa2LNAy8CuE2roraIQ==","X-Received":"by 2002:adf:dfc2:0:b0:242:5877:1ebc with SMTP id\n\tq2-20020adfdfc2000000b0024258771ebcmr12117212wrn.33.1670932127757; \n\tTue, 13 Dec 2022 03:48:47 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 13 Dec 2022 11:48:32 +0000","Message-Id":"<20221213114836.15473-2-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20221213114836.15473-1-naush@raspberrypi.com>","References":"<20221213114836.15473-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"At present, the controller algorithms access the bcm2835_isp_stats structure,\nwhich is hardware specific. It would be desirable to abstract out the statistics\nstructure to remove hardware specific headers from the algorithms source files.\n\nDefine a new templated RegionStats class that encompasses region based\nstatistics generated by the ISP. For the VC4 ISP, this can be used to hold\nRGB sums and focus FoM values.\n\nDefine a new Statistics structure that holds all the VC4 ISP statistics output.\nThis includes AGC histograms, AGC/AWB region sums and focus FoM regions.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\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","diff":"diff --git a/src/ipa/raspberrypi/controller/region_stats.h b/src/ipa/raspberrypi/controller/region_stats.h\nnew file mode 100644\nindex 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+\tstruct Region {\n+\t\tT val;\n+\t\tuint32_t counted;\n+\t\tuint32_t uncounted;\n+\t};\n+\n+\tRegionStats()\n+\t\t: size_({}), numFloating_(0), default_({})\n+\t{\n+\t}\n+\n+\tvoid init(const libcamera::Size &size, unsigned int numFloating = 0)\n+\t{\n+\t\tsize_ = size;\n+\t\tnumFloating_ = numFloating;\n+\t\tregions_.clear();\n+\t\tregions_.resize(size_.width * size_.height + numFloating_);\n+\t}\n+\n+\tvoid init(unsigned int num)\n+\t{\n+\t\tsize_ = libcamera::Size(num, 1);\n+\t\tnumFloating_ = 0;\n+\t\tregions_.clear();\n+\t\tregions_.resize(num);\n+\t}\n+\n+\tunsigned int numRegions() const\n+\t{\n+\t\treturn size_.width * size_.height;\n+\t}\n+\n+\tunsigned int numFloatingRegions() const\n+\t{\n+\t\treturn numFloating_;\n+\t}\n+\n+\tlibcamera::Size size() const\n+\t{\n+\t\treturn size_;\n+\t}\n+\n+\tvoid set(unsigned int index, const Region &region)\n+\t{\n+\t\tif (index >= numRegions())\n+\t\t\treturn;\n+\t\tset_(index, region);\n+\t}\n+\n+\tvoid set(const libcamera::Point &pos, const Region &region)\n+\t{\n+\t\tset(pos.y * size_.width + pos.x, region);\n+\t}\n+\n+\tvoid setFloating(unsigned int index, const Region &region)\n+\t{\n+\t\tif (index >= numFloatingRegions())\n+\t\t\treturn;\n+\t\tset(numRegions() + index, region);\n+\t}\n+\n+\tconst Region &get(unsigned int index) const\n+\t{\n+\t\tif (index >= numRegions())\n+\t\t\treturn default_;\n+\t\treturn get_(index);\n+\t}\n+\n+\tconst T &get(const libcamera::Point &pos) const\n+\t{\n+\t\treturn get(pos.y * size_.width + pos.x);\n+\t}\n+\n+\tconst T &getFloating(unsigned int index) const\n+\t{\n+\t\tif (index >= numFloatingRegions())\n+\t\t\treturn default_;\n+\t\treturn get_(numRegions() + index);\n+\t}\n+\n+\ttypename std::vector<Region>::iterator begin() { return regions_.begin(); }\n+\ttypename std::vector<Region>::iterator end() { return regions_.end(); }\n+\ttypename std::vector<Region>::const_iterator begin() const { return regions_.begin(); }\n+\ttypename std::vector<Region>::const_iterator end() const { return regions_.end(); }\n+\n+private:\n+\tvoid set_(unsigned int index, const Region &region)\n+\t{\n+\t\tregions_[index] = region;\n+\t}\n+\n+\tconst Region &get_(unsigned int index) const\n+\t{\n+\t\treturn regions_[index];\n+\t}\n+\n+\tlibcamera::Size size_;\n+\tunsigned int numFloating_;\n+\tstd::vector<Region> regions_;\n+\tRegion default_;\n+};\n+\n+} /* namespace RPiController */\ndiff --git a/src/ipa/raspberrypi/statistics.h b/src/ipa/raspberrypi/statistics.h\nnew file mode 100644\nindex 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+\tRgbySums(uint64_t _rSum = 0, uint64_t _gSum = 0, uint64_t _bSum = 0, uint64_t _ySum = 0)\n+\t\t: rSum(_rSum), gSum(_gSum), bSum(_bSum), ySum(_ySum)\n+\t{\n+\t}\n+\tuint64_t rSum;\n+\tuint64_t gSum;\n+\tuint64_t bSum;\n+\tuint64_t ySum;\n+};\n+\n+using RgbyRegions = RegionStats<RgbySums>;\n+using FocusRegions = RegionStats<uint64_t>;\n+\n+struct Statistics {\n+\t/*\n+\t * Positioning of the AGC statistics gathering in the pipeline:\n+\t * Pre-WB correction or post-WB correction.\n+\t * Assume this is post-LSC.\n+\t */\n+\tenum class AgcStatsPos { PreWb, PostWb };\n+\tconst AgcStatsPos agcStatsPos;\n+\n+\t/*\n+\t * Positioning of the AWB/ALSC statistics gathering in the pipeline:\n+\t * Pre-LSC or post-LSC.\n+\t */\n+\tenum class ColourStatsPos { PreLsc, PostLsc };\n+\tconst ColourStatsPos colourStatsPos;\n+\n+\tStatistics(AgcStatsPos a, ColourStatsPos c)\n+\t\t: agcStatsPos(a), colourStatsPos(c)\n+\t{\n+\t}\n+\n+\t/* Histogram statistics. Not all histograms may be populated! */\n+\tHistogram rHist;\n+\tHistogram gHist;\n+\tHistogram bHist;\n+\tHistogram yHist;\n+\n+\t/* Row sums for flicker avoidance. */\n+\tstd::vector<RgbySums> rowSums;\n+\n+\t/* Region based colour sums. */\n+\tRgbyRegions agcRegions;\n+\tRgbyRegions awbRegions;\n+\n+\t/* Region based focus FoM. */\n+\tFocusRegions focusRegions;\n+};\n+\n+} /* namespace RPiController */\n","prefixes":["libcamera-devel","v3","1/5"]}