{"id":13393,"url":"https://patchwork.libcamera.org/api/patches/13393/?format=json","web_url":"https://patchwork.libcamera.org/patch/13393/","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":"<20210818155403.268694-7-jeanmichel.hautbois@ideasonboard.com>","date":"2021-08-18T15:54:00","name":"[libcamera-devel,v3,6/9] ipa: ipu3: convert AWB to the new algorithm interface","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"fd5a56a46205fa6b2562e49ae77dc8472e5c9433","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/13393/mbox/","series":[{"id":2370,"url":"https://patchwork.libcamera.org/api/series/2370/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2370","date":"2021-08-18T15:53:54","name":"IPU3: Introduce modularity for algorithms","version":3,"mbox":"https://patchwork.libcamera.org/series/2370/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13393/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13393/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 3829DC3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 18 Aug 2021 15:54:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C7DE76890C;\n\tWed, 18 Aug 2021 17:54:16 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3C6B1688C4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 18 Aug 2021 17:54:10 +0200 (CEST)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:946e:2bbb:370e:41e4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E6F3F466;\n\tWed, 18 Aug 2021 17:54:09 +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=\"sOQWfWGD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1629302050;\n\tbh=QlqwPGZFRsLJyTE62+Hxl365naFAKq40/nKHsupaPEA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=sOQWfWGDOvSUon/K4N8GtDRRiiejrwhlYfkodaypj/YBfAgSmRLJbo0BBI73R4En0\n\tntSebGjQdG9SVl3NDyazhDd5mvg4QxDmtSYYONv3K6u8GxuIk/7Uc37K5+zpDvYWYe\n\tiINs7o0FY1Tu08myNvOEH9fgO66yRwrajrDZg86U=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 18 Aug 2021 17:54:00 +0200","Message-Id":"<20210818155403.268694-7-jeanmichel.hautbois@ideasonboard.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20210818155403.268694-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20210818155403.268694-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 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 it 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>\n---\n src/ipa/ipu3/ipa_context.h |   8 +++\n src/ipa/ipu3/ipu3.cpp      |   5 +-\n src/ipa/ipu3/ipu3_awb.cpp  | 107 ++++++++++++++++++-------------------\n src/ipa/ipu3/ipu3_awb.h    |   6 +--\n 4 files changed, 65 insertions(+), 61 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 5964ba6d..beae3ac6 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -29,6 +29,14 @@ struct IPAFrameContext {\n \t\tdouble gain;\n \t} agc;\n \n+\tstruct Awb {\n+\t\tstruct Gains {\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 Contrast {\n \t\tstruct ipu3_uapi_gamma_corr_lut gammaCorrection;\n \t} contrast;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex ee0dd9fe..2b4a4c8c 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -339,7 +339,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@@ -420,7 +419,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@@ -446,7 +445,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,\n \texposure_ = context_.frameContext.agc.exposure;\n \tgain_ = camHelper_->gainCode(context_.frameContext.agc.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..f90aa492 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,39 +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+\tzones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY);\n }\n \n-void IPU3Awb::initialise(ipu3_uapi_params &params, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid)\n+IPU3Awb::~IPU3Awb()\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 /**\n@@ -321,22 +275,65 @@ 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 = 8191 | IPU3_UAPI_AWB_RGBS_THR_B_EN | IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT;\n+\n+\tawbGrid_ = context.configuration.grid.bdsGrid;\n+\n+\tparams.acc_param.awb.config.grid = context.configuration.grid.bdsGrid;\n+\tparams.acc_param.bnr = imguCssBnrDefaults;\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+\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.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.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.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..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","v3","6/9"]}