From patchwork Fri Aug 20 14:11:03 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: 13419 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 99424C3241 for ; Fri, 20 Aug 2021 14:11:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72EF5688E4; Fri, 20 Aug 2021 16:11:09 +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="vrlwA9Kl"; 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 7AECB68891 for ; Fri, 20 Aug 2021 16:11:08 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:e43b:edb2:932:6b0a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1798A11C7; Fri, 20 Aug 2021 16:11:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1629468668; bh=hNfEyxjZFLpM7+KQ0AoV4PB4Fh8fszSxNvv4HPIV2PQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vrlwA9KlFwHg+gEWQSHco3h5nIlhTx2+U0P0FKFdvjdgsDjcGIq04Z/SRXutXthgX mNT8x3fdjW60mRyaEmDmGibJ/owIybF71SS5Rl89TMfDxjG9aWR9jPGodWVn+K70Sq DTrSF4Fi77E32BSqFAKtv/+zhd82Z30HECGxFQrs= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Fri, 20 Aug 2021 16:11:03 +0200 Message-Id: <20210820141104.94438-2-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210820141104.94438-1-jeanmichel.hautbois@ideasonboard.com> References: <20210820141104.94438-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] ipa: ipu3: agc: remove local storage of the grid 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" The IPASessionConfiguration now has the grid configuration stored. Use it at process() call in AGC and pass it as a reference to the private functions when needed. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/agc.cpp | 29 +++++++++++++++-------------- src/ipa/ipu3/algorithms/agc.h | 5 ++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp index e4598b2e..0bb462e6 100644 --- a/src/ipa/ipu3/algorithms/agc.cpp +++ b/src/ipa/ipu3/algorithms/agc.cpp @@ -57,10 +57,9 @@ Agc::Agc() { } -int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo) +int Agc::configure([[maybe_unused]] IPAContext &context, + const IPAConfigInfo &configInfo) { - aeGrid_ = context.configuration.grid.bdsGrid; - lineDuration_ = configInfo.sensorInfo.lineLength * 1.0s / configInfo.sensorInfo.pixelRate; maxExposureTime_ = kMaxExposure * lineDuration_; @@ -68,7 +67,8 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo) return 0; } -void Agc::processBrightness(const ipu3_uapi_stats_3a *stats) +void Agc::processBrightness(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid) { const struct ipu3_uapi_grid_config statsAeGrid = stats->stats_4a_config.awb_config.grid; Rectangle aeRegion = { statsAeGrid.x_start, @@ -76,19 +76,19 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats) static_cast(statsAeGrid.x_end - statsAeGrid.x_start) + 1, static_cast(statsAeGrid.y_end - statsAeGrid.y_start) + 1 }; Point topleft = aeRegion.topLeft(); - int topleftX = topleft.x >> aeGrid_.block_width_log2; - int topleftY = topleft.y >> aeGrid_.block_height_log2; + int topleftX = topleft.x >> grid.block_width_log2; + int topleftY = topleft.y >> grid.block_height_log2; /* Align to the grid cell width and height */ - uint32_t startX = topleftX << aeGrid_.block_width_log2; - uint32_t startY = topleftY * aeGrid_.width << aeGrid_.block_width_log2; - uint32_t endX = (startX + (aeRegion.size().width >> aeGrid_.block_width_log2)) << aeGrid_.block_width_log2; + uint32_t startX = topleftX << grid.block_width_log2; + uint32_t startY = topleftY * grid.width << grid.block_width_log2; + uint32_t endX = (startX + (aeRegion.size().width >> grid.block_width_log2)) << grid.block_width_log2; uint32_t i, j; uint32_t count = 0; uint32_t hist[knumHistogramBins] = { 0 }; for (j = topleftY; - j < topleftY + (aeRegion.size().height >> aeGrid_.block_height_log2); + j < topleftY + (aeRegion.size().height >> grid.block_height_log2); j++) { for (i = startX + startY; i < endX + startY; i += kCellSize) { /* @@ -96,9 +96,9 @@ void Agc::processBrightness(const ipu3_uapi_stats_3a *stats) * We observed a bit shift which makes the value 160 to be 32 in the stats grid. * Use the one passed at init time. */ - if (stats->awb_raw_buffer.meta_data[i + 4 + j * aeGrid_.width] == 0) { - uint8_t Gr = stats->awb_raw_buffer.meta_data[i + 0 + j * aeGrid_.width]; - uint8_t Gb = stats->awb_raw_buffer.meta_data[i + 3 + j * aeGrid_.width]; + if (stats->awb_raw_buffer.meta_data[i + 4 + j * grid.width] == 0) { + uint8_t Gr = stats->awb_raw_buffer.meta_data[i + 0 + j * grid.width]; + uint8_t Gb = stats->awb_raw_buffer.meta_data[i + 3 + j * grid.width]; hist[(Gr + Gb) / 2]++; count++; } @@ -190,7 +190,8 @@ void Agc::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { uint32_t &exposure = context.frameContext.agc.exposure; double &gain = context.frameContext.agc.gain; - processBrightness(stats); + struct ipu3_uapi_grid_config &grid = context.configuration.grid.bdsGrid; + processBrightness(stats, grid); lockExposureGain(exposure, gain); frameCount_++; } diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h index 1739d2fd..e36797d3 100644 --- a/src/ipa/ipu3/algorithms/agc.h +++ b/src/ipa/ipu3/algorithms/agc.h @@ -33,12 +33,11 @@ public: void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override; private: - void processBrightness(const ipu3_uapi_stats_3a *stats); + void processBrightness(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid); void filterExposure(); void lockExposureGain(uint32_t &exposure, double &gain); - struct ipu3_uapi_grid_config aeGrid_; - uint64_t frameCount_; uint64_t lastFrame_; From patchwork Fri Aug 20 14:11:04 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: 13420 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 6F481BD87C for ; Fri, 20 Aug 2021 14:11:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BEE776890C; Fri, 20 Aug 2021 16:11:09 +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="AMxYudN4"; 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 9723668895 for ; Fri, 20 Aug 2021 16:11:08 +0200 (CEST) Received: from tatooine.ideasonboard.com (unknown [IPv6:2a01:e0a:169:7140:e43b:edb2:932:6b0a]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 440F01207; Fri, 20 Aug 2021 16:11:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1629468668; bh=Kn4dOWGVOfFsaVwfXmNAH+/vKUk/FrkM9vo6k1q4vbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMxYudN4a5JfCM3GTj7g9iBqLCHjdwOhZdAW+99JjsYY0HATVMqak6mDDEacpI23z 50Q2NPxKFn4w0Hz+0oNeWxnYJh18zyNfdyukV3kBJdtZrsGWNeqxbtcNRy+MT4kn2z pUgTqmjgCpB6BrBo4DHnuFsXAKwQd9zoRkuH4q6o= From: Jean-Michel Hautbois To: libcamera-devel@lists.libcamera.org Date: Fri, 20 Aug 2021 16:11:04 +0200 Message-Id: <20210820141104.94438-3-jeanmichel.hautbois@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210820141104.94438-1-jeanmichel.hautbois@ideasonboard.com> References: <20210820141104.94438-1-jeanmichel.hautbois@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] ipa: ipu3: awb: remove local storage of the grid 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" The IPASessionConfiguration now has the grid configuration stored. Use it it at prepare() and process() calls in AWB and pass it as a reference to the private functions when needed. Signed-off-by: Jean-Michel Hautbois Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/algorithms/awb.cpp | 27 +++++++++++++++------------ src/ipa/ipu3/algorithms/awb.h | 8 ++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/ipa/ipu3/algorithms/awb.cpp b/src/ipa/ipu3/algorithms/awb.cpp index e15f7406..c193c080 100644 --- a/src/ipa/ipu3/algorithms/awb.cpp +++ b/src/ipa/ipu3/algorithms/awb.cpp @@ -175,20 +175,21 @@ void Awb::generateZones(std::vector &zones) } /* Translate the IPU3 statistics into the default statistics region array */ -void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats) +void Awb::generateAwbStats(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid) { - uint32_t regionWidth = round(awbGrid_.width / static_cast(kAwbStatsSizeX)); - uint32_t regionHeight = round(awbGrid_.height / static_cast(kAwbStatsSizeY)); + uint32_t regionWidth = round(grid.width / static_cast(kAwbStatsSizeX)); + uint32_t regionHeight = round(grid.height / static_cast(kAwbStatsSizeY)); /* * Generate a (kAwbStatsSizeX x kAwbStatsSizeY) array from the IPU3 grid which is - * (awbGrid_.width x awbGrid_.height). + * (grid.width x grid.height). */ for (unsigned int j = 0; j < kAwbStatsSizeY * regionHeight; j++) { for (unsigned int i = 0; i < kAwbStatsSizeX * regionWidth; i++) { - uint32_t cellPosition = j * awbGrid_.width + i; + uint32_t cellPosition = j * grid.width + i; uint32_t cellX = (cellPosition / regionWidth) % kAwbStatsSizeX; - uint32_t cellY = ((cellPosition / awbGrid_.width) / regionHeight) % kAwbStatsSizeY; + uint32_t cellY = ((cellPosition / grid.width) / regionHeight) % kAwbStatsSizeY; uint32_t awbRegionPosition = cellY * kAwbStatsSizeX + cellX; cellPosition *= 8; @@ -258,12 +259,13 @@ void Awb::awbGreyWorld() asyncResults_.blueGain = blueGain; } -void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats) +void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid) { ASSERT(stats->stats_3a_status.awb_en); zones_.clear(); clearAwbStats(); - generateAwbStats(stats); + generateAwbStats(stats, grid); generateZones(zones_); LOG(IPU3Awb, Debug) << "Valid zones: " << zones_.size(); if (zones_.size() > 10) { @@ -275,7 +277,8 @@ void Awb::calculateWBGains(const ipu3_uapi_stats_3a *stats) void Awb::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { - calculateWBGains(stats); + struct ipu3_uapi_grid_config grid = context.configuration.grid.bdsGrid; + calculateWBGains(stats, grid); /* * Gains are only recalculated if enough zones were detected. @@ -296,7 +299,7 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params) | IPU3_UAPI_AWB_RGBS_THR_B_EN | 8191; - awbGrid_ = context.configuration.grid.bdsGrid; + struct ipu3_uapi_grid_config &grid = context.configuration.grid.bdsGrid; params->acc_param.awb.config.grid = context.configuration.grid.bdsGrid; @@ -310,8 +313,8 @@ void Awb::prepare(IPAContext &context, ipu3_uapi_params *params) params->acc_param.bnr = imguCssBnrDefaults; 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.x_reset = grid.x_start - (bdsOutputSize.width / 2); + params->acc_param.bnr.opt_center.y_reset = grid.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 diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h index fac54e45..a16dd68d 100644 --- a/src/ipa/ipu3/algorithms/awb.h +++ b/src/ipa/ipu3/algorithms/awb.h @@ -71,15 +71,15 @@ public: }; private: - void calculateWBGains(const ipu3_uapi_stats_3a *stats); + void calculateWBGains(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid); void generateZones(std::vector &zones); - void generateAwbStats(const ipu3_uapi_stats_3a *stats); + void generateAwbStats(const ipu3_uapi_stats_3a *stats, + const ipu3_uapi_grid_config &grid); void clearAwbStats(); void awbGreyWorld(); uint32_t estimateCCT(double red, double green, double blue); - struct ipu3_uapi_grid_config awbGrid_; - std::vector zones_; IspStatsRegion awbStats_[kAwbStatsSizeX * kAwbStatsSizeY]; AwbStatus asyncResults_;