From patchwork Tue Nov 22 11:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17830 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 5E1A7BE08B for ; Tue, 22 Nov 2022 11:22:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 11081603CE; Tue, 22 Nov 2022 12:22:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669116149; bh=YmRgADhS3s4kSwmcHgSScFX3tgmguW1qArHN7RPr/5I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uW5DALLZOwCBfTk4Dknuq0AonVD3UIuCFFHhcwTJLYisg9zHN+yfq0GOZXds/AkHG OtYBJ2T+RjKrXQBmwkKvkc6uhfWfXbo9/nkv3T90O3Dz/bKSfDgESHufE+gvbUJC84 9NBtbthgE45RCCAt0zGsasbklMq2O811lCtz4nlzgRAlAiVi8Z2djfBIBEMRVvESn/ CY+6j6CpNaA8tHMQl1Z+GN7dS0+UecU2O3HqlQM6D38UiJI9U3AYgvc+MDjMB9y35h PUrswJnodIQDHOumRFczvH9orUldofnoRjAlhuoTSvx9gwLVLJ7d1RSKqby15Hef7N j5+MPwiH55Xdg== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3551561F2B for ; Tue, 22 Nov 2022 12:22:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="phmvlgWa"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id e11so11304781wru.8 for ; Tue, 22 Nov 2022 03:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=84I5pgUTPV442TRgUl4HrW7AgpbIpJKmlWRibV0h/I4=; b=phmvlgWah2hV1vjsEKp5ZfZlNGpLiaawYE1R9o4/MHB0p7E4+p22zWwVfrnfaLkmM4 PO8sHCdvg3n7aN50wk81AHSIJ4ShxhKFPrKlR63W+9ceuqzHILHupoKpO4DQo5PsYxxn 6P/MhoW4NLWBlrf4avbOHB3VzwvgHZXdKO6qR+CvrMDujYe31OuSUS1uByVYTQ7EwoMj 1rVftyaXqbF+0PUStO33EYHutT9Ijw4k3Vq4fkfmQ6IfpNBKWc5XIuoSAoOOUH4/f94N 403RepUHpEfzuhnoRlLOcOLB+goEG8dO+2zZz2vsxzJtzU23+lpfBrfZJIdubZVRMUyY fRdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=84I5pgUTPV442TRgUl4HrW7AgpbIpJKmlWRibV0h/I4=; b=TICtatDBd4jc3jw48Uiyy+mMLPy+gRRquanLO9QhiOz1gZM2BRl1weykGDoSg+I7EC eG8xUlNsRb0mv17YMmCDhVJUo5mqT499b9a9Tu5btqJa8TOdKGqkqFr4JolMYyHKZjFt 4s87z6w2RD6c3fdQimond7qbwOVL/01zok7lIAg9ZYUFpXjXd9KpwRc1WWjRLh976UET Z4+tgwDRHXL8RnimjUBTK0koJDVDVBT1vLgb1cwG/yoyU4kqTKaD3osXfr4WuCWXFm4Z Jzfpl6j74jryTFKWDRF9uYQGBOS9NMpGyNE8nAkYuqSS2Ps9SgQLTdOjWUjx1JgV4b6+ 6z4A== X-Gm-Message-State: ANoB5pnQHKjC8CHaBWmnuZAQQWhMkLd24IRBGbBApGsxNdqNXiSTBARM dXiSYend9bmR0JWQBKh7kiULLlBSK4AWZQ== X-Google-Smtp-Source: AA0mqf6WeZtqpmhakrTBt5+bLFCcjeN3XcRd+2fXR4daE2NtufFNs3t6ZCEN0DGGSJOp3Efg7qz17w== X-Received: by 2002:adf:dc8b:0:b0:22e:2b7:f215 with SMTP id r11-20020adfdc8b000000b0022e02b7f215mr6731651wrj.512.1669116147541; Tue, 22 Nov 2022 03:22:27 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id q125-20020a1c4383000000b003c6cd82596esm21400388wma.43.2022.11.22.03.22.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 03:22:27 -0800 (PST) To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Nov 2022 11:22:20 +0000 Message-Id: <20221122112224.31691-2-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122112224.31691-1-naush@raspberrypi.com> References: <20221122112224.31691-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/5] ipa: raspberrypi: Generalise statistics X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" At present, the controller algorithms access the bcm2835_isp_stats structure, which is hardware specific. It would be desirable to abstract out the statistics structure to remove hardware specific headers from the algorithms source files. Define a new templated RegionStats class that encompasses region based statistics generated by the ISP. For the VC4 ISP, this can be used to hold RGB sums and focus FoM values. Define a new Statistics structure that holds all the VC4 ISP statistics output. This includes AGC hostograms, AGC/AWB region sums and focus FoM regions. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman --- src/ipa/raspberrypi/controller/region_stats.h | 109 ++++++++++++++++++ src/ipa/raspberrypi/statistics.h | 70 +++++++++++ 2 files changed, 179 insertions(+) create mode 100644 src/ipa/raspberrypi/controller/region_stats.h create mode 100644 src/ipa/raspberrypi/statistics.h diff --git a/src/ipa/raspberrypi/controller/region_stats.h b/src/ipa/raspberrypi/controller/region_stats.h new file mode 100644 index 000000000000..8a3453617654 --- /dev/null +++ b/src/ipa/raspberrypi/controller/region_stats.h @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * region_stats.h - Raspberry Pi region based statistics container + */ +#pragma once + +#include +#include +#include + +namespace RPiController { + +template +class RegionStats +{ +public: + RegionStats() + : numRows_(0), numCols_(0), numFloating_(0) + { + } + + void init(unsigned int numRows, unsigned int numCols = 1, unsigned int numFloating = 0) + { + numRows_ = numRows; + numCols_ = numCols; + numFloating_ = numFloating; + regions_.resize(numRows_ * numCols_ + numFloating_); + } + + unsigned int numRegions() const + { + return numRows_ * numCols_; + } + + unsigned int numFloatingRegions() const + { + return numFloating_; + } + + void set(unsigned int index, const T &value, uint32_t counted, uint32_t uncounted) + { + if (index >= numRegions()) + return; + set_(index, value, counted, uncounted); + } + + void set(unsigned int row, unsigned int col, const T &value, uint32_t counted, uint32_t uncounted) + { + set(row * numCols_ + col, value, counted, uncounted); + } + + void setFloating(unsigned int index, const T &value, uint32_t counted, uint32_t uncounted) + { + if (index >= numFloatingRegions()) + return; + set(numRegions() + index, value, counted, uncounted); + } + + const T &get(unsigned int index, uint32_t &counted, uint32_t &uncounted) const + { + counted = uncounted = 0; + if (index >= numRegions()) + return default_; + return get_(index, counted, uncounted); + } + + const T &get(unsigned int row, unsigned int col, uint32_t &counted, uint32_t &uncounted) const + { + return get(row * numCols_ + col, counted, uncounted); + } + + const T &getFloating(unsigned int index, uint32_t &counted, uint32_t &uncounted) const + { + counted = uncounted = 0; + if (index >= numFloatingRegions()) + return default_; + return get_(numRegions() + index, counted, uncounted); + } + +private: + void set_(unsigned int index, const T &value, uint32_t counted, uint32_t uncounted) + { + regions_[index] = { value, counted, uncounted }; + } + + const T &get_(unsigned int index, uint32_t &counted, uint32_t &uncounted) const + { + counted = regions_[index].counted; + uncounted = regions_[index].uncounted; + return regions_[index].value; + } + + unsigned int numRows_; + unsigned int numCols_; + unsigned int numFloating_; + + struct Region { + T value; + uint32_t counted; + uint32_t uncounted; + }; + + std::vector regions_; + T default_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/statistics.h b/src/ipa/raspberrypi/statistics.h new file mode 100644 index 000000000000..a762bf3d41aa --- /dev/null +++ b/src/ipa/raspberrypi/statistics.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2022, Raspberry Pi Ltd + * + * statistics.h - Raspberry Pi generic statistics structure + */ +#pragma once + +#include +#include +#include + +#include "histogram.h" +#include "region_stats.h" + +namespace RPiController { + +struct RgbySums { + RgbySums(uint64_t _rSum = 0, uint64_t _gSum = 0, uint64_t _bSum = 0, uint64_t _ySum = 0) + : rSum(_rSum), gSum(_gSum), bSum(_bSum), ySum(_ySum) + { + } + uint64_t rSum; + uint64_t gSum; + uint64_t bSum; + uint64_t ySum; +}; + +using RgbyRegions = RegionStats; +using FocusRegions = RegionStats; + +struct Statistics { + /* + * Positioning of the AGC statistics gathering in the pipeline: + * Pre-WB correction or post-WB correction. + * Assume this is post-LSC. + */ + enum class AgcStatsPos { PreWb, PostWb }; + const AgcStatsPos agcStatsPos; + + /* + * Positioning of the AWB/ALSC statistics gathering in the pipeline: + * Pre-LSC or post-LSC. + */ + enum class ColourStatsPos { PreLsc, PostLsc }; + const ColourStatsPos colourStatsPos; + + Statistics(AgcStatsPos a, ColourStatsPos c) + : agcStatsPos(a), colourStatsPos(c) + { + } + + /* Histogram statistics. Not all histograms may be populated! */ + Histogram rHist; + Histogram gHist; + Histogram bHist; + Histogram yHist; + + /* Row sums for flicker avoidance. */ + std::vector rowSums; + + /* Region based colour sums. */ + RgbyRegions agcRegions; + RgbyRegions awbRegions; + + /* Region based focus FoM. */ + FocusRegions focusRegions; +}; + +} /* namespace RPiController */