{"id":13334,"url":"https://patchwork.libcamera.org/api/patches/13334/?format=json","web_url":"https://patchwork.libcamera.org/patch/13334/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","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-7-jeanmichel.hautbois@ideasonboard.com>","date":"2021-08-12T16:52:39","name":"[libcamera-devel,v2,06/10] ipa: ipu3: convert AWB to the new algorithm interface","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9bdf49986c42ab3484443f4be3a356ec8ce3b0cf","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/?format=json","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13334/mbox/","series":[{"id":2347,"url":"https://patchwork.libcamera.org/api/series/2347/?format=json","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/13334/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13334/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 2BAA9C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Aug 2021 16:52:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E8BE4688C4;\n\tThu, 12 Aug 2021 18:52:54 +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 EDFD868891\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Aug 2021 18:52:47 +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 A3CFF8AF;\n\tThu, 12 Aug 2021 18:52:47 +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=\"Poa9ICk6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628787167;\n\tbh=KLJ7ueKcUdsxv2t3EztSUTwOHoGSxLt+SGRVnzaeI1w=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Poa9ICk6cHQp/Unffdaq6yofNr40DXo71Sg4Q0O6jsvFaA8GziQN4uMFvSY/Te5qg\n\tWqP0nqFxBze1EW5pZK6NYySq21B4Gb8wnsoN/xLI861Q27B4PhEts23ocb0r3ZTH2o\n\t4BICBZ8epOs+y0pIaoYQ05oq9hF8LbjBGiXhV4ps=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 12 Aug 2021 18:52:39 +0200","Message-Id":"<20210812165243.276977-7-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 06/10] ipa: ipu3: convert AWB to the\n\tnew algorithm 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 it with the context to the existing\nAWB algorithm. IPAFrameContext now has a new structure to store the\ngains calculated byt the AWB algorithm.\n\nWhen a 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>\n---\n src/ipa/ipu3/ipa_context.h |  8 ++++\n src/ipa/ipu3/ipu3.cpp      |  5 +--\n src/ipa/ipu3/ipu3_awb.cpp  | 76 ++++++++++++++++++++------------------\n src/ipa/ipu3/ipu3_awb.h    |  6 +--\n 4 files changed, 54 insertions(+), 41 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex e995c663..7bb4f598 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -38,6 +38,14 @@ struct IPAFrameContext {\n \t\tdouble gain;\n \t} agc;\n \n+\tstruct Awb {\n+\t\tstruct Gains {\n+\t\t\tdouble redGain;\n+\t\t\tdouble greenGain;\n+\t\t\tdouble blueGain;\n+\t\t} gains;\n+\t} awb;\n+\n \tstruct Contrast {\n \t\tuint16_t lut[IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES];\n \t} contrast;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex e09adfc3..dba5554d 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -230,7 +230,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo)\n \t}\n \n \tawbAlgo_ = std::make_unique<IPU3Awb>();\n-\tawbAlgo_->initialise(params_, context_.configuration.grid.bdsOutputSize, context_.configuration.grid.bdsGrid);\n \n \tagcAlgo_ = std::make_unique<IPU3Agc>();\n \tagcAlgo_->initialise(context_.configuration.grid.bdsGrid, sensorInfo_);\n@@ -311,7 +310,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@@ -337,7 +336,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n \tgain = context_.frameContext.agc.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 0f3bcdc9..b422b095 100644\n--- a/src/ipa/ipu3/ipu3_awb.cpp\n+++ b/src/ipa/ipu3/ipu3_awb.cpp\n@@ -121,42 +121,14 @@ IPU3Awb::IPU3Awb()\n \tasyncResults_.greenGain = 1.0;\n \tasyncResults_.redGain = 1.0;\n \tasyncResults_.temperatureK = 4500;\n+\n+\tzones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);\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.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 = 8191 | IPU3_UAPI_AWB_RGBS_THR_B_EN | IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT;\n-\tawbGrid_ = bdsGrid;\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 /**\n  * The function estimates the correlated color temperature using\n  * from RGB color space input.\n@@ -303,17 +275,51 @@ 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+\tcontext.frameContext.awb.gains.blueGain = asyncResults_.blueGain;\n+\tcontext.frameContext.awb.gains.greenGain = asyncResults_.greenGain;\n+\tcontext.frameContext.awb.gains.redGain = asyncResults_.redGain;\n+}\n+\n+void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params &params)\n {\n+\tparams.use.acc_awb = 1;\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 = 8191 | IPU3_UAPI_AWB_RGBS_THR_B_EN | IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT;\n+\tawbGrid_ = context.configuration.grid.bdsGrid;\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+\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+\n+\tparams.use.acc_ccm = 1;\n+\tparams.acc_param.ccm = imguCssCcmDefault;\n+\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.greenGain;\n+\tparams.acc_param.bnr.wb_gains.r = 4096 * context.frameContext.awb.gains.redGain;\n+\tparams.acc_param.bnr.wb_gains.b = 4096 * context.frameContext.awb.gains.blueGain;\n+\tparams.acc_param.bnr.wb_gains.gb = 16 * context.frameContext.awb.gains.greenGain;\n \n \tLOG(IPU3Awb, Debug) << \"Color temperature estimated: \" << asyncResults_.temperatureK;\n \ndiff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/ipu3_awb.h\nindex eeb2920b..4de3fae2 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","v2","06/10"]}