From patchwork Fri Mar 22 13:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19790 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 AD52EC32C3 for ; Fri, 22 Mar 2024 13:15:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5497F63354; Fri, 22 Mar 2024 14:15:16 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jMwdG0Qe"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82BA3632E7 for ; Fri, 22 Mar 2024 14:15:09 +0100 (CET) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 86991D50; Fri, 22 Mar 2024 14:14:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1711113280; bh=eBnNF8fPnn3dj5kMYozHbwOefdh6RqSKyouYwf3Qs1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jMwdG0QeI/ox7dlXz7Hwv3ax6NQpDvaP4ESeJR5/n39/V+7uIlXpyWc7loyWn4zd+ i00Sre5/2rNWbhhnmg1qAhQwitdYbKy6xdViXdbS9urfguiCNWlSuYdw4I2k4p3AYk yRVHGtbKnRVMJwe2dJQ3L/sDaD3jlTgggLXFUHtA= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH 05/10] ipa: ipu3: Parse and store Agc stats Date: Fri, 22 Mar 2024 13:14:46 +0000 Message-Id: <20240322131451.3092931-6-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240322131451.3092931-1-dan.scally@ideasonboard.com> References: <20240322131451.3092931-1-dan.scally@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In preparation for switching to a derivation of MeanLuminanceAgc, add a function to parse and store the statistics for easy retrieval in an overriding estimateLuminance() function. Signed-off-by: Daniel Scally --- src/ipa/ipu3/algorithms/agc.cpp | 33 +++++++++++++++++++++++++++++++++ src/ipa/ipu3/algorithms/agc.h | 8 ++++++++ 2 files changed, 41 insertions(+) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index 606a237a..ee9a42cf 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -142,6 +142,39 @@ double Agc::measureBrightness(const ipu3_uapi_stats_3a *stats, return Histogram(Span(hist)).interQuantileMean(0.98, 1.0); } +void Agc::parseStatistics(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid) +{ + uint32_t hist[knumHistogramBins] = { 0 }; + + reds_.clear(); + greens_.clear(); + blues_.clear(); + + for (unsigned int cellY = 0; cellY < grid.height; cellY++) { + for (unsigned int cellX = 0; cellX < grid.width; cellX++) { + uint32_t cellPosition = cellY * stride_ + cellX; + + const ipu3_uapi_awb_set_item *cell = + reinterpret_cast( + &stats->awb_raw_buffer.meta_data[cellPosition]); + + reds_.push_back(cell->R_avg); + greens_.push_back((cell->Gr_avg + cell->Gb_avg) / 2); + blues_.push_back(cell->B_avg); + + /* + * Store the average green value to estimate the + * brightness. Even the overexposed pixels are + * taken into account. + */ + hist[(cell->Gr_avg + cell->Gb_avg) / 2]++; + } + } + + hist_ = Histogram(Span(hist)); +} + /** * \brief Apply a filter on the exposure value to limit the speed of changes * \param[in] exposureValue The target exposure from the AGC algorithm diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 9d6e3ff1..7ed0ef7a 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -13,6 +13,8 @@ #include +#include "libipa/histogram.h" + #include "algorithm.h" namespace libcamera { @@ -43,6 +45,8 @@ private: const ipu3_uapi_grid_config &grid, const ipu3_uapi_stats_3a *stats, double gain); + void parseStatistics(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid); uint64_t frameCount_; @@ -55,6 +59,10 @@ private: utils::Duration filteredExposure_; uint32_t stride_; + std::vector reds_; + std::vector blues_; + std::vector greens_; + Histogram hist_; }; } /* namespace ipa::ipu3::algorithms */