From patchwork Thu Aug 12 16:52:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13334 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2BAA9C3241 for ; Thu, 12 Aug 2021 16:52:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8BE4688C4; Thu, 12 Aug 2021 18:52:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Poa9ICk6"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EDFD868891 for ; Thu, 12 Aug 2021 18:52:47 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:3d6d:7284:3c48:5edc]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A3CFF8AF; Thu, 12 Aug 2021 18:52:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628787167; bh=KLJ7ueKcUdsxv2t3EztSUTwOHoGSxLt+SGRVnzaeI1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Poa9ICk6cHQp/Unffdaq6yofNr40DXo71Sg4Q0O6jsvFaA8GziQN4uMFvSY/Te5qg WqP0nqFxBze1EW5pZK6NYySq21B4Gb8wnsoN/xLI861Q27B4PhEts23ocb0r3ZTH2o 4BICBZ8epOs+y0pIaoYQ05oq9hF8LbjBGiXhV4ps= From: Jean-Michel Hautbois 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 Subject: [libcamera-devel] [PATCH v2 06/10] ipa: ipu3: convert AWB to the new algorithm interface X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When the stats are received, pass it with the context to the existing AWB algorithm. IPAFrameContext now has a new structure to store the gains calculated byt the AWB algorithm. When a EventFillParams event is received, call prepare() and set the new gains accordingly in the params structure. There is no more a need for the IPU3Awb::initialise() function, as the params are always set in prepare(). Signed-off-by: Jean-Michel Hautbois Reviewed-by: Kieran Bingham --- src/ipa/ipu3/ipa_context.h | 8 ++++ src/ipa/ipu3/ipu3.cpp | 5 +-- src/ipa/ipu3/ipu3_awb.cpp | 76 ++++++++++++++++++++------------------ src/ipa/ipu3/ipu3_awb.h | 6 +-- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h index e995c663..7bb4f598 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -38,6 +38,14 @@ struct IPAFrameContext { double gain; } agc; + struct Awb { + struct Gains { + double redGain; + double greenGain; + double blueGain; + } gains; + } awb; + struct Contrast { uint16_t lut[IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES]; } contrast; diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index e09adfc3..dba5554d 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -230,7 +230,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo) } awbAlgo_ = std::make_unique(); - awbAlgo_->initialise(params_, context_.configuration.grid.bdsOutputSize, context_.configuration.grid.bdsGrid); agcAlgo_ = std::make_unique(); agcAlgo_->initialise(context_.configuration.grid.bdsGrid, sensorInfo_); @@ -311,7 +310,7 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) algo->prepare(context_, params_); if (agcAlgo_->updateControls()) - awbAlgo_->updateWbParameters(params_); + awbAlgo_->prepare(context_, params_); *params = params_; @@ -337,7 +336,7 @@ void IPAIPU3::parseStatistics(unsigned int frame, gain = context_.frameContext.agc.gain; gain_ = camHelper_->gainCode(gain); - awbAlgo_->calculateWBGains(stats); + awbAlgo_->process(context_, stats); if (agcAlgo_->updateControls()) setControls(frame); diff --git a/src/ipa/ipu3/ipu3_awb.cpp b/src/ipa/ipu3/ipu3_awb.cpp index 0f3bcdc9..b422b095 100644 --- a/src/ipa/ipu3/ipu3_awb.cpp +++ b/src/ipa/ipu3/ipu3_awb.cpp @@ -121,42 +121,14 @@ IPU3Awb::IPU3Awb() asyncResults_.greenGain = 1.0; asyncResults_.redGain = 1.0; asyncResults_.temperatureK = 4500; + + zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY); } IPU3Awb::~IPU3Awb() { } -void IPU3Awb::initialise(ipu3_uapi_params ¶ms, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid) -{ - params.use.acc_awb = 1; - params.acc_param.awb.config.rgbs_thr_gr = 8191; - params.acc_param.awb.config.rgbs_thr_r = 8191; - params.acc_param.awb.config.rgbs_thr_gb = 8191; - params.acc_param.awb.config.rgbs_thr_b = 8191 | IPU3_UAPI_AWB_RGBS_THR_B_EN | IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT; - awbGrid_ = bdsGrid; - - params.use.acc_bnr = 1; - params.acc_param.bnr = imguCssBnrDefaults; - /** - * Optical center is column (respectively row) startminus X (respectively Y) center. - * For the moment use BDS as a first approximation, but it should - * be calculated based on Shading (SHD) parameters. - */ - params.acc_param.bnr.column_size = bdsOutputSize.width; - params.acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2); - params.acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2); - params.acc_param.bnr.opt_center_sqr.x_sqr_reset = params.acc_param.bnr.opt_center.x_reset - * params.acc_param.bnr.opt_center.x_reset; - params.acc_param.bnr.opt_center_sqr.y_sqr_reset = params.acc_param.bnr.opt_center.y_reset - * params.acc_param.bnr.opt_center.y_reset; - - params.use.acc_ccm = 1; - params.acc_param.ccm = imguCssCcmDefault; - - zones_.reserve(kAwbStatsSizeX * kAwbStatsSizeY); -} - /** * The function estimates the correlated color temperature using * from RGB color space input. @@ -303,17 +275,51 @@ void IPU3Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats) } } -void IPU3Awb::updateWbParameters(ipu3_uapi_params ¶ms) +void IPU3Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) +{ + calculateWBGains(stats); + context.frameContext.awb.gains.blueGain = asyncResults_.blueGain; + context.frameContext.awb.gains.greenGain = asyncResults_.greenGain; + context.frameContext.awb.gains.redGain = asyncResults_.redGain; +} + +void IPU3Awb::prepare(IPAContext &context, ipu3_uapi_params ¶ms) { + params.use.acc_awb = 1; + params.acc_param.awb.config.rgbs_thr_gr = 8191; + params.acc_param.awb.config.rgbs_thr_r = 8191; + params.acc_param.awb.config.rgbs_thr_gb = 8191; + params.acc_param.awb.config.rgbs_thr_b = 8191 | IPU3_UAPI_AWB_RGBS_THR_B_EN | IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT; + awbGrid_ = context.configuration.grid.bdsGrid; + + params.use.acc_bnr = 1; + params.acc_param.bnr = imguCssBnrDefaults; + /** + * Optical center is column (respectively row) startminus X (respectively Y) center. + * For the moment use BDS as a first approximation, but it should + * be calculated based on Shading (SHD) parameters. + */ + Size &bdsOutputSize = context.configuration.grid.bdsOutputSize; + params.acc_param.bnr.column_size = bdsOutputSize.width; + params.acc_param.bnr.opt_center.x_reset = awbGrid_.x_start - (bdsOutputSize.width / 2); + params.acc_param.bnr.opt_center.y_reset = awbGrid_.y_start - (bdsOutputSize.height / 2); + params.acc_param.bnr.opt_center_sqr.x_sqr_reset = params.acc_param.bnr.opt_center.x_reset + * params.acc_param.bnr.opt_center.x_reset; + params.acc_param.bnr.opt_center_sqr.y_sqr_reset = params.acc_param.bnr.opt_center.y_reset + * params.acc_param.bnr.opt_center.y_reset; + + params.use.acc_ccm = 1; + params.acc_param.ccm = imguCssCcmDefault; + /* * Green gains should not be touched and considered 1. * Default is 16, so do not change it at all. * 4096 is the value for a gain of 1.0 */ - params.acc_param.bnr.wb_gains.gr = 16; - params.acc_param.bnr.wb_gains.r = 4096 * asyncResults_.redGain; - params.acc_param.bnr.wb_gains.b = 4096 * asyncResults_.blueGain; - params.acc_param.bnr.wb_gains.gb = 16; + params.acc_param.bnr.wb_gains.gr = 16 * context.frameContext.awb.gains.greenGain; + params.acc_param.bnr.wb_gains.r = 4096 * context.frameContext.awb.gains.redGain; + params.acc_param.bnr.wb_gains.b = 4096 * context.frameContext.awb.gains.blueGain; + params.acc_param.bnr.wb_gains.gb = 16 * context.frameContext.awb.gains.greenGain; LOG(IPU3Awb, Debug) << "Color temperature estimated: " << asyncResults_.temperatureK; diff --git a/src/ipa/ipu3/ipu3_awb.h b/src/ipa/ipu3/ipu3_awb.h index eeb2920b..4de3fae2 100644 --- a/src/ipa/ipu3/ipu3_awb.h +++ b/src/ipa/ipu3/ipu3_awb.h @@ -29,9 +29,8 @@ public: IPU3Awb(); ~IPU3Awb(); - void initialise(ipu3_uapi_params ¶ms, const Size &bdsOutputSize, struct ipu3_uapi_grid_config &bdsGrid); - void calculateWBGains(const ipu3_uapi_stats_3a *stats); - void updateWbParameters(ipu3_uapi_params ¶ms); + void prepare(IPAContext &context, ipu3_uapi_params ¶ms) override; + void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override; struct Ipu3AwbCell { unsigned char greenRedAvg; @@ -72,6 +71,7 @@ public: }; private: + void calculateWBGains(const ipu3_uapi_stats_3a *stats); void generateZones(std::vector &zones); void generateAwbStats(const ipu3_uapi_stats_3a *stats); void clearAwbStats();