From patchwork Tue Dec 13 11:48:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 17996 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 B8A91C328D for ; Tue, 13 Dec 2022 11:48:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A809963360; Tue, 13 Dec 2022 12:48:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1670932130; bh=VUsG/0hDy7HJda57ZvAicpnKqWLEc8nGuOSYSLpEzLQ=; 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=s8SmKqwyG2NuSlwsFyTGcGzfwY2XCfp+gMFxoTo+bOYPmF2Tx7twkX63/N/XljQs3 HWBQdrGY2M9pwl42FhCDSJ0kIrwasRmD+fqSxuKhTfpZP9JHWlYAOr+oHfBNxa3cC1 PC8PizSIuCmsDAt7m2AIHeJSRIpf0c2t8BJM8o+5vJMS0Bz/1IGFhUOqyFfEi6xQTl z5+XWf2BEWSfrbgFyY3j0ZtXjJ27YxQHGgdMlLeVj2KxmTueVFL8yBVOnilox6NTCH 5DBHezje+TReU2TFu52FKAcI7agvwUqgO4aMFOpjnrKg0ya6DjQpASMMLmgCceMuWf nNJ9Dr/IYaHZQ== Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 66F3B63354 for ; Tue, 13 Dec 2022 12:48:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="j1thFQVn"; dkim-atps=neutral Received: by mail-wr1-x42f.google.com with SMTP id o5so15333346wrm.1 for ; Tue, 13 Dec 2022 03:48:48 -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=UzGll8qwMNu1ew3kASktX78GxzRx0n9eVyC6tPz+/7A=; b=j1thFQVnggX0tyOFdDiaD67k8ZG0YCXNMI/LGLjcGMqRTEdQNkKKE9XhUgRplST+q/ tVjavjlb8Y8K8fOsLqKbRSXNk5tZ+vUkC2B/CfoFLiwD/GQP9JUo+T0tKJcGr5xFkEtA czomtR1jLZo3sX96ifn/pIXKKEfGIYPWNe/18bjopHubvyHUHiVLFB4XYZSGmfJqO1L/ Wmj36YxqzHJWnDVwwVE4637frXlg2R1p1eFo6a8huJR5rXD5MLrluEzbd+dLSUZfyg+/ 3YzkTkNBfEZbMRtVKlLq80++xxq7oJXo1IN9NkxKIea40su8UUuKNCC4Jwc7k0Il74CJ I3LA== 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=UzGll8qwMNu1ew3kASktX78GxzRx0n9eVyC6tPz+/7A=; b=4lQgn9PT1mvKwL5D+joWorLFo5cXnGiWgu4L5Apqj640KB1X355HkHMvMeywSIEDBJ 3V8EOn9fR7G6rYh6TqnQmQUoUEpmubIo7GWDayOcnUi8OLIsvOaZ8tcwrSFrEn4PgtJy bSTZnXmWYPmuy+0nUTU80wtHcXiL+6wumHRvBIoIqsMuCTKy2eHYRarb21+9ncninsdb 0S1FCvwL+6dICjfhri94+YV5ruGkSWOYIk0EZkPbqV1dn5mmmxT8lxQ3Zdku/STrrEbK jGSmc1JRT75BzEKpT5Cd99ZY8zraQTcty2bn45LLIUncIB+S2y3vItvc0M7wxTTRsPog BFpQ== X-Gm-Message-State: ANoB5plpXkqB4nLt76isgJ4m1hGCPY2hFCfa/r2Yo7sFdgABVc0sTzlN NFVqiTCYSsQRpqMLRMtPfw9nUvrPIabPKncO X-Google-Smtp-Source: AA0mqf4kdmOCIXI25SGf8+96JF5RuIQmuhCRCPO4Bh6mpZ/uPEEnrXp6jJBPAa2LNAy8CuE2roraIQ== X-Received: by 2002:adf:dfc2:0:b0:242:5877:1ebc with SMTP id q2-20020adfdfc2000000b0024258771ebcmr12117212wrn.33.1670932127757; Tue, 13 Dec 2022 03:48:47 -0800 (PST) Received: from naush-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id j8-20020a5d4528000000b0024287d9d4a8sm11574541wra.74.2022.12.13.03.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 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 Subject: [libcamera-devel] [PATCH v3 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 histograms, AGC/AWB region sums and focus FoM regions. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham --- src/ipa/raspberrypi/controller/region_stats.h | 123 ++++++++++++++++++ src/ipa/raspberrypi/statistics.h | 70 ++++++++++ 2 files changed, 193 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..9aaf3a58a6f7 --- /dev/null +++ b/src/ipa/raspberrypi/controller/region_stats.h @@ -0,0 +1,123 @@ +/* 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 + +#include + +namespace RPiController { + +template +class RegionStats +{ +public: + struct Region { + T val; + uint32_t counted; + uint32_t uncounted; + }; + + RegionStats() + : size_({}), numFloating_(0), default_({}) + { + } + + void init(const libcamera::Size &size, unsigned int numFloating = 0) + { + size_ = size; + numFloating_ = numFloating; + regions_.clear(); + regions_.resize(size_.width * size_.height + numFloating_); + } + + void init(unsigned int num) + { + size_ = libcamera::Size(num, 1); + numFloating_ = 0; + regions_.clear(); + regions_.resize(num); + } + + unsigned int numRegions() const + { + return size_.width * size_.height; + } + + unsigned int numFloatingRegions() const + { + return numFloating_; + } + + libcamera::Size size() const + { + return size_; + } + + void set(unsigned int index, const Region ®ion) + { + if (index >= numRegions()) + return; + set_(index, region); + } + + void set(const libcamera::Point &pos, const Region ®ion) + { + set(pos.y * size_.width + pos.x, region); + } + + void setFloating(unsigned int index, const Region ®ion) + { + if (index >= numFloatingRegions()) + return; + set(numRegions() + index, region); + } + + const Region &get(unsigned int index) const + { + if (index >= numRegions()) + return default_; + return get_(index); + } + + const T &get(const libcamera::Point &pos) const + { + return get(pos.y * size_.width + pos.x); + } + + const T &getFloating(unsigned int index) const + { + if (index >= numFloatingRegions()) + return default_; + return get_(numRegions() + index); + } + + typename std::vector::iterator begin() { return regions_.begin(); } + typename std::vector::iterator end() { return regions_.end(); } + typename std::vector::const_iterator begin() const { return regions_.begin(); } + typename std::vector::const_iterator end() const { return regions_.end(); } + +private: + void set_(unsigned int index, const Region ®ion) + { + regions_[index] = region; + } + + const Region &get_(unsigned int index) const + { + return regions_[index]; + } + + libcamera::Size size_; + unsigned int numFloating_; + std::vector regions_; + Region 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 */