[{"id":19005,"web_url":"https://patchwork.libcamera.org/comment/19005/","msgid":"<YSPSYXNzn5rJcsZU@pendragon.ideasonboard.com>","date":"2021-08-23T16:52:49","subject":"Re: [libcamera-devel] [PATCH v1 5/7] ipa: ipu3: rename AGC algorithm","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jean-Michel,\n\nThank you for the patch.\n\nOn Mon, Aug 23, 2021 at 02:49:35PM +0200, Jean-Michel Hautbois wrote:\n> The initial AGC algorithm is a simple one, which calculates the exposure\n> and gain values by trying to have a mean histogram value to 128.\n\nIs this right ? I'm reading the code as targetting a value of 128 (maybe\nwe should say 0.5 instead, to avoid depending on the number of bits per\npixel in comments) for the mean of the top 2% of the histogram.\n\n> Rename it as \"AgcMean\" to make it easy to distinguish.\n> \n> Now that we are modular, we can have multiple algorithms for one\n> functionnality (here, AGC). Naming those algorithms makes it easier to\n\ns/functionnality/functionality/\n\n> chose between them.\n> \n> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  .../ipu3/algorithms/{agc.cpp => agc_mean.cpp} | 31 +++++++++----------\n>  src/ipa/ipu3/algorithms/{agc.h => agc_mean.h} |  8 ++---\n>  src/ipa/ipu3/algorithms/meson.build           |  2 +-\n>  src/ipa/ipu3/ipu3.cpp                         |  4 +--\n>  4 files changed, 22 insertions(+), 23 deletions(-)\n>  rename src/ipa/ipu3/algorithms/{agc.cpp => agc_mean.cpp} (87%)\n>  rename src/ipa/ipu3/algorithms/{agc.h => agc_mean.h} (90%)\n> \n> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc_mean.cpp\n> similarity index 87%\n> rename from src/ipa/ipu3/algorithms/agc.cpp\n> rename to src/ipa/ipu3/algorithms/agc_mean.cpp\n> index 5ff50f4a..193f6e9a 100644\n> --- a/src/ipa/ipu3/algorithms/agc.cpp\n> +++ b/src/ipa/ipu3/algorithms/agc_mean.cpp\n> @@ -2,10 +2,10 @@\n>  /*\n>   * Copyright (C) 2021, Ideas On Board\n>   *\n> - * ipu3_agc.cpp - AGC/AEC control algorithm\n> + * agc_mean.cpp - AGC/AEC control algorithm\n\n\"AGC/AEC mean-based control algorithm\" ?\n\nI'm not sure if mean vs. metering are the most descriptive names, but I\ndon't have better proposals at this point.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>   */\n>  \n> -#include \"agc.h\"\n> +#include \"agc_mean.h\"\n>  \n>  #include <algorithm>\n>  #include <chrono>\n> @@ -23,7 +23,7 @@ using namespace std::literals::chrono_literals;\n>  \n>  namespace ipa::ipu3::algorithms {\n>  \n> -LOG_DEFINE_CATEGORY(IPU3Agc)\n> +LOG_DEFINE_CATEGORY(IPU3AgcMean)\n>  \n>  /* Number of frames to wait before calculating stats on minimum exposure */\n>  static constexpr uint32_t kInitialFrameMinAECount = 4;\n> @@ -50,16 +50,15 @@ static constexpr double kEvGainTarget = 0.5;\n>  /* A cell is 8 bytes and contains averages for RGB values and saturation ratio */\n>  static constexpr uint8_t kCellSize = 8;\n>  \n> -Agc::Agc()\n> +AgcMean::AgcMean()\n>  \t: frameCount_(0), lastFrame_(0), iqMean_(0.0), lineDuration_(0s),\n>  \t  maxExposureTime_(0s), prevExposure_(0s), prevExposureNoDg_(0s),\n>  \t  currentExposure_(0s), currentExposureNoDg_(0s)\n>  {\n>  }\n>  \n> -int Agc::configure([[maybe_unused]] IPAContext &context,\n> -\t\t   const IPAConfigInfo &configInfo)\n> -{\n> +int AgcMean::configure([[maybe_unused]] IPAContext &context,\n> +\t\t        const IPAConfigInfo &configInfo){\n>  \tlineDuration_ = configInfo.sensorInfo.lineLength * 1.0s\n>  \t\t      / configInfo.sensorInfo.pixelRate;\n>  \tmaxExposureTime_ = kMaxExposure * lineDuration_;\n> @@ -67,7 +66,7 @@ int Agc::configure([[maybe_unused]] IPAContext &context,\n>  \treturn 0;\n>  }\n>  \n> -void Agc::processBrightness(const ipu3_uapi_stats_3a *stats,\n> +void AgcMean::processBrightness(const ipu3_uapi_stats_3a *stats,\n>  \t\t\t    const ipu3_uapi_grid_config &grid)\n>  {\n>  \tconst struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid;\n> @@ -109,7 +108,7 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats,\n>  \tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n>  }\n>  \n> -void Agc::filterExposure()\n> +void AgcMean::filterExposure()\n>  {\n>  \tdouble speed = 0.2;\n>  \tif (prevExposure_ == 0s) {\n> @@ -140,10 +139,10 @@ void Agc::filterExposure()\n>  \tif (prevExposureNoDg_ <\n>  \t    prevExposure_ * fastReduceThreshold)\n>  \t\tprevExposureNoDg_ = prevExposure_ * fastReduceThreshold;\n> -\tLOG(IPU3Agc, Debug) << \"After filtering, total_exposure \" << prevExposure_;\n> +\tLOG(IPU3AgcMean, Debug) << \"After filtering, total_exposure \" << prevExposure_;\n>  }\n>  \n> -void Agc::lockExposureGain(uint32_t &exposure, double &gain)\n> +void AgcMean::lockExposureGain(uint32_t &exposure, double &gain)\n>  {\n>  \t/* Algorithm initialization should wait for first valid frames */\n>  \t/* \\todo - have a number of frames given by DelayedControls ?\n> @@ -153,20 +152,20 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain)\n>  \n>  \t/* Are we correctly exposed ? */\n>  \tif (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) {\n> -\t\tLOG(IPU3Agc, Debug) << \"!!! Good exposure with iqMean = \" << iqMean_;\n> +\t\tLOG(IPU3AgcMean, Debug) << \"!!! Good exposure with iqMean = \" << iqMean_;\n>  \t} else {\n>  \t\tdouble newGain = kEvGainTarget * knumHistogramBins / iqMean_;\n>  \n>  \t\t/* extracted from Rpi::Agc::computeTargetExposure */\n>  \t\tlibcamera::utils::Duration currentShutter = exposure * lineDuration_;\n>  \t\tcurrentExposureNoDg_ = currentShutter * gain;\n> -\t\tLOG(IPU3Agc, Debug) << \"Actual total exposure \" << currentExposureNoDg_\n> +\t\tLOG(IPU3AgcMean, Debug) << \"Actual total exposure \" << currentExposureNoDg_\n>  \t\t\t\t    << \" Shutter speed \" << currentShutter\n>  \t\t\t\t    << \" Gain \" << gain;\n>  \t\tcurrentExposure_ = currentExposureNoDg_ * newGain;\n>  \t\tlibcamera::utils::Duration maxTotalExposure = maxExposureTime_ * kMaxGain;\n>  \t\tcurrentExposure_ = std::min(currentExposure_, maxTotalExposure);\n> -\t\tLOG(IPU3Agc, Debug) << \"Target total exposure \" << currentExposure_;\n> +\t\tLOG(IPU3AgcMean, Debug) << \"Target total exposure \" << currentExposure_;\n>  \n>  \t\t/* \\todo: estimate if we need to desaturate */\n>  \t\tfilterExposure();\n> @@ -181,12 +180,12 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain)\n>  \t\t\tnewExposure = currentExposure_ / gain;\n>  \t\t\texposure = std::clamp(static_cast<uint32_t>(exposure * currentExposure_ / newExposure), kMinExposure, kMaxExposure);\n>  \t\t}\n> -\t\tLOG(IPU3Agc, Debug) << \"Adjust exposure \" << exposure * lineDuration_ << \" and gain \" << gain;\n> +\t\tLOG(IPU3AgcMean, Debug) << \"Adjust exposure \" << exposure * lineDuration_ << \" and gain \" << gain;\n>  \t}\n>  \tlastFrame_ = frameCount_;\n>  }\n>  \n> -void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n> +void AgcMean::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n>  {\n>  \tuint32_t &exposure = context.frameContext.agc.exposure;\n>  \tdouble &gain = context.frameContext.agc.gain;\n> diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc_mean.h\n> similarity index 90%\n> rename from src/ipa/ipu3/algorithms/agc.h\n> rename to src/ipa/ipu3/algorithms/agc_mean.h\n> index e36797d3..97114121 100644\n> --- a/src/ipa/ipu3/algorithms/agc.h\n> +++ b/src/ipa/ipu3/algorithms/agc_mean.h\n> @@ -2,7 +2,7 @@\n>  /*\n>   * Copyright (C) 2021, Ideas On Board\n>   *\n> - * agc.h - IPU3 AGC/AEC control algorithm\n> + * agc_mean.h - IPU3 AGC/AEC control algorithm\n>   */\n>  #ifndef __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__\n>  #define __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__\n> @@ -23,11 +23,11 @@ namespace ipa::ipu3::algorithms {\n>  \n>  using utils::Duration;\n>  \n> -class Agc : public Algorithm\n> +class AgcMean : public Algorithm\n>  {\n>  public:\n> -\tAgc();\n> -\t~Agc() = default;\n> +\tAgcMean();\n> +\t~AgcMean() = default;\n>  \n>  \tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n>  \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n> diff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\n> index deae225b..807b53ea 100644\n> --- a/src/ipa/ipu3/algorithms/meson.build\n> +++ b/src/ipa/ipu3/algorithms/meson.build\n> @@ -1,7 +1,7 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>  \n>  ipu3_ipa_algorithms = files([\n> -    'agc.cpp',\n> +    'agc_mean.cpp',\n>      'algorithm.cpp',\n>      'awb.cpp',\n>      'tone_mapping.cpp',\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index 0ed0a6f1..b73c4f7b 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -29,7 +29,7 @@\n>  \n>  #include \"libcamera/internal/mapped_framebuffer.h\"\n>  \n> -#include \"algorithms/agc.h\"\n> +#include \"algorithms/agc_mean.h\"\n>  #include \"algorithms/algorithm.h\"\n>  #include \"algorithms/awb.h\"\n>  #include \"algorithms/tone_mapping.h\"\n> @@ -266,7 +266,7 @@ int IPAIPU3::init(const IPASettings &settings,\n>  \t*ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n>  \n>  \t/* Construct our Algorithms */\n> -\talgorithms_.push_back(std::make_unique<algorithms::Agc>());\n> +\talgorithms_.push_back(std::make_unique<algorithms::AgcMean>());\n>  \talgorithms_.push_back(std::make_unique<algorithms::Awb>());\n>  \talgorithms_.push_back(std::make_unique<algorithms::ToneMapping>());\n>","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 29171BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 16:53:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9D689688A3;\n\tMon, 23 Aug 2021 18:53:01 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E56B06025B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 18:52:59 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 601192A5;\n\tMon, 23 Aug 2021 18:52:59 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"A6rVUNxm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629737579;\n\tbh=R2Adoo/tfPGfGmLTFL40D1EB+tQc35R3Yn22QKqg8yk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=A6rVUNxmudRKy2txRyaKOpPyPt+cjTK2kcip/Lg8KyGFhv5Rm4M7B7dd0snBfUIWz\n\trqAxWToz5pcZn1rZUCCRKrCSEMeSyaD7WukSQP2DTKuOXfRC51DoBwNu9gcL/9YiMb\n\tptOhqpiesiS4SQtKfmECxmlWI1zX09OMvQOQQ9GY=","Date":"Mon, 23 Aug 2021 19:52:49 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<YSPSYXNzn5rJcsZU@pendragon.ideasonboard.com>","References":"<20210823124937.253539-1-jeanmichel.hautbois@ideasonboard.com>\n\t<20210823124937.253539-6-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210823124937.253539-6-jeanmichel.hautbois@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v1 5/7] ipa: ipu3: rename AGC algorithm","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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]