Show a patch.

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

{
    "id": 13414,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13414/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13414/",
    "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": "<20210820065316.44343-7-jeanmichel.hautbois@ideasonboard.com>",
    "date": "2021-08-20T06:53:13",
    "name": "[libcamera-devel,v5,6/9] ipa: ipu3: convert AWB to the new algorithm interface",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ac5a677525fc0d692d8df90557641e4efd0a2cd6",
    "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/13414/mbox/",
    "series": [
        {
            "id": 2374,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2374/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2374",
            "date": "2021-08-20T06:53:07",
            "name": "IPU3: Introduce modularity for algorithms",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/2374/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13414/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13414/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 56E6AC3246\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Aug 2021 06:53:32 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6D2EE68918;\n\tFri, 20 Aug 2021 08:53:31 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 389586891A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Aug 2021 08:53:23 +0200 (CEST)",
            "from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:e43b:edb2:932:6b0a])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DD7368C8;\n\tFri, 20 Aug 2021 08:53:21 +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=\"dKWYKVZR\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629442402;\n\tbh=Kf8GtVvGycpEgCk/ah5RWS6GYVMnp4Lgo+I526NA+7M=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=dKWYKVZRTXyx1BgBJTUpyp3Wu9GhYeq9H6GDCApiy+rvjWKa+/CYS9Bk5h4h+8Nyk\n\tyNhwcr9lJ/r3C6BRqmpBoVb/kno6GNt2kJ8Tj1ynddSRMYkWHeuAHT5Nm45FnE29/Q\n\tRrk9nqRnRzDe1II9vbvjTdMs7lSnGtKK0nMGGPoI=",
        "From": "Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 20 Aug 2021 08:53:13 +0200",
        "Message-Id": "<20210820065316.44343-7-jeanmichel.hautbois@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20210820065316.44343-1-jeanmichel.hautbois@ideasonboard.com>",
        "References": "<20210820065316.44343-1-jeanmichel.hautbois@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5 6/9] ipa: ipu3: convert AWB to the new\n\talgorithm interface",
        "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": "When the stats are received, pass them with the context to the existing\nAWB algorithm. IPAFrameContext now has a new structure to store the\ngains calculated by the AWB algorithm.\n\nWhen an EventFillParams event is received, call prepare() and set the new\ngains accordingly in the params structure.\nThere is no more a need for the IPU3Awb::initialise() function, as the\nparams are always set in prepare().\n\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/ipu3/ipa_context.h |   8 +++\n src/ipa/ipu3/ipu3.cpp      |  23 ++++++--\n src/ipa/ipu3/ipu3_awb.cpp  | 109 ++++++++++++++++++-------------------\n src/ipa/ipu3/ipu3_awb.h    |   6 +-\n 4 files changed, 83 insertions(+), 63 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 4b12f129..24dd8bf7 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -24,6 +24,14 @@ struct IPASessionConfiguration {\n };\n \n struct IPAFrameContext {\n+\tstruct {\n+\t\tstruct {\n+\t\t\tdouble red;\n+\t\t\tdouble green;\n+\t\t\tdouble blue;\n+\t\t} gains;\n+\t} awb;\n+\n \tstruct {\n \t\tstruct ipu3_uapi_gamma_corr_lut gammaCorrection;\n \t} toneMapping;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 3713b07b..823df34b 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -92,6 +92,23 @@\n  * \\brief BDS output size configured by the pipeline handler\n  */\n \n+/**\n+ * \\struct IPAFrameContext::awb\n+ * \\brief Context for the Automatic White Balance algorithm\n+ *\n+ * \\struct IPAFrameContext::awb::gains\n+ * \\brief White balance gains\n+ *\n+ * \\var IPAFrameContext::awb::gains::red\n+ * \\brief White balance gain for R channel\n+ *\n+ * \\var IPAFrameContext::awb::gains::green\n+ * \\brief White balance gain for G channel\n+ *\n+ * \\var IPAFrameContext::awb::gains::blue\n+ * \\brief White balance gain for B channel\n+ */\n+\n /**\n  * \\struct IPAFrameContext::toneMapping\n  * \\brief Context for ToneMapping and Gamma control\n@@ -357,8 +374,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \t}\n \n \tawbAlgo_ = std::make_unique<IPU3Awb>();\n-\tawbAlgo_->initialise(params_, context_.configuration.grid.bdsOutputSize,\n-\t\t\t     context_.configuration.grid.bdsGrid);\n \tagcAlgo_ = std::make_unique<IPU3Agc>();\n \tagcAlgo_->initialise(context_.configuration.grid.bdsGrid, sensorInfo_);\n \n@@ -438,7 +453,7 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params)\n \t\talgo->prepare(context_, &params_);\n \n \tif (agcAlgo_->updateControls())\n-\t\tawbAlgo_->updateWbParameters(params_);\n+\t\tawbAlgo_->prepare(context_, &params_);\n \n \t*params = params_;\n \n@@ -461,7 +476,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n \tagcAlgo_->process(stats, exposure_, gain);\n \tgain_ = camHelper_->gainCode(gain);\n \n-\tawbAlgo_->calculateWBGains(stats);\n+\tawbAlgo_->process(context_, stats);\n \n \tif (agcAlgo_->updateControls())\n \t\tsetControls(frame);\ndiff --git a/src/ipa/ipu3/ipu3_awb.cpp b/src/ipa/ipu3/ipu3_awb.cpp\nindex c2d9e0c1..728162fe 100644\n--- a/src/ipa/ipu3/ipu3_awb.cpp\n+++ b/src/ipa/ipu3/ipu3_awb.cpp\n@@ -107,25 +107,6 @@ static const struct ipu3_uapi_bnr_static_config imguCssBnrDefaults = {\n \t.opt_center_sqr = { 419904, 133956 },\n };\n \n-/* Default settings for Auto White Balance replicated from the Kernel*/\n-static const struct ipu3_uapi_awb_config_s imguCssAwbDefaults = {\n-\t.rgbs_thr_gr = 8191,\n-\t.rgbs_thr_r = 8191,\n-\t.rgbs_thr_gb = 8191,\n-\t.rgbs_thr_b = 8191 | IPU3_UAPI_AWB_RGBS_THR_B_EN | IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT,\n-\t.grid = {\n-\t\t.width = 160,\n-\t\t.height = 36,\n-\t\t.block_width_log2 = 3,\n-\t\t.block_height_log2 = 4,\n-\t\t.height_per_slice = 1, /* Overridden by kernel. */\n-\t\t.x_start = 0,\n-\t\t.y_start = 0,\n-\t\t.x_end = 0,\n-\t\t.y_end = 0,\n-\t},\n-};\n-\n /* Default color correction matrix defined as an identity matrix */\n static const struct ipu3_uapi_ccm_mat_config imguCssCcmDefault = {\n \t8191, 0, 0, 0,\n@@ -140,41 +121,12 @@ IPU3Awb::IPU3Awb()\n \tasyncResults_.greenGain = 1.0;\n \tasyncResults_.redGain = 1.0;\n \tasyncResults_.temperatureK = 4500;\n-}\n-\n-IPU3Awb::~IPU3Awb()\n-{\n-}\n-\n-void IPU3Awb::initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid)\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-\n-\tparams.use.acc_bnr = 1;\n-\tparams.acc_param.bnr = imguCssBnrDefaults;\n-\t/**\n-\t * Optical center is column (respectively row) startminus X (respectively Y) center.\n-\t * For the moment use BDS as a first approximation, but it should\n-\t * be calculated based on Shading (SHD) parameters.\n-\t */\n-\tparams.acc_param.bnr.column_size = bdsOutputSize.width;\n-\tparams.acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2);\n-\tparams.acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2);\n-\tparams.acc_param.bnr.opt_center_sqr.x_sqr_reset = params.acc_param.bnr.opt_center.x_reset\n-\t\t\t\t\t\t\t* params.acc_param.bnr.opt_center.x_reset;\n-\tparams.acc_param.bnr.opt_center_sqr.y_sqr_reset = params.acc_param.bnr.opt_center.y_reset\n-\t\t\t\t\t\t\t* params.acc_param.bnr.opt_center.y_reset;\n-\n-\tparams.use.acc_ccm = 1;\n-\tparams.acc_param.ccm = imguCssCcmDefault;\n \n \tzones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);\n }\n \n+IPU3Awb::~IPU3Awb() = default;\n+\n /**\n  * The function estimates the correlated color temperature using\n  * from RGB color space input.\n@@ -321,22 +273,67 @@ void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats)\n \t}\n }\n \n-void IPU3Awb::updateWbParameters(ipu3_uapi_params &params)\n+void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n {\n+\tcalculateWBGains(stats);\n+\n+\t/*\n+\t * Gains are only recalculated if enough zones were detected.\n+\t * The results are cached, so if no results were calculated, we set the\n+\t * cached values from asyncResults_ here.\n+\t */\n+\tcontext.frameContext.awb.gains.blue = asyncResults_.blueGain;\n+\tcontext.frameContext.awb.gains.green = asyncResults_.greenGain;\n+\tcontext.frameContext.awb.gains.red = asyncResults_.redGain;\n+}\n+\n+void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params *params)\n+{\n+\tparams->acc_param.awb.config.rgbs_thr_gr = 8191;\n+\tparams->acc_param.awb.config.rgbs_thr_r = 8191;\n+\tparams->acc_param.awb.config.rgbs_thr_gb = 8191;\n+\tparams->acc_param.awb.config.rgbs_thr_b = IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT\n+\t\t\t\t\t       | IPU3_UAPI_AWB_RGBS_THR_B_EN\n+\t\t\t\t\t       | 8191;\n+\n+\tawbGrid_ = context.configuration.grid.bdsGrid;\n+\n+\tparams->acc_param.awb.config.grid = context.configuration.grid.bdsGrid;\n+\n+\t/*\n+\t * Optical center is column start (respectively row start) of the\n+\t * region of interest minus its X center (respectively Y center).\n+\t *\n+\t * For the moment use BDS as a first approximation, but it should\n+\t * be calculated based on Shading (SHD) parameters.\n+\t */\n+\tparams->acc_param.bnr = imguCssBnrDefaults;\n+\tSize &bdsOutputSize = context.configuration.grid.bdsOutputSize;\n+\tparams->acc_param.bnr.column_size = bdsOutputSize.width;\n+\tparams->acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2);\n+\tparams->acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2);\n+\tparams->acc_param.bnr.opt_center_sqr.x_sqr_reset = params->acc_param.bnr.opt_center.x_reset\n+\t\t\t\t\t\t\t* params->acc_param.bnr.opt_center.x_reset;\n+\tparams->acc_param.bnr.opt_center_sqr.y_sqr_reset = params->acc_param.bnr.opt_center.y_reset\n+\t\t\t\t\t\t\t* params->acc_param.bnr.opt_center.y_reset;\n \t/*\n \t * Green gains should not be touched and considered 1.\n \t * Default is 16, so do not change it at all.\n \t * 4096 is the value for a gain of 1.0\n \t */\n-\tparams.acc_param.bnr.wb_gains.gr = 16;\n-\tparams.acc_param.bnr.wb_gains.r = 4096 * asyncResults_.redGain;\n-\tparams.acc_param.bnr.wb_gains.b = 4096 * asyncResults_.blueGain;\n-\tparams.acc_param.bnr.wb_gains.gb = 16;\n+\tparams->acc_param.bnr.wb_gains.gr = 16 * context.frameContext.awb.gains.green;\n+\tparams->acc_param.bnr.wb_gains.r = 4096 * context.frameContext.awb.gains.red;\n+\tparams->acc_param.bnr.wb_gains.b = 4096 * context.frameContext.awb.gains.blue;\n+\tparams->acc_param.bnr.wb_gains.gb = 16 * context.frameContext.awb.gains.green;\n \n \tLOG(IPU3Awb, Debug) << \"Color temperature estimated: \" << asyncResults_.temperatureK;\n \n \t/* The CCM matrix may change when color temperature will be used */\n-\tparams.acc_param.ccm = imguCssCcmDefault;\n+\tparams->acc_param.ccm = imguCssCcmDefault;\n+\n+\tparams->use.acc_awb = 1;\n+\tparams->use.acc_bnr = 1;\n+\tparams->use.acc_ccm = 1;\n }\n \n } /* namespace ipa::ipu3 */\ndiff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/ipu3_awb.h\nindex eeb2920b..12703489 100644\n--- a/src/ipa/ipu3/ipu3_awb.h\n+++ b/src/ipa/ipu3/ipu3_awb.h\n@@ -29,9 +29,8 @@ public:\n \tIPU3Awb();\n \t~IPU3Awb();\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+\tvoid prepare(IPAContext &context, ipu3_uapi_params *params) override;\n+\tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n \n \tstruct Ipu3AwbCell {\n \t\tunsigned char greenRedAvg;\n@@ -72,6 +71,7 @@ public:\n \t};\n \n private:\n+\tvoid calculateWBGains(const ipu3_uapi_stats_3a *stats);\n \tvoid generateZones(std::vector<RGB> &zones);\n \tvoid generateAwbStats(const ipu3_uapi_stats_3a *stats);\n \tvoid clearAwbStats();\n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "6/9"
    ]
}