Show a patch.

GET /api/1.1/patches/13255/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13255,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13255/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13255/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20210809092007.79067-5-jeanmichel.hautbois@ideasonboard.com>",
    "date": "2021-08-09T09:20:06",
    "name": "[libcamera-devel,RFC,4/5] ipa: ipu3: Move IPU3 awb into algorithms",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "d5ca0f331f0b0408cc186235b58b87b5c207530d",
    "submitter": {
        "id": 75,
        "url": "https://patchwork.libcamera.org/api/1.1/people/75/?format=api",
        "name": "Jean-Michel Hautbois",
        "email": "jeanmichel.hautbois@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13255/mbox/",
    "series": [
        {
            "id": 2320,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2320/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2320",
            "date": "2021-08-09T09:20:02",
            "name": "IPU3: Introduce modularity for algorithms",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2320/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13255/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13255/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 8BC89C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  9 Aug 2021 09:20:21 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B54168890;\n\tMon,  9 Aug 2021 11:20:21 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D63268823\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 Aug 2021 11:20:16 +0200 (CEST)",
            "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:14c5:c0eb:b1fb:db22])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D57049A;\n\tMon,  9 Aug 2021 11:20:16 +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=\"gl+KvdV7\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628500816;\n\tbh=79d8ZYNWuPlZ0uJhLoLd85PBr4/ElSJ4Ynhvfhaw9Dc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=gl+KvdV7f1QkLSdpy2ds+hT9ZatuPTuWEbMFB4HLG2bua96rsdQx6xPgjInfKXzlc\n\tUYq1w58i/JX621kNY1UjkB0v9XseAXgU2x4TlzPHo8N+oguTJrRKMUX05uADi4i0tg\n\tQEwaVZ66ygBSIomlTP9nMn9pav7Qn8sJPs/7Q674=",
        "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  9 Aug 2021 11:20:06 +0200",
        "Message-Id": "<20210809092007.79067-5-jeanmichel.hautbois@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20210809092007.79067-1-jeanmichel.hautbois@ideasonboard.com>",
        "References": "<20210809092007.79067-1-jeanmichel.hautbois@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC PATCH 4/5] ipa: ipu3: Move IPU3 awb 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": "Use the Context class and algorithm interface to properly call the AWB\nalgorithm from IPAIPU3.\nWe need to pass the BDS grid size calculated, pass those through the Context\nclass in a dedicated Awb structure.\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n .../ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} | 42 ++++++++++++-------\n src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} | 29 ++++++-------\n src/ipa/ipu3/algorithms/meson.build           |  1 +\n src/ipa/ipu3/ipa_context.h                    | 12 ++++++\n src/ipa/ipu3/ipu3.cpp                         | 30 ++++++-------\n src/ipa/ipu3/meson.build                      |  1 -\n 6 files changed, 66 insertions(+), 49 deletions(-)\n rename src/ipa/ipu3/{ipu3_awb.cpp => algorithms/awb.cpp} (92%)\n rename src/ipa/ipu3/{ipu3_awb.h => algorithms/awb.h} (79%)",
    "diff": "diff --git a/src/ipa/ipu3/ipu3_awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp\nsimilarity index 92%\nrename from src/ipa/ipu3/ipu3_awb.cpp\nrename to src/ipa/ipu3/algorithms/awb.cpp\nindex 043c3838..92a41b65 100644\n--- a/src/ipa/ipu3/ipu3_awb.cpp\n+++ b/src/ipa/ipu3/algorithms/awb.cpp\n@@ -2,9 +2,9 @@\n /*\n  * Copyright (C) 2021, Ideas On Board\n  *\n- * ipu3_awb.cpp - AWB control algorithm\n+ * awb.cpp - AWB control algorithm\n  */\n-#include \"ipu3_awb.h\"\n+#include \"awb.h\"\n \n #include <cmath>\n #include <numeric>\n@@ -14,7 +14,7 @@\n \n namespace libcamera {\n \n-namespace ipa::ipu3 {\n+namespace ipa::ipu3::algorithms {\n \n LOG_DEFINE_CATEGORY(IPU3Awb)\n \n@@ -134,7 +134,7 @@ static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = {\n \t0, 0, 8191, 0\n };\n \n-IPU3Awb::IPU3Awb()\n+Awb::Awb()\n \t: Algorithm()\n {\n \tasyncResults_.blueGain = 1.0;\n@@ -143,17 +143,19 @@ IPU3Awb::IPU3Awb()\n \tasyncResults_.temperatureK = 4500;\n }\n \n-IPU3Awb::~IPU3Awb()\n+Awb::~Awb()\n {\n }\n \n-void IPU3Awb::initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid)\n+int Awb::configure(IPAContext &context)\n {\n+\tipu3_uapi_params &params = context.params;\n+\tSize &bdsOutputSize = context.awb.grid.bdsOutputSize;\n+\n \tparams.use.acc_awb = 1;\n \tparams.acc_param.awb.config = imguCssAwbDefaults;\n \n-\tawbGrid_ = bdsGrid;\n-\tparams.acc_param.awb.config.grid = awbGrid_;\n+\tawbGrid_ = context.awb.grid.bdsGrid;\n \n \tparams.use.acc_bnr = 1;\n \tparams.acc_param.bnr = imguCssBnrDefaults;\n@@ -174,6 +176,8 @@ void IPU3Awb::initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, st\n \tparams.acc_param.ccm = imguCssCcmDefault;\n \n \tzones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);\n+\n+\treturn 0;\n }\n \n /**\n@@ -190,7 +194,7 @@ void IPU3Awb::initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, st\n  * More detailed information can be found in:\n  * https://en.wikipedia.org/wiki/Color_temperature#Approximation\n  */\n-uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)\n+uint32_t Awb::estimateCCT(double red, double green, double blue)\n {\n \t/* Convert the RGB values to CIE tristimulus values (XYZ) */\n \tdouble X = (-0.14282) * (red) + (1.54924) * (green) + (-0.95641) * (blue);\n@@ -207,7 +211,7 @@ uint32_t IPU3Awb::estimateCCT(double red, double green, double blue)\n }\n \n /* Generate an RGB vector with the average values for each region */\n-void IPU3Awb::generateZones(std::vector<RGB> &zones)\n+void Awb::generateZones(std::vector<RGB> &zones)\n {\n \tfor (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {\n \t\tRGB zone;\n@@ -224,7 +228,7 @@ void IPU3Awb::generateZones(std::vector<RGB> &zones)\n }\n \n /* Translate the IPU3 statistics into the default statistics region array */\n-void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)\n+void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)\n {\n \tuint32_t regionWidth = round(awbGrid_.width / static_cast<double>(kAwbStatsSizeX));\n \tuint32_t regionHeight = round(awbGrid_.height / static_cast<double>(kAwbStatsSizeY));\n@@ -256,7 +260,7 @@ void IPU3Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats)\n \t}\n }\n \n-void IPU3Awb::clearAwbStats()\n+void Awb::clearAwbStats()\n {\n \tfor (unsigned int i = 0; i < kAwbStatsSizeX * kAwbStatsSizeY; i++) {\n \t\tawbStats_[i].bSum = 0;\n@@ -267,7 +271,7 @@ void IPU3Awb::clearAwbStats()\n \t}\n }\n \n-void IPU3Awb::awbGreyWorld()\n+void Awb::awbGreyWorld()\n {\n \tLOG(IPU3Awb, Debug) << \"Grey world AWB\";\n \t/*\n@@ -307,7 +311,7 @@ void IPU3Awb::awbGreyWorld()\n \tasyncResults_.blueGain = blueGain;\n }\n \n-void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)\n+void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)\n {\n \tASSERT(stats->stats_3a_status.awb_en);\n \tzones_.clear();\n@@ -322,7 +326,7 @@ void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)\n \t}\n }\n \n-void IPU3Awb::updateWbParameters(ipu3_uapi_params &params)\n+void Awb::updateWbParameters(ipu3_uapi_params &params)\n {\n \t/*\n \t * Green gains should not be touched and considered 1.\n@@ -340,6 +344,12 @@ void IPU3Awb::updateWbParameters(ipu3_uapi_params &params)\n \tparams.acc_param.ccm = imguCssCcmDefault;\n }\n \n-} /* namespace ipa::ipu3 */\n+void Awb::process(IPAContext &context)\n+{\n+\tcalculateWBGains(context.stats);\n+\tupdateWbParameters(context.params);\n+}\n+\n+} /* namespace ipa::ipu3::algorithms */\n \n } /* namespace libcamera */\ndiff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/algorithms/awb.h\nsimilarity index 79%\nrename from src/ipa/ipu3/ipu3_awb.h\nrename to src/ipa/ipu3/algorithms/awb.h\nindex 8b05ac03..37690b37 100644\n--- a/src/ipa/ipu3/ipu3_awb.h\n+++ b/src/ipa/ipu3/algorithms/awb.h\n@@ -2,10 +2,10 @@\n /*\n  * Copyright (C) 2021, Ideas On Board\n  *\n- * ipu3_awb.h - IPU3 AWB control algorithm\n+ * awb.h - IPU3 AWB control algorithm\n  */\n-#ifndef __LIBCAMERA_IPU3_AWB_H__\n-#define __LIBCAMERA_IPU3_AWB_H__\n+#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__\n+#define __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__\n \n #include <vector>\n \n@@ -13,26 +13,24 @@\n \n #include <libcamera/geometry.h>\n \n-#include \"algorithms/algorithm.h\"\n-#include \"libipa/algorithm.h\"\n+#include \"algorithm.h\"\n \n namespace libcamera {\n \n-namespace ipa::ipu3 {\n+namespace ipa::ipu3::algorithms {\n \n /* Region size for the statistics generation algorithm */\n static constexpr uint32_t kAwbStatsSizeX = 16;\n static constexpr uint32_t kAwbStatsSizeY = 12;\n \n-class IPU3Awb : public ipa::Algorithm\n+class Awb : public Algorithm\n {\n public:\n-\tIPU3Awb();\n-\t~IPU3Awb();\n+\tAwb();\n+\t~Awb();\n \n-\tvoid initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid);\n-\tvoid calculateWBGains(const ipu3_uapi_stats_3a *stats);\n-\tvoid updateWbParameters(ipu3_uapi_params &params);\n+\tint configure(IPAContext &context) override;\n+\tvoid process(IPAContext &context) override;\n \n \tstruct Ipu3AwbCell {\n \t\tunsigned char greenRedAvg;\n@@ -73,6 +71,9 @@ public:\n \t};\n \n private:\n+\tvoid calculateWBGains(const ipu3_uapi_stats_3a *stats);\n+\tvoid updateWbParameters(ipu3_uapi_params &params);\n+\n \tvoid generateZones(std::vector<RGB> &zones);\n \tvoid generateAwbStats(const ipu3_uapi_stats_3a *stats);\n \tvoid clearAwbStats();\n@@ -86,7 +87,7 @@ private:\n \tAwbStatus asyncResults_;\n };\n \n-} /* namespace ipa::ipu3 */\n+} /* namespace ipa::ipu3::algorithms */\n \n } /* namespace libcamera*/\n-#endif /* __LIBCAMERA_IPU3_AWB_H__ */\n+#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__ */\ndiff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\nindex f71d1e61..df36d719 100644\n--- a/src/ipa/ipu3/algorithms/meson.build\n+++ b/src/ipa/ipu3/algorithms/meson.build\n@@ -1,5 +1,6 @@\n # SPDX-License-Identifier: CC0-1.0\n \n ipu3_ipa_algorithms = files([\n+    'awb.cpp',\n     'contrast.cpp',\n ])\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 5d717be5..c43b275b 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -11,6 +11,8 @@\n \n #include <linux/intel-ipu3.h>\n \n+#include <libcamera/geometry.h>\n+\n namespace libcamera {\n \n namespace ipa::ipu3 {\n@@ -21,6 +23,16 @@ struct IPAContext {\n \n \t/* Output Parameters which will be written to the hardware */\n \tipu3_uapi_params params;\n+\n+\t/* AWB specific parameters to share */\n+\tstruct Awb {\n+\t\tstruct Grid {\n+\t\t\t/* BDS grid plane config used by the kernel */\n+\t\t\tipu3_uapi_grid_config bdsGrid;\n+\t\t\t/* BDS output size configured by the pipeline handler */\n+\t\t\tSize bdsOutputSize;\n+\t\t} grid;\n+\t} awb;\n };\n \n } /* namespace ipa::ipu3 */\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 7035802f..82506461 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -23,11 +23,11 @@\n #include \"libcamera/internal/framebuffer.h\"\n \n #include \"algorithms/algorithm.h\"\n+#include \"algorithms/awb.h\"\n #include \"algorithms/contrast.h\"\n #include \"ipa_context.h\"\n \n #include \"ipu3_agc.h\"\n-#include \"ipu3_awb.h\"\n #include \"libipa/camera_sensor_helper.h\"\n \n static constexpr uint32_t kMaxCellWidthPerSet = 160;\n@@ -81,8 +81,6 @@ private:\n \tuint32_t minGain_;\n \tuint32_t maxGain_;\n \n-\t/* Interface to the AWB algorithm */\n-\tstd::unique_ptr<IPU3Awb> awbAlgo_;\n \t/* Interface to the AEC/AGC algorithm */\n \tstd::unique_ptr<IPU3Agc> agcAlgo_;\n \t/* Interface to the Camera Helper */\n@@ -105,6 +103,7 @@ int IPAIPU3::init(const IPASettings &settings)\n \t}\n \n \t/* Construct our Algorithms */\n+\talgorithms_.emplace_back(new algorithms::Awb());\n \talgorithms_.emplace_back(new algorithms::Contrast());\n \n \t/* Reset all the hardware settings */\n@@ -138,7 +137,7 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \tuint32_t minError = std::numeric_limits<uint32_t>::max();\n \tSize best;\n \tSize bestLog2;\n-\tbdsGrid_ = {};\n+\tipu3_uapi_grid_config &bdsGrid = context_.awb.grid.bdsGrid;\n \n \tfor (uint32_t widthShift = 3; widthShift <= 7; ++widthShift) {\n \t\tuint32_t width = std::min(kMaxCellWidthPerSet,\n@@ -162,14 +161,14 @@ void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n \t\t}\n \t}\n \n-\tbdsGrid_.width = best.width >> bestLog2.width;\n-\tbdsGrid_.block_width_log2 = bestLog2.width;\n-\tbdsGrid_.height = best.height >> bestLog2.height;\n-\tbdsGrid_.block_height_log2 = bestLog2.height;\n+\tbdsGrid.width = best.width >> bestLog2.width;\n+\tbdsGrid.block_width_log2 = bestLog2.width;\n+\tbdsGrid.height = best.height >> bestLog2.height;\n+\tbdsGrid.block_height_log2 = bestLog2.height;\n \n \tLOG(IPAIPU3, Debug) << \"Best grid found is: (\"\n-\t\t\t    << (int)bdsGrid_.width << \" << \" << (int)bdsGrid_.block_width_log2 << \") x (\"\n-\t\t\t    << (int)bdsGrid_.height << \" << \" << (int)bdsGrid_.block_height_log2 << \")\";\n+\t\t\t    << (int)bdsGrid.width << \" << \" << (int)bdsGrid.block_width_log2 << \") x (\"\n+\t\t\t    << (int)bdsGrid.height << \" << \" << (int)bdsGrid.block_height_log2 << \")\";\n }\n \n int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n@@ -211,13 +210,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \n \tdefVBlank_ = itVBlank->second.def().get<int32_t>();\n \n+\t/* Prepare AWB parameters */\n \tcalculateBdsGrid(configInfo.bdsOutputSize);\n+\tcontext_.awb.grid.bdsOutputSize = configInfo.bdsOutputSize;\n \n \tconfigureAlgorithms();\n \n-\tawbAlgo_ = std::make_unique<IPU3Awb>();\n-\tawbAlgo_->initialise(context_.params, configInfo.bdsOutputSize, bdsGrid_);\n-\n+\tbdsGrid_ = context_.awb.grid.bdsGrid;\n \tagcAlgo_ = std::make_unique<IPU3Agc>();\n \tagcAlgo_->initialise(bdsGrid_, sensorInfo_);\n \n@@ -293,9 +292,6 @@ void IPAIPU3::processControls([[maybe_unused]] unsigned int frame,\n \n void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n {\n-\tif (agcAlgo_->updateControls())\n-\t\tawbAlgo_->updateWbParameters(context_.params);\n-\n \t*params = context_.params;\n \n \tIPU3Action op;\n@@ -349,8 +345,6 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n \tagcAlgo_->process(stats, exposure_, gain);\n \tgain_ = camHelper_->gainCode(gain);\n \n-\tawbAlgo_->calculateWBGains(stats);\n-\n \tif (agcAlgo_->updateControls())\n \t\tsetControls(frame);\n \ndiff --git a/src/ipa/ipu3/meson.build b/src/ipa/ipu3/meson.build\nindex fcb27d68..d1126947 100644\n--- a/src/ipa/ipu3/meson.build\n+++ b/src/ipa/ipu3/meson.build\n@@ -7,7 +7,6 @@ ipa_name = 'ipa_ipu3'\n ipu3_ipa_sources = files([\n     'ipu3.cpp',\n     'ipu3_agc.cpp',\n-    'ipu3_awb.cpp',\n ])\n \n ipu3_ipa_sources += ipu3_ipa_algorithms\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "4/5"
    ]
}