Patch Detail
Show a patch.
GET /api/patches/13338/?format=api
{ "id": 13338, "url": "https://patchwork.libcamera.org/api/patches/13338/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13338/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210812165243.276977-11-jeanmichel.hautbois@ideasonboard.com>", "date": "2021-08-12T16:52:43", "name": "[libcamera-devel,v2,10/10] ipa: ipu3: Move IPU3 agc into algorithms", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "41b3e2bce4f6090f7ca5d38237fe64993816a09a", "submitter": { "id": 75, "url": "https://patchwork.libcamera.org/api/people/75/?format=api", "name": "Jean-Michel Hautbois", "email": "jeanmichel.hautbois@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13338/mbox/", "series": [ { "id": 2347, "url": "https://patchwork.libcamera.org/api/series/2347/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2347", "date": "2021-08-12T16:52:33", "name": "IPU3: Introduce modularity for algorithms", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2347/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/13338/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13338/checks/", "tags": {}, "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 51F76C3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Aug 2021 16:52:57 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1BD2C688E5;\n\tThu, 12 Aug 2021 18:52:57 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AE6D568888\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Aug 2021 18:52:48 +0200 (CEST)", "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:3d6d:7284:3c48:5edc])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 606A3F49;\n\tThu, 12 Aug 2021 18:52:48 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"BzxGvtL0\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628787168;\n\tbh=sAhwgxc/CJEHwOiAylZPRmpj1nbil3YQro0CQZzQ0h0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BzxGvtL0ETo7sCByiwHGJflbJOe2XAa+LGcOCFPHX7LfLbdHzONqs8D7ihJmjjfdy\n\tW4JKNGnfCjmTXdCgtc7gAUKS6UeiMmjZ3NTg6/95RxfWC5RFhwMfk0Pz41ugS4Z5HD\n\tz0dhhydjQ91yqCmTE71WFeVuuahjTlKEr4Yy7Cvc=", "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 12 Aug 2021 18:52:43 +0200", "Message-Id": "<20210812165243.276977-11-jeanmichel.hautbois@ideasonboard.com>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20210812165243.276977-1-jeanmichel.hautbois@ideasonboard.com>", "References": "<20210812165243.276977-1-jeanmichel.hautbois@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 10/10] ipa: ipu3: Move IPU3 agc into\n\talgorithms", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Now that the interface is properly used by the AGC class, move it into\nipa::ipu3::algorithms and let the loops do the calls.\nAs we need to exchange the exposure_ and gain_ by passing them through the\nFrameContext, use the calculated values in setControls() function to\nease the reading.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n .../ipu3/{ipu3_agc.cpp => algorithms/agc.cpp} | 18 +++++++--------\n src/ipa/ipu3/{ipu3_agc.h => algorithms/agc.h} | 20 ++++++++---------\n src/ipa/ipu3/algorithms/meson.build | 1 +\n src/ipa/ipu3/ipu3.cpp | 22 +++++++------------\n src/ipa/ipu3/meson.build | 1 -\n 5 files changed, 28 insertions(+), 34 deletions(-)\n rename src/ipa/ipu3/{ipu3_agc.cpp => algorithms/agc.cpp} (94%)\n rename src/ipa/ipu3/{ipu3_agc.h => algorithms/agc.h} (73%)", "diff": "diff --git a/src/ipa/ipu3/ipu3_agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nsimilarity index 94%\nrename from src/ipa/ipu3/ipu3_agc.cpp\nrename to src/ipa/ipu3/algorithms/agc.cpp\nindex 0d0584a8..ee3d3bc2 100644\n--- a/src/ipa/ipu3/ipu3_agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -5,7 +5,7 @@\n * ipu3_agc.cpp - AGC/AEC control algorithm\n */\n \n-#include \"ipu3_agc.h\"\n+#include \"agc.h\"\n \n #include <algorithm>\n #include <chrono>\n@@ -21,7 +21,7 @@ namespace libcamera {\n \n using namespace std::literals::chrono_literals;\n \n-namespace ipa::ipu3 {\n+namespace ipa::ipu3::algorithms {\n \n LOG_DEFINE_CATEGORY(IPU3Agc)\n \n@@ -50,7 +50,7 @@ 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-IPU3Agc::IPU3Agc()\n+Agc::Agc()\n \t: frameCount_(0), lastFrame_(0),\n \t iqMean_(0.0), lineDuration_(0s), maxExposureTime_(0s),\n \t prevExposure_(0s), prevExposureNoDg_(0s),\n@@ -58,7 +58,7 @@ IPU3Agc::IPU3Agc()\n {\n }\n \n-int IPU3Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n+int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n {\n \taeGrid_ = context.configuration.grid.bdsGrid;\n \n@@ -68,7 +68,7 @@ int IPU3Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)\n \treturn 0;\n }\n \n-void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n+void Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n {\n \tconst struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid;\n \tRectangle aeRegion = { statsAeGrid.x_start,\n@@ -109,7 +109,7 @@ void IPU3Agc::processBrightness(const ipu3_uapi_stats_3a *stats)\n \tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n }\n \n-void IPU3Agc::filterExposure()\n+void Agc::filterExposure()\n {\n \tdouble speed = 0.2;\n \tif (prevExposure_ == 0s) {\n@@ -143,7 +143,7 @@ void IPU3Agc::filterExposure()\n \tLOG(IPU3Agc, Debug) << \"After filtering, total_exposure \" << prevExposure_;\n }\n \n-void IPU3Agc::lockExposureGain(uint32_t &exposure, double &gain)\n+void Agc::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@@ -186,7 +186,7 @@ void IPU3Agc::lockExposureGain(uint32_t &exposure, double &gain)\n \tlastFrame_ = frameCount_;\n }\n \n-void IPU3Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n+void Agc::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@@ -195,6 +195,6 @@ void IPU3Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n \tframeCount_++;\n }\n \n-} /* namespace ipa::ipu3 */\n+} /* namespace ipa::ipu3::algorithms */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/ipu3/ipu3_agc.h b/src/ipa/ipu3/algorithms/agc.h\nsimilarity index 73%\nrename from src/ipa/ipu3/ipu3_agc.h\nrename to src/ipa/ipu3/algorithms/agc.h\nindex 0e922664..1739d2fd 100644\n--- a/src/ipa/ipu3/ipu3_agc.h\n+++ b/src/ipa/ipu3/algorithms/agc.h\n@@ -2,10 +2,10 @@\n /*\n * Copyright (C) 2021, Ideas On Board\n *\n- * ipu3_agc.h - IPU3 AGC/AEC control algorithm\n+ * agc.h - IPU3 AGC/AEC control algorithm\n */\n-#ifndef __LIBCAMERA_IPU3_AGC_H__\n-#define __LIBCAMERA_IPU3_AGC_H__\n+#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__\n+#define __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__\n \n #include <linux/intel-ipu3.h>\n \n@@ -13,21 +13,21 @@\n \n #include <libcamera/geometry.h>\n \n-#include \"algorithms/algorithm.h\"\n+#include \"algorithm.h\"\n \n namespace libcamera {\n \n struct IPACameraSensorInfo;\n \n-namespace ipa::ipu3 {\n+namespace ipa::ipu3::algorithms {\n \n using utils::Duration;\n \n-class IPU3Agc : public Algorithm\n+class Agc : public Algorithm\n {\n public:\n-\tIPU3Agc();\n-\t~IPU3Agc() = default;\n+\tAgc();\n+\t~Agc() = default;\n \n \tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n \tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n@@ -53,8 +53,8 @@ private:\n \tDuration currentExposureNoDg_;\n };\n \n-} /* namespace ipa::ipu3 */\n+} /* namespace ipa::ipu3::algorithms */\n \n } /* namespace libcamera */\n \n-#endif /* __LIBCAMERA_IPU3_AGC_H__ */\n+#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__ */\ndiff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\nindex 9ef2dd41..e75d92e0 100644\n--- a/src/ipa/ipu3/algorithms/meson.build\n+++ b/src/ipa/ipu3/algorithms/meson.build\n@@ -1,6 +1,7 @@\n # SPDX-License-Identifier: CC0-1.0\n \n ipu3_ipa_algorithms = files([\n+ 'agc.cpp',\n 'awb.cpp',\n 'contrast.cpp',\n 'grid.cpp',\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex bea2a372..a99fbcac 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -30,10 +30,10 @@\n #include \"libcamera/internal/mapped_framebuffer.h\"\n \n #include \"algorithms/algorithm.h\"\n+#include \"algorithms/agc.h\"\n #include \"algorithms/awb.h\"\n #include \"algorithms/contrast.h\"\n #include \"algorithms/grid.h\"\n-#include \"ipu3_agc.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n namespace libcamera {\n@@ -84,8 +84,6 @@ private:\n \tuint32_t minGain_;\n \tuint32_t maxGain_;\n \n-\t/* Interface to the AEC/AGC algorithm */\n-\tstd::unique_ptr<IPU3Agc> agcAlgo_;\n \t/* Interface to the Camera Helper */\n \tstd::unique_ptr<CameraSensorHelper> camHelper_;\n \n@@ -167,6 +165,7 @@ int IPAIPU3::init(const IPASettings &settings,\n \t/* Construct our Algorithms */\n \talgorithms_.emplace_back(new algorithms::Grid());\n \t/* Grid needs to be prepared before AWB */\n+\talgorithms_.emplace_back(new algorithms::Agc());\n \talgorithms_.emplace_back(new algorithms::Awb());\n \talgorithms_.emplace_back(new algorithms::Contrast());\n \n@@ -229,9 +228,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \t\t\treturn ret;\n \t}\n \n-\tagcAlgo_ = std::make_unique<IPU3Agc>();\n-\tagcAlgo_->configure(context_, configInfo);\n-\n \treturn 0;\n }\n \n@@ -320,17 +316,12 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n \t\t\t [[maybe_unused]] const ipu3_uapi_stats_3a *stats)\n {\n \tControlList ctrls(controls::controls);\n+\tcontext_.frameContext.agc.gain = camHelper_->gain(gain_);\n+\tcontext_.frameContext.agc.exposure = exposure_;\n+\n \tfor (auto const &algo : algorithms_)\n \t\talgo->process(context_, stats);\n \n-\tdouble gain = camHelper_->gain(gain_);\n-\tcontext_.frameContext.agc.exposure = exposure_;\n-\tcontext_.frameContext.agc.gain = gain;\n-\tagcAlgo_->process(context_, stats);\n-\texposure_ = context_.frameContext.agc.exposure;\n-\tgain = context_.frameContext.agc.gain;\n-\tgain_ = camHelper_->gainCode(gain);\n-\n \tsetControls(frame);\n \n \t/* \\todo Use VBlank value calculated from each frame exposure. */\n@@ -350,6 +341,9 @@ void IPAIPU3::setControls(unsigned int frame)\n \tIPU3Action op;\n \top.op = ActionSetSensorControls;\n \n+\texposure_ = context_.frameContext.agc.exposure;\n+\tgain_ = camHelper_->gainCode(context_.frameContext.agc.gain);\n+\n \tControlList ctrls(ctrls_);\n \tctrls.set(V4L2_CID_EXPOSURE, static_cast<int32_t>(exposure_));\n \tctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast<int32_t>(gain_));\ndiff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build\nindex d1126947..39320980 100644\n--- a/src/ipa/ipu3/meson.build\n+++ b/src/ipa/ipu3/meson.build\n@@ -6,7 +6,6 @@ ipa_name = 'ipa_ipu3'\n \n ipu3_ipa_sources = files([\n 'ipu3.cpp',\n- 'ipu3_agc.cpp',\n ])\n \n ipu3_ipa_sources += ipu3_ipa_algorithms\n", "prefixes": [ "libcamera-devel", "v2", "10/10" ] }