From patchwork Fri Aug 27 08:02:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13537 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 06726C3242 for ; Fri, 27 Aug 2021 08:02:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2196168944; Fri, 27 Aug 2021 10:02:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uNLgUwU6"; 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 9620068934 for ; Fri, 27 Aug 2021 10:02:33 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:ccf5:c267:eba8:cbb5]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3F81D5A1; Fri, 27 Aug 2021 10:02:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1630051353; bh=ylY8JUqFcCTcaOX8cROKMKWFYzNWCUw4JDPb2NVnA7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uNLgUwU6wEYznryuU1hcthpmwmxnzX/72WHn9DIF7u913AeUNvvmIP1NJqxiO+PNu Wec/eCkvX32MXUe4K4tAyAvuu781muC6t2eCOZICuyRxxA/sBpEEcqpbyKBHxUcpNu c70MMbod/jEVBeFuiLRh889p4gi79G++jd+t9V3g= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Fri, 27 Aug 2021 10:02:25 +0200 Message-Id: <20210827080227.26370-3-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210827080227.26370-1-jeanmichel.hautbois@ideasonboard.com> References: <20210827080227.26370-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] ipa: ipu3: Rename AGC algorithm 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" The initial AGC algorithm is a simple one, which calculates the exposure and gain values by trying to have a target of 0.5 for the top 2% of the histogram. Rename it as "AgcMean" to make it easy to distinguish. Now that we are modular, we can have multiple algorithms for one functionality (here, AGC). Naming those algorithms makes it easier to chose between them. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- .../ipu3/algorithms/{agc.cpp => agc_mean.cpp} | 31 +++++++++---------- src/ipa/ipu3/algorithms/{agc.h => agc_mean.h} | 8 ++--- src/ipa/ipu3/algorithms/meson.build | 2 +- src/ipa/ipu3/ipu3.cpp | 4 +-- 4 files changed, 22 insertions(+), 23 deletions(-) rename src/ipa/ipu3/algorithms/{agc.cpp => agc_mean.cpp} (87%) rename src/ipa/ipu3/algorithms/{agc.h => agc_mean.h} (90%) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc_mean.cpp similarity index 87% rename from src/ipa/ipu3/algorithms/agc.cpp rename to src/ipa/ipu3/algorithms/agc_mean.cpp index 5ff50f4a..193f6e9a 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc_mean.cpp @@ -2,10 +2,10 @@ /* * Copyright (C) 2021, Ideas On Board * - * ipu3_agc.cpp - AGC/AEC control algorithm + * agc_mean.cpp - AGC/AEC control algorithm */ -#include "agc.h" +#include "agc_mean.h" #include #include @@ -23,7 +23,7 @@ using namespace std::literals::chrono_literals; namespace ipa::ipu3::algorithms { -LOG_DEFINE_CATEGORY(IPU3Agc) +LOG_DEFINE_CATEGORY(IPU3AgcMean) /* Number of frames to wait before calculating stats on minimum exposure */ static constexpr uint32_t kInitialFrameMinAECount = 4; @@ -50,16 +50,15 @@ static constexpr double kEvGainTarget = 0.5; /* A cell is 8 bytes and contains averages for RGB values and saturation ratio */ static constexpr uint8_t kCellSize = 8; -Agc::Agc() +AgcMean::AgcMean() : frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s), maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s), currentExposure_(0s), currentExposureNoDg_(0s) { } -int Agc::configure([[maybe_unused]] IPAContext &context, - const IPAConfigInfo &configInfo) -{ +int AgcMean::configure([[maybe_unused]] IPAContext &context, + const IPAConfigInfo &configInfo){ lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s / configInfo.sensorInfo.pixelRate; maxExposureTime_ = kMaxExposure * lineDuration_; @@ -67,7 +66,7 @@ int Agc::configure([[maybe_unused]] IPAContext &context, return 0; } -void Agc::processBrightness(const ipu3_uapi_stats_3a *stats, +void AgcMean::processBrightness(const ipu3_uapi_stats_3a *stats, const ipu3_uapi_grid_config &grid) { const struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid; @@ -109,7 +108,7 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats, iqMean_ = Histogram(Span(hist)).interQuantileMean(0.98, 1.0); } -void Agc::filterExposure() +void AgcMean::filterExposure() { double speed = 0.2; if (prevExposure_ == 0s) { @@ -140,10 +139,10 @@ void Agc::filterExposure() if (prevExposureNoDg_ < prevExposure_ * fastReduceThreshold) prevExposureNoDg_ = prevExposure_ * fastReduceThreshold; - LOG(IPU3Agc, Debug) << "After filtering, total_exposure " << prevExposure_; + LOG(IPU3AgcMean, Debug) << "After filtering, total_exposure " << prevExposure_; } -void Agc::lockExposureGain(uint32_t &exposure, double &gain) +void AgcMean::lockExposureGain(uint32_t &exposure, double &gain) { /* Algorithm initialization should wait for first valid frames */ /* \todo - have a number of frames given by DelayedControls ? @@ -153,20 +152,20 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) /* Are we correctly exposed ? */ if (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) { - LOG(IPU3Agc, Debug) << "!!! Good exposure with iqMean = " << iqMean_; + LOG(IPU3AgcMean, Debug) << "!!! Good exposure with iqMean = " << iqMean_; } else { double newGain = kEvGainTarget * knumHistogramBins / iqMean_; /* extracted from Rpi::Agc::computeTargetExposure */ libcamera::utils::Duration currentShutter = exposure * lineDuration_; currentExposureNoDg_ = currentShutter * gain; - LOG(IPU3Agc, Debug) << "Actual total exposure " << currentExposureNoDg_ + LOG(IPU3AgcMean, Debug) << "Actual total exposure " << currentExposureNoDg_ << " Shutter speed " << currentShutter << " Gain " << gain; currentExposure_ = currentExposureNoDg_ * newGain; libcamera::utils::Duration maxTotalExposure = maxExposureTime_ * kMaxGain; currentExposure_ = std::min(currentExposure_, maxTotalExposure); - LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_; + LOG(IPU3AgcMean, Debug) << "Target total exposure " << currentExposure_; /* \todo: estimate if we need to desaturate */ filterExposure(); @@ -181,12 +180,12 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain) newExposure = currentExposure_ / gain; exposure = std::clamp(static_cast(exposure * currentExposure_ / newExposure), kMinExposure, kMaxExposure); } - LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain; + LOG(IPU3AgcMean, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain; } lastFrame_ = frameCount_; } -void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) +void AgcMean::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { uint32_t &exposure = context.frameContext.agc.exposure; double &gain = context.frameContext.agc.gain; diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc_mean.h similarity index 90% rename from src/ipa/ipu3/algorithms/agc.h rename to src/ipa/ipu3/algorithms/agc_mean.h index e36797d3..97114121 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc_mean.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2021, Ideas On Board * - * agc.h - IPU3 AGC/AEC control algorithm + * agc_mean.h - IPU3 AGC/AEC control algorithm */ #ifndef __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__ #define __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__ @@ -23,11 +23,11 @@ namespace ipa::ipu3::algorithms { using utils::Duration; -class Agc : public Algorithm +class AgcMean : public Algorithm { public: - Agc(); - ~Agc() = default; + AgcMean(); + ~AgcMean() = default; int configure(IPAContext &context, const IPAConfigInfo &configInfo) override; void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override; diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build index deae225b..807b53ea 100644 --- a/src/ipa/ipu3/algorithms/meson.build +++ b/src/ipa/ipu3/algorithms/meson.build @@ -1,7 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 ipu3_ipa_algorithms = files([ - 'agc.cpp', + 'agc_mean.cpp', 'algorithm.cpp', 'awb.cpp', 'tone_mapping.cpp', diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index cbb3f440..6332fc06 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -29,7 +29,7 @@ #include "libcamera/internal/mapped_framebuffer.h" -#include "algorithms/agc.h" +#include "algorithms/agc_mean.h" #include "algorithms/algorithm.h" #include "algorithms/awb.h" #include "algorithms/tone_mapping.h" @@ -269,7 +269,7 @@ int IPAIPU3::init(const IPASettings &settings, *ipaControls = ControlInfoMap(std::move(controls), controls::controls); /* Construct our Algorithms */ - algorithms_.push_back(std::make_unique()); + algorithms_.push_back(std::make_unique()); algorithms_.push_back(std::make_unique()); algorithms_.push_back(std::make_unique());